CodeSampleX

サンプル

signal-exit 3.0.7

検証済みサンプル — npm signal-exit 3.0.7. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: onExit registers an exit callback and returns an unregister…

sha256:32a1c9e1c6c725b407cff187013015ca086ad67013166b721ad5fb39b27cb5ee

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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();
}

オリジンシーダー

匿名