CodeSampleX

Sample

semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers

Verified sample for npm semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers. The contract ran on node 22 · linux alpine/x64 · docker and…

sha256:b6b85e7f8ec9fe58d8fb16b6b1be3b72ddc9f123a397c870d1649387ed9d8a56

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 node 22.22 linux 24 · ubuntu · glibc 2.39 x64 node 22.22 javascript npm 11 wsl

Verification-run environments

Environment Contract Stages Run
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 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

Case

HOW
Goal
verify pkg:npm/semver@7.8.5
Packages
Symbols
  • RELEASE_TYPES
  • SEMVER_SPEC_VERSION
  • SemVer
  • compareIdentifiers
  • rcompareIdentifiers
  • truncate
Environment
node 22.22.2
Created
2026-08-19T08:38:31Z

Contract

  1. assert semver.SemVer constructs version instances with parsed major, minor, patch, prerelease, and build metadata
  2. assert SemVer instance methods compareMain and comparePre isolate version core and prerelease comparison
  3. assert semver.compareIdentifiers compares identifier tokens by numeric precedence and ASCII lexicographical order
  4. assert semver.rcompareIdentifiers provides reverse ordering for identifier tokens
  5. assert semver.truncate shortens version numbers to major, minor, or patch resolution
  6. assert semver constants define SEMVER_SPEC_VERSION and all valid RELEASE_TYPES

Files

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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.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@22.22.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:8f67351a31b76af16d39cf1defab93d6541f5526276a8b6fd15bc6653db5107f","constraints":{"executionContext":"node"},"contract":["assert semver.SemVer constructs version instances with parsed major, minor, patch, prerelease, and build metadata","assert SemVer instance methods compareMain and comparePre isolate version core and prerelease comparison","assert semver.compareIdentifiers compares identifier tokens by numeric precedence and ASCII lexicographical order","assert semver.rcompareIdentifiers provides reverse ordering for identifier tokens","assert semver.truncate shortens version numbers to major, minor, or patch resolution","assert semver constants define SEMVER_SPEC_VERSION and all valid RELEASE_TYPES"],"goal":"verify pkg:npm/semver@7.8.5","kind":"HOW","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["RELEASE_TYPES","SEMVER_SPEC_VERSION","SemVer","compareIdentifiers","rcompareIdentifiers","truncate"]},"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":"11.8.0","runtime":"node","runtimeVersion":"22.22.2","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:npm/semver@7.8.5"],"schemaVersion":1,"symbols":["RELEASE_TYPES","SEMVER_SPEC_VERSION","SemVer","compareIdentifiers","rcompareIdentifiers","truncate"],"verifierAdapter":"node-typescript@1"}
index.mjs
import semver from 'semver';

/**
 * Construct a SemVer instance from a version string.
 */
export function createSemVer(versionStr, options = {}) {
  return new semver.SemVer(versionStr, options);
}

/**
 * Compare two individual identifier components using SemVer 2.0.0 precedence rules.
 */
export function compareIdentifiers(a, b) {
  return semver.compareIdentifiers(a, b);
}

/**
 * Reverse-compare two individual identifier components.
 */
export function rcompareIdentifiers(a, b) {
  return semver.rcompareIdentifiers(a, b);
}

/**
 * Truncate a semantic version string to a specific release level ('major', 'minor', 'patch').
 */
export function truncateVersion(versionStr, type) {
  return semver.truncate(versionStr, type);
}

/**
 * Export semver spec constants.
 */
export const SEMVER_SPEC_VERSION = semver.SEMVER_SPEC_VERSION;
export const RELEASE_TYPES = semver.RELEASE_TYPES;
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=="
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "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@22.22.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import semver from 'semver';
import {
  createSemVer,
  compareIdentifiers,
  rcompareIdentifiers,
  truncateVersion,
  SEMVER_SPEC_VERSION,
  RELEASE_TYPES
} from '../index.mjs';

// 1. assert semver.SemVer constructs version instances with parsed major, minor, patch, prerelease, and build metadata
{
  const sv = createSemVer('2.4.1-alpha.3+exp.sha.5114f85');
  assert.ok(sv instanceof semver.SemVer);
  assert.equal(sv.major, 2);
  assert.equal(sv.minor, 4);
  assert.equal(sv.patch, 1);
  assert.deepEqual(sv.prerelease, ['alpha', 3]);
  assert.deepEqual(sv.build, ['exp', 'sha', '5114f85']);
  assert.equal(sv.version, '2.4.1-alpha.3');
  assert.equal(sv.raw, '2.4.1-alpha.3+exp.sha.5114f85');
  assert.equal(sv.format(), '2.4.1-alpha.3');
  assert.equal(sv.toString(), '2.4.1-alpha.3');
}

// 2. assert SemVer instance methods compareMain and comparePre isolate version core and prerelease comparison
{
  const v1 = createSemVer('1.2.3-alpha.1');
  const v2 = createSemVer('1.2.3-beta.2');
  const v3 = createSemVer('1.2.4-alpha.1');

  // compareMain evaluates only major, minor, patch fields
  assert.equal(v1.compareMain(v2), 0);
  assert.equal(v1.compareMain(v3), -1);
  assert.equal(v3.compareMain(v1), 1);

  // comparePre evaluates only prerelease components
  assert.equal(v1.comparePre(v2), -1);
  assert.equal(v2.comparePre(v1), 1);
  assert.equal(v1.comparePre('1.2.3-alpha.1'), 0);
}

// 3. assert semver.compareIdentifiers compares identifier tokens by numeric precedence and ASCII lexicographical order
{
  // Numeric tokens compared numerically: 2 < 10
  assert.equal(compareIdentifiers('2', '10'), -1);
  assert.equal(compareIdentifiers('10', '2'), 1);
  assert.equal(compareIdentifiers('5', '5'), 0);

  // Numeric tokens have lower precedence than non-numeric tokens
  assert.equal(compareIdentifiers('99', 'alpha'), -1);
  assert.equal(compareIdentifiers('alpha', '99'), 1);

  // Non-numeric tokens compared lexicographically in ASCII sort order
  assert.equal(compareIdentifiers('alpha', 'beta'), -1);
  assert.equal(compareIdentifiers('rc', 'beta'), 1);
  assert.equal(compareIdentifiers('patch', 'patch'), 0);
}

// 4. assert semver.rcompareIdentifiers provides reverse ordering for identifier tokens
{
  assert.equal(rcompareIdentifiers('2', '10'), 1);
  assert.equal(rcompareIdentifiers('alpha', 'beta'), 1);
  assert.equal(rcompareIdentifiers('beta', 'alpha'), -1);
  assert.equal(rcompareIdentifiers('same', 'same'), 0);
}

// 5. assert semver.truncate shortens version numbers to major, minor, or patch resolution
{
  assert.equal(truncateVersion('1.5.8-beta.2', 'major'), '1.0.0');
  assert.equal(truncateVersion('1.5.8-beta.2', 'minor'), '1.5.0');
  assert.equal(truncateVersion('1.5.8-beta.2', 'patch'), '1.5.8');
  assert.equal(truncateVersion('3.2.1', 'major'), '3.0.0');
}

// 6. assert semver constants define SEMVER_SPEC_VERSION and all valid RELEASE_TYPES
{
  assert.equal(SEMVER_SPEC_VERSION, '2.0.0');
  assert.deepEqual(RELEASE_TYPES, [
    'major',
    'premajor',
    'minor',
    'preminor',
    'patch',
    'prepatch',
    'prerelease'
  ]);
}

console.log('PASS: all contract assertions satisfied');

Origin Seeder

anonymous