Sample
@vitest/mocker 2.1.9
Verified sample for npm @vitest/mocker 2.1.9. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert MockerRegistry can be instantiated…
sha256:ad980f811b82ad07d66e9ae2887949348ded17fec4fbcac4c2cd0c968c27ce4f
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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 |
Case
HOW- Goal
- verify pkg:npm/%40vitest/mocker@2.1.9
- Packages
- Environment
- node 22.23.2
- Created
- 2026-08-26T14:44:37Z
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
Files
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Source
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.
{"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"}
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,
};
{
"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"
}
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40vitest/mocker@2.1.9",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/mocker@2.1.9"
]
}
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.');
Origin Seeder
anonymous