CodeSampleX

Пример

delayed-stream 1.0.0

Проверенный пример — npm delayed-stream 1.0.0. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: DelayedStream.create wraps a source stream…

sha256:716bf507183c11c9db0a9a78c0352df113b3372a9d391d2a38aa1f467baff149

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

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

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

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

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

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Кейс

HOW
Цель
verify pkg:npm/delayed-stream@1.0.0
Пакеты
Окружение
node 22.23.2
Создан
2026-08-20T20:30:14Z

Контракт

  1. DelayedStream.create wraps a source stream with default or custom options
  2. DelayedStream buffers events emitted by the source before resume is called
  3. DelayedStream flushes buffered events in chronological order on resume
  4. DelayedStream continues forwarding real-time events after release
  5. DelayedStream.prototype.pipe transmits buffered and incoming data to destination writable stream
  6. DelayedStream emits error event when buffered data exceeds maxDataSize limit
  7. DelayedStream.prototype.setEncoding proxies encoding settings to the source stream

Файлы

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

Скачать артефакт с исходным кодом (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/delayed-stream@1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/delayed-stream@1.0.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:9fdcae59bcbe91bfc84f3bf3a34818086d3623498837c4c998b2ec60c2116264","constraints":{"executionContext":"node"},"contract":["DelayedStream.create wraps a source stream with default or custom options","DelayedStream buffers events emitted by the source before resume is called","DelayedStream flushes buffered events in chronological order on resume","DelayedStream continues forwarding real-time events after release","DelayedStream.prototype.pipe transmits buffered and incoming data to destination writable stream","DelayedStream emits error event when buffered data exceeds maxDataSize limit","DelayedStream.prototype.setEncoding proxies encoding settings to the source stream"],"goal":"verify pkg:npm/delayed-stream@1.0.0","kind":"HOW","packages":["pkg:npm/delayed-stream@1.0.0"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/delayed-stream@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/delayed-stream@1.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "delayed-stream-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "delayed-stream-verification",
      "version": "1.0.0",
      "dependencies": {
        "delayed-stream": "1.0.0"
      }
    },
    "node_modules/delayed-stream": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
      "license": "MIT",
      "engines": {
        "node": ">=0.4.0"
      }
    }
  }
}
package.json
{
  "name": "delayed-stream-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for delayed-stream",
  "dependencies": {
    "delayed-stream": "1.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/delayed-stream@1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/delayed-stream@1.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert');
const { PassThrough, Writable } = require('node:stream');
const EventEmitter = require('node:events');
const DelayedStream = require('delayed-stream');

async function runContractTests() {
  // 1. DelayedStream.create wraps a source stream with default or custom options
  const ptDefault = new PassThrough();
  const dsDefault = DelayedStream.create(ptDefault);
  assert.strictEqual(dsDefault.source, ptDefault);
  assert.strictEqual(dsDefault.maxDataSize, 1024 * 1024);
  assert.strictEqual(dsDefault.pauseStream, true);

  const ptCustom = new PassThrough();
  const dsCustom = DelayedStream.create(ptCustom, { maxDataSize: 2048, pauseStream: false });
  assert.strictEqual(dsCustom.maxDataSize, 2048);
  assert.strictEqual(dsCustom.pauseStream, false);

  // 2. DelayedStream buffers events emitted by the source before resume is called
  const source2 = new EventEmitter();
  source2.pause = () => {};
  source2.resume = () => {};
  const ds2 = DelayedStream.create(source2);

  let receivedBeforeResume = 0;
  ds2.on('data', () => { receivedBeforeResume++; });

  source2.emit('data', Buffer.from('hello '));
  source2.emit('data', Buffer.from('world'));
  source2.emit('custom-event', 42);

  assert.strictEqual(receivedBeforeResume, 0);
  assert.strictEqual(ds2._bufferedEvents.length, 3);
  assert.strictEqual(ds2.dataSize, 11);

  // 3. DelayedStream flushes buffered events in chronological order on resume
  const eventsReceived = [];
  let customValue = null;
  ds2.on('data', chunk => eventsReceived.push(chunk.toString()));
  ds2.on('custom-event', val => { customValue = val; });

  ds2.resume();

  assert.deepStrictEqual(eventsReceived, ['hello ', 'world']);
  assert.strictEqual(customValue, 42);
  assert.strictEqual(ds2._bufferedEvents.length, 0);

  // 4. DelayedStream continues forwarding real-time events after release
  source2.emit('data', Buffer.from('!'));
  assert.deepStrictEqual(eventsReceived, ['hello ', 'world', '!']);

  // 5. DelayedStream.prototype.pipe transmits buffered and incoming data to destination writable stream
  const source5 = new PassThrough();
  const ds5 = DelayedStream.create(source5);

  source5.write('chunk-1;');
  source5.write('chunk-2;');

  let pipedOutput = '';
  const destination = new Writable({
    write(chunk, encoding, callback) {
      pipedOutput += chunk.toString();
      callback();
    }
  });

  const pipedPromise = new Promise(resolve => {
    destination.on('finish', resolve);
  });

  ds5.pipe(destination);
  source5.write('chunk-3');
  source5.end();

  await pipedPromise;
  assert.strictEqual(pipedOutput, 'chunk-1;chunk-2;chunk-3');

  // 6. DelayedStream emits error event when buffered data exceeds maxDataSize limit
  const source6 = new EventEmitter();
  source6.pause = () => {};
  source6.resume = () => {};
  const ds6 = DelayedStream.create(source6, { maxDataSize: 10 });

  let errorCaught = null;
  ds6.on('error', err => { errorCaught = err; });

  source6.emit('data', Buffer.from('small'));
  assert.strictEqual(errorCaught, null);
  source6.emit('data', Buffer.from('exceeding-the-limit'));
  assert(errorCaught instanceof Error);
  assert(errorCaught.message.includes('DelayedStream#maxDataSize of 10 bytes exceeded'));

  // 7. DelayedStream.prototype.setEncoding proxies encoding settings to the source stream
  const source7 = new PassThrough();
  const ds7 = DelayedStream.create(source7);
  ds7.setEncoding('utf8');
  assert.strictEqual(source7.readableEncoding, 'utf8');

  console.log('DelayedStream contract verified successfully.');
}

runContractTests().catch(err => {
  console.error(err);
  process.exit(1);
});

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

аноним