CodeSampleX

샘플

bare-signals 5.0.0: constants

검증된 샘플 — npm bare-signals 5.0.0: constants. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: package manifest exports Signal class and declares…

sha256:f01ff11e25fab2dcd9df014d16d0a21ddec273e3b3f9da7c81fb21bcb0efa3cc

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-14

케이스

HOW
목표
verify bare-signals.constants in pkg:npm/bare-signals@5.0.0
패키지
심벌
  • bare-signals.constants
환경
node 22.23.2
생성일
2026-09-14T22:44:45Z

컨트랙트

  1. package manifest exports Signal class and declares constants property in bare-signals@5.0.0
  2. TypeScript definitions in index.d.ts declare constants as Record<string, number> within Signal namespace
  3. native C binding in binding.c exports signals map containing standard POSIX signal definitions
  4. Signal.constants exposes the dictionary mapping signal names to numeric signal values
  5. helper getSignalNumber resolves numeric value for supported signal names from constants
  6. helper getSignalName performs reverse lookup of signal name from numeric value in constants
  7. helper isSupportedSignal validates whether a given signal name exists in constants
  8. Signal constructor resolves string signal names to numeric signums using constants map
  9. Signal constructor rejects signal names absent from constants with UNKNOWN_SIGNAL error

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 bare-signals.constants in pkg:npm/bare-signals@5.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-signals@5.0.0
Demonstrate these symbols/APIs:
  - bare-signals.constants

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:5bdab0628282b13ff8a9441234d4ddc692c4996071f329c91dad73fd75a0f65f","contract":["package manifest exports Signal class and declares constants property in bare-signals@5.0.0","TypeScript definitions in index.d.ts declare constants as Record\u003cstring, number\u003e within Signal namespace","native C binding in binding.c exports signals map containing standard POSIX signal definitions","Signal.constants exposes the dictionary mapping signal names to numeric signal values","helper getSignalNumber resolves numeric value for supported signal names from constants","helper getSignalName performs reverse lookup of signal name from numeric value in constants","helper isSupportedSignal validates whether a given signal name exists in constants","Signal constructor resolves string signal names to numeric signums using constants map","Signal constructor rejects signal names absent from constants with UNKNOWN_SIGNAL error"],"goal":"verify bare-signals.constants in pkg:npm/bare-signals@5.0.0","kind":"HOW","packages":["pkg:npm/bare-signals@5.0.0"],"schemaVersion":1,"symbols":["bare-signals.constants"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-signals@5.0.0"],"schemaVersion":1,"subject":"pkg:npm/bare-signals@5.0.0","symbols":["bare-signals.constants"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-signals-constants",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-signals-constants",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-signals": "5.0.0"
      }
    },
    "node_modules/bare-events": {
      "version": "2.9.2",
      "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.2.tgz",
      "integrity": "sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "bare-abort-controller": "*"
      },
      "peerDependenciesMeta": {
        "bare-abort-controller": {
          "optional": true
        }
      }
    },
    "node_modules/bare-signals": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/bare-signals/-/bare-signals-5.0.0.tgz",
      "integrity": "sha512-8Gn8bBFUh2AUCJ9wWWFjSGWIo1HIUSIQnXRJGSm/f7GCDMqsuJhRmR1dT+HtDaDBkeu2l8Koxt2JLurfJ5yHVw==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-events": "^2.5.3"
      },
      "engines": {
        "bare": ">=1.7.0"
      }
    }
  }
}
package.json
{
  "name": "sample-bare-signals-constants",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-signals": "5.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bare-signals.constants in pkg:npm/bare-signals@5.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-signals@5.0.0"
  ],
  "symbols": [
    "bare-signals.constants"
  ]
}
src/index.mjs
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

/**
 * Checks whether a signal name is present in the provided constants mapping.
 *
 * @param {string} signalName
 * @param {Record<string, number>} constants
 * @returns {boolean}
 */
export function isSupportedSignal(signalName, constants) {
  if (typeof signalName !== 'string' || !constants) {
    return false;
  }
  return Object.prototype.hasOwnProperty.call(constants, signalName);
}

/**
 * Resolves a signal name to its numeric signum using the constants mapping.
 * Throws UNKNOWN_SIGNAL if the signal name is not present in constants.
 *
 * @param {string} signalName
 * @param {Record<string, number>} constants
 * @returns {number}
 */
export function getSignalNumber(signalName, constants) {
  if (!isSupportedSignal(signalName, constants)) {
    const SignalError = require('bare-signals/errors');
    throw SignalError.UNKNOWN_SIGNAL(`Unknown signal '${signalName}'`);
  }
  return constants[signalName];
}

/**
 * Performs reverse lookup to find a signal name corresponding to a numeric signum.
 *
 * @param {number} signum
 * @param {Record<string, number>} constants
 * @returns {string | null}
 */
export function getSignalName(signum, constants) {
  if (typeof signum !== 'number' || !constants) {
    return null;
  }
  for (const [name, num] of Object.entries(constants)) {
    if (num === signum) {
      return name;
    }
  }
  return null;
}

/**
 * Returns a list of all signal names available in the constants mapping.
 *
 * @param {Record<string, number>} constants
 * @returns {string[]}
 */
