CodeSampleX

Sample

semver 7.7.4

Verified sample for npm semver 7.7.4. The contract ran on node 22 · linux alpine/x64 · docker and passed: semver parses, validates, cleans, coerces, and…

sha256:86f9ab064a551c1429a7b873f7cd6a644f4301d58c4bfae4fca84102a18abd8f

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
2
Signing keys that built it
2
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20
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-08

Case

HOW
Goal
verify pkg:npm/semver@7.7.4
Packages
Created
2026-08-20T03:31:21Z

Contract

  1. semver parses, validates, cleans, coerces, and increments semantic version strings across release types
  2. semver compares semantic version precedence with comparison predicates, sorting, and diff calculation
  3. semver evaluates version satisfaction, range subsets, and intersection across complex range expressions
  4. semver constructs SemVer, Range, and Comparator instances exposing structured version components and comparator sets

Files

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

Download the source artifact (tar.gz)

Source

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/semver@7.7.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/semver@7.7.4

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:cf61c4fc3d76c3b03823077a8a9aecb86533aada56c6e05e0375d9c11d93b3a0","contract":["semver parses, validates, cleans, coerces, and increments semantic version strings across release types","semver compares semantic version precedence with comparison predicates, sorting, and diff calculation","semver evaluates version satisfaction, range subsets, and intersection across complex range expressions","semver constructs SemVer, Range, and Comparator instances exposing structured version components and comparator sets"],"goal":"verify pkg:npm/semver@7.7.4","kind":"HOW","packages":["pkg:npm/semver@7.7.4"],"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/semver@7.7.4"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "semver-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "semver-sample",
      "version": "1.0.0",
      "dependencies": {
        "semver": "7.7.4"
      }
    },
    "node_modules/semver": {
      "version": "7.7.4",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
      "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "semver-sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "semver": "7.7.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/semver@7.7.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/semver@7.7.4"
  ]
}
src/index.mjs
import semver from 'semver';

export function parseVersion(version, options) {
  return semver.valid(version, options);
}

export function cleanVersion(version, options) {
  return semver.clean(version, options);
}

export function coerceVersion(input, options) {
  const coerced = semver.coerce(input, options);
  return coerced ? coerced.version : null;
}

export function incrementVersion(version, release, options, identifier) {
  return semver.inc(version, release, options, identifier);
}

export function compareVersions(v1, v2, options) {
  return semver.compare(v1, v2, options);
}

export function isGreaterThan(v1, v2, options) {
  return semver.gt(v1, v2, options);
}

export function isLessThan(v1, v2, options) {
  return semver.lt(v1, v2, options);
}

export function areEqual(v1, v2, options) {
  return semver.eq(v1, v2, options);
}

export function getVersionDiff(v1, v2) {
  return semver.diff(v1, v2);
}

export function satisfiesRange(version, range, options) {
  return semver.satisfies(version, range, options);
}

export function findMaxSatisfying(versions, range, options) {
  return semver.maxSatisfying(versions, range, options);
}

export function findMinSatisfying(versions, range, options) {
  return semver.minSatisfying(versions, range, options);
}

export function getMinVersion(range, options) {
  const min = semver.minVersion(range, options);
  return min ? min.version : null;
}

export function isSubset(subRange, domRange, options) {
  return semver.subset(subRange, domRange, options);
}

export function rangesIntersect(r1, r2, options) {
  return semver.intersects(r1, r2, options);
}

export function createSemVer(version, options) {
  return new semver.SemVer(version, options);
}

export function createRange(range, options) {
  return new semver.Range(range, options);
}

export function createComparator(comp, options) {
  return new semver.Comparator(comp, options);
}

export { semver };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  parseVersion,
  cleanVersion,
  coerceVersion,
  incrementVersion,
  compareVersions,
  isGreaterThan,
  isLessThan,
  areEqual,
  getVersionDiff,
  satisfiesRange,
  findMaxSatisfying,
  findMinSatisfying,
  getMinVersion,
  isSubset,
  rangesIntersect,
  createSemVer,
  createRange,
  createComparator,
} from '../src/index.mjs';

// Contract 1: semver parses, validates, cleans, coerces, and increments semantic version strings across release types
{
  assert.strictEqual(parseVersion('7.7.4'), '7.7.4', 'Valid semver string parses cleanly');
  assert.strictEqual(parseVersion('v7.7.4'), '7.7.4', 'Prefix v is stripped in valid()');
  assert.strictEqual(parseVersion('invalid-7.7.4'), null, 'Invalid semver returns null');

  assert.strictEqual(cleanVersion('  =v7.7.4   '), '7.7.4', 'cleanVersion strips whitespace and v/= prefix');
  assert.strictEqual(cleanVersion('7.7.4.1'), null, 'cleanVersion rejects invalid 4-segment version');

  assert.strictEqual(coerceVersion('v7'), '7.0.0', 'Coerce partial version v7 to 7.0.0');
  assert.strictEqual(coerceVersion('release-7.7.4-final'), '7.7.4', 'Coerce extracts semver string');

  assert.strictEqual(incrementVersion('7.7.4', 'major'), '8.0.0', 'Increment major release');
  assert.strictEqual(incrementVersion('7.7.4', 'minor'), '7.8.0', 'Increment minor release');
  assert.strictEqual(incrementVersion('7.7.4', 'patch'), '7.7.5', 'Increment patch release');
  assert.strictEqual(incrementVersion('7.7.4', 'prerelease', undefined, 'beta'), '7.7.5-beta.0', 'Increment prerelease identifier');
  assert.strictEqual(incrementVersion('7.7.5-beta.0', 'prerelease'), '7.7.5-beta.1', 'Increment existing prerelease number');
}

