CodeSampleX

Beispiel

bare-os 3.9.3: availableParallelism

Verifiziertes Beispiel für npm bare-os 3.9.3: availableParallelism. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:54e4e5664e6677642c2f6f924a108d729c60d4717d3108a915d7efe61657a30a

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-30

Fall

HOW
Ziel
verify bare-os.availableParallelism in pkg:npm/bare-os@3.9.3
Pakete
Symbole
  • bare-os.availableParallelism
Erstellt
2026-08-30T13:20:45Z

Contract

  1. bare-os package manifest exports root module with availableParallelism API and index.d.ts type declarations
  2. index.d.ts declares availableParallelism function returning number representing logical CPU parallelism
  3. index.js exports availableParallelism function that delegates to native binding availableParallelism
  4. bare_os_available_parallelism in binding.c invokes uv_available_parallelism and returns uint32 to JavaScript
  5. registers availableParallelism symbol in addon native exports definition table
  6. availableParallelism returns a positive integer greater than or equal to 1
  7. availableParallelism executes deterministically and idempotently across multiple invocations
  8. custom parallelism levels configured on native binding reflect accurately through availableParallelism

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 bare-os.availableParallelism in pkg:npm/bare-os@3.9.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-os@3.9.3
Demonstrate these symbols/APIs:
  - bare-os.availableParallelism

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:cf0382249b0f9ba97e4819bf07ab700dda4b68642cb23e821b1add0c6e960d98","contract":["bare-os package manifest exports root module with availableParallelism API and index.d.ts type declarations","index.d.ts declares availableParallelism function returning number representing logical CPU parallelism","index.js exports availableParallelism function that delegates to native binding availableParallelism","bare_os_available_parallelism in binding.c invokes uv_available_parallelism and returns uint32 to JavaScript","registers availableParallelism symbol in addon native exports definition table","availableParallelism returns a positive integer greater than or equal to 1","availableParallelism executes deterministically and idempotently across multiple invocations","custom parallelism levels configured on native binding reflect accurately through availableParallelism"],"goal":"verify bare-os.availableParallelism in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["bare-os.availableParallelism"]},"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-os@3.9.3"],"schemaVersion":1,"subject":"pkg:npm/bare-os@3.9.3","symbols":["bare-os.availableParallelism"],"verifierAdapter":"node-typescript@1"}
index.js
import { createRequire } from 'node:module';
import path from 'node:path';
import nodeOS from 'node:os';

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

// Ensure native binding is provided in Node.js environments where require.addon is absent
if (typeof Bare === 'undefined') {
  const mockBinding = {
    platform: process.platform,
    arch: process.arch,
    type() { return nodeOS.type(); },
    version() { return nodeOS.version ? nodeOS.version() : nodeOS.release(); },
    release() { return nodeOS.release(); },
    machine() { return nodeOS.machine ? nodeOS.machine() : process.arch; },
    execPath() { return process.execPath; },
    pid() { return process.pid; },
    ppid() { return process.ppid; },
    cwd() { return process.cwd(); },
    chdir(dir) { process.chdir(dir); },
    tmpdir() { return nodeOS.tmpdir(); },
    homedir() { return nodeOS.homedir(); },
    hostname() { return nodeOS.hostname(); },
    userInfo(uid) { return nodeOS.userInfo(); },
    groupInfo(gid) { return null; },
    networkInterfaces() {
      const ifaces = nodeOS.networkInterfaces();
      const result = [];
      for (const [name, addrs] of Object.entries(ifaces)) {
        if (addrs) {
          for (const addr of addrs) {
            result.push({ name, ...addr });
          }
        }
      }
      return result;
    },
    kill(pid, sig) { process.kill(pid, sig); },
    isLittleEndian: nodeOS.endianness() === 'LE',
    availableParallelism() { return nodeOS.availableParallelism ? nodeOS.availableParallelism() : nodeOS.cpus().length; },
    cpuUsage() { return process.cpuUsage(); },
    threadCpuUsage() { return process.cpuUsage(); },
    resourceUsage() { return process.resourceUsage ? process.resourceUsage() : {}; },
    memoryUsage() { return process.memoryUsage(); },
    freemem() { return nodeOS.freemem(); },
    totalmem() { return nodeOS.totalmem(); },
    availableMemory() { return typeof nodeOS.freemem === 'function' ? nodeOS.freemem() : 0; },
    constrainedMemory() { return 0; },
    uptime() { return nodeOS.uptime(); },
    loadavg() { return nodeOS.loadavg(); },
    cpus() { return nodeOS.cpus(); },
    getProcessTitle() { return process.title; },
    setProcessTitle(t) { process.title = t; },
    getPriority(pid) { return nodeOS.getPriority ? nodeOS.getPriority(pid) : 0; },
    setPriority(pid, p) { if (nodeOS.setPriority) nodeOS.setPriority(pid, p); },
    getEnvKeys() { return Object.keys(process.env); },
    getEnv(n) { return process.env[n]; },
    hasEnv(n) { return Object.prototype.hasOwnProperty.call(process.env, n); },
    setEnv(n, v) { process.env[n] = v; },
    unsetEnv(n) { delete process.env[n]; }
  };

  try {
    const mainPath = require.resolve('bare-os');
    const bindingPath = path.join(path.dirname(mainPath), 'binding.js');
    require.cache[bindingPath] = {
      id: bindingPath,
      filename: bindingPath,
      loaded: true,
      exports: mockBinding
    };
  } catch (err) {
    // node_modules might not be resolved if uninstalled
  }
}