export function listSupportedSignals(constants) {
  if (!constants || typeof constants !== 'object') {
    return [];
  }
  return Object.keys(constants);
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import {
  isSupportedSignal,
  getSignalNumber,
  getSignalName,
  listSupportedSignals,
} from '../src/index.mjs';

const require = createRequire(import.meta.url);

// 1. Resolve package manifest and verify export map and metadata
const pkgPath = require.resolve('bare-signals/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-signals', 'Package name must be bare-signals');
assert.equal(pkg.version, '5.0.0', 'Package version must be 5.0.0');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.equal(pkg.addon, true, 'Package must be marked as addon');
assert.equal(pkg.engines?.bare, '>=1.7.0', 'Package must specify Bare engine requirement');

assert.ok(pkg.exports, 'Package must define exports map');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must specify index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must specify index.js default');

const pkgDir = path.dirname(pkgPath);

// 2. Verify TypeScript type definitions in index.d.ts
const indexDts = fs.readFileSync(path.join(pkgDir, 'index.d.ts'), 'utf8');
assert.ok(indexDts.includes('declare class Signal'), 'index.d.ts must declare Signal class');
assert.ok(indexDts.includes('declare namespace Signal'), 'index.d.ts must declare Signal namespace');
assert.ok(
  indexDts.includes('export const constants: Record<string, number>'),
  'index.d.ts must declare constants as Record<string, number>'
);
assert.ok(indexDts.includes('export = Signal'), 'index.d.ts must export Signal');

// 3. Verify native C binding source in binding.c
const bindingCPath = path.join(pkgDir, 'binding.c');
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');
assert.ok(
  bindingC.includes('err = js_set_named_property(env, exports, "signals", signals);'),
  'binding.c must export signals property'
);
assert.ok(bindingC.includes('#ifdef SIGHUP'), 'binding.c must handle SIGHUP');
assert.ok(bindingC.includes('#ifdef SIGINT'), 'binding.c must handle SIGINT');
assert.ok(bindingC.includes('#ifdef SIGQUIT'), 'binding.c must handle SIGQUIT');
assert.ok(bindingC.includes('#ifdef SIGKILL'), 'binding.c must handle SIGKILL');
assert.ok(bindingC.includes('#ifdef SIGTERM'), 'binding.c must handle SIGTERM');

// 4. Mock binding to test Signal.constants in offline runtime
const bindingPath = path.join(pkgDir, 'binding.js');
const mockSignals = {
  SIGHUP: 1,
  SIGINT: 2,
  SIGQUIT: 3,
  SIGKILL: 9,
  SIGUSR1: 10,
  SIGUSR2: 12,
  SIGTERM: 15,
};

let nextHandleId = 1;
require.cache[bindingPath] = {
  id: bindingPath,
  filename: bindingPath,
  loaded: true,
  exports: {
    signals: mockSignals,
    init: (ctx, onsignal, onclose) => ({
      id: nextHandleId++,
      ctx,
      onsignal,
      onclose,
    }),
    start: () => {},
    stop: () => {},
    ref: () => {},
    unref: () => {},
    close: (handle) => {
      setImmediate(() => {
        handle.onclose.call(handle.ctx);
      });
    },
  },
};

const Signal = require('bare-signals');
assert.equal(typeof Signal, 'function', 'bare-signals export must be a class constructor');
assert.equal(typeof Signal.constants, 'object', 'Signal.constants must be an object');
assert.deepEqual(Signal.constants, mockSignals, 'Signal.constants must match mock signals map');
assert.equal(Signal.constants.SIGINT, 2, 'Signal.constants.SIGINT must be 2');
assert.equal(Signal.constants.SIGTERM, 15, 'Signal.constants.SIGTERM must be 15');
assert.equal(Signal.constants.SIGKILL, 9, 'Signal.constants.SIGKILL must be 9');

// 5. Test helper functions with constants
assert.equal(isSupportedSignal('SIGINT', Signal.constants), true, 'isSupportedSignal returns true for SIGINT');
assert.equal(isSupportedSignal('SIGUNKNOWN', Signal.constants), false, 'isSupportedSignal returns false for SIGUNKNOWN');
assert.equal(isSupportedSignal(null, Signal.constants), false, 'isSupportedSignal handles null safely');

assert.equal(getSignalNumber('SIGINT', Signal.constants), 2, 'getSignalNumber returns 2 for SIGINT');
assert.equal(getSignalNumber('SIGTERM', Signal.constants), 15, 'getSignalNumber returns 15 for SIGTERM');
assert.throws(
  () => getSignalNumber('SIGINVALID', Signal.constants),
  (err) => err.code === 'UNKNOWN_SIGNAL',
  'getSignalNumber throws UNKNOWN_SIGNAL for invalid signal'
);

assert.equal(getSignalName(2, Signal.constants), 'SIGINT', 'getSignalName returns SIGINT for signum 2');
assert.equal(getSignalName(15, Signal.constants), 'SIGTERM', 'getSignalName returns SIGTERM for signum 15');
assert.equal(getSignalName(999, Signal.constants), null, 'getSignalName returns null for unknown signum');

const supported = listSupportedSignals(Signal.constants);
assert.deepEqual(
  supported,
  ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGKILL', 'SIGUSR1', 'SIGUSR2', 'SIGTERM'],
  'listSupportedSignals returns all registered signal names'
);

// 6. Test Signal constructor behavior with constants
const sig = new Signal('SIGINT');
assert.equal(sig._signum, 2, 'Signal constructor resolves SIGINT to signum 2 via constants');

const sigterm = new Signal('SIGTERM');
assert.equal(sigterm._signum, 15, 'Signal constructor resolves SIGTERM to signum 15 via constants');

assert.throws(
  () => new Signal('SIGNOTINCONSTANTS'),
  (err) => err.code === 'UNKNOWN_SIGNAL',
  'Signal constructor throws UNKNOWN_SIGNAL when signal name not in constants'
);

console.log('Contract tests passed successfully.');

오리진 시더

익명