CodeSampleX

Exemplo

bare-hrtime 2.1.1: hrtime, hrtime.bigint

Amostra verificada para npm bare-hrtime 2.1.1: hrtime, hrtime.bigint. O contrato rodou em node 22 · linux alpine/x64 · docker e passou.

sha256:a291e096b3782d3028b6e755dbb63774b53e57cba58f94a9d4a6159e8a9d07e8

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-27

Caso

HOW
Objetivo
verify pkg:npm/bare-hrtime@2.1.1
Pacotes
Símbolos
  • hrtime
  • hrtime.bigint
Ambiente
node 22.23.2
Criado
2026-08-27T14:19:47Z

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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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
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:df7d8b1a0d94523e1a670ff31b6d329beab9d4cf140ba15743559813f9d3b913","constraints":{"executionContext":"node"},"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","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/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,
  "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"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
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 origem

anônimo