CodeSampleX

Exemplo

bare-events 2.9.1

Amostra verificada para npm bare-events 2.9.1. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: EventEmitter can be instantiated and exposes…

sha256:b34b91b43684e00999b5bf4804c65359cbfbc48fe958ac50586442e5c871de2f

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-23
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Caso

HOW
Objetivo
verify pkg:npm/bare-events@2.9.1
Pacotes
Criado
2026-08-23T15:56:46Z

Contrato

  1. EventEmitter can be instantiated and exposes event listener and emission methods
  2. on and emit register listener functions and synchronously invoke them with passed arguments
  3. once registers a one-time listener that executes exactly once and is automatically removed
  4. off removes a previously registered listener function for a specific event
  5. removeAllListeners removes all listeners for a given event or all registered events
  6. prependListener and prependOnceListener add listeners to the beginning of the invocation chain
  7. EventEmitter.once static helper returns a promise resolving with event arguments when emitted
  8. EventEmitter.on static helper returns an async iterable yielding event arguments until aborted
  9. EventEmitter.forward lazily forwards events from a source emitter to a destination emitter
  10. listenerCount and eventNames accurately reflect registered listeners on the emitter

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-events@2.9.1

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:b44aa762836e85b1739d6d94532ca105f4feaefce7e9bb3dbf1d1a3a4211f1eb","contract":["EventEmitter can be instantiated and exposes event listener and emission methods","on and emit register listener functions and synchronously invoke them with passed arguments","once registers a one-time listener that executes exactly once and is automatically removed","off removes a previously registered listener function for a specific event","removeAllListeners removes all listeners for a given event or all registered events","prependListener and prependOnceListener add listeners to the beginning of the invocation chain","EventEmitter.once static helper returns a promise resolving with event arguments when emitted","EventEmitter.on static helper returns an async iterable yielding event arguments until aborted","EventEmitter.forward lazily forwards events from a source emitter to a destination emitter","listenerCount and eventNames accurately reflect registered listeners on the emitter"],"goal":"verify pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.1"],"schemaVersion":1},"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/bare-events@2.9.1"],"schemaVersion":1,"subject":"pkg:npm/bare-events@2.9.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events",
      "version": "1.0.0",
      "dependencies": {
        "bare-events": "2.9.1"
      }
    },
    "node_modules/bare-events": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.1.tgz",
      "integrity": "sha512-Z0oHEHAFDZkffN8Qc39zNZjQlMDkPJRyyyZieU1VH7u8c5S+qHZ2S8ixdKIAxEjfHO7FJxXmJWgteOghVanIsg==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "bare-abort-controller": "*"
      },
      "peerDependenciesMeta": {
        "bare-abort-controller": {
          "optional": true
        }
      }
    }
  }
}
package.json
{
  "name": "sample-bare-events",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. EventEmitter can be instantiated and exposes event listener and emission methods
{
  const ee = new EventEmitter();
  assert.ok(ee instanceof EventEmitter);
  assert.equal(typeof ee.on, 'function');
  assert.equal(typeof ee.emit, 'function');
  assert.equal(typeof ee.once, 'function');
  assert.equal(typeof ee.off, 'function');
  assert.equal(typeof ee.addListener, 'function');
  assert.equal(typeof ee.removeListener, 'function');
  assert.equal(typeof ee.removeAllListeners, 'function');
}

// 2. on and emit register listener functions and synchronously invoke them with passed arguments
{
  const ee = new EventEmitter();
  const received = [];
  ee.on('data', (a, b) => {
    received.push({ a, b });
  });

  const emitted1 = ee.emit('data', 'first', 1);
  const emitted2 = ee.emit('data', 'second', 2);
  const emitted3 = ee.emit('unhandled', 'third');

  assert.equal(emitted1, true);
  assert.equal(emitted2, true);
  assert.equal(emitted3, false);
  assert.deepEqual(received, [
    { a: 'first', b: 1 },
    { a: 'second', b: 2 }
  ]);
}

// 3. once registers a one-time listener that executes exactly once and is automatically removed
{
  const ee = new EventEmitter();
  let count = 0;
  ee.once('tick', () => {
    count++;
  });

  ee.emit('tick');
  ee.emit('tick');
  assert.equal(count, 1);
  assert.equal(ee.listenerCount('tick'), 0);
}

// 4. off removes a previously registered listener function for a specific event
{
  const ee = new EventEmitter();
  let calls = 0;
  const handler = () => {
    calls++;
  };

  ee.on('custom', handler);
  ee.emit('custom');
  assert.equal(calls, 1);

  ee.off('custom', handler);
  ee.emit('custom');
  assert.equal(calls, 1);
}

// 5. removeAllListeners removes all listeners for a given event or all registered events
{
  const ee = new EventEmitter();
  ee.on('eventA', () => {});
  ee.on('eventA', () => {});
  ee.on('eventB', () => {});

  assert.equal(ee.listenerCount('eventA'), 2);
  ee.removeAllListeners('eventA');
  assert.equal(ee.listenerCount('eventA'), 0);
  assert.equal(ee.listenerCount('eventB'), 1);

  ee.removeAllListeners();
  assert.equal(ee.listenerCount('eventB'), 0);
  assert.deepEqual(ee.eventNames(), []);
}

// 6. prependListener and prependOnceListener add listeners to the beginning of the invocation chain
{
  const ee = new EventEmitter();
  const order = [];

  ee.on('order', () => order.push('normal'));
  ee.prependListener('order', () => order.push('prepended'));
  ee.prependOnceListener('order', () => order.push('prependedOnce'));

  ee.emit('order');
  assert.deepEqual(order, ['prependedOnce', 'prepended', 'normal']);

  ee.emit('order');
  assert.deepEqual(order, ['prependedOnce', 'prepended', 'normal', 'prepended', 'normal']);
}

// 7. EventEmitter.once static helper returns a promise resolving with event arguments when emitted
{
  const ee = new EventEmitter();
  const promise = EventEmitter.once(ee, 'success');
  ee.emit('success', 'value1', 'value2');
  const result = await promise;
  assert.deepEqual(result, ['value1', 'value2']);
}

// 8. EventEmitter.on static helper returns an async iterable yielding event arguments until aborted
{
  const ee = new EventEmitter();
  const ac = new AbortController();
  const iterator = EventEmitter.on(ee, 'stream', { signal: ac.signal });

  ee.emit('stream', 'first-item');
  ee.emit('stream', 'second-item');

  const item1 = await iterator.next();
  assert.deepEqual(item1.value, ['first-item']);
  assert.equal(item1.done, false);

  const item2 = await iterator.next();
  assert.deepEqual(item2.value, ['second-item']);
  assert.equal(item2.done, false);

  ac.abort();
}

// 9. EventEmitter.forward lazily forwards events from a source emitter to a destination emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'forwardedEvent');

  const received = [];
  dest.on('forwardedEvent', (msg) => {
    received.push(msg);
  });

  src.emit('forwardedEvent', 'payload');
  assert.deepEqual(received, ['payload']);
}

// 10. listenerCount and eventNames accurately reflect registered listeners on the emitter
{
  const ee = new EventEmitter();
  const fn1 = () => {};
  const fn2 = () => {};

  ee.on('alpha', fn1);
  ee.on('alpha', fn2);
  ee.on('beta', fn1);

  assert.equal(ee.listenerCount('alpha'), 2);
  assert.equal(ee.listenerCount('beta'), 1);
  assert.equal(ee.listenerCount('gamma'), 0);

  const names = ee.eventNames();
  assert.deepEqual(names.sort(), ['alpha', 'beta']);
}

Seeder de origem

anônimo