CodeSampleX

Ejemplo

@vitest/mocker 2.1.9

Muestra verificada para npm @vitest/mocker 2.1.9. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: assert MockerRegistry can be…

sha256:ad980f811b82ad07d66e9ae2887949348ded17fec4fbcac4c2cd0c968c27ce4f

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

Caso

HOW
Objetivo
verify pkg:npm/%40vitest/mocker@2.1.9
Paquetes
Entorno
node 22.23.2
Creado
2026-08-26T14:44:37Z

Contrato

  1. assert MockerRegistry can be instantiated and starts empty
  2. assert registry.register with type manual creates and registers a ManualMockedModule with raw and url
  3. assert manual mock resolve() invokes the factory function and caches the result
  4. assert registry.register with type automock creates and registers an AutomockedModule
  5. assert registry.register with type autospy creates and registers an AutospiedModule
  6. assert registry.register with type redirect creates and registers a RedirectedModule with redirect target
  7. assert registry.get and registry.has retrieve registered mocked modules by url
  8. assert registry.register can deserialize and register serialized mock modules
  9. assert registry.register throws TypeError when registering an already instantiated mock
  10. assert registry.delete removes an entry and registry.clear resets all registered modules

Archivos

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/%40vitest/mocker@2.1.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/mocker@2.1.9

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:cdd792f060530559a45474b0176f318f4d5b3fd804a6fbb682d3bc8a19893c97","contract":["assert MockerRegistry can be instantiated and starts empty","assert registry.register with type manual creates and registers a ManualMockedModule with raw and url","assert manual mock resolve() invokes the factory function and caches the result","assert registry.register with type automock creates and registers an AutomockedModule","assert registry.register with type autospy creates and registers an AutospiedModule","assert registry.register with type redirect creates and registers a RedirectedModule with redirect target","assert registry.get and registry.has retrieve registered mocked modules by url","assert registry.register can deserialize and register serialized mock modules","assert registry.register throws TypeError when registering an already instantiated mock","assert registry.delete removes an entry and registry.clear resets all registered modules"],"goal":"verify pkg:npm/%40vitest/mocker@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/mocker@2.1.9"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40vitest/mocker@2.1.9"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/mocker@2.1.9","verifierAdapter":"node-typescript@1"}
index.js
const {
  MockerRegistry,
  AutomockedModule,
  AutospiedModule,
  ManualMockedModule,
  RedirectedModule,
} = require('@vitest/mocker');

/**
 * Creates a new MockerRegistry instance.
 * @returns {MockerRegistry}
 */
function createRegistry() {
  return new MockerRegistry();
}

/**
 * Registers a manual mock with a factory function.
 * @param {MockerRegistry} registry
 * @param {string} raw
 * @param {string} url
 * @param {() => any} factory
 * @returns {ManualMockedModule}
 */
function registerManualMock(registry, raw, url, factory) {
  return registry.register('manual', raw, url, factory);
}

/**
 * Registers an automock.
 * @param {MockerRegistry} registry
 * @param {string} raw
 * @param {string} url
 * @returns {AutomockedModule}
 */
function registerAutomock(registry, raw, url) {
  return registry.register('automock', raw, url);
}

/**
 * Registers an autospy mock.
 * @param {MockerRegistry} registry
 * @param {string} raw
 * @param {string} url
 * @returns {AutospiedModule}
 */
function registerAutospy(registry, raw, url) {
  return registry.register('autospy', raw, url);
}

/**
 * Registers a redirect mock.
 * @param {MockerRegistry} registry
 * @param {string} raw
 * @param {string} url
 * @param {string} redirect
 * @returns {RedirectedModule}
 */
function registerRedirectMock(registry, raw, url, redirect) {
  return registry.register('redirect', raw, url, redirect);
}

