CodeSampleX

샘플

bare-os 3.9.3: getEnvKeys

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

sha256:2917be43e7d8198e12b8ad5deda7fc9e4f1ff7d6fb09bdc016ef8a8ed9ea3345

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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 getEnvKeys in pkg:npm/bare-os@3.9.3
패키지
심벌
  • getEnvKeys
생성일
2026-08-27T06:31:32Z

컨트랙트

  1. package manifest specifies bare-os 3.9.3 with Bare addon configuration and exports root entrypoint index.js with index.d.ts type declarations
  2. index.d.ts declares getEnvKeys returning string array and companion getEnv, hasEnv, setEnv, and unsetEnv functions
  3. binding.c implements bare_os_get_env_keys calling uv_os_environ and returning UTF-8 string array of environment variable keys
  4. index.js exports getEnvKeys delegating to binding.getEnvKeys and enforces string validation on environment helper arguments
  5. getEnvKeys returns array of environment variable keys and reflects setEnv and unsetEnv lifecycle operations

파일

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

소스 아티팩트 내려받기 (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 getEnvKeys 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:
  - getEnvKeys

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:d9c724e7f14e8a223cef410a4939812d359904c6cf8d0a62945916489f3a4b75","contract":["package manifest specifies bare-os 3.9.3 with Bare addon configuration and exports root entrypoint index.js with index.d.ts type declarations","index.d.ts declares getEnvKeys returning string array and companion getEnv, hasEnv, setEnv, and unsetEnv functions","binding.c implements bare_os_get_env_keys calling uv_os_environ and returning UTF-8 string array of environment variable keys","index.js exports getEnvKeys delegating to binding.getEnvKeys and enforces string validation on environment helper arguments","getEnvKeys returns array of environment variable keys and reflects setEnv and unsetEnv lifecycle operations"],"goal":"verify getEnvKeys in pkg:npm/bare-os@3.9.3","kind":"HOW","packages":["pkg:npm/bare-os@3.9.3"],"schemaVersion":1,"symbols":["getEnvKeys"]},"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":["getEnvKeys"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-os-getenvkeys",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-os-getenvkeys",
      "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-getenvkeys",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-os": "3.9.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify getEnvKeys in pkg:npm/bare-os@3.9.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-os@3.9.3"
  ],
  "symbols": [
    "getEnvKeys"
  ]
}
test/contract.mjs
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. Package manifest verification for bare-os@3.9.3
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 Bare addon');
assert.equal(pkg.engines?.bare, '>=1.14.0', 'Package must specify Bare engine requirement');

assert.ok(pkg.exports, 'Package must define exports map');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must specify ./index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must specify ./index.js default');

const pkgDir = path.dirname(pkgPath);

// 2. TypeScript declaration inspection for getEnvKeys and environment APIs
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');

assert.ok(indexDts.includes('export function getEnvKeys(): string[]'), 'index.d.ts must declare getEnvKeys(): string[]');
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');

// 3. Native C binding inspection
const bindingCPath = path.join(pkgDir, 'binding.c');
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist in package root');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');

assert.ok(bindingC.includes('bare_os_get_env_keys'), 'binding.c must define bare_os_get_env_keys');
assert.ok(bindingC.includes('uv_os_environ'), 'binding.c must call uv_os_environ for retrieving environment keys');
assert.ok(bindingC.includes('uv_os_free_environ'), 'binding.c must call uv_os_free_environ to release environment buffer');
assert.ok(bindingC.includes('js_create_array_with_length'), 'binding.c must construct array for environment keys');
assert.ok(bindingC.includes('V("getEnvKeys", bare_os_get_env_keys)'), 'binding.c must register getEnvKeys export');

// 4. Module source inspection (index.js)
const indexJs = fs.readFileSync(path.join(pkgDir, 'index.js'), 'utf8');
assert.ok(indexJs.includes('exports.getEnvKeys = function getEnvKeys()'), 'index.js must export getEnvKeys');
assert.ok(indexJs.includes('return binding.getEnvKeys()'), 'index.js getEnvKeys must delegate to binding');
assert.ok(indexJs.includes("validateString(name, 'Name')"), 'index.js must validate name argument as string');
assert.ok(indexJs.includes("validateString(value, 'Value')"), 'index.js must validate value argument as string');

