CodeSampleX

Beispiel

compare-version 0.1.2: compare semver version strings

Verifiziertes Beispiel für npm compare-version 0.1.2: compare semver version strings. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:e6d7f4601dfe9e249a181b57733b90e9d38b3fff5c0e6a8b9773892d82393eda

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
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

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

Fall

HOW
Ziel
compare semver version strings
Pakete
Symbole
  • compare-version
Umgebung
node 22.23.2
Erstellt
2026-08-26T09:12:29Z

Contract

  1. assert compare-version returns 1 when first version is greater than second version
  2. assert compare-version returns -1 when first version is less than second version
  3. assert compare-version returns 0 when version strings are identical or equivalent
  4. assert compare-version handles version comparisons with differing segment counts
  5. assert compare-version returns false when non-string arguments are provided

Dateien

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

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: compare semver version strings
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/compare-version@0.1.2
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:381958919d06981bb73bb64679d35bbb0bdf5010dd8fd3644b92c8cb32e52550","constraints":{"executionContext":"node"},"contract":["assert compare-version returns 1 when first version is greater than second version","assert compare-version returns -1 when first version is less than second version","assert compare-version returns 0 when version strings are identical or equivalent","assert compare-version handles version comparisons with differing segment counts","assert compare-version returns false when non-string arguments are provided"],"goal":"compare semver version strings","kind":"HOW","packages":["pkg:npm/compare-version@0.1.2"],"schemaVersion":1,"symbols":["compare-version"]},"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/compare-version@0.1.2"],"schemaVersion":1,"subject":"pkg:npm/compare-version@0.1.2","symbols":["compare-version"],"verifierAdapter":"node-typescript@1"}
index.js
const compare = require('compare-version');

/**
 * Compare two semver version strings.
 *
 * @param {string} a - First semver version string.
 * @param {string} b - Second semver version string.
 * @returns {number|boolean} 1 if a > b, -1 if a < b, 0 if a == b, false if invalid arguments.
 */
function compareVersion(a, b) {
  return compare(a, b);
}

module.exports = {
  compareVersion,
  compare,
};
package-lock.json
{
  "name": "sample-compare-version",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-compare-version",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "compare-version": "0.1.2"
      }
    },
    "node_modules/compare-version": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/compare-version/-/compare-version-0.1.2.tgz",
      "integrity": "sha512-pJDh5/4wrEnXX/VWRZvruAGHkzKdr46z11OlTPN+VrATlWWhSKewNCJ1futCO5C7eJB3nPMFZA1LeYtcFboZ2A==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-compare-version",
  "version": "1.0.0",
  "description": "Clean-room sample verifying pkg:npm/compare-version@0.1.2 functionality",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "compare-version": "0.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "compare semver version strings",
  "kind": "HOW",
  "packages": [
    "pkg:npm/compare-version@0.1.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import compare from 'compare-version';
import { compareVersion } from '../index.js';

// 1. Returns 1 when the first version is greater than the second version
assert.strictEqual(
  compare('1.11.0', '1.10.0'),
  1,
  'compare-version returns 1 when first version has a greater minor version'
);

assert.strictEqual(
  compareVersion('2.0.0', '1.9.9'),
  1,
  'compareVersion returns 1 when first version has a greater major version'
);

// 2. Returns -1 when the first version is less than the second version
assert.strictEqual(
  compare('1.10.0', '1.11.0'),
  -1,
  'compare-version returns -1 when first version has a smaller minor version'
);

assert.strictEqual(
  compareVersion('1.0.0', '1.0.1'),
  -1,
  'compareVersion returns -1 when first version has a smaller patch version'
);

// 3. Returns 0 when versions are equal
assert.strictEqual(
  compare('1.10.0', '1.10.0'),
  0,
  'compare-version returns 0 when version strings are identical'
);

// 4. Handles versions with differing segment lengths
assert.strictEqual(
  compare('1.0.0', '1.0'),
  0,
  'compare-version returns 0 when trailing zero segments are omitted'
);

assert.strictEqual(
  compare('1.0.1', '1.0'),
  1,
  'compare-version returns 1 when first version has an extra non-zero segment'
);

assert.strictEqual(
  compare('1.0', '1.0.1'),
  -1,
  'compare-version returns -1 when second version has an extra non-zero segment'
);

// 5. Returns false for invalid non-string inputs
assert.strictEqual(
  compare(1, 2),
  false,
  'compare-version returns false when non-string arguments are passed'
);

assert.strictEqual(
  compareVersion('1.0.0', null),
  false,
  'compareVersion returns false when second argument is null'
);

console.log('All contract assertions passed.');

Ursprungs-Seeder

anonym