CodeSampleX

サンプル

signal-exit 4.1.0

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

sha256:d2fe5dd9721042199af69f6e68faacff51c5b20dc71a6495df8f6afa513d6fce

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21
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-08

ケース

HOW
ゴール
verify pkg:npm/signal-exit@4.1.0
パッケージ
作成日
2026-08-21T15:26:09Z

コントラクト

  1. onExit registers an exit callback and returns an unregister function
  2. calling the returned unregister function prevents the callback from firing
  3. onExit callback receives the numeric exit code when process.exit is called
  4. onExit callback receives code 0 when the event loop drains naturally
  5. signals export provides an array of standard POSIX signal names

ファイル

  • 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@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/signal-exit@4.1.0

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:4a938f4764183a7c899a81e9186d80e611c1731583eabdde9cd75a2843486ea3","contract":["onExit registers an exit callback and returns an unregister function","calling the returned unregister function prevents the callback from firing","onExit callback receives the numeric exit code when process.exit is called","onExit callback receives code 0 when the event loop drains naturally","signals export provides an array of standard POSIX signal names"],"goal":"verify pkg:npm/signal-exit@4.1.0","kind":"HOW","packages":["pkg:npm/signal-exit@4.1.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/signal-exit@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/signal-exit@4.1.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-signal-exit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-signal-exit",
      "version": "1.0.0",
      "dependencies": {
        "signal-exit": "4.1.0"
      }
    },
    "node_modules/signal-exit": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
      "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
      "license": "ISC",
      "engines": {
        "node": ">=14"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    }
  }
}
package.json
{
  "name": "verify-signal-exit",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "signal-exit": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/signal-exit@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/signal-exit@4.1.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { onExit, signals } from 'signal-exit';

// 1. Verify exports and types
assert.equal(typeof onExit, 'function', 'onExit must be a function');
assert.ok(Array.isArray(signals), 'signals must be an array');
assert.ok(signals.includes('SIGINT'), 'signals array should contain SIGINT');
assert.ok(signals.includes('SIGTERM'), 'signals array should contain SIGTERM');

// 2. Verify onExit returns an unregister function
const remove = onExit(() => {});
assert.equal(typeof remove, 'function', 'onExit must return an unregister function');
remove();

// 3. Test exit handler invocation on process.exit
const exitTestCode = `
import { onExit } from 'signal-exit';
onExit((code, signal) => {
  process.stdout.write('EXIT_CODE:' + code + ',SIGNAL:' + signal + '\\n');
});
process.exit(42);
`;

const exitRes = spawnSync(process.execPath, ['--input-type=module', '-e', exitTestCode], {
  encoding: 'utf8',
});
assert.equal(exitRes.status, 42, 'Child process should exit with code 42');
assert.ok(exitRes.stdout.includes('EXIT_CODE:42,SIGNAL:null'), 'Exit handler must receive exit code 42');

// 4. Test unregister function prevents handler invocation
const unregTestCode = `
import { onExit } from 'signal-exit';
const unreg = onExit(() => {
  process.stdout.write('UNEXPECTED_CALL\\n');
});
unreg();
process.exit(0);
`;

const unregRes = spawnSync(process.execPath, ['--input-type=module', '-e', unregTestCode], {
  encoding: 'utf8',
});
assert.equal(unregRes.status, 0, 'Child process should exit with code 0');
assert.ok(!unregRes.stdout.includes('UNEXPECTED_CALL'), 'Unregistered handler must not be invoked');

// 5. Test exit handler invocation on event loop drain
const drainTestCode = `
import { onExit } from 'signal-exit';
onExit((code, signal) => {
  process.stdout.write('DRAIN_CODE:' + code + ',SIGNAL:' + signal + '\\n');
});
`;

const drainRes = spawnSync(process.execPath, ['--input-type=module', '-e', drainTestCode], {
  encoding: 'utf8',
});
assert.equal(drainRes.status, 0, 'Child process should exit with code 0 on event loop drain');
assert.ok(drainRes.stdout.includes('DRAIN_CODE:0,SIGNAL:null'), 'Exit handler must receive code 0 on natural exit');

console.log('Contract verification passed for signal-exit');

オリジンシーダー

匿名