CodeSampleX

示例

bare-os 3.9.3: arch

已验证示例 — npm bare-os 3.9.3: arch. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: bare-os package manifest specifies package metadata, engine…

sha256:b62ac1278fed6a1681ab80184bddd00a22d732e7101bdc1611d9fdee57bcfb46

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify arch in pkg:npm/bare-os@3.9.3
包
符号
  • arch
环境
node 22.23.2
创建时间
2026-08-27T09:30:38Z

契约

  1. bare-os package manifest specifies package metadata, engine requirements, and exports mapping
  2. index.d.ts declares arch function returning supported CPU architecture union type
  3. index.js exports arch function delegating to native binding arch property
  4. bare_os_exports in binding.c defines arch property using BARE_ARCH compile-time constant
  5. bare-os.arch returns architecture string from addon binding and matches platform arch
  6. bare-os.arch returns expected architecture when configured with custom binding mock
  7. getArch helper retrieves architecture string matching bare-os.arch
  8. bare-os.arch executes deterministically across multiple invocations

文件

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

下载源代码构件 (tar.gz)

源代码

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 arch 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:
  - arch
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:d8bc9d56a8543600b8027477e23af71e6472fe85ca3cae22fecbad720fc25da2","constraints":{"executionContext":"node"},"contract":["bare-os package manifest specifies package metadata, engine requirements, and exports mapping","index.d.ts declares arch function returning supported CPU architecture union type","index.js exports arch function delegating to native binding arch property","bare_os_exports in binding.c defines arch property using BARE_ARCH compile-time constant","bare-os.arch returns architecture string from addon binding and matches platform arch","bare-os.arch returns expected architecture when configured with custom binding mock","getArch helper retrieves architecture string matching bare-os.arch","bare-os.arch executes deterministically across multiple invocations"],"goal":"verify arch in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["arch"]},"contractCommand":["node","test/contract.js"],"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-os@3.9.3"],"schemaVersion":1,"subject":"pkg:npm/bare-os@3.9.3","symbols":["arch"],"verifierAdapter":"node-typescript@1"}
index.js
const path = require('node:path');
const nodeOS = require('node:os');

/**
 * Initializes and loads the bare-os module with an underlying binding.
 * @param {object} [bindingMock] - Optional custom binding implementation.
 * @returns {object} The loaded bare-os module.
 */
function loadBareOS(bindingMock) {
  const pkgPath = require.resolve('bare-os/package');
  const bindingPath = path.join(path.dirname(pkgPath), 'binding.js');

  if (!require.cache[bindingPath] || bindingMock) {
    require.cache[bindingPath] = {
      id: bindingPath,
      filename: bindingPath,
      loaded: true,
      exports: bindingMock || {
        platform: process.platform,
        arch: process.arch,
        type: () => nodeOS.type(),
        version: () => (typeof nodeOS.version === 'function' ? nodeOS.version() : nodeOS.release()),
        release: () => nodeOS.release(),
        machine: () => (typeof nodeOS.machine === 'function' ? nodeOS.machine() : process.arch),
        isLittleEndian: nodeOS.endianness() === 'LE'
      }
    };
  }

  if (bindingMock) {
    const mainPath = require.resolve('bare-os');
    delete require.cache[mainPath];
  }

  return require('bare-os');
}

/**
 * Retrieves the CPU architecture string using bare-os arch().
 * @returns {string} The CPU architecture string ('arm' | 'arm64' | 'ia32' | 'x64').
 */
function getArch() {
  const os = loadBareOS();
  return os.arch();
}

module.exports = {
  loadBareOS,
  getArch
};
package-lock.json
{
  "name": "sample-bare-os-arch",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-os-arch",
      "version": "1.0.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-arch",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "bare-os": "3.9.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify arch in pkg:npm/bare-os@3.9.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-os@3.9.3"
  ],
  "symbols": [
    "arch"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { loadBareOS, getArch } = require('../index.js');

// 1. Resolve package manifest and verify package structure
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.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 indexDtsPath = path.join(pkgDir, 'index.d.ts');
const indexJsPath = path.join(pkgDir, 'index.js');
const bindingCPath = path.join(pkgDir, 'binding.c');

// 2. Verify arch type declaration in index.d.ts
assert.ok(fs.existsSync(indexDtsPath), 'index.d.ts must exist');
const indexDts = fs.readFileSync(indexDtsPath, 'utf8');
assert.match(
  indexDts,
  /export\s+function\s+arch\(\)\s*:\s*'arm'\s*\|\s*'arm64'\s*\|\s*'ia32'\s*\|\s*'x64'/,
  "index.d.ts must declare export function arch(): 'arm' | 'arm64' | 'ia32' | 'x64'"
);

// 3. Verify arch export in index.js
assert.ok(fs.existsSync(indexJsPath), 'index.js must exist');
const indexJs = fs.readFileSync(indexJsPath, 'utf8');
assert.match(
  indexJs,
  /exports\.arch\s*=\s*function\s+arch\s*\(\)\s*\{\s*return\s+binding\.arch\s*\}/,
  'index.js must define arch delegating to binding.arch'
);

// 4. Verify native C binding definition in binding.c
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');
assert.ok(
  bindingC.includes('V("arch", BARE_ARCH)'),
  'binding.c must export arch string property defined by BARE_ARCH'
);

// 5. Verify default binding loading and runtime arch() execution
const bareOs = loadBareOS();
assert.equal(typeof bareOs.arch, 'function', 'bare-os.arch must be a function');
const defaultArch = bareOs.arch();
assert.equal(typeof defaultArch, 'string', 'bare-os.arch() must return a string');
assert.ok(['arm', 'arm64', 'ia32', 'x64'].includes(defaultArch), `arch must be a recognized architecture string, got ${defaultArch}`);
assert.equal(defaultArch, process.arch, 'default binding arch must match process.arch');

// 6. Verify arch with custom binding mocks (e.g. arm64, ia32)
const arm64Mock = {
  platform: 'linux',
  arch: 'arm64'
};
const arm64OS = loadBareOS(arm64Mock);
assert.equal(arm64OS.arch(), 'arm64', 'bare-os.arch() must return arm64 when configured with arm64 binding');

const x64Mock = {
  platform: 'linux',
  arch: 'x64'
};
const x64OS = loadBareOS(x64Mock);
assert.equal(x64OS.arch(), 'x64', 'bare-os.arch() must return x64 when configured with x64 binding');

// 7. Verify getArch helper matches bare-os.arch()
const helperArch = getArch();
assert.equal(helperArch, x64OS.arch(), 'getArch helper must return current bare-os arch() value');

// 8. Verify idempotency and deterministic returns across repeated calls
const firstCall = x64OS.arch();
const secondCall = x64OS.arch();
const thirdCall = x64OS.arch();
assert.equal(firstCall, secondCall, 'repeated calls to arch() must return identical values');
assert.equal(secondCall, thirdCall, 'repeated calls to arch() must remain stable');

console.log('Contract passed: arch in pkg:npm/bare-os@3.9.3 successfully verified');

原始种子者

匿名