CodeSampleX

Ejemplo

proc-log 6.1.0: log

Muestra verificada para npm proc-log 6.1.0: log. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: proc-log exports log, output, time…

sha256:a1522fbc41bc747148534e71a0e6663316959c7f3c3ab7c69d5f5a5bbd252d83

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:npm/proc-log@6.1.0
Paquetes
Símbolos
  • log
Entorno
node 22.23.2
Creado
2026-08-27T20:31:07Z

Contrato

  1. proc-log exports log, output, time, input objects and META symbol
  2. log object contains standard log LEVELS array and KEYS mapping
  3. log level methods emit log events with level name and arguments on process
  4. log pause and resume emit corresponding log control events on process
  5. output methods emit output events with corresponding stream levels on process
  6. time start and end emit time events on process with timer names
  7. time start accepts a function callback and automatically emits time end on completion
  8. input start, end, and read emit input events on process

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/proc-log@6.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proc-log@6.1.0
Demonstrate these symbols/APIs:
  - log

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:e70cdd9879ffd342292ff4230a93cc817d256a0ccbca02b96cf94ee376917cca","contract":["proc-log exports log, output, time, input objects and META symbol","log object contains standard log LEVELS array and KEYS mapping","log level methods emit log events with level name and arguments on process","log pause and resume emit corresponding log control events on process","output methods emit output events with corresponding stream levels on process","time start and end emit time events on process with timer names","time start accepts a function callback and automatically emits time end on completion","input start, end, and read emit input events on process"],"goal":"verify pkg:npm/proc-log@6.1.0","kind":"HOW","packages":["pkg:npm/proc-log@6.1.0"],"schemaVersion":1,"symbols":["log"]},"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/proc-log@6.1.0"],"schemaVersion":1,"subject":"pkg:npm/proc-log@6.1.0","symbols":["log"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-proc-log",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-proc-log",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "proc-log": "6.1.0"
      }
    },
    "node_modules/proc-log": {
      "version": "6.1.0",
      "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-6.1.0.tgz",
      "integrity": "sha512-iG+GYldRf2BQ0UDUAd6JQ/RwzaQy6mXmsk/IzlYyal4A4SNFw54MeH4/tLkF4I5WoWG9SQwuqWzS99jaFQHBuQ==",
      "license": "ISC",
      "engines": {
        "node": "^20.17.0 || >=22.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-proc-log",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for proc-log@6.1.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "proc-log": "6.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/proc-log@6.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proc-log@6.1.0"
  ],
  "symbols": [
    "log"
  ]
}
src/index.js
const { log, output, time, input, META } = require('proc-log');

/**
 * Emit a standard log event through proc-log.
 *
 * @param {string} level - Log level name (e.g., 'info', 'warn', 'error')
 * @param {...any} args - Arguments to pass along with the log event
 * @returns {boolean} Whether the event was emitted
 */
function emitLog(level, ...args) {
  if (typeof log[level] === 'function') {
    return log[level](...args);
  }
  return process.emit('log', level, ...args);
}

/**
 * Measure execution time of a synchronous or asynchronous function.
 *
 * @param {string} name - Timer label
 * @param {Function} [fn] - Optional function to time
 * @returns {any} Result of fn if provided, or an end() function
 */
function measureTime(name, fn) {
  return time.start(name, fn);
}

module.exports = {
  log,
  output,
  time,
  input,
  META,
  emitLog,
  measureTime
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  log,
  output,
  time,
  input,
  META,
  emitLog,
  measureTime
} = require('../src/index.js');

