CodeSampleX

샘플

semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers

검증된 샘플 — npm semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:b6b85e7f8ec9fe58d8fb16b6b1be3b72ddc9f123a397c870d1649387ed9d8a56

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 node 22.22 linux 24 · ubuntu · glibc 2.39 x64 node 22.22 javascript npm 11 wsl

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/semver@7.8.5
패키지
심벌
  • RELEASE_TYPES
  • SEMVER_SPEC_VERSION
  • SemVer
  • compareIdentifiers
  • rcompareIdentifiers
  • truncate
환경
node 22.22.2
생성일
2026-08-19T08:38:31Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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');

오리진 시더

익명