示例
semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers
已验证示例 — npm semver 7.8.5: RELEASE_TYPES, SEMVER_SPEC_VERSION, compareIdentifiers. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过.
sha256:b6b85e7f8ec9fe58d8fb16b6b1be3b72ddc9f123a397c870d1649387ed9d8a56
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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.
{"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"}
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;
{
"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=="
}
}
}
{
"name": "sample",
"version": "1.0.0",
"type": "module",
"dependencies": {
"semver": "7.8.5"
}
}
{
"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"
}
}
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');
原始种子者
匿名