CodeSampleX

Ejemplo

bare-hrtime 2.1.1: hrtime, hrtime.bigint

Muestra verificada para npm bare-hrtime 2.1.1: hrtime, hrtime.bigint. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:58ed7e001626878dece306b8fdcaaa15391da5d3e31c2340eefddf8aa7cf4c35

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 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

Caso

HOW
Objetivo
verify pkg:npm/bare-hrtime@2.1.1
Paquetes
Símbolos
  • hrtime
  • hrtime.bigint
Creado
2026-08-26T14:08:35Z

Contrato

  1. package manifest specifies Bare addon configuration and exports for root and package subpaths
  2. declares high-resolution timer functions hrtime and hrtime.bigint in index.d.ts
  3. implements nanosecond to second/nanosecond tuple conversion and past timestamp differential calculation
  4. ships native Bare C addon binding with uv_hrtime and multi-platform prebuild artifacts

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/bare-hrtime@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-hrtime@2.1.1
Demonstrate these symbols/APIs:
  - hrtime
  - hrtime.bigint

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:27f645771acf7fba45242ec0daf24de19dbdd8ce2640de47ca30889a7c387c77","contract":["package manifest specifies Bare addon configuration and exports for root and package subpaths","declares high-resolution timer functions hrtime and hrtime.bigint in index.d.ts","implements nanosecond to second/nanosecond tuple conversion and past timestamp differential calculation","ships native Bare C addon binding with uv_hrtime and multi-platform prebuild artifacts"],"goal":"verify pkg:npm/bare-hrtime@2.1.1","kind":"HOW","packages":["pkg:npm/bare-hrtime@2.1.1"],"schemaVersion":1,"symbols":["hrtime","hrtime.bigint"]},"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/bare-hrtime@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/bare-hrtime@2.1.1","symbols":["hrtime","hrtime.bigint"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-hrtime",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-hrtime",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-hrtime": "2.1.1"
      }
    },
    "node_modules/bare-hrtime": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/bare-hrtime/-/bare-hrtime-2.1.1.tgz",
      "integrity": "sha512-VMb3tHo05gsnbu3OXTmkDiwTjMlOsbQmKoysKqKEyR09m77TuDrYFbj3Q5GGk10dAKsUHrnXmwCaeJqzVpB5ZA==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "sample-bare-hrtime",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-hrtime": "2.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-hrtime@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-hrtime@2.1.1"
  ],
  "symbols": [
    "hrtime",
    "hrtime.bigint"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve bare-hrtime package manifest and verify exports and metadata
const pkgPath = require.resolve('bare-hrtime/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-hrtime', 'Package name must be bare-hrtime');
assert.equal(pkg.version, '2.1.1', 'Package version must be 2.1.1');
assert.equal(pkg.description, 'High-resolution timers for JavaScript', 'Description must match');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.equal(pkg.addon, true, 'Package must be marked as addon');

assert.ok(pkg.exports, 'Package must define exports');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must have index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must have index.js default');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to package.json');

const pkgDir = path.dirname(pkgPath);
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
const indexJs = fs.readFileSync(path.join(pkgDir, 'index.js'), 'utf8');
const bindingJs = fs.readFileSync(path.join(pkgDir, 'binding.js'), 'utf8');
const bindingC = fs.readFileSync(path.join(pkgDir, 'binding.c'), 'utf8');

// 2. Verify TypeScript declarations (index.d.ts) for hrtime and hrtime.bigint
assert.ok(indexDts.includes('declare function hrtime('), 'index.d.ts must declare hrtime function');
assert.ok(indexDts.includes('prev?: ArrayLike<number>'), 'index.d.ts must accept optional prev parameter');
assert.ok(indexDts.includes('[seconds: number, nanoseconds: number]'), 'index.d.ts must return [seconds, nanoseconds] tuple');
assert.ok(indexDts.includes('declare namespace hrtime'), 'index.d.ts must declare hrtime namespace');
assert.ok(indexDts.includes('export function bigint(): bigint'), 'index.d.ts must declare hrtime.bigint returning bigint');
assert.ok(indexDts.includes('export = hrtime'), 'index.d.ts must export hrtime');

// 3. Verify JavaScript wrapper implementation & timing arithmetic contract
assert.ok(indexJs.includes("const binding = require('./binding')"), 'index.js must require binding');
assert.ok(indexJs.includes('module.exports = exports = function hrtime(past)'), 'index.js must define hrtime(past)');
assert.ok(indexJs.includes('exports.bigint = function hrtime()'), 'index.js must define exports.bigint');

// Test the high-resolution timing arithmetic behavior as implemented in index.js
function simulateHrtime(nowBigInt, past) {
  let now = nowBigInt;
  if (past) now -= BigInt(past[0]) * 1000000000n + BigInt(past[1]);
  return [Number(now / 1000000000n), Number(now % 1000000000n)];
}

// Case A: Base timestamp conversion from nanoseconds to [seconds, nanoseconds]
const t0 = 123456789012345678n; // 123456789 seconds, 12345678 nanoseconds
const tuple0 = simulateHrtime(t0);
assert.equal(tuple0[0], 123456789, 'Seconds part must match');
assert.equal(tuple0[1], 12345678, 'Nanoseconds part must match');

// Case B: Differential timing (past timestamp diff)
// Elapsed: 2 seconds and 500,000,000 nanoseconds
const pastTimestamp = [123456787, 12345678];
const diff = simulateHrtime(t0, pastTimestamp);
assert.equal(diff[0], 2, 'Diff seconds part must be 2');
assert.equal(diff[1], 0, 'Diff nanoseconds part must be 0');

// Case C: Sub-second elapsed delta with nanosecond rollover
const t1 = 1000000000n; // 1s 0ns
const pastSubSecond = [0, 500000000]; // 0s 500000000ns
const diffSubSecond = simulateHrtime(t1, pastSubSecond);
assert.equal(diffSubSecond[0], 0, 'Elapsed seconds should be 0');
assert.equal(diffSubSecond[1], 500000000, 'Elapsed nanoseconds should be 500000000');

// 4. Verify C native addon binding and multi-platform prebuilt binaries
assert.ok(bindingC.includes('BARE_MODULE(bare_hrtime, bare_hrtime_exports)'), 'binding.c must register bare_hrtime BARE_MODULE');
assert.ok(bindingC.includes('uv_hrtime()'), 'binding.c must invoke uv_hrtime() for high-resolution timestamps');
assert.ok(bindingC.includes('js_create_bigint_uint64'), 'binding.c must return uint64 BigInt value');
assert.ok(bindingJs.includes('module.exports = require.addon()'), 'binding.js must load native addon via require.addon()');
assert.ok(fs.existsSync(path.join(pkgDir, 'CMakeLists.txt')), 'CMakeLists.txt must exist');

// Verify prebuilt native binaries for supported platforms
const prebuildsDir = path.join(pkgDir, 'prebuilds');
const expectedTargets = [
  'linux-x64',
  'linux-arm64',
  'darwin-x64',
  'darwin-arm64',
  'win32-x64',
  'win32-arm64',
  'android-arm64',
  'ios-arm64'
];

for (const target of expectedTargets) {
  const prebuildPath = path.join(prebuildsDir, target, 'bare-hrtime.bare');
  assert.ok(fs.existsSync(prebuildPath), `Prebuild binary for ${target} must exist at ${prebuildPath}`);
  const stats = fs.statSync(prebuildPath);
  assert.ok(stats.size > 0, `Prebuild binary for ${target} must not be empty`);
}

console.log('Contract tests passed successfully.');

Seeder de origen

anónimo