CodeSampleX

サンプル

@npmcli/promise-spawn 8.0.3: promiseSpawn

検証済みサンプル — npm @npmcli/promise-spawn 8.0.3: promiseSpawn. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: promiseSpawn(cmd, args, opts, extra)…

sha256:87d36a86f2eeb87bbdf4749f5c0cf687cda110997421195de6d237d18a1bb813

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

実行証拠

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

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

検証実行環境

環境 コントラクト ステージ 実行日
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-10-18

ケース

HOW
ゴール
verify pkg:npm/%40npmcli/promise-spawn@8.0.3
パッケージ
シンボル
  • promiseSpawn
作成日
2026-10-18T01:39:44Z

コントラクト

  1. promiseSpawn(cmd, args, opts, extra) spawns a child process and resolves with { cmd, args, code: 0, signal: null, stdout, stderr, ...extra } where stdout and stderr are trimmed strings by default
  2. Passing { stdioString: false } in opts returns raw Buffer instances for stdout and stderr without trimming
  3. The returned Promise exposes .stdin and .process properties referencing the underlying child process streams and handle
  4. When the child exits with a non-zero code, the promise rejects with Error('command failed') decorated with code, signal, stdout, stderr, and extra properties

ファイル

  • 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/%40npmcli/promise-spawn@8.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40npmcli/promise-spawn@8.0.3

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:d7f346821404d0c430de0e568ec785cc561c6d4e7058124a11f3a0006dc1470e","contract":["promiseSpawn(cmd, args, opts, extra) spawns a child process and resolves with { cmd, args, code: 0, signal: null, stdout, stderr, ...extra } where stdout and stderr are trimmed strings by default","Passing { stdioString: false } in opts returns raw Buffer instances for stdout and stderr without trimming","The returned Promise exposes .stdin and .process properties referencing the underlying child process streams and handle","When the child exits with a non-zero code, the promise rejects with Error('command failed') decorated with code, signal, stdout, stderr, and extra properties"],"goal":"verify pkg:npm/%40npmcli/promise-spawn@8.0.3","kind":"HOW","packages":["pkg:npm/%40npmcli/promise-spawn@8.0.3"],"schemaVersion":1,"symbols":["promiseSpawn"]},"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/%40npmcli/promise-spawn@8.0.3"],"schemaVersion":1,"subject":"pkg:npm/%40npmcli/promise-spawn@8.0.3","symbols":["promiseSpawn"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-promise-spawn",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-promise-spawn",
      "version": "1.0.0",
      "dependencies": {
        "@npmcli/promise-spawn": "8.0.3"
      }
    },
    "node_modules/@npmcli/promise-spawn": {
      "version": "8.0.3",
      "resolved": "https://registry.npmjs.org/@npmcli/promise-spawn/-/promise-spawn-8.0.3.tgz",
      "integrity": "sha512-Yb00SWaL4F8w+K8YGhQ55+xE4RUNdMHV43WZGsiTM92gS+lC0mGsn7I4hLug7pbao035S6bj3Y3w0cUNGLfmkg==",
      "license": "ISC",
      "dependencies": {
        "which": "^5.0.0"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/isexe": {
      "version": "3.1.5",
      "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.5.tgz",
      "integrity": "sha512-6B3tLtFqtQS4ekarvLVMZ+X+VlvQekbe4taUkf/rhVO3d/h0M2rfARm/pXLcPEsjjMsFgrFgSrhQIxcSVrBz8w==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/which": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/which/-/which-5.0.0.tgz",
      "integrity": "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==",
      "license": "ISC",
      "dependencies": {
        "isexe": "^3.1.1"
      },
      "bin": {
        "node-which": "bin/which.js"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    }
  }
}
package.json
{
  "name": "verify-promise-spawn",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@npmcli/promise-spawn": "8.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40npmcli/promise-spawn@8.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40npmcli/promise-spawn@8.0.3"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict'
import promiseSpawn from '@npmcli/promise-spawn'

// 1. Successful execution returns trimmed stdout/stderr strings and extra properties
const ok = await promiseSpawn(
  process.execPath,
  ['-e', 'process.stdout.write("  hello world  \\n"); process.stderr.write("  warn  \\n")'],
  {},
  { tag: 'ok-run' }
)
assert.equal(ok.code, 0)
assert.equal(ok.signal, null)
assert.equal(ok.stdout, 'hello world')
assert.equal(ok.stderr, 'warn')
assert.equal(ok.tag, 'ok-run')
assert.deepEqual(ok.args, ['-e', 'process.stdout.write("  hello world  \\n"); process.stderr.write("  warn  \\n")'])

// 2. stdioString: false returns raw Buffers without trimming
const raw = await promiseSpawn(
  process.execPath,
  ['-e', 'process.stdout.write("raw\\n")'],
  { stdioString: false }
)
assert.ok(Buffer.isBuffer(raw.stdout))
assert.equal(raw.stdout.toString('utf8'), 'raw\n')
assert.ok(Buffer.isBuffer(raw.stderr))
assert.equal(raw.stderr.length, 0)

// 3. Returned promise exposes .stdin and .process handles
const childPromise = promiseSpawn(
  process.execPath,
  ['-e', 'process.stdin.pipe(process.stdout)']
)
assert.ok(childPromise.stdin)
assert.ok(childPromise.process)
childPromise.stdin.end('piped input\n')
const piped = await childPromise
assert.equal(piped.stdout, 'piped input')

// 4. Non-zero exit code rejects with Error('command failed') decorated with result + extra
await assert.rejects(
  () => promiseSpawn(
    process.execPath,
    ['-e', 'process.stderr.write("boom\\n"); process.exit(3)'],
    {},
    { context: 'fail-test' }
  ),
  (err) => {
    assert.equal(err.message, 'command failed')
    assert.equal(err.code, 3)
    assert.equal(err.stderr, 'boom')
    assert.equal(err.context, 'fail-test')
    return true
  }
)

オリジンシーダー

匿名