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. node 22 · linux alpine/x64 · docker에서 contract를 실행해…

sha256:50f3874a1f035e31de85007158f8f8c9dadabd25f15f167efa37629a4c1577fd

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

오리진 시더

익명