// Contract 2: semver compares semantic version precedence with comparison predicates, sorting, and diff calculation
{
  assert.strictEqual(compareVersions('7.7.4', '7.7.5'), -1, '7.7.4 < 7.7.5');
  assert.strictEqual(compareVersions('8.0.0', '7.9.9'), 1, '8.0.0 > 7.9.9');
  assert.strictEqual(compareVersions('7.7.4', '7.7.4'), 0, 'Identical versions return 0');

  assert.strictEqual(isGreaterThan('7.7.4', '7.7.3'), true, '7.7.4 > 7.7.3');
  assert.strictEqual(isGreaterThan('7.7.4', '7.7.4'), false, 'Equal versions return false for gt');
  assert.strictEqual(isLessThan('7.7.4-alpha.1', '7.7.4'), true, 'Prerelease has lower precedence');
  assert.strictEqual(areEqual('7.7.4', 'v7.7.4'), true, 'Equal across prefix');

  const versions = ['7.10.0', '7.2.0', '8.0.0', '7.0.1', '7.0.0-beta', '7.0.0'];
  versions.sort(compareVersions);
  assert.deepStrictEqual(
    versions,
    ['7.0.0-beta', '7.0.0', '7.0.1', '7.2.0', '7.10.0', '8.0.0'],
    'Versions sort by semver precedence'
  );

  assert.strictEqual(getVersionDiff('7.7.4', '8.0.0'), 'major', 'Diff is major');
  assert.strictEqual(getVersionDiff('7.7.4', '7.8.0'), 'minor', 'Diff is minor');
  assert.strictEqual(getVersionDiff('7.7.4', '7.7.5'), 'patch', 'Diff is patch');
  assert.strictEqual(getVersionDiff('7.7.4-beta.0', '7.7.4-beta.1'), 'prerelease', 'Diff is prerelease');
  assert.strictEqual(getVersionDiff('7.7.4', '7.7.4'), null, 'Identical versions have null diff');
}

// Contract 3: semver evaluates version satisfaction, range subsets, and intersection across complex range expressions
{
  assert.strictEqual(satisfiesRange('7.7.4', '^7.0.0'), true, '7.7.4 satisfies ^7.0.0');
  assert.strictEqual(satisfiesRange('8.0.0', '^7.0.0'), false, '8.0.0 does not satisfy ^7.0.0');
  assert.strictEqual(satisfiesRange('7.7.4', '~7.7.0'), true, '7.7.4 satisfies ~7.7.0');
  assert.strictEqual(satisfiesRange('7.8.0', '~7.7.0'), false, '7.8.0 does not satisfy ~7.7.0');
  assert.strictEqual(satisfiesRange('7.7.4', '>=7.0.0 <8.0.0'), true, 'Satisfies range comparator set');

  const available = ['7.0.0', '7.1.0', '7.7.0', '7.7.4', '8.0.0'];
  assert.strictEqual(findMaxSatisfying(available, '^7.0.0'), '7.7.4', 'Max satisfying version for ^7.0.0');
  assert.strictEqual(findMinSatisfying(available, '>=7.1.0'), '7.1.0', 'Min satisfying version for >=7.1.0');
  assert.strictEqual(findMaxSatisfying(available, '^9.0.0'), null, 'Returns null if no satisfying version');

  assert.strictEqual(getMinVersion('^7.7.4'), '7.7.4', 'Min version for ^7.7.4 is 7.7.4');
  assert.strictEqual(isSubset('^7.7.0', '^7.0.0'), true, '^7.7.0 is subset of ^7.0.0');
  assert.strictEqual(isSubset('^7.0.0', '^7.7.0'), false, '^7.0.0 is not subset of ^7.7.0');
  assert.strictEqual(rangesIntersect('^7.0.0', '>=7.7.0 <8.0.0'), true, 'Ranges intersect');
  assert.strictEqual(rangesIntersect('^7.0.0', '>=8.0.0'), false, 'Disjoint ranges do not intersect');
}

// Contract 4: semver constructs SemVer, Range, and Comparator instances exposing structured version components and comparator sets
{
  const semverObj = createSemVer('7.7.4-alpha.2+build.99');
  assert.strictEqual(semverObj.major, 7, 'Major component is 7');
  assert.strictEqual(semverObj.minor, 7, 'Minor component is 7');
  assert.strictEqual(semverObj.patch, 4, 'Patch component is 4');
  assert.deepStrictEqual(semverObj.prerelease, ['alpha', 2], 'Prerelease array matches');
  assert.deepStrictEqual(semverObj.build, ['build', '99'], 'Build metadata matches');
  assert.strictEqual(semverObj.format(), '7.7.4-alpha.2', 'Formatted version string');

  const rangeObj = createRange('>=7.0.0 <8.0.0 || >=9.0.0');
  assert.strictEqual(rangeObj.test('7.7.4'), true, 'Range tests 7.7.4 true');
  assert.strictEqual(rangeObj.test('8.5.0'), false, 'Range tests 8.5.0 false');
  assert.strictEqual(rangeObj.test('9.1.0'), true, 'Range tests 9.1.0 true on alternate set');
  assert.ok(rangeObj.set.length >= 2, 'Range contains multiple comparator sets');

  const comp = createComparator('>=7.7.4');
  assert.strictEqual(comp.operator, '>=', 'Comparator operator is >=');
  assert.strictEqual(comp.semver.version, '7.7.4', 'Comparator semver is 7.7.4');
  assert.strictEqual(comp.test('7.7.4'), true, 'Comparator tests 7.7.4 true');
  assert.strictEqual(comp.test('7.7.3'), false, 'Comparator tests 7.7.3 false');
}

console.log('All pkg:npm/semver@7.7.4 contracts passed successfully.');

Origin Seeder

anonymous