CodeSampleX

샘플

obug 2.1.4

검증된 샘플 — npm obug 2.1.4. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: createDebug creates a namespaced debugger instance with the specified…

sha256:75cf2a1e50ff57ca527c700288e382013fef0017a7774968baedee7238167e3e

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

케이스

HOW
목표
verify pkg:npm/obug@2.1.4
패키지
환경
node 22.23.2
생성일
2026-08-28T05:56:02Z

컨트랙트

  1. createDebug creates a namespaced debugger instance with the specified namespace string
  2. enable activates debug output for matching namespaces including wildcard patterns
  3. disable deactivates all debug namespaces and returns the previously active namespace string
  4. enabled reports whether a given namespace is currently active
  5. namespaces returns the string of currently active debug namespaces
  6. Debugger.extend creates a child debugger whose namespace is prefixed with the parent namespace
  7. createDebug supports custom formatters and custom log sink functions

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • 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/obug@2.1.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/obug@2.1.4
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:2d228f05cdf069830938562877f687234a55be3f51087d5afea4e6edf3b3f6b4","constraints":{"executionContext":"node"},"contract":["createDebug creates a namespaced debugger instance with the specified namespace string","enable activates debug output for matching namespaces including wildcard patterns","disable deactivates all debug namespaces and returns the previously active namespace string","enabled reports whether a given namespace is currently active","namespaces returns the string of currently active debug namespaces","Debugger.extend creates a child debugger whose namespace is prefixed with the parent namespace","createDebug supports custom formatters and custom log sink functions"],"goal":"verify pkg:npm/obug@2.1.4","kind":"HOW","packages":["pkg:npm/obug@2.1.4"],"schemaVersion":1},"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/obug@2.1.4"],"schemaVersion":1,"subject":"pkg:npm/obug@2.1.4","verifierAdapter":"node-typescript@1"}
index.mjs
import { createDebug, enable, disable, enabled, namespaces } from 'obug';

export function createLogger(namespace, options) {
  return createDebug(namespace, options);
}

export function configureNamespaces(pattern) {
  enable(pattern);
}

export function resetNamespaces() {
  return disable();
}

export function isNamespaceEnabled(name) {
  return enabled(name);
}

export function getActiveNamespaces() {
  return namespaces();
}

