CodeSampleX

Ejemplo

node-abi 3.96.0: getTarget

Muestra verificada para npm node-abi 3.96.0: getTarget. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: getTarget is exported as a…

sha256:4917c25bf5419a9de0224641a7c991ae464b4ad7bd5fba984d3e5f86ac5f2498

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify node-abi.getTarget in pkg:npm/node-abi@3.96.0
Paquetes
Símbolos
  • node-abi.getTarget
Creado
2026-09-07T06:01:15Z

Contrato

  1. getTarget is exported as a function from node-abi
  2. getTarget resolves Node.js ABI version string to target version
  3. getTarget defaults to node runtime when runtime parameter is omitted
  4. getTarget resolves Electron ABI version string to target version
  5. getTarget returns non-numeric version string input directly
  6. getTarget throws an Error for unknown ABI versions

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.getTarget 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.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:666caf822ee33da729936e440f21560f32dc74a2aea0391727cd2e57779bda6a","contract":["getTarget is exported as a function from node-abi","getTarget resolves Node.js ABI version string to target version","getTarget defaults to node runtime when runtime parameter is omitted","getTarget resolves Electron ABI version string to target version","getTarget returns non-numeric version string input directly","getTarget throws an Error for unknown ABI versions"],"goal":"verify node-abi.getTarget in pkg:npm/node-abi@3.96.0","kind":"HOW","packages":["pkg:npm/node-abi@3.96.0"],"schemaVersion":1,"symbols":["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.96.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@3.96.0","symbols":["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.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.getTarget 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.getTarget in pkg:npm/node-abi@3.96.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@3.96.0"
  ],
  "symbols": [
    "node-abi.getTarget"
  ]
}
src/index.js
const nodeAbi = require('node-abi');

/**
 * 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,
  getTarget: nodeAbi.getTarget,
  resolveTarget
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

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

async function runTests() {
  // 1. 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');

  // 2. getTarget resolves Node.js ABI version string to target version
  assert.equal(resolveTarget('127', 'node'), '22.0.0', 'ABI 127 for node should resolve to 22.0.0');
  assert.equal(resolveTarget('115', 'node'), '20.0.0', 'ABI 115 for node should resolve to 20.0.0');
  assert.equal(resolveTarget('108', 'node'), '18.0.0', 'ABI 108 for node should resolve to 18.0.0');

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

  // 4. getTarget resolves Electron ABI version string to target version
  assert.equal(resolveTarget('123', 'electron'), '30.0.0', 'ABI 123 for electron should resolve to 30.0.0');
  assert.equal(resolveTarget('119', 'electron'), '28.0.0', 'ABI 119 for electron should resolve to 28.0.0');

  // 5. getTarget returns non-numeric version string input directly
  assert.equal(resolveTarget('v22.0.0', 'node'), 'v22.0.0', 'Passing non-numeric version string should return itself');

  // 6. getTarget throws an Error for unknown ABI versions
  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.getTarget passed successfully.');
}

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

Seeder de origen

anónimo