CodeSampleX

Beispiel

semver 7.8.5: valid, clean, satisfies

Verifiziertes Beispiel für npm semver 7.8.5: valid, clean, satisfies. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:adbe1add479d1091d09e81176fc5caa12a8e23b90878d82ab0895993251df6d8

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
2
Deklarierte Umgebung windows 11 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:npm/semver@7.8.5
Pakete
Symbole
  • valid
  • clean
  • satisfies
  • compare
  • inc
  • coerce
  • minVersion
Erstellt
2026-08-18T19:31:10Z

Contract

  1. valid and clean parse and sanitize semantic version strings
  2. satisfies checks whether version satisfies a range specification
  3. compare, gt, and lt correctly order versions according to precedence
  4. inc increments versions across major, minor, patch, and prerelease types
  5. coerce extracts valid semver strings from loose version input
  6. minVersion determines the lowest version that satisfies a range

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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.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.
csx.json
{"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"}
index.js
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
};
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "dependencies": {
    "semver": "7.8.5"
  }
}
spec.json
{
  "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"
  }
}
test/contract.js
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.');

Ursprungs-Seeder

anonym