CodeSampleX

샘플

debug 2.6.9: disable, enable, enabled

검증된 샘플 — npm debug 2.6.9: disable, enable, enabled. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: debug creates a debugger instance with the…

sha256:ac8aeec2da7f977a865578b4bb788f80a1a853c85386361848d10a6c007d3a6b

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

컨트랙트

  1. debug creates a debugger instance with the given namespace property and enabled status
  2. debug.enable configures active namespace patterns matching wildcards and prefixes
  3. debug.disable deactivates all active namespace patterns
  4. debug.enabled evaluates whether a namespace string matches current enabled configuration
  5. debug.formatters allows registering custom argument formatters invoked during logging
  6. debug executes custom log function when enabled and does not invoke log function when disabled

파일

  • 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/debug@2.6.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/debug@2.6.9
Demonstrate these symbols/APIs:
  - debug
  - debug.disable
  - debug.enable
  - debug.enabled
  - debug.formatters

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:5477608183eadba0a8bc835f9e72c740b76570ef10443c2d61e157452cbb2532","contract":["debug creates a debugger instance with the given namespace property and enabled status","debug.enable configures active namespace patterns matching wildcards and prefixes","debug.disable deactivates all active namespace patterns","debug.enabled evaluates whether a namespace string matches current enabled configuration","debug.formatters allows registering custom argument formatters invoked during logging","debug executes custom log function when enabled and does not invoke log function when disabled"],"goal":"verify pkg:npm/debug@2.6.9","kind":"HOW","packages":["pkg:npm/debug@2.6.9"],"schemaVersion":1,"symbols":["debug","debug.disable","debug.enable","debug.enabled","debug.formatters"]},"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/debug@2.6.9"],"schemaVersion":1,"subject":"pkg:npm/debug@2.6.9","symbols":["debug","debug.disable","debug.enable","debug.enabled","debug.formatters"],"verifierAdapter":"node-typescript@1"}
index.mjs
import debug from 'debug';

/**
 * Creates a scoped debug logger for the given namespace.
 *
 * @param {string} namespace - The namespace to associate with the logger.
 * @returns {Function} A configured debug instance.
 */
export function createLogger(namespace) {
  return debug(namespace);
}

/**
 * Enables debug output for namespaces matching the given pattern.
 *
 * @param {string} namespaces - Comma- or space-separated pattern of namespaces to enable.
 */
export function enableLogging(namespaces) {
  debug.enable(namespaces);
}

/**
 * Disables all debug logging namespaces.
 */
export function disableLogging() {
  debug.disable();
}

/**
 * Checks whether logging is enabled for the specified namespace.
 *
 * @param {string} namespace - The namespace to check.
 * @returns {boolean} True if the namespace is enabled, false otherwise.
 */
export function isLoggingEnabled(namespace) {
  return debug.enabled(namespace);
}

/**
 * Registers a custom formatter for a format specifier character.
 *
 * @param {string} letter - Single character format specifier.
 * @param {Function} formatter - Formatting function receiving the value.
 */
export function registerFormatter(letter, formatter) {
  debug.formatters[letter] = formatter;
}