export { createDebug, enable, disable, enabled, namespaces };
package-lock.json
{
  "name": "sample-obug",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-obug",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "obug": "2.1.4"
      }
    },
    "node_modules/obug": {
      "version": "2.1.4",
      "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.4.tgz",
      "integrity": "sha512-4a+OsYv9UktOJKE+l1A4OufDgdRF9PifWj+tJnHURo/P+WOxpG4GzUFL9qCalmWauao6ogiG+QvnCovwPoyAWA==",
      "funding": [
        "https://github.com/sponsors/sxzz",
        "https://opencollective.com/debug"
      ],
      "license": "MIT",
      "engines": {
        "node": ">=12.20.0"
      }
    }
  }
}
package.json
{
  "name": "sample-obug",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/obug@2.1.4",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "obug": "2.1.4"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/obug@2.1.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/obug@2.1.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "esm",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import util from 'node:util';
import { createDebug, enable, disable, enabled, namespaces } from 'obug';
import {
  createLogger,
  configureNamespaces,
  resetNamespaces,
  isNamespaceEnabled,
  getActiveNamespaces
} from '../index.mjs';

async function main() {
  // Test 1: createDebug creates a namespaced debugger instance
  const logs = [];
  const logSink = (...args) => {
    logs.push(args);
  };

  const debug = createDebug('sample:app', {
    useColors: false,
    log: logSink
  });

  assert.strictEqual(typeof debug, 'function', 'createDebug must return a callable function');
  assert.strictEqual(debug.namespace, 'sample:app', 'Debugger must retain its namespace');
  assert.strictEqual(typeof debug.extend, 'function', 'Debugger must have an extend method');

  // Initially disable all namespaces
  disable();
  assert.strictEqual(debug.enabled, false, 'Debugger should be disabled after disable()');
  assert.strictEqual(enabled('sample:app'), false, 'enabled() should return false for sample:app when disabled');
  assert.strictEqual(namespaces(), '', 'namespaces() should return empty string after disable()');

  // Test 2: enable activates matching namespaces including wildcards
  enable('sample:*');
  assert.strictEqual(debug.enabled, true, 'Debugger should become enabled when namespace matches pattern');
  assert.strictEqual(enabled('sample:app'), true, 'enabled() must return true for matching namespace');
  assert.strictEqual(enabled('other:app'), false, 'enabled() must return false for non-matching namespace');
  assert.strictEqual(namespaces(), 'sample:*', 'namespaces() must return active namespace pattern');

  // Test 3: Calling debugger outputs formatted message when enabled
  logs.length = 0;
  debug('processing item %d: %s', 42, 'test-item');
  assert.strictEqual(logs.length, 1, 'Calling enabled debugger must invoke custom log function');
  const formattedOutput = util.format(...logs[0]);
  assert.ok(formattedOutput.includes('sample:app'), 'Formatted output must include the namespace');
  assert.ok(formattedOutput.includes('processing item 42: test-item'), 'Formatted output must format arguments');

  // Test 4: Debugger.extend creates hierarchical sub-namespaces
  const subWorker = debug.extend('worker');
  assert.strictEqual(subWorker.namespace, 'sample:app:worker', 'extend must create colon-delimited child namespace');
  assert.strictEqual(subWorker.enabled, true, 'Extended debugger inherits enablement');

  logs.length = 0;
  subWorker('worker task completed');
  assert.strictEqual(logs.length, 1, 'Extended debugger must invoke log function');
  const subFormatted = util.format(...logs[0]);
  assert.ok(subFormatted.includes('sample:app:worker'), 'Sub-debugger output must include extended namespace');
  assert.ok(subFormatted.includes('worker task completed'), 'Sub-debugger output must include message');

  // Test 5: disable deactivates all namespaces and returns previous pattern
  const previous = disable();
  assert.strictEqual(previous, 'sample:*', 'disable() must return the previous pattern string');
  assert.strictEqual(debug.enabled, false, 'Debugger enabled property must be false after disable()');
  assert.strictEqual(subWorker.enabled, false, 'Extended debugger enabled property must be false after disable()');

  logs.length = 0;
  debug('this message should not be logged');
  assert.strictEqual(logs.length, 0, 'Disabled debugger must not produce log output');

  // Test 6: Custom formatters
  enable('sample:fmt');
  const fmtLogs = [];
  const fmtDebug = createDebug('sample:fmt', {
    useColors: false,
    log: (...args) => fmtLogs.push(args),
    formatters: {
      h: (val) => Buffer.from(val).toString('hex')
    }
  });

  fmtDebug('data in hex: %h', 'csx-test');
  assert.strictEqual(fmtLogs.length, 1, 'Custom formatter debugger must log output');
  const fmtOutput = util.format(...fmtLogs[0]);
  assert.ok(fmtOutput.includes('6373782d74657374'), 'Custom formatter %h must transform string to hex');

  // Test 7: Helper functions from index.mjs
  configureNamespaces('helper:*');
  assert.strictEqual(isNamespaceEnabled('helper:db'), true, 'configureNamespaces must enable namespace');
  assert.strictEqual(getActiveNamespaces(), 'helper:*', 'getActiveNamespaces must return active pattern');

  const helperLogger = createLogger('helper:db', {
    useColors: false,
    log: logSink
  });
  assert.strictEqual(helperLogger.namespace, 'helper:db', 'createLogger helper must return configured instance');

  resetNamespaces();
  assert.strictEqual(isNamespaceEnabled('helper:db'), false, 'resetNamespaces must disable all namespaces');

  console.log('obug contract verification passed.');
  process.exit(0);
}

main().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명