CodeSampleX

示例

at-least-node 1.0.0: verify node version meets minimum requirement with at-least-node

已验证示例 — npm at-least-node 1.0.0: verify node version meets minimum requirement with at-least-node. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过.

sha256:50f3874a1f035e31de85007158f8f8c9dadabd25f15f167efa37629a4c1577fd

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

执行证据

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

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

验证运行环境

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

案例

HOW
目标
verify node version meets minimum requirement with at-least-node
包
环境
node 22.23.2
创建时间
2026-08-26T09:24:51Z

契约

  1. atLeastNode is a callable function accepting a target version string
  2. returns true when current node version is greater than the required major version
  3. returns true when current node version equals the required version string
  4. returns false when current node version is less than the required major version
  5. handles semantic version strings with major minor and patch numbers correctly
  6. helper function checks minimum version requirement for runtime feature gating

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 version meets minimum requirement with at-least-node
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/at-least-node@1.0.0
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:bb376e77ba80b0b8f72ba43302a63ae56eac810670a74663d91f049e7da42440","constraints":{"executionContext":"node"},"contract":["atLeastNode is a callable function accepting a target version string","returns true when current node version is greater than the required major version","returns true when current node version equals the required version string","returns false when current node version is less than the required major version","handles semantic version strings with major minor and patch numbers correctly","helper function checks minimum version requirement for runtime feature gating"],"goal":"verify node version meets minimum requirement with at-least-node","kind":"HOW","packages":["pkg:npm/at-least-node@1.0.0"],"schemaVersion":1},"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/at-least-node@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/at-least-node@1.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-at-least-node",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-at-least-node",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "at-least-node": "1.0.0"
      }
    },
    "node_modules/at-least-node": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
      "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==",
      "license": "ISC",
      "engines": {
        "node": ">= 4.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-at-least-node",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for at-least-node@1.0.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "at-least-node": "1.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify node version meets minimum requirement with at-least-node",
  "kind": "HOW",
  "packages": [
    "pkg:npm/at-least-node@1.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const atLeastNode = require('at-least-node');

/**
 * Checks if the current Node.js runtime version is at least the specified minimum version.
 *
 * @param {string} minVersion - The target minimum version (e.g. '10.0.0', '18.0.0', '22.0.0').
 * @returns {boolean} True if current node version is greater than or equal to minVersion.
 */
function isNodeAtLeast(minVersion) {
  return atLeastNode(minVersion);
}

/**
 * Checks if a specific feature requiring a minimum Node.js version is supported by the current runtime.
 *
 * @param {string} requiredVersion - The minimum version required by the feature.
 * @returns {{ supported: boolean, currentVersion: string, requiredVersion: string }}
 */
function checkFeatureSupport(requiredVersion) {
  return {
    supported: atLeastNode(requiredVersion),
    currentVersion: process.versions.node,
    requiredVersion
  };
}

module.exports = {
  atLeastNode,
  isNodeAtLeast,
  checkFeatureSupport
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  atLeastNode,
  isNodeAtLeast,
  checkFeatureSupport
} = require('../src/index.js');

async function testAll() {
  const currentVersion = process.versions.node;
  const [currentMajor, currentMinor, currentPatch] = currentVersion.split('.').map(Number);

  // 1. atLeastNode is a callable function accepting a target version string
  assert.equal(typeof atLeastNode, 'function', 'atLeastNode should be a function');
  assert.equal(typeof isNodeAtLeast, 'function', 'isNodeAtLeast should be a function');
  assert.equal(typeof checkFeatureSupport, 'function', 'checkFeatureSupport should be a function');

  // 2. returns true when current node version is greater than the required major version
  const olderMajor = `${Math.max(1, currentMajor - 5)}.0.0`;
  assert.equal(atLeastNode(olderMajor), true, `should return true for older major version ${olderMajor}`);
  assert.equal(isNodeAtLeast(olderMajor), true, `helper should return true for older major version ${olderMajor}`);

  // 3. returns true when current node version equals the required version string
  assert.equal(atLeastNode(currentVersion), true, `should return true when matching exact current version ${currentVersion}`);
  assert.equal(isNodeAtLeast(currentVersion), true, `helper should return true when matching exact current version`);

  // 4. returns false when current node version is less than the required major version
  const futureMajor = `${currentMajor + 10}.0.0`;
  assert.equal(atLeastNode(futureMajor), false, `should return false for future major version ${futureMajor}`);
  assert.equal(isNodeAtLeast(futureMajor), false, `helper should return false for future major version ${futureMajor}`);

  // 5. handles semantic version strings with major minor and patch numbers correctly
  const sameMajorOlderMinor = `${currentMajor}.${Math.max(0, currentMinor - 1)}.0`;
  assert.equal(atLeastNode(sameMajorOlderMinor), true, `should return true for older minor version within same major`);

  const sameMajorFutureMinor = `${currentMajor}.${currentMinor + 5}.0`;
  assert.equal(atLeastNode(sameMajorFutureMinor), false, `should return false for future minor version within same major`);

  // 6. helper function checks minimum version requirement for runtime feature gating
  const supportOlder = checkFeatureSupport(olderMajor);
  assert.deepEqual(supportOlder, {
    supported: true,
    currentVersion,
    requiredVersion: olderMajor
  });

  const supportFuture = checkFeatureSupport(futureMajor);
  assert.deepEqual(supportFuture, {
    supported: false,
    currentVersion,
    requiredVersion: futureMajor
  });

  console.log('All at-least-node contract tests passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

原始种子者

匿名