export default debug;
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "debug": "2.6.9"
      }
    },
    "node_modules/debug": {
      "version": "2.6.9",
      "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
      "license": "MIT",
      "dependencies": {
        "ms": "2.0.0"
      }
    },
    "node_modules/ms": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
      "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "debug": "2.6.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/debug@2.6.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/debug@2.6.9"
  ],
  "symbols": [
    "debug",
    "debug.disable",
    "debug.enable",
    "debug.enabled",
    "debug.formatters"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import debug from 'debug';
import {
  createLogger,
  enableLogging,
  disableLogging,
  isLoggingEnabled,
  registerFormatter
} from '../index.mjs';

// Case 1: debug creates a debugger instance with the given namespace property and enabled status
{
  debug.disable();
  const log = debug('app:worker');
  assert.equal(typeof log, 'function', 'debug() should return a logger function');
  assert.equal(log.namespace, 'app:worker', 'logger should retain assigned namespace');
  assert.equal(log.enabled, false, 'logger should default to disabled when no namespaces are enabled');

  const helper = createLogger('app:service');
  assert.equal(typeof helper, 'function', 'createLogger helper should return a logger function');
  assert.equal(helper.namespace, 'app:service', 'createLogger helper should set namespace');
  assert.equal(helper.enabled, false, 'createLogger helper should default to disabled');
}

// Case 2: debug.enable configures active namespace patterns matching wildcards and prefixes
{
  debug.disable();
  enableLogging('app:*,db:*,-db:hidden');

  assert.equal(debug.enabled('app:server'), true, 'app:server matches app:*');
  assert.equal(debug.enabled('app:client:auth'), true, 'app:client:auth matches app:*');
  assert.equal(debug.enabled('db:query'), true, 'db:query matches db:*');
  assert.equal(debug.enabled('db:hidden'), false, 'db:hidden is excluded by -db:hidden');
  assert.equal(debug.enabled('other:task'), false, 'other:task does not match active patterns');

  const appLog = createLogger('app:server');
  assert.equal(appLog.enabled, true, 'newly created debug instance for matched namespace is enabled');
  const otherLog = createLogger('other:task');
  assert.equal(otherLog.enabled, false, 'newly created debug instance for unmatched namespace is disabled');
}

// Case 3: debug.disable deactivates all active namespace patterns
{
  enableLogging('app:*,db:*');
  assert.equal(debug.enabled('app:server'), true);
  assert.equal(debug.enabled('db:query'), true);

  disableLogging();

  assert.equal(debug.enabled('app:server'), false, 'app:server disabled after disableLogging()');
  assert.equal(debug.enabled('db:query'), false, 'db:query disabled after disableLogging()');

  const log = createLogger('app:server');
  assert.equal(log.enabled, false, 'debug instance created after disable is disabled');
}

// Case 4: debug.enabled evaluates whether a namespace string matches current enabled configuration
{
  enableLogging('worker:*,api:v1:*,-api:v1:internal');
  assert.equal(isLoggingEnabled('worker:pool'), true, 'matches worker:*');
  assert.equal(isLoggingEnabled('api:v1:users'), true, 'matches api:v1:*');
  assert.equal(isLoggingEnabled('api:v1:internal'), false, 'excluded by -api:v1:internal');
  assert.equal(isLoggingEnabled('api:v2:users'), false, 'does not match api:v1:*');
}

// Case 5: debug.formatters allows registering custom argument formatters invoked during logging
{
  registerFormatter('h', (val) => '0x' + Number(val).toString(16));
  enableLogging('test:format');
  const log = createLogger('test:format');

  let output = '';
  log.log = (...args) => {
    output = args.join(' ');
  };

  log('address: %h', 255);
  assert.match(output, /0xff/, 'custom %h formatter formats 255 to 0xff');
}

// Case 6: debug executes custom log function when enabled and does not invoke log function when disabled
{
  disableLogging();
  let disabledCalls = 0;
  const disabledLog = createLogger('test:disabled');
  disabledLog.log = () => {
    disabledCalls++;
  };
  disabledLog('this should not be logged');
  assert.equal(disabledCalls, 0, 'disabled logger must not call log function');

  enableLogging('test:enabled');
  let enabledCalls = 0;
  let loggedArgs = null;
  const enabledLog = createLogger('test:enabled');
  enabledLog.log = (...args) => {
    enabledCalls++;
    loggedArgs = args;
  };
  enabledLog('hello', 'world');
  assert.equal(enabledCalls, 1, 'enabled logger must invoke custom log function');
  assert.ok(loggedArgs !== null, 'loggedArgs should be captured');
  assert.equal(loggedArgs[1], 'world', 'second argument should be forwarded');
}

console.log('All contract assertions passed.');

오리진 시더

익명