Ejemplo
semver 7.8.5: valid, clean, satisfies
Muestra verificada para npm semver 7.8.5: valid, clean, satisfies. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.
sha256:adbe1add479d1091d09e81176fc5caa12a8e23b90878d82ab0895993251df6d8
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
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
windows 11 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-19 |
| 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-09-07 |
Caso
HOW- Objetivo
- verify pkg:npm/semver@7.8.5
- Paquetes
- Símbolos
-
- valid
- clean
- satisfies
- compare
- inc
- coerce
- minVersion
- Creado
- 2026-08-18T19:31:10Z
Contrato
- valid and clean parse and sanitize semantic version strings
- satisfies checks whether version satisfies a range specification
- compare, gt, and lt correctly order versions according to precedence
- inc increments versions across major, minor, patch, and prerelease types
- coerce extracts valid semver strings from loose version input
- minVersion determines the lowest version that satisfies a range
Archivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Código fuente
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/semver@7.8.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/semver@7.8.5
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@11.8.0
- runtime: node@24.13.1
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:caa4994804a5cc6f998bb34b7d2a972a8b0a1117c878a7baf242a9e2a45ccb7c","constraints":{"executionContext":"node"},"contract":["valid and clean parse and sanitize semantic version strings","satisfies checks whether version satisfies a range specification","compare, gt, and lt correctly order versions according to precedence","inc increments versions across major, minor, patch, and prerelease types","coerce extracts valid semver strings from loose version input","minVersion determines the lowest version that satisfies a range"],"goal":"verify pkg:npm/semver@7.8.5","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["valid","clean","satisfies","compare","inc","coerce","minVersion"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["valid","clean","satisfies","compare","inc","coerce","minVersion"],"verifierAdapter":"node-typescript@1"}
const semver = require('semver');
/**
* Validates and cleans a semantic version string.
* @param {string} version
* @returns {string | null}
*/
function cleanVersion(version) {
return semver.clean(version);
}
/**
* Increments a version by the given release type.
* @param {string} version
* @param {semver.ReleaseType} release
* @param {string} [identifier]
* @returns {string | null}
*/
function incrementVersion(version, release, identifier) {
return semver.inc(version, release, identifier);
}
/**
* Coerces a loose string to a semver string.
* @param {string | number} value
* @returns {string | null}
*/
function coerceVersion(value) {
const result = semver.coerce(value);
return result ? result.version : null;
}
/**
* Compares two semantic versions.
* @param {string} v1
* @param {string} v2
* @returns {1 | 0 | -1}
*/
function compareVersions(v1, v2) {
return semver.compare(v1, v2);
}
module.exports = {
cleanVersion,
incrementVersion,
coerceVersion,
compareVersions
};
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"semver": "7.8.5"
}
},
"node_modules/semver": {
"version": "7.8.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
"integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
}
}
}
{
"name": "sample",
"version": "1.0.0",
"dependencies": {
"semver": "7.8.5"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/semver@7.8.5",
"kind": "HOW",
"packages": [
"pkg:npm/semver@7.8.5"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
const assert = require('node:assert/strict');
const semver = require('semver');
const {
cleanVersion,
incrementVersion,
coerceVersion,
compareVersions
} = require('../index.js');
assert.equal(typeof semver.valid, 'function', 'semver.valid must be a function');
assert.equal(typeof semver.clean, 'function', 'semver.clean must be a function');
assert.equal(typeof semver.inc, 'function', 'semver.inc must be a function');
assert.equal(typeof semver.coerce, 'function', 'semver.coerce must be a function');
assert.equal(typeof semver.compare, 'function', 'semver.compare must be a function');
assert.equal(typeof semver.satisfies, 'function', 'semver.satisfies must be a function');
// Contract 1: valid and clean parse and sanitize semantic version strings
{
assert.equal(semver.valid('1.2.3'), '1.2.3');
assert.equal(semver.valid('v1.2.3'), '1.2.3');
assert.equal(semver.valid('2.0.0-beta.1+build.123'), '2.0.0-beta.1');
assert.equal(semver.valid('not-a-version'), null);
assert.equal(semver.clean(' =v1.2.3 '), '1.2.3');
assert.equal(semver.clean(' ~1.2.3 '), null);
assert.equal(cleanVersion(' =v1.2.3 '), '1.2.3');
assert.equal(cleanVersion('invalid'), null);
}
// Contract 2: satisfies checks whether version satisfies a range specification
{
assert.equal(semver.satisfies('1.2.3', '^1.2.0'), true);
assert.equal(semver.satisfies('1.3.0', '~1.2.0'), false);
assert.equal(semver.satisfies('2.0.0', '>=1.0.0 <3.0.0'), true);
assert.equal(semver.satisfies('3.0.0', '>=1.0.0 <3.0.0'), false);
assert.equal(semver.satisfies('1.2.3-alpha.1', '^1.2.0', { includePrerelease: true }), true);
}
// Contract 3: compare, gt, and lt correctly order versions according to precedence
{
assert.equal(semver.compare('1.2.3', '1.2.4'), -1);
assert.equal(semver.compare('1.2.4', '1.2.3'), 1);
assert.equal(semver.compare('1.2.3', '1.2.3'), 0);
assert.equal(compareVersions('1.2.3', '1.2.4'), -1);
assert.equal(semver.gt('1.10.0', '1.9.0'), true);
assert.equal(semver.lt('1.2.3', '1.2.4'), true);
assert.equal(semver.eq('1.2.3', '1.2.3'), true);
assert.equal(semver.gt('1.2.3', '1.2.3-beta'), true);
}
// Contract 4: inc increments versions across major, minor, patch, and prerelease types
{
assert.equal(semver.inc('1.2.3', 'major'), '2.0.0');
assert.equal(semver.inc('1.2.3', 'minor'), '1.3.0');
assert.equal(semver.inc('1.2.3', 'patch'), '1.2.4');
assert.equal(incrementVersion('1.2.3', 'patch'), '1.2.4');
assert.equal(semver.inc('1.2.3', 'prerelease', 'alpha'), '1.2.4-alpha.0');
assert.equal(semver.inc('1.2.4-alpha.0', 'prerelease'), '1.2.4-alpha.1');
assert.equal(semver.inc('1.2.3', 'premajor', 'beta'), '2.0.0-beta.0');
assert.equal(semver.inc('invalid-version', 'patch'), null);
}
// Contract 5: coerce extracts valid semver strings from loose version input
{
assert.equal(coerceVersion('v4'), '4.0.0');
assert.equal(coerceVersion('version 1.2'), '1.2.0');
assert.equal(coerceVersion('release-4.5.6.7'), '4.5.6');
assert.equal(coerceVersion('unrelated text'), null);
const coerced = semver.coerce('package-3.14.15');
assert.notEqual(coerced, null);
assert.equal(coerced.version, '3.14.15');
assert.equal(coerced.major, 3);
assert.equal(coerced.minor, 14);
assert.equal(coerced.patch, 15);
}
// Contract 6: minVersion determines the lowest version that satisfies a range
{
assert.equal(semver.minVersion('>=1.2.0')?.version, '1.2.0');
assert.equal(semver.minVersion('^2.1.0')?.version, '2.1.0');
assert.equal(semver.minVersion('~3.0.0')?.version, '3.0.0');
assert.throws(
() => semver.minVersion('invalid-range'),
(err) => err instanceof TypeError
);
}
console.log('All semver contract assertions passed successfully.');
Seeder de origen
anónimo