CodeSampleX

샘플

bare-os 3.9.3: arch

검증된 샘플 — npm bare-os 3.9.3: arch. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: bare-os package manifest specifies package metadata, engine…

sha256:b62ac1278fed6a1681ab80184bddd00a22d732e7101bdc1611d9fdee57bcfb46

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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');

오리진 시더

익명