async function testAll() {
  // 1. proc-log exports log, output, time, input objects and META symbol
  assert.equal(typeof log, 'object', 'log should be an object');
  assert.equal(typeof output, 'object', 'output should be an object');
  assert.equal(typeof time, 'object', 'time should be an object');
  assert.equal(typeof input, 'object', 'input should be an object');
  assert.equal(typeof META, 'symbol', 'META should be a symbol');
  assert.equal(META.description, 'proc-log.meta', 'META description should match');

  // 2. log object contains standard log LEVELS array and KEYS mapping
  assert.ok(Array.isArray(log.LEVELS), 'log.LEVELS should be an array');
  assert.deepEqual(log.LEVELS, [
    'notice',
    'error',
    'warn',
    'info',
    'verbose',
    'http',
    'silly',
    'timing',
    'pause',
    'resume'
  ]);
  assert.equal(typeof log.KEYS, 'object', 'log.KEYS should be an object');
  for (const level of log.LEVELS) {
    assert.equal(log.KEYS[level], level, `log.KEYS.${level} should equal '${level}'`);
    assert.equal(typeof log[level], 'function', `log.${level} should be a function`);
  }

  // 3. log level methods emit log events with level name and arguments on process
  const logEvents = [];
  const logListener = (level, ...args) => {
    logEvents.push({ level, args });
  };
  process.on('log', logListener);

  log.info('test-prefix', 'info message', { code: 200 });
  log.warn('warn-prefix', 'warning message');
  log.error('err-prefix', 'error occurred');
  log.notice('notice-prefix', 'notice message');
  log.verbose('verb-prefix', 'verbose details');
  log.http('http-prefix', 'GET /test');
  log.silly('silly-prefix', 'silly traces');
  log.timing('timing-prefix', 'build finished');

  emitLog('info', 'helper-prefix', 'helper message');

  process.removeListener('log', logListener);

  assert.equal(logEvents.length, 9, 'Should receive 9 log events');
  assert.deepEqual(logEvents[0], { level: 'info', args: ['test-prefix', 'info message', { code: 200 }] });
  assert.deepEqual(logEvents[1], { level: 'warn', args: ['warn-prefix', 'warning message'] });
  assert.deepEqual(logEvents[2], { level: 'error', args: ['err-prefix', 'error occurred'] });
  assert.deepEqual(logEvents[3], { level: 'notice', args: ['notice-prefix', 'notice message'] });
  assert.deepEqual(logEvents[4], { level: 'verbose', args: ['verb-prefix', 'verbose details'] });
  assert.deepEqual(logEvents[5], { level: 'http', args: ['http-prefix', 'GET /test'] });
  assert.deepEqual(logEvents[6], { level: 'silly', args: ['silly-prefix', 'silly traces'] });
  assert.deepEqual(logEvents[7], { level: 'timing', args: ['timing-prefix', 'build finished'] });
  assert.deepEqual(logEvents[8], { level: 'info', args: ['helper-prefix', 'helper message'] });

  // 4. log pause and resume emit corresponding log control events on process
  const controlEvents = [];
  const controlListener = (level, ...args) => {
    controlEvents.push({ level, args });
  };
  process.on('log', controlListener);

  log.pause();
  log.resume();

  process.removeListener('log', controlListener);

  assert.equal(controlEvents.length, 2, 'Should receive pause and resume events');
  assert.deepEqual(controlEvents[0], { level: 'pause', args: [] });
  assert.deepEqual(controlEvents[1], { level: 'resume', args: [] });

  // 5. output methods emit output events with corresponding stream levels on process
  const outputEvents = [];
  const outputListener = (level, ...args) => {
    outputEvents.push({ level, args });
  };
  process.on('output', outputListener);

  output.standard('standard output data');
  output.error('error output data');
  output.buffer('buffered chunk');
  output.flush();

  process.removeListener('output', outputListener);

  assert.equal(outputEvents.length, 4, 'Should receive 4 output events');
  assert.deepEqual(outputEvents[0], { level: 'standard', args: ['standard output data'] });
  assert.deepEqual(outputEvents[1], { level: 'error', args: ['error output data'] });
  assert.deepEqual(outputEvents[2], { level: 'buffer', args: ['buffered chunk'] });
  assert.deepEqual(outputEvents[3], { level: 'flush', args: [] });

  // 6. time start and end emit time events on process with timer names
  const timeEvents = [];
  const timeListener = (stage, name) => {
    timeEvents.push({ stage, name });
  };
  process.on('time', timeListener);

  const endFn = time.start('manual-timer');
  assert.equal(typeof endFn, 'function', 'time.start without fn should return end function');
  endFn();
  time.end('direct-timer');

  process.removeListener('time', timeListener);

  assert.equal(timeEvents.length, 3);
  assert.deepEqual(timeEvents[0], { stage: 'start', name: 'manual-timer' });
  assert.deepEqual(timeEvents[1], { stage: 'end', name: 'manual-timer' });
  assert.deepEqual(timeEvents[2], { stage: 'end', name: 'direct-timer' });

  // 7. time start accepts a function callback and automatically emits time end on completion
  const autoTimeEvents = [];
  const autoTimeListener = (stage, name) => {
    autoTimeEvents.push({ stage, name });
  };
  process.on('time', autoTimeListener);

  const syncResult = measureTime('sync-task', () => {
    return 10 + 20;
  });
  assert.equal(syncResult, 30, 'measureTime sync should return result');

  const asyncResult = await measureTime('async-task', async () => {
    return 'async-done';
  });
  assert.equal(asyncResult, 'async-done', 'measureTime async should resolve result');

  process.removeListener('time', autoTimeListener);

  assert.equal(autoTimeEvents.length, 4);
  assert.deepEqual(autoTimeEvents[0], { stage: 'start', name: 'sync-task' });
  assert.deepEqual(autoTimeEvents[1], { stage: 'end', name: 'sync-task' });
  assert.deepEqual(autoTimeEvents[2], { stage: 'start', name: 'async-task' });
  assert.deepEqual(autoTimeEvents[3], { stage: 'end', name: 'async-task' });

  // 8. input start, end, and read emit input events on process
  const inputEvents = [];
  const inputListener = (action, ...args) => {
    inputEvents.push({ action, args });
  };
  process.on('input', inputListener);

  input.start('prompt');
  input.end('prompt');

  let pendingResolve;
  process.once('input', (action, resolve, reject, ...args) => {
    if (action === 'read') {
      pendingResolve = resolve;
    }
  });

  const readPromise = input.read('password-prompt');
  assert.ok(readPromise instanceof Promise, 'input.read should return a promise');
  if (pendingResolve) {
    pendingResolve('user-input-value');
  }
  const readResult = await readPromise;
  assert.equal(readResult, 'user-input-value');

  process.removeListener('input', inputListener);

  console.log('All proc-log contract tests passed successfully.');
}

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

Seeder de origen

anónimo