Exemplo
destroy 1.2.0: destroy a stream cleanly and handle error listeners
Amostra verificada para npm destroy 1.2.0: destroy a stream cleanly and handle error listeners. O contrato rodou em node 22 · linux alpine/x64 · docker e…
sha256:48e2ab08076cabe202dd1266fa09df2a9a279de92a234f7f6f3721262bcd1de7
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-27 |
Caso
HOW- Objetivo
- destroy a stream cleanly and handle error listeners
- Pacotes
- Símbolos
-
- destroy
- Ambiente
- node 22.23.2
- Criado
- 2026-08-27T12:20:51Z
Contrato
- assert destroy returns the passed stream instance
- assert destroy marks readable stream as destroyed
- assert destroy marks writable stream as destroyed
- assert destroy handles transform streams including zlib gzip
- assert destroy with suppress true removes error listeners and attaches a noop handler preventing unhandled error exceptions
- assert destroy without suppress preserves existing error listeners
- assert destroy safely returns non-stream objects and primitives without throwing
- assert destroy invokes custom destroy method on stream-like objects
Arquivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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: destroy a stream cleanly and handle error listeners
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/destroy@1.2.0
Demonstrate these symbols/APIs:
- destroy
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.
{"case":{"caseId":"case:sha256:3856553551c31083c0e3aed341fa8a2381c9d1fb6167dc23031d6d61044a611a","contract":["assert destroy returns the passed stream instance","assert destroy marks readable stream as destroyed","assert destroy marks writable stream as destroyed","assert destroy handles transform streams including zlib gzip","assert destroy with suppress true removes error listeners and attaches a noop handler preventing unhandled error exceptions","assert destroy without suppress preserves existing error listeners","assert destroy safely returns non-stream objects and primitives without throwing","assert destroy invokes custom destroy method on stream-like objects"],"goal":"destroy a stream cleanly and handle error listeners","kind":"HOW","packages":["pkg:npm/destroy@1.2.0"],"schemaVersion":1,"symbols":["destroy"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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/destroy@1.2.0"],"schemaVersion":1,"subject":"pkg:npm/destroy@1.2.0","symbols":["destroy"],"verifierAdapter":"node-typescript@1"}
const destroy = require('destroy');
function destroyStream(stream, suppress) {
return destroy(stream, suppress);
}
function destroyWithSuppress(stream) {
return destroy(stream, true);
}
module.exports = {
destroy,
destroyStream,
destroyWithSuppress,
};
{
"name": "sample-destroy",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-destroy",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"destroy": "1.2.0"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
}
}
}
{
"name": "sample-destroy",
"version": "1.0.0",
"description": "Minimal clean-room sample verifying stream destruction and error suppression with destroy",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"destroy": "1.2.0"
}
}
{
"schemaVersion": 1,
"goal": "destroy a stream cleanly and handle error listeners",
"kind": "HOW",
"packages": [
"pkg:npm/destroy@1.2.0"
],
"symbols": [
"destroy"
]
}
import assert from 'node:assert/strict';
import { Readable, Writable, PassThrough } from 'node:stream';
import zlib from 'node:zlib';
import destroy from 'destroy';
import { destroyStream, destroyWithSuppress } from '../index.js';
// 1. assert destroy returns the passed stream instance
const readable1 = new Readable({ read() {} });
const ret1 = destroy(readable1);
assert.equal(ret1, readable1, 'destroy must return the same stream instance');
// 2. assert destroy marks readable stream as destroyed
const readable2 = new Readable({ read() {} });
destroyStream(readable2);
assert.equal(readable2.destroyed, true, 'readable stream must have destroyed set to true');
// 3. assert destroy marks writable stream as destroyed
const writable = new Writable({
write(chunk, enc, cb) {
cb();
},
});
destroyStream(writable);
assert.equal(writable.destroyed, true, 'writable stream must have destroyed set to true');
// 4. assert destroy handles transform streams including zlib gzip
const gzip = zlib.createGzip();
destroyStream(gzip);
assert.equal(gzip.destroyed, true, 'gzip stream must be marked destroyed');
// 5. assert destroy with suppress true removes error listeners and attaches a noop handler preventing unhandled error exceptions
const errorStream = new PassThrough();
let errorListenerCalled = false;
errorStream.on('error', () => {
errorListenerCalled = true;
});
assert.equal(errorStream.listenerCount('error'), 1, 'stream should have 1 error listener initially');
destroyWithSuppress(errorStream);
assert.equal(errorListenerCalled, false, 'previous error listener must not be called');
assert.equal(errorStream.listenerCount('error'), 1, 'stream should have 1 noop error listener after suppress');
assert.doesNotThrow(() => {
errorStream.emit('error', new Error('suppressed test error'));
}, 'emitting error on stream destroyed with suppress must not throw unhandled error');
// 6. assert destroy without suppress preserves existing error listeners
const preservedStream = new PassThrough();
let preservedListenerCalled = false;
preservedStream.on('error', () => {
preservedListenerCalled = true;
});
destroyStream(preservedStream, false);
assert.equal(preservedStream.listenerCount('error'), 1, 'error listener count should remain 1');
preservedStream.emit('error', new Error('expected error'));
assert.equal(preservedListenerCalled, true, 'original error listener must be invoked');
// 7. assert destroy safely returns non-stream objects and primitives without throwing
const dummyObj = { custom: 'value' };
assert.equal(destroy(dummyObj), dummyObj, 'destroy on object must return the object');
assert.equal(destroy(null), null, 'destroy on null must return null');
assert.equal(destroy(undefined), undefined, 'destroy on undefined must return undefined');
assert.equal(destroy(12345), 12345, 'destroy on number must return number');
assert.equal(destroy('stream-id'), 'stream-id', 'destroy on string must return string');
// 8. assert destroy invokes custom destroy method on stream-like objects
let customDestroyCalled = false;
const customStream = new Readable({ read() {} });
customStream.destroy = function () {
customDestroyCalled = true;
this.destroyed = true;
return this;
};
destroy(customStream);
assert.equal(customDestroyCalled, true, 'custom destroy function must be executed');
assert.equal(customStream.destroyed, true, 'custom stream destroyed property must be true');
console.log('All destroy contract assertions passed.');
Seeder de origem
anônimo