CodeSampleX

Exemple

mitt 3.0.1: emitter.emit

Échantillon vérifié pour npm mitt 3.0.1: emitter.emit. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:11c9b0aad5ee70cc3759453b32bfe7659c35ce0b4cf38ca5dba7f5d56ff23636

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 emitter.emit in pkg:npm/mitt@3.0.1
Paquets
Symboles
  • emitter.emit
Environnement
node 22.23.2
Créé
2026-08-26T01:00:49Z

Contrat

  1. emitter.emit invokes registered event handlers synchronously with the provided payload.
  2. emitter.emit invokes wildcard handlers registered with '*' passing the event type and payload.
  3. emitter.emit executes safely as a no-op when no handlers are registered for the event type.
  4. emitter.emit passes undefined to handlers when called without a payload argument.
  5. emitter.emit invokes multiple handlers for the same event in registration order.

Fichiers

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

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 emitter.emit in pkg:npm/mitt@3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/mitt@3.0.1
Demonstrate these symbols/APIs:
  - emitter.emit
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:e0c3aa0046f3cb788785fac75595ef5d2dc0625a563e326cb8ca799887d4464d","constraints":{"executionContext":"node"},"contract":["emitter.emit invokes registered event handlers synchronously with the provided payload.","emitter.emit invokes wildcard handlers registered with '*' passing the event type and payload.","emitter.emit executes safely as a no-op when no handlers are registered for the event type.","emitter.emit passes undefined to handlers when called without a payload argument.","emitter.emit invokes multiple handlers for the same event in registration order."],"goal":"verify emitter.emit in pkg:npm/mitt@3.0.1","kind":"HOW","packages":["pkg:npm/mitt@3.0.1"],"schemaVersion":1,"symbols":["emitter.emit"]},"contractCommand":["node","test/contract.cjs"],"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/mitt@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/mitt@3.0.1","symbols":["emitter.emit"],"verifierAdapter":"node-typescript@1"}
index.js
const mitt = require('mitt');

function createEmitter(all) {
  return mitt(all);
}

module.exports = {
  mitt,
  createEmitter,
};
package-lock.json
{
  "name": "verify-mitt-emit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-mitt-emit",
      "version": "1.0.0",
      "dependencies": {
        "mitt": "3.0.1"
      }
    },
    "node_modules/mitt": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
      "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "verify-mitt-emit",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for emitter.emit in mitt",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "mitt": "3.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify emitter.emit in pkg:npm/mitt@3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/mitt@3.0.1"
  ],
  "symbols": [
    "emitter.emit"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const { mitt, createEmitter } = require('../index.js');

// Contract 1: emitter.emit invokes registered event handlers synchronously with the provided payload.
{
  const emitter = createEmitter();
  const received = [];

  emitter.on('user:login', (data) => {
    received.push(data);
  });

  const payload = { userId: 'usr-123', timestamp: 1700000000 };
  emitter.emit('user:login', payload);

  assert.strictEqual(received.length, 1);
  assert.deepStrictEqual(received[0], payload);
  assert.strictEqual(received[0], payload, 'Payload reference should be preserved');
}

// Contract 2: emitter.emit invokes wildcard handlers registered with '*' passing the event type and payload.
{
  const emitter = mitt();
  const wildcardEvents = [];

  emitter.on('*', (type, event) => {
    wildcardEvents.push({ type, event });
  });

  emitter.emit('item:create', { id: 1, name: 'Sample' });
  emitter.emit('item:delete', { id: 1 });

  assert.strictEqual(wildcardEvents.length, 2);
  assert.deepStrictEqual(wildcardEvents[0], {
    type: 'item:create',
    event: { id: 1, name: 'Sample' },
  });
  assert.deepStrictEqual(wildcardEvents[1], {
    type: 'item:delete',
    event: { id: 1 },
  });
}

// Contract 3: emitter.emit executes safely as a no-op when no handlers are registered for the event type.
{
  const emitter = createEmitter();
  assert.doesNotThrow(() => {
    emitter.emit('unregistered:event', { data: 'test' });
    emitter.emit('another:event');
  });
}

// Contract 4: emitter.emit passes undefined to handlers when called without a payload argument.
{
  const emitter = createEmitter();
  let receivedPayload = 'not-called';
  let callCount = 0;

  emitter.on('ping', (event) => {
    callCount += 1;
    receivedPayload = event;
  });

  emitter.emit('ping');

  assert.strictEqual(callCount, 1);
  assert.strictEqual(receivedPayload, undefined);
}

// Contract 5: emitter.emit invokes multiple handlers for the same event in registration order.
{
  const emitter = createEmitter();
  const executionOrder = [];

  emitter.on('action', () => {
    executionOrder.push('first');
  });
  emitter.on('action', () => {
    executionOrder.push('second');
  });
  emitter.on('action', () => {
    executionOrder.push('third');
  });

  emitter.emit('action', { value: 42 });

  assert.deepStrictEqual(executionOrder, ['first', 'second', 'third']);
}

console.log('All emitter.emit contract tests passed.');

Seeder d'origine

anonyme