CodeSampleX

Exemple

pump 3.0.4

Échantillon vérifié pour npm pump 3.0.4. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : pump throws Error when fewer than two…

sha256:eb6aeac4edccdcbb8f0695c85355496257cb56af5e87be78b67049b328bac748

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-23

Cas

HOW
Objectif
verify pkg:npm/pump@3.0.4
Paquets
Créé
2026-08-23T13:25:32Z

Contrat

  1. pump throws Error when fewer than two streams are provided
  2. pump pipes data from readable stream through transform stream to writable stream and invokes callback on success
  3. pump accepts an array of streams and completes data piping successfully
  4. pump invokes callback with error and destroys downstream writable stream when upstream readable stream emits an error
  5. pump invokes callback with error and destroys upstream readable stream when downstream writable stream emits an error
  6. pump destroys all streams in the pipeline when an intermediate transform stream emits an error
  7. pump returns the destination stream from the pipeline

Fichiers

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

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 pkg:npm/pump@3.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pump@3.0.4

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:d3c34f9b7c348d9c5b897a2faca80a49a626db1e15fec96a29ab0579b571eaa9","contract":["pump throws Error when fewer than two streams are provided","pump pipes data from readable stream through transform stream to writable stream and invokes callback on success","pump accepts an array of streams and completes data piping successfully","pump invokes callback with error and destroys downstream writable stream when upstream readable stream emits an error","pump invokes callback with error and destroys upstream readable stream when downstream writable stream emits an error","pump destroys all streams in the pipeline when an intermediate transform stream emits an error","pump returns the destination stream from the pipeline"],"goal":"verify pkg:npm/pump@3.0.4","kind":"HOW","packages":["pkg:npm/pump@3.0.4"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/pump@3.0.4"],"schemaVersion":1,"subject":"pkg:npm/pump@3.0.4","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-pump",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-pump",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "pump": "3.0.4"
      }
    },
    "node_modules/end-of-stream": {
      "version": "1.4.5",
      "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
      "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
      "license": "MIT",
      "dependencies": {
        "once": "^1.4.0"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/pump": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",
      "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",
      "license": "MIT",
      "dependencies": {
        "end-of-stream": "^1.1.0",
        "once": "^1.3.1"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "csx-sample-pump",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for pump",
  "main": "test/contract.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "pump": "3.0.4"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/pump@3.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pump@3.0.4"
  ]
}
test/contract.js
const assert = require('node:assert/strict');
const { Readable, Writable, Transform, PassThrough } = require('node:stream');
const pump = require('pump');

async function runContract() {
  // 1. pump throws Error when fewer than two streams are provided
  {
    assert.throws(
      () => pump(),
      /^Error: pump requires two streams per minimum$/,
      'pump() without arguments should throw Error'
    );
    assert.throws(
      () => pump(new PassThrough()),
      /^Error: pump requires two streams per minimum$/,
      'pump(singleStream) should throw Error'
    );
    assert.throws(
      () => pump([new PassThrough()]),
      /^Error: pump requires two streams per minimum$/,
      'pump([singleStream]) should throw Error'
    );
  }

  // 2. pump pipes data from readable stream through transform stream to writable stream and invokes callback on success
  await new Promise((resolve, reject) => {
    const chunks = [];
    const source = Readable.from(['hello', ' ', 'world']);
    const uppercase = new Transform({
      transform(chunk, encoding, callback) {
        callback(null, chunk.toString().toUpperCase());
      }
    });
    const destination = new Writable({
      write(chunk, encoding, callback) {
        chunks.push(chunk.toString());
        callback();
      }
    });

    pump(source, uppercase, destination, (err) => {
      try {
        assert.ifError(err);
        assert.equal(chunks.join(''), 'HELLO WORLD');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // 3. pump accepts an array of streams and completes data piping successfully
  await new Promise((resolve, reject) => {
    const received = [];
    const source = Readable.from(['item1', 'item2', 'item3']);
    const destination = new Writable({
      write(chunk, encoding, callback) {
        received.push(chunk.toString());
        callback();
      }
    });

    pump([source, destination], (err) => {
      try {
        assert.ifError(err);
        assert.deepEqual(received, ['item1', 'item2', 'item3']);
        resolve();
      } catch (e) {
        reject(e);
      }
    });
  });

  // 4. pump invokes callback with error and destroys downstream writable stream when upstream readable stream emits an error
  await new Promise((resolve, reject) => {
    const source = new PassThrough();
    const destination = new PassThrough();

    let destDestroyed = false;
    destination.on('close', () => {
      destDestroyed = true;
    });

    pump(source, destination, (err) => {
      try {
        assert(err, 'Expected error in callback');
        assert.equal(err.message, 'source failed');
        assert.equal(destination.destroyed || destDestroyed, true, 'Destination should be destroyed');
        resolve();
      } catch (e) {
        reject(e);
      }
    });

    source.destroy(new Error('source failed'));
  });

  // 5. pump invokes callback with error and destroys upstream readable stream when downstream writable stream emits an error
  await new Promise((resolve, reject) => {
    const source = new PassThrough();
    const destination = new PassThrough();

    let sourceDestroyed = false;
    source.on('close', () => {
      sourceDestroyed = true;
    });

    pump(source, destination, (err) => {
      try {
        assert(err, 'Expected error in callback');
        assert.equal(err.message, 'destination failed');
        assert.equal(source.destroyed || sourceDestroyed, true, 'Source should be destroyed');
        resolve();
      } catch (e) {
        reject(e);
      }
    });

    destination.destroy(new Error('destination failed'));
  });

  // 6. pump destroys all streams in the pipeline when an intermediate transform stream emits an error
  await new Promise((resolve, reject) => {
    const source = new PassThrough();
    const transform = new PassThrough();
    const destination = new PassThrough();

    pump(source, transform, destination, (err) => {
      try {
        assert(err, 'Expected error in callback');
        assert.equal(err.message, 'transform failed');
        assert.equal(source.destroyed, true, 'Source should be destroyed');
        assert.equal(destination.destroyed, true, 'Destination should be destroyed');
        resolve();
      } catch (e) {
        reject(e);
      }
    });

    transform.destroy(new Error('transform failed'));
  });

  // 7. pump returns the destination stream from the pipeline
  {
    const source = new PassThrough();
    const destination = new PassThrough();
    const result = pump(source, destination);
    assert.strictEqual(result, destination, 'pump should return the last stream');
  }

  console.log('All pump contract assertions passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder d'origine

anonyme