CodeSampleX

Exemple

cross-spawn 7.0.6: cross-spawn

Échantillon vérifié pour npm cross-spawn 7.0.6: cross-spawn. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:16485ebfe716dd75c9e7351ada1212ac6dff8035da0898f4479e291a67474c32

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

Cas

HOW
Objectif
verify cross-spawn in pkg:npm/cross-spawn@7.0.6
Paquets
Symboles
  • cross-spawn
Créé
2026-08-26T10:41:56Z

Contrat

  1. crossSpawn.sync executes command synchronously and returns status 0 with valid pid
  2. crossSpawn.sync decodes stdout and stderr as strings when encoding option is provided
  3. crossSpawn.sync passes arguments and custom environment variables to child process
  4. crossSpawn.sync captures non-zero exit code and standard error on failure
  5. crossSpawn.sync reports ENOENT error when binary does not exist
  6. crossSpawn executes command asynchronously and streams stdout
  7. crossSpawn pipes stdin to child process
  8. crossSpawn emits error event with ENOENT for non-existent command

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 cross-spawn in pkg:npm/cross-spawn@7.0.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/cross-spawn@7.0.6
Demonstrate these symbols/APIs:
  - cross-spawn

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:1cc8daf8fd9f26210030a336410d0a881e5ccfbc52d25b7800d5643cc87cb74f","contract":["crossSpawn.sync executes command synchronously and returns status 0 with valid pid","crossSpawn.sync decodes stdout and stderr as strings when encoding option is provided","crossSpawn.sync passes arguments and custom environment variables to child process","crossSpawn.sync captures non-zero exit code and standard error on failure","crossSpawn.sync reports ENOENT error when binary does not exist","crossSpawn executes command asynchronously and streams stdout","crossSpawn pipes stdin to child process","crossSpawn emits error event with ENOENT for non-existent command"],"goal":"verify cross-spawn in pkg:npm/cross-spawn@7.0.6","kind":"HOW","packages":["pkg:npm/cross-spawn@7.0.6"],"schemaVersion":1,"symbols":["cross-spawn"]},"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/cross-spawn@7.0.6"],"schemaVersion":1,"subject":"pkg:npm/cross-spawn@7.0.6","symbols":["cross-spawn"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "cross-spawn-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "cross-spawn-verification",
      "version": "1.0.0",
      "dependencies": {
        "cross-spawn": "7.0.6"
      }
    },
    "node_modules/cross-spawn": {
      "version": "7.0.6",
      "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
      "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
      "license": "MIT",
      "dependencies": {
        "path-key": "^3.1.0",
        "shebang-command": "^2.0.0",
        "which": "^2.0.1"
      },
      "engines": {
        "node": ">= 8"
      }
    },
    "node_modules/isexe": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
      "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
      "license": "ISC"
    },
    "node_modules/path-key": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
      "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/shebang-command": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
      "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
      "license": "MIT",
      "dependencies": {
        "shebang-regex": "^3.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/shebang-regex": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
      "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/which": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
      "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
      "license": "ISC",
      "dependencies": {
        "isexe": "^2.0.0"
      },
      "bin": {
        "node-which": "bin/node-which"
      },
      "engines": {
        "node": ">= 8"
      }
    }
  }
}
package.json
{
  "name": "cross-spawn-verification",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "cross-spawn": "7.0.6"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cross-spawn in pkg:npm/cross-spawn@7.0.6",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cross-spawn@7.0.6"
  ],
  "symbols": [
    "cross-spawn"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import spawn from 'cross-spawn';

// 1. crossSpawn.sync executes command synchronously and returns status 0 with valid pid
const resultSync = spawn.sync('node', ['-e', 'console.log("hello cross-spawn")']);
assert.strictEqual(resultSync.status, 0);
assert.strictEqual(resultSync.signal, null);
assert.strictEqual(resultSync.error, null);
assert.ok(typeof resultSync.pid === 'number' && resultSync.pid > 0);
assert.ok(resultSync.stdout.toString().includes('hello cross-spawn'));

// 2. crossSpawn.sync decodes stdout and stderr as strings when encoding option is provided
const resultEncoded = spawn.sync('node', ['-e', 'console.log("encoded-output")'], {
  encoding: 'utf8'
});
assert.strictEqual(resultEncoded.status, 0);
assert.strictEqual(resultEncoded.stdout.trim(), 'encoded-output');
assert.strictEqual(resultEncoded.stderr, '');

// 3. crossSpawn.sync passes arguments and custom environment variables to child process
const resultEnv = spawn.sync('node', ['-e', 'console.log(process.env.TEST_VAR, process.argv[1])', 'arg1'], {
  encoding: 'utf8',
  env: { ...process.env, TEST_VAR: 'custom_value' }
});
assert.strictEqual(resultEnv.status, 0);
assert.ok(resultEnv.stdout.includes('custom_value arg1'));

// 4. crossSpawn.sync captures non-zero exit code and standard error on failure
const resultFail = spawn.sync('node', ['-e', 'console.error("error occurred"); process.exit(42)'], {
  encoding: 'utf8'
});
assert.strictEqual(resultFail.status, 42);
assert.ok(resultFail.stderr.includes('error occurred'));

// 5. crossSpawn.sync reports ENOENT error when binary does not exist
const resultEnoent = spawn.sync('non_existent_command_123456_xyz', ['--test']);
assert.ok(resultEnoent.error !== null && resultEnoent.error !== undefined);
assert.strictEqual(resultEnoent.error.code, 'ENOENT');

// 6. crossSpawn executes command asynchronously and streams stdout
const child = spawn('node', ['-e', 'console.log("async output")']);
let stdoutData = '';
child.stdout.on('data', (chunk) => {
  stdoutData += chunk.toString();
});

const [exitCode] = await new Promise((resolve) => {
  child.on('close', (code, signal) => {
    resolve([code, signal]);
  });
});
assert.strictEqual(exitCode, 0);
assert.ok(stdoutData.includes('async output'));

// 7. crossSpawn pipes stdin to child process
const childStdin = spawn('node', ['-e', 'process.stdin.pipe(process.stdout)']);
let pipedOutput = '';
childStdin.stdout.on('data', (chunk) => {
  pipedOutput += chunk.toString();
});
childStdin.stdin.write('piped-input-data\n');
childStdin.stdin.end();

const [stdinExitCode] = await new Promise((resolve) => {
  childStdin.on('close', (code) => {
    resolve([code]);
  });
});
assert.strictEqual(stdinExitCode, 0);
assert.strictEqual(pipedOutput.trim(), 'piped-input-data');

// 8. crossSpawn emits error event with ENOENT for non-existent command
const childMissing = spawn('non_existent_binary_xyz_123456', ['--arg']);
const missingError = await new Promise((resolve) => {
  childMissing.on('error', (err) => {
    resolve(err);
  });
});
assert.ok(missingError !== null);
assert.strictEqual(missingError.code, 'ENOENT');

console.log('Contract passed');

Seeder d'origine

anonyme