CodeSampleX

Пример

signal-exit 3.0.7

Проверенный пример — npm signal-exit 3.0.7. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: onExit registers an exit callback and returns…

sha256:32a1c9e1c6c725b407cff187013015ca086ad67013166b721ad5fb39b27cb5ee

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify pkg:npm/signal-exit@3.0.7
Пакеты
Окружение
node 22.23.2
Создан
2026-08-23T13:32:00Z

Контракт

  1. onExit registers an exit callback and returns an unregister function
  2. calling the returned unregister function prevents the exit callback from firing
  3. onExit throws AssertionError when a non-function callback is passed
  4. onExit callback receives the numeric exit code when process.exit is called
  5. onExit callback receives exit code 0 when the Node.js event loop terminates naturally
  6. onExit callback receives the signal name when the process receives a termination signal
  7. onExit with alwaysLast option executes after standard exit listeners
  8. signals export provides an array of standard POSIX termination signal names
  9. load and unload functions control the lifecycle of process exit listeners

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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/signal-exit@3.0.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/signal-exit@3.0.7
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:1c92273ec54f68150fc27d112b87417f352dffff5dcf9b01b339be09f4668bec","constraints":{"executionContext":"node"},"contract":["onExit registers an exit callback and returns an unregister function","calling the returned unregister function prevents the exit callback from firing","onExit throws AssertionError when a non-function callback is passed","onExit callback receives the numeric exit code when process.exit is called","onExit callback receives exit code 0 when the Node.js event loop terminates naturally","onExit callback receives the signal name when the process receives a termination signal","onExit with alwaysLast option executes after standard exit listeners","signals export provides an array of standard POSIX termination signal names","load and unload functions control the lifecycle of process exit listeners"],"goal":"verify pkg:npm/signal-exit@3.0.7","kind":"HOW","packages":["pkg:npm/signal-exit@3.0.7"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/signal-exit@3.0.7"],"schemaVersion":1,"subject":"pkg:npm/signal-exit@3.0.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-signal-exit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-signal-exit",
      "version": "1.0.0",
      "dependencies": {
        "signal-exit": "3.0.7"
      }
    },
    "node_modules/signal-exit": {
      "version": "3.0.7",
      "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
      "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-signal-exit",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "signal-exit": "3.0.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/signal-exit@3.0.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/signal-exit@3.0.7"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { spawn, spawnSync } from 'node:child_process';
import onExit from 'signal-exit';

// 1. onExit registers an exit callback and returns an unregister function
{
	const unregister = onExit(() => {});
	assert.equal(typeof unregister, 'function');
	unregister();
}

// 2. calling the returned unregister function prevents the exit callback from firing
{
	const code = `
		const onExit = require('signal-exit');
		const remove = onExit(() => {
			process.stdout.write('UNREGISTER_FAILED');
		});
		remove();
		process.exit(0);
	`;
	const res = spawnSync(process.execPath, ['-e', code], { encoding: 'utf8' });
	assert.equal(res.status, 0);
	assert.ok(!res.stdout.includes('UNREGISTER_FAILED'));
}

// 3. onExit throws AssertionError when a non-function callback is passed
{
	assert.throws(
		() => {
			onExit(null);
		},
		{
			name: 'AssertionError',
		}
	);
}

// 4. onExit callback receives the numeric exit code when process.exit is called
{
	const code = `
		const fs = require('fs');
		const onExit = require('signal-exit');
		onExit((code, signal) => {
			fs.writeSync(1, 'EXIT_CODE:' + code + ':' + signal);
		});
		process.exit(42);
	`;
	const res = spawnSync(process.execPath, ['-e', code], { encoding: 'utf8' });
	assert.equal(res.status, 42);
	assert.ok(res.stdout.includes('EXIT_CODE:42:null'));
}

// 5. onExit callback receives exit code 0 when the Node.js event loop terminates naturally
{
	const code = `
		const fs = require('fs');
		const onExit = require('signal-exit');
		onExit((code, signal) => {
			fs.writeSync(1, 'NATURAL_EXIT:' + code + ':' + signal);
		});
	`;
	const res = spawnSync(process.execPath, ['-e', code], { encoding: 'utf8' });
	assert.equal(res.status, 0);
	assert.ok(res.stdout.includes('NATURAL_EXIT:0:null'));
}

// 6. onExit callback receives the signal name when the process receives a termination signal
await new Promise((resolve, reject) => {
	const code = `
		const fs = require('fs');
		const onExit = require('signal-exit');
		onExit((code, signal) => {
			fs.writeSync(1, 'SIGNAL:' + signal);
		});
		setInterval(() => {}, 1000);
	`;
	const child = spawn(process.execPath, ['-e', code], { stdio: ['pipe', 'pipe', 'inherit'] });
	let out = '';
	child.stdout.on('data', (d) => {
		out += d.toString();
	});
	setTimeout(() => {
		child.kill('SIGTERM');
	}, 100);
	child.on('close', () => {
		try {
			assert.ok(out.includes('SIGNAL:SIGTERM'));
			resolve();
		} catch (err) {
			reject(err);
		}
	});
});

// 7. onExit with alwaysLast option executes after standard exit listeners
{
	const code = `
		const fs = require('fs');
		const onExit = require('signal-exit');
		onExit((code, signal) => {
			fs.writeSync(1, 'LAST\\n');
		}, { alwaysLast: true });
		onExit((code, signal) => {
			fs.writeSync(1, 'FIRST\\n');
		});
		process.exit(0);
	`;
	const res = spawnSync(process.execPath, ['-e', code], { encoding: 'utf8' });
	assert.equal(res.status, 0);
	assert.equal(res.stdout, 'FIRST\nLAST\n');
}

// 8. signals export provides an array of standard POSIX termination signal names
{
	const sigs = onExit.signals();
	assert.ok(Array.isArray(sigs));
	assert.ok(sigs.includes('SIGINT'));
	assert.ok(sigs.includes('SIGTERM'));
	assert.ok(sigs.includes('SIGHUP'));
}

// 9. load and unload functions control the lifecycle of process exit listeners
{
	assert.equal(typeof onExit.load, 'function');
	assert.equal(typeof onExit.unload, 'function');
	onExit.load();
	onExit.unload();
}

Исходный сидер

аноним