// 5. Runtime binding execution and environment key lifecycle
const bindingPath = path.join(pkgDir, 'binding.js');
const envStore = new Map([
  ['NODE_ENV', 'test'],
  ['SAMPLE_ENV_A', 'sample_val_a'],
  ['SAMPLE_ENV_B', 'sample_val_b']
]);

require.cache[bindingPath] = {
  id: bindingPath,
  filename: bindingPath,
  loaded: true,
  exports: {
    getEnvKeys: () => Array.from(envStore.keys()),
    getEnv: (name) => envStore.get(name),
    hasEnv: (name) => envStore.has(name),
    setEnv: (name, value) => { envStore.set(name, value); },
    unsetEnv: (name) => { envStore.delete(name); }
  }
};

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

assert.equal(typeof bareOs.getEnvKeys, 'function', 'bare-os must export getEnvKeys function');

// Verify initial keys
const initialKeys = bareOs.getEnvKeys();
assert.ok(Array.isArray(initialKeys), 'getEnvKeys() must return an Array');
assert.equal(initialKeys.length, 3, 'initial keys length must match store');
assert.ok(initialKeys.includes('NODE_ENV'), 'getEnvKeys must include NODE_ENV');
assert.ok(initialKeys.includes('SAMPLE_ENV_A'), 'getEnvKeys must include SAMPLE_ENV_A');
assert.ok(initialKeys.includes('SAMPLE_ENV_B'), 'getEnvKeys must include SAMPLE_ENV_B');

// Verify setEnv lifecycle updates getEnvKeys
const testKey = 'CSX_SAMPLE_KEY';
const testValue = 'csx_sample_value_123';
assert.equal(bareOs.hasEnv(testKey), false, 'hasEnv must be false before setEnv');
assert.equal(bareOs.getEnv(testKey), undefined, 'getEnv must return undefined before setEnv');
assert.ok(!bareOs.getEnvKeys().includes(testKey), 'getEnvKeys must not contain key before setEnv');

bareOs.setEnv(testKey, testValue);
assert.equal(bareOs.hasEnv(testKey), true, 'hasEnv must be true after setEnv');
assert.equal(bareOs.getEnv(testKey), testValue, 'getEnv must return stored value after setEnv');
const keysAfterSet = bareOs.getEnvKeys();
assert.ok(keysAfterSet.includes(testKey), 'getEnvKeys must contain key after setEnv');
assert.equal(keysAfterSet.length, 4, 'keys count must increase by 1');

// Verify unsetEnv lifecycle updates getEnvKeys
bareOs.unsetEnv(testKey);
assert.equal(bareOs.hasEnv(testKey), false, 'hasEnv must be false after unsetEnv');
assert.equal(bareOs.getEnv(testKey), undefined, 'getEnv must return undefined after unsetEnv');
const keysAfterUnset = bareOs.getEnvKeys();
assert.ok(!keysAfterUnset.includes(testKey), 'getEnvKeys must not contain key after unsetEnv');
assert.equal(keysAfterUnset.length, 3, 'keys count must return to original');

// Verify argument validation in helper functions
assert.throws(() => bareOs.getEnv(123), TypeError, 'getEnv with non-string must throw TypeError');
assert.throws(() => bareOs.hasEnv(null), TypeError, 'hasEnv with non-string must throw TypeError');
assert.throws(() => bareOs.setEnv('KEY', 456), TypeError, 'setEnv with non-string value must throw TypeError');
assert.throws(() => bareOs.setEnv(false, 'VAL'), TypeError, 'setEnv with non-string key must throw TypeError');
assert.throws(() => bareOs.unsetEnv({}), TypeError, 'unsetEnv with non-string key must throw TypeError');

console.log('Contract tests passed successfully.');

오리진 시더

익명