CodeSampleX

Exemplo

@npmcli/promise-spawn 8.0.3: promiseSpawn

Amostra verificada para npm @npmcli/promise-spawn 8.0.3: promiseSpawn. O contrato rodou em node 22 · linux debian/x64 · docker e passou.

sha256:87d36a86f2eeb87bbdf4749f5c0cf687cda110997421195de6d237d18a1bb813

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:npm/%40npmcli/promise-spawn@8.0.3
Pacotes
Símbolos
  • promiseSpawn
Criado
2026-10-18T01:39:44Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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
  }
)

Seeder de origem

anônimo