サンプル
bare-os 3.9.3: getEnv
検証済みサンプル — npm bare-os 3.9.3: getEnv. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: package manifest specifies Bare addon configuration, Bare…
sha256:1939b719640cd1f76206c729fc1445f4aac609b1671dbb91ee8021ccb0ffbb7f
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。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 getEnv in pkg:npm/bare-os@3.9.3
- パッケージ
- シンボル
-
- getEnv
- 環境
- node 22.23.2
- 作成日
- 2026-08-27T09:40:55Z
コントラクト
- package manifest specifies Bare addon configuration, Bare engine requirement, and exports root and subpaths for bare-os@3.9.3
- declares getEnv, hasEnv, setEnv, unsetEnv, and getEnvKeys in index.d.ts
- binding.c implements bare_os_get_env via uv_os_getenv and exports getEnv
- getEnv returns string value for existing environment variable and undefined for missing variable
- getEnv validates name argument throwing TypeError when non-string value is provided
- setEnv and unsetEnv update environment state reflected in getEnv, hasEnv, and getEnvKeys with argument validation
ファイル
- PROMPT.md
- csx.json
- index.js
- 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 getEnv 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:
- getEnv
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.
{"case":{"caseId":"case:sha256:f2072d8ad0d64e78240de7d49d85145bf84fa4a3195bad702eb47c52266ab14d","constraints":{"executionContext":"node"},"contract":["package manifest specifies Bare addon configuration, Bare engine requirement, and exports root and subpaths for bare-os@3.9.3","declares getEnv, hasEnv, setEnv, unsetEnv, and getEnvKeys in index.d.ts","binding.c implements bare_os_get_env via uv_os_getenv and exports getEnv","getEnv returns string value for existing environment variable and undefined for missing variable","getEnv validates name argument throwing TypeError when non-string value is provided","setEnv and unsetEnv update environment state reflected in getEnv, hasEnv, and getEnvKeys with argument validation"],"goal":"verify getEnv in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["getEnv"]},"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-os@3.9.3"],"schemaVersion":1,"subject":"pkg:npm/bare-os@3.9.3","symbols":["getEnv"],"verifierAdapter":"node-typescript@1"}
const path = require('node:path');
// Ensure native binding is provided in Node.js environments where require.addon is absent
if (typeof Bare === 'undefined') {
const envMap = new Map();
if (typeof process !== 'undefined' && process.env) {
for (const [k, v] of Object.entries(process.env)) {
envMap.set(k, v);
}
}
const mockBinding = {
platform: process.platform,
arch: process.arch,
getEnv(name) {
return envMap.get(name);
},
hasEnv(name) {
return envMap.has(name);
},
setEnv(name, value) {
envMap.set(name, value);
},
unsetEnv(name) {
envMap.delete(name);
},
getEnvKeys() {
return Array.from(envMap.keys());
}
};
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
};
}
const os = require('bare-os');
function getEnv(name) {
return os.getEnv(name);
}
function hasEnv(name) {
return os.hasEnv(name);
}
function setEnv(name, value) {
os.setEnv(name, value);
}
function unsetEnv(name) {
os.unsetEnv(name);
}
function getEnvKeys() {
return os.getEnvKeys();
}
module.exports = {
...os,
getEnv,
hasEnv,
setEnv,
unsetEnv,
getEnvKeys
};
{
"name": "sample-bare-os-getenv",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-os-getenv",
"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-getenv",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"dependencies": {
"bare-os": "3.9.3"
}
}
{
"schemaVersion": 1,
"goal": "verify getEnv in pkg:npm/bare-os@3.9.3",
"kind": "HOW",
"packages": [
"pkg:npm/bare-os@3.9.3"
],
"symbols": [
"getEnv"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import Module from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
const require = Module.createRequire(import.meta.url);
// 1. Resolve bare-os package manifest and metadata
const pkgPath = require.resolve('bare-os/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const pkgDir = path.dirname(pkgPath);
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');
// 2. Verify TypeScript declarations for getEnv and env operations
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
assert.ok(indexDts.includes('export function getEnv(name: string): string | undefined'), 'index.d.ts must declare getEnv');
assert.ok(indexDts.includes('export function hasEnv(name: string): boolean'), 'index.d.ts must declare hasEnv');
assert.ok(indexDts.includes('export function setEnv(name: string, value: string): void'), 'index.d.ts must declare setEnv');
assert.ok(indexDts.includes('export function unsetEnv(name: string): void'), 'index.d.ts must declare unsetEnv');
assert.ok(indexDts.includes('export function getEnvKeys(): string[]'), 'index.d.ts must declare getEnvKeys');
// 3. Verify C native addon source and build configuration
const bindingC = fs.readFileSync(path.join(pkgDir, 'binding.c'), 'utf8');
assert.ok(bindingC.includes('bare_os_get_env'), 'binding.c must implement bare_os_get_env');
assert.ok(bindingC.includes('uv_os_getenv('), 'binding.c must invoke uv_os_getenv');
assert.ok(bindingC.includes('V("getEnv", bare_os_get_env)'), 'binding.c must export getEnv function');
assert.ok(bindingC.includes('V("hasEnv", bare_os_has_env)'), 'binding.c must export hasEnv function');
assert.ok(bindingC.includes('V("setEnv", bare_os_set_env)'), 'binding.c must export setEnv function');
assert.ok(bindingC.includes('V("unsetEnv", bare_os_unset_env)'), 'binding.c must export unsetEnv function');
assert.ok(bindingC.includes('V("getEnvKeys", bare_os_get_env_keys)'), 'binding.c must export getEnvKeys function');
// 4. Verify JS wrapper execution and argument validation with mocked binding
const envStore = new Map([
['EXISTING_VAR', 'sample_value_123'],
['EMPTY_VAR', '']
]);
const mockBinding = {
getEnv(name) {
return envStore.get(name);
},
hasEnv(name) {
return envStore.has(name);
},
setEnv(name, value) {
envStore.set(name, value);
},
unsetEnv(name) {
envStore.delete(name);
},
getEnvKeys() {
return Array.from(envStore.keys());
}
};
const bindingPath = path.join(pkgDir, 'binding.js');
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: mockBinding
};
const bareOs = require('bare-os');
assert.equal(typeof bareOs.getEnv, 'function', 'bare-os must export getEnv function');
assert.equal(typeof bareOs.hasEnv, 'function', 'bare-os must export hasEnv function');
assert.equal(typeof bareOs.setEnv, 'function', 'bare-os must export setEnv function');
assert.equal(typeof bareOs.unsetEnv, 'function', 'bare-os must export unsetEnv function');
assert.equal(typeof bareOs.getEnvKeys, 'function', 'bare-os must export getEnvKeys function');
// Test getEnv retrieval of existing vs missing variables
assert.equal(bareOs.getEnv('EXISTING_VAR'), 'sample_value_123', 'getEnv must return correct value for existing var');
assert.equal(bareOs.getEnv('EMPTY_VAR'), '', 'getEnv must return empty string for empty var');
assert.equal(bareOs.getEnv('NON_EXISTENT_VAR'), undefined, 'getEnv must return undefined for non-existent var');
// Test getEnv argument validation
assert.throws(() => bareOs.getEnv(123), {
name: 'TypeError',
message: 'Name must be a string. Received type number (123)'
}, 'getEnv must reject number');
assert.throws(() => bareOs.getEnv(null), {
name: 'TypeError',
message: 'Name must be a string. Received type object (null)'
}, 'getEnv must reject null');
assert.throws(() => bareOs.getEnv(undefined), {
name: 'TypeError',
message: 'Name must be a string. Received type undefined (undefined)'
}, 'getEnv must reject undefined');
assert.throws(() => bareOs.getEnv({}), {
name: 'TypeError',
message: 'Name must be a string. Received type object ([object Object])'
}, 'getEnv must reject object');
// Test hasEnv, setEnv, unsetEnv, getEnvKeys interactions
assert.equal(bareOs.hasEnv('EXISTING_VAR'), true, 'hasEnv must return true for existing var');
assert.equal(bareOs.hasEnv('NON_EXISTENT_VAR'), false, 'hasEnv must return false for missing var');
bareOs.setEnv('DYNAMIC_VAR', 'dynamic_val');
assert.equal(bareOs.getEnv('DYNAMIC_VAR'), 'dynamic_val', 'getEnv must return updated value after setEnv');
assert.equal(bareOs.hasEnv('DYNAMIC_VAR'), true, 'hasEnv must return true after setEnv');
assert.ok(bareOs.getEnvKeys().includes('DYNAMIC_VAR'), 'getEnvKeys must include newly set variable');
bareOs.unsetEnv('DYNAMIC_VAR');
assert.equal(bareOs.getEnv('DYNAMIC_VAR'), undefined, 'getEnv must return undefined after unsetEnv');
assert.equal(bareOs.hasEnv('DYNAMIC_VAR'), false, 'hasEnv must return false after unsetEnv');
assert.ok(!bareOs.getEnvKeys().includes('DYNAMIC_VAR'), 'getEnvKeys must not include unset variable');
// Test argument validation on setEnv and unsetEnv
assert.throws(() => bareOs.setEnv(123, 'val'), {
name: 'TypeError',
message: 'Name must be a string. Received type number (123)'
});
assert.throws(() => bareOs.setEnv('name', 456), {
name: 'TypeError',
message: 'Value must be a string. Received type number (456)'
});
assert.throws(() => bareOs.unsetEnv(123), {
name: 'TypeError',
message: 'Name must be a string. Received type number (123)'
});
console.log('Contract tests passed successfully.');
オリジンシーダー
匿名