CodeSampleX

샘플

tinyexec 1.3.0: ExecProcess

검증된 샘플 — npm tinyexec 1.3.0: ExecProcess. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: ExecProcess creates an unspawned process representation…

sha256:340fb5f885cb227e5ea373efafe2c61a33a337750ab8e57ccfe3096986485aab

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript 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-06

케이스

HOW
목표
verify tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0
패키지
심벌
  • tinyexec.ExecProcess
환경
node 22.23.2
생성일
2026-09-06T12:35:40Z

컨트랙트

  1. ExecProcess creates an unspawned process representation that starts execution upon spawn
  2. ExecProcess exposes child process properties including exitCode and signalCode
  3. ExecProcess is thenable and resolves to stdout, stderr, and exitCode upon completion
  4. ExecProcess supports passing stdin input string to the spawned process
  5. ExecProcess supports streaming and async iteration over output lines
  6. ExecProcess pipe method chains output to another process
  7. ExecProcess throws NonZeroExitError on non-zero exit code when throwOnError is enabled
  8. ExecProcess aborts execution and updates aborted flag when AbortSignal triggers
  9. ExecProcess kill method terminates the running process

파일

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

소스 아티팩트 내려받기 (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 tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tinyexec@1.3.0
Demonstrate these symbols/APIs:
  - tinyexec.ExecProcess
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:1ba6208fce34a18d783dc76f066a80ece7b5a7f7adb41ea8d507db9e036abe1b","constraints":{"executionContext":"node"},"contract":["ExecProcess creates an unspawned process representation that starts execution upon spawn","ExecProcess exposes child process properties including exitCode and signalCode","ExecProcess is thenable and resolves to stdout, stderr, and exitCode upon completion","ExecProcess supports passing stdin input string to the spawned process","ExecProcess supports streaming and async iteration over output lines","ExecProcess pipe method chains output to another process","ExecProcess throws NonZeroExitError on non-zero exit code when throwOnError is enabled","ExecProcess aborts execution and updates aborted flag when AbortSignal triggers","ExecProcess kill method terminates the running process"],"goal":"verify tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0","kind":"HOW","packages":["pkg:npm/tinyexec@1.3.0"],"schemaVersion":1,"symbols":["tinyexec.ExecProcess"]},"contractCommand":["node","test/contract.cjs"],"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/tinyexec@1.3.0"],"schemaVersion":1,"subject":"pkg:npm/tinyexec@1.3.0","symbols":["tinyexec.ExecProcess"],"verifierAdapter":"node-typescript@1"}
index.cjs
'use strict';

const { ExecProcess, NonZeroExitError } = require('tinyexec');

/**
 * Creates and spawns an ExecProcess instance.
 * @param {string} command - Command to run
 * @param {string[]} [args] - Arguments array
 * @param {object} [options] - Options
 * @returns {ExecProcess}
 */
function createProcess(command, args, options) {
  const proc = new ExecProcess(command, args, options);
  proc.spawn();
  return proc;
}

/**
 * Creates an unspawned ExecProcess instance.
 * @param {string} command - Command to run
 * @param {string[]} [args] - Arguments array
 * @param {object} [options] - Options
 * @returns {ExecProcess}
 */
function buildProcess(command, args, options) {
  return new ExecProcess(command, args, options);
}

module.exports = {
  ExecProcess,
  NonZeroExitError,
  createProcess,
  buildProcess
};
package-lock.json
{
  "name": "sample-tinyexec-execprocess",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tinyexec-execprocess",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tinyexec": "1.3.0"
      }
    },
    "node_modules/tinyexec": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.0.tgz",
      "integrity": "sha512-QKAl9m8gWWGHV8jZcPeym6j+XULi6tOf1mT83WYJ4Lk2ytW/uwAWkrP0uFsdoYMdueVJ0qs26wZ+23xeB4ibNQ==",
      "license": "MIT",
      "engines": {
        "node": ">=18"
      }
    }
  }
}
package.json
{
  "name": "sample-tinyexec-execprocess",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0",
  "main": "index.cjs",
  "dependencies": {
    "tinyexec": "1.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tinyexec@1.3.0"
  ],
  "symbols": [
    "tinyexec.ExecProcess"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const {
  ExecProcess,
  NonZeroExitError,
  createProcess,
  buildProcess
} = require('../index.cjs');

async function main() {
  // 1. ExecProcess is exported as a class constructor
  assert.equal(typeof ExecProcess, 'function', 'ExecProcess must be a constructor');
  assert.equal(typeof createProcess, 'function', 'createProcess helper must be a function');
  assert.equal(typeof buildProcess, 'function', 'buildProcess helper must be a function');

  // 2. ExecProcess creates an unspawned process representation that starts execution upon spawn
  {
    const proc = buildProcess('node', ['-e', 'console.log("unspawned-to-spawned")']);
    assert.equal(proc.process, undefined, 'process must be undefined before spawn');
    assert.equal(proc.pid, undefined, 'pid must be undefined before spawn');
    proc.spawn();
    assert.ok(proc.process, 'process must be defined after spawn');
    assert.equal(typeof proc.pid, 'number', 'pid must be a number after spawn');
    const result = await proc;
    assert.equal(result.exitCode, 0);
    assert.equal(result.stdout.trim(), 'unspawned-to-spawned');
  }

  // 3. ExecProcess exposes child process properties including exitCode and signalCode
  {
    const proc = createProcess('node', ['-e', 'process.exit(4)']);
    const result = await proc;
    assert.equal(result.exitCode, 4);
    assert.equal(proc.exitCode, 4);
    assert.equal(proc.signalCode, null);
  }

  // 4. ExecProcess is thenable and resolves to stdout, stderr, and exitCode upon completion
  {
    const proc = createProcess('node', [
      '-e',
      'console.log("contract stdout payload"); console.error("contract stderr payload");'
    ]);
    const result = await proc;
    assert.equal(result.exitCode, 0);
    assert.equal(result.stdout.trim(), 'contract stdout payload');
    assert.equal(result.stderr.trim(), 'contract stderr payload');
  }

  // 5. ExecProcess supports passing stdin input string to the spawned process
  {
    const proc = createProcess('node', ['-e', 'process.stdin.pipe(process.stdout)'], {
      stdin: 'execprocess-stdin-content'
    });
    const result = await proc;
    assert.equal(result.exitCode, 0);
    assert.equal(result.stdout.trim(), 'execprocess-stdin-content');
  }

  // 6. ExecProcess supports streaming and async iteration over output lines
  {
    const proc = createProcess('node', ['-e', 'console.log("line-alpha"); console.log("line-beta");']);
    const lines = [];
    for await (const line of proc) {
      lines.push(line.trim());
    }
    assert.deepEqual(lines, ['line-alpha', 'line-beta']);
  }

  // 7. ExecProcess pipe method chains output to another process
  {
    const source = createProcess('node', ['-e', 'console.log("pipe-source-text")']);
    const piped = source.pipe('node', [
      '-e',
      'let buf = ""; process.stdin.on("data", c => buf += c); process.stdin.on("end", () => console.log(buf.trim().toUpperCase()));'
    ]);
    const result = await piped;
    assert.equal(result.exitCode, 0);
    assert.equal(result.stdout.trim(), 'PIPE-SOURCE-TEXT');
  }

  // 8. ExecProcess throws NonZeroExitError on non-zero exit code when throwOnError is enabled
  {
    await assert.rejects(
      async () => {
        const proc = createProcess('node', ['-e', 'process.stderr.write("nonzero failure message"); process.exit(8);'], {
          throwOnError: true
        });
        await proc;
      },
      (err) => {
        assert(err instanceof NonZeroExitError, 'Error must be an instance of NonZeroExitError');
        assert.equal(err.exitCode, 8);
        assert.equal(err.output?.stderr, 'nonzero failure message');
        return true;
      }
    );
  }

  // 9. ExecProcess aborts execution and updates aborted flag when AbortSignal triggers
  {
    const controller = new AbortController();
    const proc = createProcess('node', ['-e', 'setInterval(() => {}, 1000);'], {
      signal: controller.signal
    });
    await new Promise((resolve) => setTimeout(resolve, 50));
    controller.abort();
    await proc;
    assert.equal(proc.aborted, true);
    assert.equal(proc.killed, true);
  }

  // 10. ExecProcess kill method terminates the running process
  {
    const proc = createProcess('node', ['-e', 'setInterval(() => {}, 1000);']);
    await new Promise((resolve) => setTimeout(resolve, 50));
    const killed = proc.kill('SIGTERM');
    assert.equal(killed, true);
    await proc;
    assert.equal(proc.killed, true);
  }

  console.log('Contract assertions passed.');
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

오리진 시더

익명