Exemple
@babel/helper-validator-option 7.29.7
Échantillon vérifié pour npm @babel/helper-validator-option 7.29.7. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:a954a900e424d67ea60c29bfd52e1d2dce34faf6f8f0797039f9df15910222cc
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-23 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-12 |
Cas
HOW- Objectif
- verify pkg:npm/%40babel/helper-validator-option@7.29.7
- Créé
- 2026-08-23T06:44:13Z
Contrat
- OptionValidator constructor initializes descriptor and formatMessage prefixes error messages with descriptor
- validateTopLevelOptions validates allowed options against TopLevelOptionShape and throws formatted error with suggestion for invalid keys
- validateBooleanOption returns given boolean value, returns defaultValue when undefined, and throws when value is not a boolean
- validateStringOption returns given string value, returns defaultValue when undefined, and throws when value is not a string
- invariant throws formatted error when condition is falsy and passes when truthy
- findSuggestion finds the candidate string with minimal Levenshtein distance
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Code 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/%40babel/helper-validator-option@7.29.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/helper-validator-option@7.29.7
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:24e08993f69688d9db9fd180c66a7e075390ffcb93f9a08d2b4afaef91e01bc9","contract":["OptionValidator constructor initializes descriptor and formatMessage prefixes error messages with descriptor","validateTopLevelOptions validates allowed options against TopLevelOptionShape and throws formatted error with suggestion for invalid keys","validateBooleanOption returns given boolean value, returns defaultValue when undefined, and throws when value is not a boolean","validateStringOption returns given string value, returns defaultValue when undefined, and throws when value is not a string","invariant throws formatted error when condition is falsy and passes when truthy","findSuggestion finds the candidate string with minimal Levenshtein distance"],"goal":"verify pkg:npm/%40babel/helper-validator-option@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/helper-validator-option@7.29.7"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/helper-validator-option@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/helper-validator-option@7.29.7","verifierAdapter":"node-typescript@1"}
{
"name": "sample-babel-helper-validator-option",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-babel-helper-validator-option",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/helper-validator-option": "7.29.7"
}
},
"node_modules/@babel/helper-validator-option": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.29.7.tgz",
"integrity": "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
}
}
}
{
"name": "sample-babel-helper-validator-option",
"version": "1.0.0",
"description": "Minimal sample verifying @babel/helper-validator-option",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@babel/helper-validator-option": "7.29.7"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40babel/helper-validator-option@7.29.7",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/helper-validator-option@7.29.7"
]
}
const {
OptionValidator,
findSuggestion,
} = require('@babel/helper-validator-option');
/**
* Creates an OptionValidator instance with the specified descriptor.
* @param {string} descriptor - The descriptor name prefix.
* @returns {OptionValidator}
*/
function createOptionValidator(descriptor) {
return new OptionValidator(descriptor);
}
/**
* Validates options object against allowed keys defined in allowedShape.
* @param {OptionValidator} validator - The OptionValidator instance.
* @param {object} options - User options object.
* @param {object} allowedShape - Shape defining allowed options.
*/
function validateOptions(validator, options, allowedShape) {
validator.validateTopLevelOptions(options, allowedShape);
}
/**
* Validates a boolean option value.
* @param {OptionValidator} validator - The OptionValidator instance.
* @param {string} name - Option name.
* @param {boolean} [value] - Option value.
* @param {boolean} [defaultValue] - Default fallback value.
* @returns {boolean}
*/
function validateBoolean(validator, name, value, defaultValue) {
return validator.validateBooleanOption(name, value, defaultValue);
}
/**
* Validates a string option value.
* @param {OptionValidator} validator - The OptionValidator instance.
* @param {string} name - Option name.
* @param {string} [value] - Option value.
* @param {string} [defaultValue] - Default fallback value.
* @returns {string}
*/
function validateString(validator, name, value, defaultValue) {
return validator.validateStringOption(name, value, defaultValue);
}
/**
* Asserts invariant condition on the validator.
* @param {OptionValidator} validator - The OptionValidator instance.
* @param {boolean} condition - Invariant condition.
* @param {string} message - Invariant failure message.
*/
function assertInvariant(validator, condition, message) {
validator.invariant(condition, message);
}
/**
* Finds the closest candidate match using Levenshtein distance.
* @param {string} query - Target string.
* @param {string[]} candidates - Array of candidate strings.
* @returns {string}
*/
function getClosestSuggestion(query, candidates) {
return findSuggestion(query, candidates);
}
module.exports = {
createOptionValidator,
validateOptions,
validateBoolean,
validateString,
assertInvariant,
getClosestSuggestion,
OptionValidator,
findSuggestion,
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
createOptionValidator,
validateOptions,
validateBoolean,
validateString,
assertInvariant,
getClosestSuggestion,
OptionValidator,
findSuggestion,
} = require('../src/index.js');
async function runContract() {
// 1. OptionValidator constructor initializes descriptor and formatMessage prefixes error messages with descriptor
const validator = createOptionValidator('MyPlugin');
assert.strictEqual(validator.descriptor, 'MyPlugin', 'descriptor should match initialized string');
assert.strictEqual(
validator.formatMessage('test message'),
'MyPlugin: test message',
'formatMessage should prefix with descriptor'
);
// 2. validateTopLevelOptions validates allowed options against TopLevelOptionShape and throws formatted error with suggestion for invalid keys
const allowedShape = { target: true, loose: false, modules: 'auto' };
assert.doesNotThrow(() => {
validateOptions(validator, { target: 'es6', loose: true }, allowedShape);
}, 'valid options should not throw');
assert.throws(
() => {
validateOptions(validator, { targt: 'es6' }, allowedShape);
},
{
name: 'Error',
message: /MyPlugin: 'targt' is not a valid top-level option\.\n- Did you mean 'target'\?/,
},
'invalid option should throw with suggestion'
);
// 3. validateBooleanOption returns given boolean value, returns defaultValue when undefined, and throws when value is not a boolean
assert.strictEqual(validateBoolean(validator, 'loose', true, false), true, 'should return true when value is true');
assert.strictEqual(validateBoolean(validator, 'loose', false, true), false, 'should return false when value is false');
assert.strictEqual(validateBoolean(validator, 'loose', undefined, true), true, 'should return defaultValue true when value is undefined');
assert.strictEqual(validateBoolean(validator, 'loose', undefined, false), false, 'should return defaultValue false when value is undefined');
assert.strictEqual(validateBoolean(validator, 'loose', undefined, undefined), undefined, 'should return undefined defaultValue when undefined');
assert.throws(
() => {
validateBoolean(validator, 'loose', 'not-a-bool');
},
{
name: 'Error',
message: /MyPlugin: 'loose' option must be a boolean\./,
},
'non-boolean value should throw'
);
// 4. validateStringOption returns given string value, returns defaultValue when undefined, and throws when value is not a string
assert.strictEqual(validateString(validator, 'module', 'commonjs', 'auto'), 'commonjs', 'should return string value');
assert.strictEqual(validateString(validator, 'module', undefined, 'auto'), 'auto', 'should return defaultValue when undefined');
assert.strictEqual(validateString(validator, 'module', undefined, undefined), undefined, 'should return undefined when no default');
assert.throws(
() => {
validateString(validator, 'module', 123);
},
{
name: 'Error',
message: /MyPlugin: 'module' option must be a string\./,
},
'non-string value should throw'
);
// 5. invariant throws formatted error when condition is falsy and passes when truthy
assert.doesNotThrow(() => {
assertInvariant(validator, true, 'should not fail');
}, 'truthy condition should not throw');
assert.throws(
() => {
assertInvariant(validator, false, 'custom invariant condition failed');
},
{
name: 'Error',
message: 'MyPlugin: custom invariant condition failed',
},
'falsy condition should throw formatted error'
);
// 6. findSuggestion finds the candidate string with minimal Levenshtein distance
assert.strictEqual(getClosestSuggestion('targt', ['target', 'source', 'output']), 'target', 'should find target');
assert.strictEqual(getClosestSuggestion('moudles', ['targets', 'modules', 'loose']), 'modules', 'should find modules');
assert.strictEqual(findSuggestion('looze', ['loose', 'strict', 'minify']), 'loose', 'should find loose');
console.log('Contract tests passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Seeder d'origine
anonyme