CodeSampleX

Sample

debug 4.3.7: disable, enable, enabled

Verified sample for npm debug 4.3.7: disable, enable, enabled. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:b72d04f00b87eba6bc94ce589fa73383c12ad9aa0ef44a50fa7adae590abd289

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:npm/debug@4.3.7
Packages
Symbols
  • debug
  • debug.disable
  • debug.enable
  • debug.enabled
  • debug.extend
Created
2026-08-27T12:46:48Z

Contract

  1. debug creates a debugger instance with the given namespace property and enabled status
  2. debug.enable activates namespaces matching pattern and updates existing debug instance enabled property
  3. debug.disable deactivates all namespaces and returns previous namespaces string
  4. debug.enabled checks whether a namespace string matches current enabled configuration including wildcard and negation prefix
  5. debug.extend creates a child debugger with namespace appended using default colon delimiter
  6. debug.extend supports custom delimiter when creating extended child debugger
  7. debug executes custom log function only when enabled and forwards namespace prefix and arguments
  8. debug does not invoke log function when namespace is disabled
  9. debug supports registering custom formatter functions in debug.formatters
  10. configureLogging helper enables specified namespaces and updates debug instance state

Files

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

Download the source artifact (tar.gz)

Source

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@4.3.7
Kind: HOW

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

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:5af7d7e45500c1bc128b64f22323d39f9dac87cd77d0e8388954fe74317fcde1","contract":["debug creates a debugger instance with the given namespace property and enabled status","debug.enable activates namespaces matching pattern and updates existing debug instance enabled property","debug.disable deactivates all namespaces and returns previous namespaces string","debug.enabled checks whether a namespace string matches current enabled configuration including wildcard and negation prefix","debug.extend creates a child debugger with namespace appended using default colon delimiter","debug.extend supports custom delimiter when creating extended child debugger","debug executes custom log function only when enabled and forwards namespace prefix and arguments","debug does not invoke log function when namespace is disabled","debug supports registering custom formatter functions in debug.formatters","configureLogging helper enables specified namespaces and updates debug instance state"],"goal":"verify pkg:npm/debug@4.3.7","kind":"HOW","packages":["pkg:npm/debug@4.3.7"],"schemaVersion":1,"symbols":["debug","debug.disable","debug.enable","debug.enabled","debug.extend"]},"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@4.3.7"],"schemaVersion":1,"subject":"pkg:npm/debug@4.3.7","symbols":["debug","debug.disable","debug.enable","debug.enabled","debug.extend"],"verifierAdapter":"node-typescript@1"}
index.mjs
import debug from 'debug';

/**
 * Creates a scoped logger with an optional sub-namespace extension.
 *
 * @param {string} namespace - The root namespace for the debugger.
 * @returns {Function} A configured debug instance.
 */
export function createLogger(namespace) {
  return debug(namespace);
}

/**
 * Creates a child logger extended from a parent logger instance.
 *
 * @param {Function} parentLogger - The parent debug instance.
 * @param {string} subNamespace - The sub-namespace to append.
 * @param {string} [delimiter] - Optional delimiter (defaults to ':').
 * @returns {Function} An extended child debug instance.
 */
export function extendLogger(parentLogger, subNamespace, delimiter) {
  if (delimiter !== undefined) {
    return parentLogger.extend(subNamespace, delimiter);
  }
  return parentLogger.extend(subNamespace);
}

/**
 * Configures global debug namespace filters.
 *
 * @param {string} namespaces - Space- or comma-delimited list of namespace patterns to enable.
 */
export function configureLogging(namespaces) {
  debug.enable(namespaces);
}

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": "4.3.7"
      }
    },
    "node_modules/debug": {
      "version": "4.3.7",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
      "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "debug": "4.3.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/debug@4.3.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/debug@4.3.7"
  ],
  "symbols": [
    "debug",
    "debug.disable",
    "debug.enable",
    "debug.enabled",
    "debug.extend"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import debug from 'debug';
import { createLogger, extendLogger, configureLogging } from '../index.mjs';

// Clean state before running tests
debug.disable();

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

  const helperLog = createLogger('app:worker');
  assert.equal(helperLog.namespace, 'app:worker', 'createLogger helper should return debug instance with namespace');
}

