CodeSampleX

Exemple

node-abi 3.94.0: getAbi, getTarget

Échantillon vérifié pour npm node-abi 3.94.0: getAbi, getTarget. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:41f586cb9e6d08454e20e0c877dd9a5b385c61af7683cd8dd0a6df2b5ea0cac2

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-28

Cas

HOW
Objectif
verify pkg:npm/node-abi@3.94.0
Paquets
Symboles
  • node-abi.getAbi
  • node-abi.getTarget
Créé
2026-08-28T08:00:00Z

Contrat

  1. getAbi is exported as a function from node-abi
  2. getTarget is exported as a function from node-abi
  3. getAbi resolves the ABI version string for standard Node.js release targets
  4. getAbi defaults to node runtime when runtime parameter is omitted
  5. getAbi resolves the ABI version string for Electron release targets
  6. getAbi returns the input unchanged when a numeric ABI string is passed
  7. getTarget resolves the target version string for given ABI and runtime
  8. getAbi and getTarget throw error when queried with unsupported target version or ABI

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Télécharger l’artefact source (tar.gz)

Code source

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 pkg:npm/node-abi@3.94.0
Kind: HOW

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

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:814d261cf7216c802666ed0deb7df226fb8d0c26f7a433308e29c68ea2e7d275","contract":["getAbi is exported as a function from node-abi","getTarget is exported as a function from node-abi","getAbi resolves the ABI version string for standard Node.js release targets","getAbi defaults to node runtime when runtime parameter is omitted","getAbi resolves the ABI version string for Electron release targets","getAbi returns the input unchanged when a numeric ABI string is passed","getTarget resolves the target version string for given ABI and runtime","getAbi and getTarget throw error when queried with unsupported target version or ABI"],"goal":"verify pkg:npm/node-abi@3.94.0","kind":"HOW","packages":["pkg:npm/node-abi@3.94.0"],"schemaVersion":1,"symbols":["node-abi.getAbi","node-abi.getTarget"]},"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.94.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@3.94.0","symbols":["node-abi.getAbi","node-abi.getTarget"],"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.94.0"
      }
    },
    "node_modules/node-abi": {
      "version": "3.94.0",
      "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.94.0.tgz",
      "integrity": "sha512-W5ZNO5KRPB5TkYmGVD9F6YqhsglXJzE6etpbmT+f6EQElhiX/UTG551cnsRGvLG3fyZEg9HwaDmNmj5nwJ4z9g==",
      "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 in node-abi@3.94.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "node-abi": "3.94.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/node-abi@3.94.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@3.94.0"
  ],
  "symbols": [
    "node-abi.getAbi",
    "node-abi.getTarget"
  ]
}
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);
}

/**
 * Resolves the target runtime version string for a given ABI number and runtime.
 *
 * @param {string} abi - ABI number string (e.g. '127').
 * @param {string} [runtime='node'] - Target runtime ('node' or 'electron').
 * @returns {string} The target version string.
 */
function resolveTarget(abi, runtime = 'node') {
  return nodeAbi.getTarget(abi, runtime);
}

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

const require = createRequire(import.meta.url);
const {
  nodeAbi,
  getAbi,
  getTarget,
  resolveAbi,
  resolveTarget
} = 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. getTarget is exported as a function from node-abi
  assert.equal(typeof nodeAbi.getTarget, 'function', 'nodeAbi.getTarget must be a function');
  assert.equal(typeof getTarget, 'function', 'getTarget must be a function');
  assert.equal(typeof resolveTarget, 'function', 'resolveTarget helper must be a function');

  // 3. getAbi resolves the ABI version string for standard Node.js release targets
  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');
  assert.equal(resolveAbi('18.0.0', 'node'), '108', 'Node 18.0.0 should map to ABI 108');

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

  // 5. getAbi resolves the ABI version string for Electron release targets
  assert.equal(resolveAbi('30.0.0', 'electron'), '123', 'Electron 30.0.0 should map to ABI 123');
  assert.equal(resolveAbi('28.0.0', 'electron'), '119', 'Electron 28.0.0 should map to ABI 119');

  // 6. getAbi returns the input unchanged when a numeric ABI string is passed
  assert.equal(resolveAbi('127'), '127', 'Passing numeric ABI string should return itself');

  // 7. getTarget resolves the target version string for given ABI and runtime
  assert.equal(resolveTarget('127', 'node'), '22.0.0', 'ABI 127 for node should resolve to 22.0.0');
  assert.equal(resolveTarget('123', 'electron'), '30.0.0', 'ABI 123 for electron should resolve to 30.0.0');
  assert.equal(resolveTarget('127'), '22.0.0', 'Omitting runtime should default to node');

  // 8. getAbi and getTarget throw error when queried with unsupported target version or ABI
  assert.throws(
    () => resolveAbi('999.0.0', 'node'),
    /Could not detect abi for version 999\.0\.0/,
    'getAbi should throw on unsupported version'
  );
  assert.throws(
    () => resolveTarget('99999', 'node'),
    /Could not detect target for abi 99999/,
    'getTarget should throw on unknown ABI'
  );

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

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

Seeder d'origine

anonyme