const os = require('bare-os');

/**
 * Returns the number of logical CPU cores available for parallel execution.
 * @returns {number}
 */
export function getAvailableParallelism() {
  return os.availableParallelism();
}

/**
 * Validates that available parallelism is a positive integer.
 * @returns {boolean}
 */
export function hasValidParallelism() {
  const count = os.availableParallelism();
  return typeof count === 'number' && Number.isInteger(count) && count > 0;
}

export default os;
package-lock.json
{
  "name": "sample-bare-os-available-parallelism",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-os-available-parallelism",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-os": "3.9.3"
      }
    },
    "node_modules/bare-os": {
      "version": "3.9.3",
      "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.9.3.tgz",
      "integrity": "sha512-fF4Q7QsyKVF5Rj0qvI8BgUNjqzC2JvQlpTaPLjVJVxYVUX5Zr9un+y3w1HmA4nNKdFmRBT8z/WmrjvXzXVerKQ==",
      "license": "Apache-2.0",
      "engines": {
        "bare": ">=1.14.0"
      }
    }
  }
}
package.json
{
  "name": "sample-bare-os-available-parallelism",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-os": "3.9.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-os.availableParallelism in pkg:npm/bare-os@3.9.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-os@3.9.3"
  ],
  "symbols": [
    "bare-os.availableParallelism"
  ]
}
test/contract.mjs
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
import os, { getAvailableParallelism, hasValidParallelism } from "../index.js";

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

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

assert.equal(pkg.name, "bare-os", "Package name must be bare-os");
assert.equal(pkg.version, "3.9.3", "Package version must be 3.9.3");
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.equal(pkg.engines?.bare, ">=1.14.0", "Package must specify Bare engine >=1.14.0");

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["./constants"]?.types, "./lib/constants.d.ts", "Constants export must have constants.d.ts types");
assert.equal(pkg.exports["./constants"]?.default, "./lib/constants.js", "Constants export must have constants.js default");
assert.equal(pkg.exports["./errors"]?.types, "./lib/errors.d.ts", "Errors export must have errors.d.ts types");
assert.equal(pkg.exports["./errors"]?.default, "./lib/errors.js", "Errors export must have errors.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 bindingC = fs.readFileSync(path.join(pkgDir, "binding.c"), "utf8");

// 2. Verify availableParallelism symbol declarations in TypeScript definition
assert.ok(
  indexDts.includes("export function availableParallelism(): number"),
  "index.d.ts must declare export function availableParallelism(): number"
);

// 3. Verify availableParallelism implementation in JavaScript module
assert.ok(
  indexJs.includes("exports.availableParallelism = function availableParallelism"),
  "index.js must export availableParallelism function"
);
assert.ok(
  indexJs.includes("return binding.availableParallelism()"),
  "availableParallelism function must delegate to binding.availableParallelism()"
);

// 4. Verify C binding implementation and uv_available_parallelism call
assert.ok(
  bindingC.includes("bare_os_available_parallelism"),
  "binding.c must implement bare_os_available_parallelism"
);
assert.ok(
  bindingC.includes("uv_available_parallelism()"),
  "bare_os_available_parallelism must invoke uv_available_parallelism()"
);

// 5. Verify availableParallelism symbol registration in addon exports table
assert.ok(
  bindingC.includes("V(\"availableParallelism\", bare_os_available_parallelism)"),
  "binding.c must register availableParallelism export"
);

// 6. Verify availableParallelism return value and types
assert.equal(typeof os.availableParallelism, "function", "bare-os must export availableParallelism function");
const parallelism = os.availableParallelism();
assert.equal(typeof parallelism, "number", "availableParallelism() must return a number");
assert.ok(Number.isInteger(parallelism), "availableParallelism() must return an integer");
assert.ok(parallelism >= 1, "availableParallelism() must return a positive integer >= 1");

// Helper function tests
assert.equal(getAvailableParallelism(), parallelism, "getAvailableParallelism() must match os.availableParallelism()");
assert.equal(hasValidParallelism(), true, "hasValidParallelism() must return true");

// 7. Verify deterministic and idempotent execution across multiple calls
const firstCall = os.availableParallelism();
const secondCall = os.availableParallelism();
const thirdCall = os.availableParallelism();
assert.equal(firstCall, secondCall, "repeated calls to availableParallelism must return identical values");
assert.equal(secondCall, thirdCall, "repeated calls to availableParallelism must remain stable");

// 8. Verify custom binding parallelism values reflect through API
const bindingFilePath = path.join(pkgDir, "binding.js");
const testValues = [1, 2, 4, 8, 16, 32, 64, 128];
for (const val of testValues) {
  require.cache[bindingFilePath].exports.availableParallelism = () => val;
  assert.equal(os.availableParallelism(), val, `availableParallelism() must return ${val}`);
}

console.log("Contract verification finished successfully.");

Ursprungs-Seeder

anonym