// Case 2: debug.enable activates namespaces matching pattern and updates existing debug instance enabled property
{
  const serverLog = debug('app:server');
  const dbLog = debug('db:query');

  assert.equal(serverLog.enabled, false, 'serverLog initially disabled');
  assert.equal(dbLog.enabled, false, 'dbLog initially disabled');

  debug.enable('app:*');

  assert.equal(serverLog.enabled, true, 'serverLog enabled after debug.enable("app:*")');
  assert.equal(dbLog.enabled, false, 'dbLog remains disabled when not matching "app:*"');
}

// Case 3: debug.disable deactivates all namespaces and returns previous namespaces string
{
  debug.enable('app:*,db:*');
  const prev = debug.disable();
  assert.equal(prev, 'app:*,db:*', 'debug.disable() should return previous enabled namespaces pattern');

  const log = debug('app:server');
  assert.equal(log.enabled, false, 'debugger should be disabled after debug.disable()');
}

// Case 4: debug.enabled checks whether a namespace string matches current enabled configuration including wildcard and negation prefix
{
  debug.enable('app:*,-app:secret');
  assert.equal(debug.enabled('app:server'), true, 'debug.enabled should return true for matched namespace');
  assert.equal(debug.enabled('db:client'), false, 'debug.enabled should return false for unmatched namespace');
  assert.equal(debug.enabled('app:secret'), false, 'debug.enabled should return false for excluded namespace with negation prefix -');
}

// Case 5: debug.extend creates a child debugger with namespace appended using default colon delimiter
{
  debug.enable('app:*');
  const rootLog = debug('app');
  const childLog = rootLog.extend('http');

  assert.equal(typeof childLog, 'function', 'extend() should return a function');
  assert.equal(childLog.namespace, 'app:http', 'extended namespace should append with default colon delimiter');
  assert.equal(childLog.enabled, true, 'extended debugger should be enabled matching pattern');

  const helperChild = extendLogger(rootLog, 'events');
  assert.equal(helperChild.namespace, 'app:events', 'extendLogger helper should extend with default delimiter');
}

// Case 6: debug.extend supports custom delimiter when creating extended child debugger
{
  const rootLog = debug('worker');
  const childLog = rootLog.extend('job1', '/');
  assert.equal(childLog.namespace, 'worker/job1', 'extended namespace should use specified custom delimiter');

  const helperCustom = extendLogger(rootLog, 'job2', '#');
  assert.equal(helperCustom.namespace, 'worker#job2', 'extendLogger helper should support custom delimiter');
}

// Case 7: debug executes custom log function only when enabled and forwards namespace prefix and arguments
{
  debug.enable('test:handler');
  const log = debug('test:handler');
  const calls = [];
  log.log = (...args) => {
    calls.push(args);
  };

  log('request received', 200);
  assert.equal(calls.length, 1, 'custom log handler should be invoked when enabled');
  assert.equal(calls[0].length, 2, 'custom log handler receives prefix string and additional arg');
  assert.ok(calls[0][0].includes('test:handler request received'), 'first argument contains formatted prefix and string');
  assert.equal(calls[0][1], 200, 'second argument passed through');
}

// Case 8: debug does not invoke log function when namespace is disabled
{
  debug.disable();
  const log = debug('test:disabled');
  let invoked = false;
  log.log = () => {
    invoked = true;
  };

  log('this message should not be logged');
  assert.equal(invoked, false, 'log handler should not be called when debugger is disabled');
}

// Case 9: debug supports registering custom formatter functions in debug.formatters
{
  debug.formatters.u = (val) => String(val).toUpperCase();
  debug.enable('test:custom-fmt');
  const log = debug('test:custom-fmt');
  const calls = [];
  log.log = (...args) => {
    calls.push(args);
  };

  log('greeting: %u', 'hello');
  assert.equal(calls.length, 1, 'log handler called');
  assert.ok(calls[0][0].includes('greeting: HELLO'), 'custom formatter %u should uppercase input in output string');

  delete debug.formatters.u;
}

// Case 10: configureLogging helper enables specified namespaces and updates debug instance state
{
  configureLogging('service:api');
  const apiLog = debug('service:api');
  const otherLog = debug('service:db');

  assert.equal(apiLog.enabled, true, 'apiLog should be enabled after configureLogging');
  assert.equal(otherLog.enabled, false, 'otherLog should be disabled after configureLogging');
}

// Reset state
debug.disable();

console.log('PASS: all debug contract assertions passed');

Origin Seeder

anonymous