CodeSampleX

샘플

bare-env 3.0.1: env

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

sha256:33c459bc715c6adbe0e652bb7ab6c9db46766d66f8c352ed06b99595d8f4a3c6

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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 pkg:npm/bare-env@3.0.1
패키지
심벌
  • env
환경
node 22.23.2
생성일
2026-08-27T13:16:32Z

컨트랙트

  1. package manifest specifies Apache-2.0 license, bare-os dependency, and exports for root and package subpaths
  2. declares Env index signature interface and env constant in TypeScript definitions (index.d.ts)
  3. exports a Proxy object delegating environment variable access to bare-os
  4. supports getting, setting, and checking presence of environment variables via property access and the in operator
  5. coerces number and boolean values to strings when setting environment variables
  6. throws an Error when attempting to set non-primitive values such as objects, arrays, functions, or symbols
  7. delegates ownKeys and getOwnPropertyDescriptor traps allowing Object.keys enumeration and descriptor lookup
  8. unsets environment variables on deleteProperty while the trap returns falsish causing Reflect.deleteProperty to evaluate to false

파일

  • 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 pkg:npm/bare-env@3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-env@3.0.1
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:807e74d79db72a2cb5c9595d3a8c03a5fc75a9eae8701bdd9b9fe27a3ecc5cc4","constraints":{"executionContext":"node"},"contract":["package manifest specifies Apache-2.0 license, bare-os dependency, and exports for root and package subpaths","declares Env index signature interface and env constant in TypeScript definitions (index.d.ts)","exports a Proxy object delegating environment variable access to bare-os","supports getting, setting, and checking presence of environment variables via property access and the in operator","coerces number and boolean values to strings when setting environment variables","throws an Error when attempting to set non-primitive values such as objects, arrays, functions, or symbols","delegates ownKeys and getOwnPropertyDescriptor traps allowing Object.keys enumeration and descriptor lookup","unsets environment variables on deleteProperty while the trap returns falsish causing Reflect.deleteProperty to evaluate to false"],"goal":"verify pkg:npm/bare-env@3.0.1","kind":"HOW","packages":["pkg:npm/bare-env@3.0.1"],"schemaVersion":1,"symbols":["env"]},"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-env@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/bare-env@3.0.1","symbols":["env"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-env",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-env",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-env": "3.0.1"
      }
    },
    "node_modules/bare-env": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/bare-env/-/bare-env-3.0.1.tgz",
      "integrity": "sha512-BdoLvnzaWR0YyyJreEx4zG2Od0AC/s9JSZ+EXyMZKunpn8zEgR/dGv37hdFUaY1bjDkcRKvcKkFyJIwlJ0CaYA==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-os": "^3.0.1"
      }
    },
    "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-env",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-env": "3.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-env@3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-env@3.0.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
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. Resolve bare-env package manifest and verify exports and metadata
const pkgPath = require.resolve('bare-env/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-env', 'Package name must be bare-env');
assert.equal(pkg.version, '3.0.1', 'Package version must be 3.0.1');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.deepEqual(pkg.dependencies, { 'bare-os': '^3.0.1' }, 'Package must depend on bare-os ^3.0.1');

assert.ok(pkg.exports, 'Package must define exports');
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');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to ./package.json');

assert.deepEqual(
  pkg.files,
  ['index.js', 'index.d.ts'],
  'Package files array must contain expected source files'
);

const pkgDir = path.dirname(pkgPath);

// 2. Verify TypeScript declarations (index.d.ts)
const indexDtsPath = path.join(pkgDir, 'index.d.ts');
assert.ok(fs.existsSync(indexDtsPath), 'index.d.ts must exist');
const indexDts = fs.readFileSync(indexDtsPath, 'utf8');
assert.ok(indexDts.includes('interface Env'), 'index.d.ts must declare interface Env');
assert.ok(indexDts.includes('[key: string]: string | undefined'), 'index.d.ts must declare string index signature');
assert.ok(indexDts.includes('declare const env: Env'), 'index.d.ts must declare const env');
assert.ok(indexDts.includes('export = env'), 'index.d.ts must export env');

// 3. Verify JavaScript implementation and Proxy traps
const indexJsPath = path.join(pkgDir, 'index.js');
assert.ok(fs.existsSync(indexJsPath), 'index.js must exist');
const indexJsCode = fs.readFileSync(indexJsPath, 'utf8');

