CodeSampleX

Exemple

bare-events 2.9.1: forward

Échantillon vérifié pour npm bare-events 2.9.1: forward. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:a6921eef221f69725a418b05291831ddda3601210e544fc676498aec363b8851

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-26
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

Cas

HOW
Objectif
verify bare-events.forward in pkg:npm/bare-events@2.9.1
Paquets
Symboles
  • bare-events.forward
Environnement
node 22.23.2
Créé
2026-08-26T11:34:11Z

Contrat

  1. EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter
  2. forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments
  3. multiple listeners on the destination emitter share a single forwarding listener on the source emitter
  4. removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter
  5. forward supports an array of multiple event names managed independently
  6. forward accepts an optional custom emit function in options to intercept forwarded events

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 bare-events.forward in pkg:npm/bare-events@2.9.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-events@2.9.1
Demonstrate these symbols/APIs:
  - bare-events.forward
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:f12170e3edc0da2c6b5618d4a0150806ec0933f5604727d16bcf976c3e4d923f","constraints":{"executionContext":"node"},"contract":["EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter","forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments","multiple listeners on the destination emitter share a single forwarding listener on the source emitter","removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter","forward supports an array of multiple event names managed independently","forward accepts an optional custom emit function in options to intercept forwarded events"],"goal":"verify bare-events.forward in pkg:npm/bare-events@2.9.1","kind":"HOW","packages":["pkg:npm/bare-events@2.9.1"],"schemaVersion":1,"symbols":["bare-events.forward"]},"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/bare-events@2.9.1"],"schemaVersion":1,"subject":"pkg:npm/bare-events@2.9.1","symbols":["bare-events.forward"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-events-forward",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-events-forward",
      "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-forward",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-events": "2.9.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-events.forward in pkg:npm/bare-events@2.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-events@2.9.1"
  ],
  "symbols": [
    "bare-events.forward"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import EventEmitter from 'bare-events';

// 1. EventEmitter.forward lazily attaches a listener to the source emitter only when a listener is registered on the destination emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'eventA');

  assert.equal(src.listenerCount('eventA'), 0);
  assert.equal(dest.listenerCount('eventA'), 0);

  const handler = () => {};
  dest.on('eventA', handler);
  assert.equal(src.listenerCount('eventA'), 1);
  assert.equal(dest.listenerCount('eventA'), 1);
}

// 2. forwarded events emitted on the source emitter are received by listeners on the destination emitter with original arguments
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'message');

  const received = [];
  dest.on('message', (arg1, arg2) => {
    received.push({ arg1, arg2 });
  });

  const emitted = src.emit('message', 'hello', 42);
  assert.equal(emitted, true);
  assert.deepEqual(received, [{ arg1: 'hello', arg2: 42 }]);
}

// 3. multiple listeners on the destination emitter share a single forwarding listener on the source emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'shared');

  const list1 = [];
  const list2 = [];
  dest.on('shared', (val) => list1.push(val));
  dest.on('shared', (val) => list2.push(val));

  assert.equal(dest.listenerCount('shared'), 2);
  assert.equal(src.listenerCount('shared'), 1);

  src.emit('shared', 'broadcast');
  assert.deepEqual(list1, ['broadcast']);
  assert.deepEqual(list2, ['broadcast']);
}

// 4. removing all listeners for an event on the destination emitter detaches the forwarding listener from the source emitter
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, 'cleanup');

  const h1 = () => {};
  const h2 = () => {};
  dest.on('cleanup', h1);
  dest.on('cleanup', h2);
  assert.equal(src.listenerCount('cleanup'), 1);

  dest.off('cleanup', h1);
  assert.equal(src.listenerCount('cleanup'), 1);

  dest.off('cleanup', h2);
  assert.equal(src.listenerCount('cleanup'), 0);
}

// 5. forward supports an array of multiple event names managed independently
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  EventEmitter.forward(src, dest, ['first', 'second']);

  assert.equal(src.listenerCount('first'), 0);
  assert.equal(src.listenerCount('second'), 0);

  const firstCalls = [];
  const secondCalls = [];
  dest.on('first', (x) => firstCalls.push(x));
  assert.equal(src.listenerCount('first'), 1);
  assert.equal(src.listenerCount('second'), 0);

  dest.on('second', (y) => secondCalls.push(y));
  assert.equal(src.listenerCount('second'), 1);

  src.emit('first', 'data-1');
  src.emit('second', 'data-2');
  assert.deepEqual(firstCalls, ['data-1']);
  assert.deepEqual(secondCalls, ['data-2']);

  dest.removeAllListeners('first');
  assert.equal(src.listenerCount('first'), 0);
  assert.equal(src.listenerCount('second'), 1);
}

// 6. forward accepts an optional custom emit function in options to intercept forwarded events
{
  const src = new EventEmitter();
  const dest = new EventEmitter();
  const intercepted = [];

  EventEmitter.forward(src, dest, 'custom', {
    emit(name, ...args) {
      intercepted.push({ name, args });
      dest.emit(name, ...args.map((s) => s.toUpperCase()));
    }
  });

  const received = [];
  dest.on('custom', (val) => received.push(val));

  src.emit('custom', 'lowercase');
  assert.deepEqual(intercepted, [{ name: 'custom', args: ['lowercase'] }]);
  assert.deepEqual(received, ['LOWERCASE']);
}

Seeder d'origine

anonyme