CodeSampleX

Exemple

tinyexec 1.3.0: ExecProcess

Échantillon vérifié pour npm tinyexec 1.3.0: ExecProcess. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:340fb5f885cb227e5ea373efafe2c61a33a337750ab8e57ccfe3096986485aab

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é node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify tinyexec.ExecProcess in pkg:npm/tinyexec@1.3.0
Paquets
Symboles
  • tinyexec.ExecProcess
Environnement
node 22.23.2
Créé
2026-09-06T12:35:40Z

Contrat

  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

Fichiers

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

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

Seeder d'origine

anonyme