CodeSampleX

Пример

pump 3.0.4

Проверенный пример — npm pump 3.0.4. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: pump throws Error when fewer than two streams are…

sha256:eb6aeac4edccdcbb8f0695c85355496257cb56af5e87be78b67049b328bac748

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify pkg:npm/pump@3.0.4
Пакеты
Создан
2026-08-23T13:25:32Z

Контракт

  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

Файлы

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

Скачать артефакт с исходным кодом (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/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);
});

Исходный сидер

аноним