assert.ok(indexJsCode.includes("require('bare-os')"), 'index.js must require bare-os');
assert.ok(indexJsCode.includes('new Proxy(Object.create(null)'), 'index.js must instantiate Proxy over null prototype');

// Test Proxy behaviour in isolated environment with bare-os mock
const mockStore = new Map();
const mockBareOs = {
  getEnvKeys: () => Array.from(mockStore.keys()),
  getEnv: (name) => mockStore.get(name),
  hasEnv: (name) => mockStore.has(name),
  setEnv: (name, val) => { mockStore.set(name, val); },
  unsetEnv: (name) => { mockStore.delete(name); }
};

const cjsModule = { exports: {} };
const customRequire = (id) => {
  if (id === 'bare-os') return mockBareOs;
  return require(id);
};
const fn = new Function('require', 'module', 'exports', indexJsCode);
fn(customRequire, cjsModule, cjsModule.exports);

const env = cjsModule.exports;

// 4. Test setting, getting, and checking existence of environment variables
env.PORT = '8080';
assert.equal(env.PORT, '8080', 'Getting set property must return value');
assert.equal(mockStore.get('PORT'), '8080', 'Setting property must store value in bare-os');
assert.equal('PORT' in env, true, 'in operator must return true for set variable');
assert.equal('NON_EXISTENT_VAR' in env, false, 'in operator must return false for missing variable');

// 5. Test type coercion for number and boolean values
env.TIMEOUT = 5000;
assert.equal(env.TIMEOUT, '5000', 'Number must be coerced to string');
assert.equal(mockStore.get('TIMEOUT'), '5000', 'Stored value must be string');

env.FEATURE_FLAG = true;
assert.equal(env.FEATURE_FLAG, 'true', 'Boolean true must be coerced to string');

env.DEBUG_MODE = false;
assert.equal(env.DEBUG_MODE, 'false', 'Boolean false must be coerced to string');

// 6. Test rejection of non-primitive types
assert.throws(
  () => { env.INVALID_OBJ = { key: 'value' }; },
  /Environment variable must be of type string, number, or boolean/,
  'Setting object must throw validation error'
);

assert.throws(
  () => { env.INVALID_ARR = [1, 2, 3]; },
  /Environment variable must be of type string, number, or boolean/,
  'Setting array must throw validation error'
);

assert.throws(
  () => { env.INVALID_FN = () => {}; },
  /Environment variable must be of type string, number, or boolean/,
  'Setting function must throw validation error'
);

assert.throws(
  () => { env.INVALID_SYM = Symbol('env'); },
  /Environment variable must be of type string, number, or boolean/,
  'Setting symbol must throw validation error'
);

// 7. Test ownKeys trap and Object.keys enumeration
const envKeys = Object.keys(env);
assert.deepEqual(
  envKeys.sort(),
  ['DEBUG_MODE', 'FEATURE_FLAG', 'PORT', 'TIMEOUT'].sort(),
  'Object.keys must enumerate all active environment variables'
);

// 8. Test getOwnPropertyDescriptor trap
const descriptor = Object.getOwnPropertyDescriptor(env, 'PORT');
assert.deepEqual(descriptor, {
  value: '8080',
  enumerable: true,
  configurable: true,
  writable: true
}, 'getOwnPropertyDescriptor must return full enumerable, configurable, writable descriptor');

// 9. Test deleteProperty trap
// Strict mode delete throws because deleteProperty trap in bare-env does not return true
assert.throws(
  () => { delete env.PORT; },
  TypeError,
  'Strict mode delete must throw TypeError due to missing explicit return in deleteProperty trap'
);
// Verify that despite the falsish return, unsetEnv was executed
assert.equal(mockStore.has('PORT'), false, 'Variable must be deleted from backing store');
assert.equal(env.PORT, undefined, 'Deleted variable must return undefined');
assert.equal('PORT' in env, false, 'Deleted variable must not be in env');

// Reflect.deleteProperty returns false without throwing
const deletedTimeout = Reflect.deleteProperty(env, 'TIMEOUT');
assert.equal(deletedTimeout, false, 'Reflect.deleteProperty returns false for bare-env proxy');
assert.equal(mockStore.has('TIMEOUT'), false, 'Reflect.deleteProperty must unset variable in backing store');

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

오리진 시더

익명