CodeSampleX

Exemple

exit 0.1.2: exit

Échantillon vérifié pour npm exit 0.1.2: exit. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : assert exit is a function…

sha256:6411e70962709c59faba8e022aecae68ba674f2d4bd1c7d04d1eb64049a2448f

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
1
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-27

Cas

HOW
Objectif
verify pkg:npm/exit@0.1.2
Paquets
Symboles
  • exit
Environnement
node 22.23.2
Créé
2026-08-27T12:41:36Z

Contrat

  1. assert exit is a function accepting exit code and streams array
  2. assert exit immediately terminates process with given code when all streams have bufferSize 0
  3. assert exit waits for non-empty streams to drain before calling process.exit
  4. assert exit replaces stream.write with noop function during termination
  5. assert exit synchronously flushes output and terminates child process with exit code
  6. assert exit registers process exit listener to ensure exit code propagation

Fichiers

  • PROMPT.md
  • csx.json
  • index.js
  • 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 pkg:npm/exit@0.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/exit@0.1.2
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:0caf1222df127738e39d1c9a83391bc54ae7a42c6548f3cb74a750581eaa5b5f","constraints":{"executionContext":"node"},"contract":["assert exit is a function accepting exit code and streams array","assert exit immediately terminates process with given code when all streams have bufferSize 0","assert exit waits for non-empty streams to drain before calling process.exit","assert exit replaces stream.write with noop function during termination","assert exit synchronously flushes output and terminates child process with exit code","assert exit registers process exit listener to ensure exit code propagation"],"goal":"verify pkg:npm/exit@0.1.2","kind":"HOW","packages":["pkg:npm/exit@0.1.2"],"schemaVersion":1,"symbols":["exit"]},"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/exit@0.1.2"],"schemaVersion":1,"subject":"pkg:npm/exit@0.1.2","symbols":["exit"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const exit = require('exit');

/**
 * Invokes exit function to flush streams and terminate process.
 *
 * @param {number} [exitCode] - Process exit status code.
 * @param {Array<object>} [streams] - Streams to drain before exit.
 */
function safeExit(exitCode, streams) {
  return exit(exitCode, streams);
}

module.exports = {
  exit,
  safeExit,
};
package-lock.json
{
  "name": "sample-exit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-exit",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "exit": "0.1.2"
      }
    },
    "node_modules/exit": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
      "integrity": "sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8.0"
      }
    }
  }
}
package.json
{
  "name": "sample-exit",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for exit",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "exit": "0.1.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/exit@0.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/exit@0.1.2"
  ],
  "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';
import { spawnSync } from 'node:child_process';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { exit, safeExit } = require('../index.js');

// Contract 1: assert exit is a function accepting exit code and streams array
assert.strictEqual(typeof exit, 'function', 'exit must be a function');
assert.strictEqual(typeof safeExit, 'function', 'safeExit must be a function');
assert.strictEqual(exit.length, 2, 'exit should accept 2 formal parameters');

// Contract 2: assert exit immediately terminates process with given code when all streams have bufferSize 0
{
  const origExit = process.exit;
  const origListeners = process.rawListeners('exit');
  let invokedCode = null;
  process.exit = (code) => {
    invokedCode = code;
  };

  try {
    const mockStream1 = { bufferSize: 0, write: () => {} };
    const mockStream2 = { bufferSize: 0, write: () => {} };
    safeExit(42, [mockStream1, mockStream2]);
    assert.strictEqual(invokedCode, 42, 'Expected process.exit to be called immediately with code 42');
  } finally {
    process.exit = origExit;
    process.removeAllListeners('exit');
    origListeners.forEach((fn) => process.on('exit', fn));
  }
}

// Contract 3: assert exit waits for non-empty streams to drain before calling process.exit
{
  const origExit = process.exit;
  const origListeners = process.rawListeners('exit');
  let invokedCode = null;
  process.exit = (code) => {
    invokedCode = code;
  };

  try {
    let drainCallback1 = null;
    let drainCallback2 = null;
    const mockStream1 = {
      bufferSize: 128,
      write: (str, enc, cb) => {
        drainCallback1 = cb;
      },
    };
    const mockStream2 = {
      bufferSize: 64,
      write: (str, enc, cb) => {
        drainCallback2 = cb;
      },
    };

    safeExit(7, [mockStream1, mockStream2]);
    assert.strictEqual(invokedCode, null, 'Process should not exit while streams are not drained');
    assert.strictEqual(typeof drainCallback1, 'function', 'Write callback 1 should be set');
    assert.strictEqual(typeof drainCallback2, 'function', 'Write callback 2 should be set');

    drainCallback1();
    assert.strictEqual(invokedCode, null, 'Process should not exit when only one stream drained');

    drainCallback2();
    assert.strictEqual(invokedCode, 7, 'Process should exit with code 7 after all streams drain');
  } finally {
    process.exit = origExit;
    process.removeAllListeners('exit');
    origListeners.forEach((fn) => process.on('exit', fn));
  }
}

// Contract 4: assert exit replaces stream.write with noop function during termination
{
  const origExit = process.exit;
  const origListeners = process.rawListeners('exit');
  let writeCalledAfterExit = false;
  process.exit = () => {};

  try {
    const mockStream = {
      bufferSize: 0,
      write: () => {
        writeCalledAfterExit = true;
      },
    };
    safeExit(0, [mockStream]);
    assert.strictEqual(typeof mockStream.write, 'function');
    mockStream.write('should be ignored');
    assert.strictEqual(writeCalledAfterExit, false, 'stream.write should be replaced with no-op');
  } finally {
    process.exit = origExit;
    process.removeAllListeners('exit');
    origListeners.forEach((fn) => process.on('exit', fn));
  }
}

// Contract 5: assert exit synchronously flushes output and terminates child process with exit code
{
  const testScript = `
    const { exit } = require(${JSON.stringify(require.resolve('../index.js'))});
    process.stdout.write('contract-stdout-payload\\n');
    process.stderr.write('contract-stderr-payload\\n');
    exit(13);
  `;
  const result = spawnSync(process.execPath, ['-e', testScript], { encoding: 'utf8' });
  assert.strictEqual(result.status, 13, 'Child process must exit with code 13');
  assert.strictEqual(result.stdout, 'contract-stdout-payload\n', 'Child process stdout must match written payload');
  assert.strictEqual(result.stderr, 'contract-stderr-payload\n', 'Child process stderr must match written payload');
}

// Contract 6: assert exit registers process exit listener to ensure exit code propagation
{
  const origExit = process.exit;
  const origListeners = process.rawListeners('exit');
  process.exit = () => {};

  try {
    const initialListenerCount = process.listenerCount('exit');
    const mockStream = { bufferSize: 0, write: () => {} };
    safeExit(9, [mockStream]);
    const postListenerCount = process.listenerCount('exit');
    assert.strictEqual(postListenerCount, initialListenerCount + 1, 'exit should attach an exit event listener');
  } finally {
    process.exit = origExit;
    process.removeAllListeners('exit');
    origListeners.forEach((fn) => process.on('exit', fn));
  }
}

console.log('All contract assertions passed successfully.');

Seeder d'origine

anonyme