CodeSampleX

示例

node-releases 2.0.51: slice

已验证示例 — npm node-releases 2.0.51: slice. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: slice extracts a subset of release records without mutating…

sha256:c2dc9a59d353c85e42439d5f1f1ea410e85a59fc2681e56f77ec8cdfe2fd8b6c

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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-05

案例

HOW
目标
verify node-releases.slice in pkg:npm/node-releases@2.0.51
包
符号
  • node-releases.slice
环境
node 22.23.2
创建时间
2026-09-05T22:53:55Z

契约

  1. slice extracts a subset of release records without mutating the source envs array
  2. slice with positive start and end extracts the exact range of release records
  3. slice with negative start extracts the most recent N releases from the end of the array
  4. slice with start index greater than or equal to array length returns an empty array
  5. slice without arguments creates a shallow copy of all release records with identical elements
  6. slice with negative start exceeding array length normalizes to index zero and returns elements from start

文件

  • PROMPT.md
  • csx.json
  • 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 node-releases.slice in pkg:npm/node-releases@2.0.51
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-releases@2.0.51
Demonstrate these symbols/APIs:
  - node-releases.slice

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:fd76e71f29f4c34221d40ff3c66978f452de3acba4352c331f0aac3d4e27d391","contract":["slice extracts a subset of release records without mutating the source envs array","slice with positive start and end extracts the exact range of release records","slice with negative start extracts the most recent N releases from the end of the array","slice with start index greater than or equal to array length returns an empty array","slice without arguments creates a shallow copy of all release records with identical elements","slice with negative start exceeding array length normalizes to index zero and returns elements from start"],"goal":"verify node-releases.slice in pkg:npm/node-releases@2.0.51","kind":"HOW","packages":["pkg:npm/node-releases@2.0.51"],"schemaVersion":1,"symbols":["node-releases.slice"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/node-releases@2.0.51"],"schemaVersion":1,"subject":"pkg:npm/node-releases@2.0.51","symbols":["node-releases.slice"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-node-releases-slice",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-releases-slice",
      "version": "1.0.0",
      "dependencies": {
        "node-releases": "2.0.51"
      }
    },
    "node_modules/node-releases": {
      "version": "2.0.51",
      "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.51.tgz",
      "integrity": "sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ==",
      "license": "MIT",
      "engines": {
        "node": ">=18"
      }
    }
  }
}
package.json
{
  "name": "sample-node-releases-slice",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "node-releases": "2.0.51"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify node-releases.slice in pkg:npm/node-releases@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-releases@2.0.51"
  ],
  "symbols": [
    "node-releases.slice"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import envs from 'node-releases/data/processed/envs.json' with { type: 'json' };

// Ensure source data is valid array
assert.ok(Array.isArray(envs), 'envs must be an array');
const initialLength = envs.length;
assert.ok(initialLength > 0, 'envs must contain records');

// 1. slice extracts a subset of release records without mutating the source envs array
const firstTen = envs.slice(0, 10);
assert.equal(firstTen.length, 10, 'Sliced length should be 10');
assert.equal(envs.length, initialLength, 'Original envs length must remain unchanged');
assert.deepEqual(firstTen[0], envs[0], 'First element of slice must match original');
assert.deepEqual(firstTen[9], envs[9], 'Tenth element of slice must match original');

// 2. slice with positive start and end extracts the exact range of release records
const range = envs.slice(5, 15);
assert.equal(range.length, 10, 'Range slice length should be 10');
assert.deepEqual(range[0], envs[5], 'First element of range must equal envs[5]');
assert.deepEqual(range[9], envs[14], 'Last element of range must equal envs[14]');

// 3. slice with negative start extracts the most recent N releases from the end of the array
const recentFive = envs.slice(-5);
assert.equal(recentFive.length, 5, 'Negative start slice should have 5 items');
assert.deepEqual(recentFive[0], envs[initialLength - 5], 'First element of negative slice must match corresponding tail index');
assert.deepEqual(recentFive[4], envs[initialLength - 1], 'Last element of negative slice must match last release');

// 4. slice with start index greater than or equal to array length returns an empty array
const emptySlice = envs.slice(initialLength + 10);
assert.ok(Array.isArray(emptySlice), 'Empty slice must be an array');
assert.equal(emptySlice.length, 0, 'Empty slice length must be 0');

// 5. slice without arguments creates a shallow copy of all release records with identical elements
const fullCopy = envs.slice();
assert.notEqual(fullCopy, envs, 'Slice shallow copy must have different reference');
assert.equal(fullCopy.length, initialLength, 'Shallow copy must have same length as source');
assert.deepEqual(fullCopy[0], envs[0], 'First element of copy must match source');
assert.deepEqual(fullCopy[initialLength - 1], envs[initialLength - 1], 'Last element of copy must match source');

// 6. slice with negative start exceeding array length normalizes to index zero and returns elements from start
const clampedSlice = envs.slice(-1000, 3);
assert.equal(clampedSlice.length, 3, 'Slice with large negative start should start at index 0');
assert.deepEqual(clampedSlice[0], envs[0], 'Element at index 0 should match source[0]');

// CommonJS compatibility check
const require = createRequire(import.meta.url);
const cjsEnvs = require('node-releases/data/processed/envs.json');
assert.ok(Array.isArray(cjsEnvs), 'CJS envs must be an array');
const cjsSlice = cjsEnvs.slice(0, 5);
assert.equal(cjsSlice.length, 5, 'CJS slice should return 5 elements');
assert.deepEqual(cjsSlice[0], cjsEnvs[0], 'CJS slice first element must match');

原始种子者

匿名