サンプル
bare-os 3.9.3: threadCpuUsage
検証済みサンプル — npm bare-os 3.9.3: threadCpuUsage. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: package manifest specifies bare-os name, version…
sha256:0c89ae0c3ca51716e63364b5e5389b7974fe2c34cba93727ffc38349ee885053
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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 threadCpuUsage in pkg:npm/bare-os@3.9.3
- パッケージ
- シンボル
-
- threadCpuUsage
- 環境
- node 22.23.2
- 作成日
- 2026-08-27T09:08:11Z
コントラクト
- package manifest specifies bare-os name, version 3.9.3, addon configuration, and Bare engine requirement
- declares CpuUsage interface and threadCpuUsage function accepting optional previous CpuUsage in index.d.ts
- native binding implements bare_os_cpu_usage_thread querying thread CPU times with uv_getrusage_thread
- threadCpuUsage() returns current thread user and system CPU times in microseconds
- threadCpuUsage(previous) calculates diff between current and previous user and system CPU times
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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 threadCpuUsage 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:
- threadCpuUsage
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: esm
- 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.
{"case":{"caseId":"case:sha256:11533e314de3e860fd4e1b83d5a7df56bae30f7e20233d67524b970639a78e0f","constraints":{"executionContext":"node"},"contract":["package manifest specifies bare-os name, version 3.9.3, addon configuration, and Bare engine requirement","declares CpuUsage interface and threadCpuUsage function accepting optional previous CpuUsage in index.d.ts","native binding implements bare_os_cpu_usage_thread querying thread CPU times with uv_getrusage_thread","threadCpuUsage() returns current thread user and system CPU times in microseconds","threadCpuUsage(previous) calculates diff between current and previous user and system CPU times"],"goal":"verify threadCpuUsage in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["threadCpuUsage"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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":["threadCpuUsage"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-bare-os-thread-cpu-usage",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-os-thread-cpu-usage",
"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"
}
}
}
}
{
"name": "sample-bare-os-thread-cpu-usage",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"bare-os": "3.9.3"
}
}
{
"schemaVersion": 1,
"goal": "verify threadCpuUsage in pkg:npm/bare-os@3.9.3",
"kind": "HOW",
"packages": [
"pkg:npm/bare-os@3.9.3"
],
"symbols": [
"threadCpuUsage"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "esm",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
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. Verify package manifest and exports
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.addon, true, 'Package must be marked as addon');
assert.equal(pkg.engines?.bare, '>=1.14.0', 'Package must specify Bare engine >=1.14.0');
const pkgDir = path.dirname(pkgPath);
// 2. Verify TypeScript type definitions for threadCpuUsage
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
assert.ok(
indexDts.includes('export interface CpuUsage {\n user: number\n system: number\n}'),
'index.d.ts must declare CpuUsage interface with user and system properties'
);
assert.ok(
indexDts.includes('export function threadCpuUsage(previous?: CpuUsage): CpuUsage'),
'index.d.ts must declare threadCpuUsage function accepting optional previous CpuUsage'
);
// 3. Verify C native binding implementation for threadCpuUsage
const bindingC = fs.readFileSync(path.join(pkgDir, 'binding.c'), 'utf8');
assert.ok(
bindingC.includes('bare_os_cpu_usage_thread(js_env_t *env, js_callback_info_t *info)'),
'binding.c must implement bare_os_cpu_usage_thread'
);
assert.ok(
bindingC.includes('uv_getrusage_thread(&usage)'),
'binding.c must query thread resource usage via uv_getrusage_thread'
);
assert.ok(
bindingC.includes('V("threadCpuUsage", bare_os_cpu_usage_thread)'),
'binding.c must export threadCpuUsage function'
);
// 4. Verify runtime behavior of threadCpuUsage function
const bindingPath = path.join(pkgDir, 'binding.js');
let simulatedThreadUsage = { user: 120000, system: 45000 };
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: {
platform: process.platform,
arch: process.arch,
threadCpuUsage: () => ({ ...simulatedThreadUsage })
}
};
const bareOs = require('bare-os');
assert.equal(typeof bareOs.threadCpuUsage, 'function', 'bare-os must export threadCpuUsage function');
// Test 4a: Calling threadCpuUsage() without previous usage returns current thread CPU times
const usage1 = bareOs.threadCpuUsage();
assert.equal(typeof usage1, 'object', 'threadCpuUsage must return an object');
assert.equal(usage1.user, 120000, 'usage.user must match simulated user time in microseconds');
assert.equal(usage1.system, 45000, 'usage.system must match simulated system time in microseconds');
// Test 4b: Calling threadCpuUsage(previous) computes delta
simulatedThreadUsage = { user: 180000, system: 70000 };
const usageDiff = bareOs.threadCpuUsage(usage1);
assert.equal(usageDiff.user, 60000, 'diff.user must be 180000 - 120000 = 60000');
assert.equal(usageDiff.system, 25000, 'diff.system must be 70000 - 45000 = 25000');
// Test 4c: Calling threadCpuUsage with zero previous
const usageDiffZero = bareOs.threadCpuUsage({ user: 0, system: 0 });
assert.equal(usageDiffZero.user, 180000, 'diff against zero must equal current user time');
assert.equal(usageDiffZero.system, 70000, 'diff against zero must equal current system time');
console.log('Contract tests passed successfully.');
オリジンシーダー
匿名