CodeSampleX

示例

@npmcli/promise-spawn 8.0.3: promiseSpawn

已验证示例 — npm @npmcli/promise-spawn 8.0.3: promiseSpawn. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: promiseSpawn(cmd, args, opts, extra) spawns a…

sha256:87d36a86f2eeb87bbdf4749f5c0cf687cda110997421195de6d237d18a1bb813

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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
  }
)

原始种子者

匿名