CodeSampleX

샘플

node-abi 3.96.0: getAbi

검증된 샘플 — npm node-abi 3.96.0: getAbi. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: getAbi is exported as a function from node-abi

sha256:d7274cf4f2c8f41875cd23cd43b52114d3ad05cdd39ef2c3f779ce6462ad5f41

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
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-abi.getAbi in pkg:npm/node-abi@3.96.0
패키지
심벌
  • node-abi.getAbi
생성일
2026-09-07T03:13:48Z

컨트랙트

  1. getAbi is exported as a function from node-abi
  2. getAbi resolves Node.js target version to corresponding ABI version string
  3. getAbi defaults to node runtime when runtime parameter is omitted
  4. getAbi resolves Electron target version to corresponding ABI version string
  5. getAbi returns numeric ABI string input directly
  6. getAbi strips leading v prefix from version string
  7. getAbi throws an Error for unsupported version targets

파일

  • 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-abi.getAbi in pkg:npm/node-abi@3.96.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-abi@3.96.0
Demonstrate these symbols/APIs:
  - node-abi.getAbi

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:cda37129f6edca937ad5aa1b0a3f721ec87bbd118c967c5c786b6b8662da67db","contract":["getAbi is exported as a function from node-abi","getAbi resolves Node.js target version to corresponding ABI version string","getAbi defaults to node runtime when runtime parameter is omitted","getAbi resolves Electron target version to corresponding ABI version string","getAbi returns numeric ABI string input directly","getAbi strips leading v prefix from version string","getAbi throws an Error for unsupported version targets"],"goal":"verify node-abi.getAbi in pkg:npm/node-abi@3.96.0","kind":"HOW","packages":["pkg:npm/node-abi@3.96.0"],"schemaVersion":1,"symbols":["node-abi.getAbi"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/node-abi@3.96.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@3.96.0","symbols":["node-abi.getAbi"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-abi",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "node-abi": "3.96.0"
      }
    },
    "node_modules/node-abi": {
      "version": "3.96.0",
      "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.96.0.tgz",
      "integrity": "sha512-rebQ/lz7i0EkoLzUVSrKRzA69zMkwLp95kKMWoMDkkM00Suxz0D7zEQPwRml5fQum24mj7bPvmlgLAmu2JCiYg==",
      "license": "MIT",
      "dependencies": {
        "semver": "^7.3.5"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/semver": {
      "version": "7.8.5",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
      "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-node-abi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for node-abi.getAbi in node-abi@3.96.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "node-abi": "3.96.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify node-abi.getAbi in pkg:npm/node-abi@3.96.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@3.96.0"
  ],
  "symbols": [
    "node-abi.getAbi"
  ]
}
src/index.js
const nodeAbi = require('node-abi');

/**
 * Resolves the Node or Electron ABI number string for a given target runtime version.
 *
 * @param {string} target - Runtime version string (e.g. '22.0.0').
 * @param {string} [runtime='node'] - Target runtime ('node' or 'electron').
 * @returns {string} The ABI version string.
 */
function resolveAbi(target, runtime = 'node') {
  return nodeAbi.getAbi(target, runtime);
}

module.exports = {
  nodeAbi,
  getAbi: nodeAbi.getAbi,
  resolveAbi
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  nodeAbi,
  getAbi,
  resolveAbi
} = require('../src/index.js');

async function runTests() {
  // 1. getAbi is exported as a function from node-abi
  assert.equal(typeof nodeAbi.getAbi, 'function', 'nodeAbi.getAbi must be a function');
  assert.equal(typeof getAbi, 'function', 'getAbi must be a function');
  assert.equal(typeof resolveAbi, 'function', 'resolveAbi helper must be a function');

  // 2. getAbi resolves Node.js target version to corresponding ABI version string
  assert.equal(resolveAbi('24.0.0', 'node'), '137', 'Node 24.0.0 should map to ABI 137');
  assert.equal(resolveAbi('22.0.0', 'node'), '127', 'Node 22.0.0 should map to ABI 127');
  assert.equal(resolveAbi('20.0.0', 'node'), '115', 'Node 20.0.0 should map to ABI 115');

  // 3. getAbi defaults to node runtime when runtime parameter is omitted
  assert.equal(resolveAbi('22.0.0'), '127', 'Omitting runtime should default to node');

  // 4. getAbi resolves Electron target version to corresponding ABI version string
  assert.equal(resolveAbi('32.0.0', 'electron'), '128', 'Electron 32.0.0 should map to ABI 128');
  assert.equal(resolveAbi('30.0.0', 'electron'), '123', 'Electron 30.0.0 should map to ABI 123');

  // 5. getAbi returns numeric ABI string input directly
  assert.equal(resolveAbi('127'), '127', 'Passing numeric ABI string should return itself');

  // 6. getAbi strips leading v prefix from version string
  assert.equal(resolveAbi('v22.0.0', 'node'), '127', 'Leading v should be stripped');

  // 7. getAbi throws an Error for unsupported version targets
  assert.throws(
    () => resolveAbi('999.0.0', 'node'),
    /Could not detect abi for version 999\.0\.0/,
    'getAbi should throw on unsupported version'
  );

  console.log('All contract assertions for node-abi.getAbi passed successfully.');
}

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

오리진 시더

익명