module.exports = {
  MockerRegistry,
  AutomockedModule,
  AutospiedModule,
  ManualMockedModule,
  RedirectedModule,
  createRegistry,
  registerManualMock,
  registerAutomock,
  registerAutospy,
  registerRedirectMock,
};
package-lock.json
{
  "name": "sample-vitest-mocker",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-mocker",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vitest/mocker": "2.1.9"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@types/estree": {
      "version": "1.0.9",
      "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",
      "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==",
      "license": "MIT"
    },
    "node_modules/@vitest/mocker": {
      "version": "2.1.9",
      "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-2.1.9.tgz",
      "integrity": "sha512-tVL6uJgoUdi6icpxmdrn5YNo3g3Dxv+IHJBr0GXHaEdTcw3F+cPKnsXFhli6nO+f/6SDKPHEK1UN+k+TQv0Ehg==",
      "license": "MIT",
      "dependencies": {
        "@vitest/spy": "2.1.9",
        "estree-walker": "^3.0.3",
        "magic-string": "^0.30.12"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      },
      "peerDependencies": {
        "msw": "^2.4.9",
        "vite": "^5.0.0"
      },
      "peerDependenciesMeta": {
        "msw": {
          "optional": true
        },
        "vite": {
          "optional": true
        }
      }
    },
    "node_modules/@vitest/spy": {
      "version": "2.1.9",
      "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.9.tgz",
      "integrity": "sha512-E1B35FwzXXTs9FHNK6bDszs7mtydNi5MIfUWpceJ8Xbfb1gBMscAnwLbEu+B44ed6W3XjL9/ehLPHR1fkf1KLQ==",
      "license": "MIT",
      "dependencies": {
        "tinyspy": "^3.0.2"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/estree-walker": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
      "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
      "license": "MIT",
      "dependencies": {
        "@types/estree": "^1.0.0"
      }
    },
    "node_modules/magic-string": {
      "version": "0.30.21",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
      "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.5"
      }
    },
    "node_modules/tinyspy": {
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz",
      "integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-mocker",
  "version": "1.0.0",
  "description": "Clean-room sample verifying @vitest/mocker@2.1.9",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "@vitest/mocker": "2.1.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40vitest/mocker@2.1.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/mocker@2.1.9"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import {
  MockerRegistry,
  AutomockedModule,
  AutospiedModule,
  ManualMockedModule,
  RedirectedModule,
  createRegistry,
  registerManualMock,
  registerAutomock,
  registerAutospy,
  registerRedirectMock,
} from '../index.js';

// 1. Instantiation and initial empty state
const registry = createRegistry();
assert.ok(registry instanceof MockerRegistry, 'createRegistry should return a MockerRegistry instance');
assert.strictEqual(registry.has('file:///mock/target'), false, 'registry should not have target initially');
assert.strictEqual(registry.get('file:///mock/target'), undefined, 'get should return undefined for non-existent mock');
assert.deepStrictEqual(Array.from(registry.keys()), [], 'keys() should be empty initially');

// 2. Register manual mock with factory
const manualFactory = () => ({ mockedFunction: () => 42, customValue: 'mocked' });
const manualMock = registerManualMock(registry, 'my-module', 'file:///mock/manual', manualFactory);

assert.ok(manualMock instanceof ManualMockedModule, 'manual mock should be an instance of ManualMockedModule');
assert.strictEqual(manualMock.type, 'manual', 'manual mock type should be "manual"');
assert.strictEqual(manualMock.raw, 'my-module', 'manual mock raw should match');
assert.strictEqual(manualMock.url, 'file:///mock/manual', 'manual mock url should match');

// 3. Resolve manual mock factory and check cache
const resolvedExports = await manualMock.resolve();
assert.strictEqual(typeof resolvedExports.mockedFunction, 'function', 'mockedFunction should be a function');
assert.strictEqual(resolvedExports.mockedFunction(), 42, 'mockedFunction should return 42');
assert.strictEqual(resolvedExports.customValue, 'mocked', 'customValue should match');
assert.strictEqual(manualMock.cache, resolvedExports, 'manualMock.cache should store resolved exports');

// 4. Register automock module
const autoMock = registerAutomock(registry, 'auto-module', 'file:///mock/auto');
assert.ok(autoMock instanceof AutomockedModule, 'automock should be an instance of AutomockedModule');
assert.strictEqual(autoMock.type, 'automock', 'automock type should be "automock"');
assert.strictEqual(autoMock.raw, 'auto-module', 'automock raw should match');
assert.strictEqual(autoMock.url, 'file:///mock/auto', 'automock url should match');

// 5. Register autospy module
const autoSpy = registerAutospy(registry, 'spy-module', 'file:///mock/spy');
assert.ok(autoSpy instanceof AutospiedModule, 'autospy should be an instance of AutospiedModule');
assert.strictEqual(autoSpy.type, 'autospy', 'autospy type should be "autospy"');
assert.strictEqual(autoSpy.raw, 'spy-module', 'autospy raw should match');
assert.strictEqual(autoSpy.url, 'file:///mock/spy', 'autospy url should match');

// 6. Register redirect module
const redirectMock = registerRedirectMock(registry, 'redirect-module', 'file:///mock/redirect', '/mock/target');
assert.ok(redirectMock instanceof RedirectedModule, 'redirect should be an instance of RedirectedModule');
assert.strictEqual(redirectMock.type, 'redirect', 'redirect type should be "redirect"');
assert.strictEqual(redirectMock.raw, 'redirect-module', 'redirect raw should match');
assert.strictEqual(redirectMock.url, 'file:///mock/redirect', 'redirect url should match');
assert.strictEqual(redirectMock.redirect, '/mock/target', 'redirect target should match');

// 7. Retrieve by url
assert.strictEqual(registry.has('file:///mock/manual'), true, 'registry.has(url) should return true');
assert.strictEqual(registry.get('file:///mock/manual'), manualMock, 'registry.get(url) should return manualMock');
assert.strictEqual(registry.get('file:///mock/auto'), autoMock, 'registry.get(url) should return autoMock');
assert.strictEqual(registry.get('file:///mock/redirect'), redirectMock, 'registry.get(url) should return redirectMock');

// 8. Deserialization via register(serializedJson)
const serializedAuto = autoMock.toJSON();
const deserializedRegistry = new MockerRegistry();
const registeredFromJSON = deserializedRegistry.register(serializedAuto);
assert.ok(registeredFromJSON instanceof AutospiedModule, 'deserialized automock should produce valid module');
assert.strictEqual(registeredFromJSON.url, 'file:///mock/auto', 'deserialized module url should match');
assert.strictEqual(deserializedRegistry.has('file:///mock/auto'), true, 'deserializedRegistry should contain registered mock');

// 9. Error handling: registering already-defined class instances throws TypeError
assert.throws(() => {
  deserializedRegistry.register(autoMock);
}, /Cannot register a mock that is already defined/);

// 10. Deletion and clearing
registry.delete('file:///mock/auto');
assert.strictEqual(registry.has('file:///mock/auto'), false, 'registry.has should be false after delete');
assert.strictEqual(registry.get('file:///mock/auto'), undefined, 'registry.get should be undefined after delete');

registry.clear();
assert.strictEqual(registry.has('file:///mock/manual'), false, 'registry.has should be false after clear');
assert.deepStrictEqual(Array.from(registry.keys()), [], 'registry.keys() should be empty after clear');

console.log('All contract assertions passed.');

Seeder de origen

anónimo