示例
clone-response 1.0.3: clone response stream with metadata and body
已验证示例 — npm clone-response 1.0.3: clone response stream with metadata and body. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过.
sha256:1fc748f96206bdbb427c5e60c3988c516d7c4fa5a42bbc5a8a88c830198f6a4d
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-26 |
案例
HOW- 目标
- clone response stream with metadata and body
- 符号
-
- cloneResponse
- 环境
- node 22.23.2
- 创建时间
- 2026-08-26T09:12:09Z
契约
- cloneResponse clones a readable stream while copying response metadata including statusCode, statusMessage, and headers
- cloneResponse throws TypeError when input is missing or lacks a pipe method
- cloneResponse preserves custom properties and pipes multi-chunk payload to the clone
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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: clone response stream with metadata and body
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/clone-response@1.0.3
Demonstrate these symbols/APIs:
- cloneResponse
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:2c7c87ea6ac0ed22fb2a90b77759f784f24d36e4991fe3513d998ad4206a9a77","contract":["cloneResponse clones a readable stream while copying response metadata including statusCode, statusMessage, and headers","cloneResponse throws TypeError when input is missing or lacks a pipe method","cloneResponse preserves custom properties and pipes multi-chunk payload to the clone"],"goal":"clone response stream with metadata and body","kind":"HOW","packages":["pkg:npm/clone-response@1.0.3"],"schemaVersion":1,"symbols":["cloneResponse"]},"contractCommand":["node","test/contract.js"],"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/clone-response@1.0.3"],"schemaVersion":1,"subject":"pkg:npm/clone-response@1.0.3","symbols":["cloneResponse"],"verifierAdapter":"node-typescript@1"}
{
"name": "clone-response-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clone-response-sample",
"version": "1.0.0",
"dependencies": {
"clone-response": "1.0.3"
}
},
"node_modules/clone-response": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz",
"integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==",
"license": "MIT",
"dependencies": {
"mimic-response": "^1.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
"license": "MIT",
"engines": {
"node": ">=4"
}
}
}
}
{
"name": "clone-response-sample",
"version": "1.0.0",
"dependencies": {
"clone-response": "1.0.3"
}
}
{
"schemaVersion": 1,
"goal": "clone response stream with metadata and body",
"kind": "HOW",
"packages": [
"pkg:npm/clone-response@1.0.3"
],
"symbols": [
"cloneResponse"
]
}
'use strict';
const cloneResponse = require('clone-response');
/**
* Creates a duplicate of an HTTP response stream with copied metadata and stream body.
*
* @param {import('stream').Readable} response - The original response stream to clone.
* @returns {import('stream').PassThrough} The cloned response stream.
*/
function createResponseClone(response) {
return cloneResponse(response);
}
/**
* Helper to collect all data chunks from a readable stream as a utf-8 string.
*
* @param {import('stream').Readable} stream - The stream to read.
* @returns {Promise<string>} The concatenated text content.
*/
function readStreamToString(stream) {
return new Promise((resolve, reject) => {
let data = '';
stream.setEncoding('utf8');
stream.on('data', chunk => {
data += chunk;
});
stream.on('end', () => {
resolve(data);
});
stream.on('error', err => {
reject(err);
});
});
}
module.exports = {
cloneResponse,
createResponseClone,
readStreamToString,
};
'use strict';
const assert = require('node:assert/strict');
const { PassThrough } = require('node:stream');
const {
cloneResponse,
createResponseClone,
readStreamToString,
} = require('../src/index.js');
async function main() {
// Contract 1: cloneResponse clones a readable stream while copying response metadata including statusCode, statusMessage, and headers
{
const original = new PassThrough();
original.statusCode = 200;
original.statusMessage = 'OK';
original.headers = {
'content-type': 'application/json',
'cache-control': 'max-age=3600',
};
original.rawHeaders = [
'Content-Type',
'application/json',
'Cache-Control',
'max-age=3600',
];
const clone = createResponseClone(original);
assert.strictEqual(clone.statusCode, 200, 'Cloned stream should preserve statusCode');
assert.strictEqual(clone.statusMessage, 'OK', 'Cloned stream should preserve statusMessage');
assert.deepStrictEqual(
clone.headers,
{
'content-type': 'application/json',
'cache-control': 'max-age=3600',
},
'Cloned stream should preserve headers object'
);
assert.deepStrictEqual(
clone.rawHeaders,
[
'Content-Type',
'application/json',
'Cache-Control',
'max-age=3600',
],
'Cloned stream should preserve rawHeaders array'
);
const payload = JSON.stringify({ message: 'cloned stream response data' });
const readPromise = readStreamToString(clone);
original.write(payload);
original.end();
const output = await readPromise;
assert.strictEqual(output, payload, 'Cloned stream body should match original streamed data');
}
// Contract 2: cloneResponse throws TypeError when input is missing or lacks a pipe method
{
const missingOrNonPipeInputs = [null, undefined, 42, 'not-a-stream', {}];
for (const invalid of missingOrNonPipeInputs) {
assert.throws(
() => cloneResponse(invalid),
(err) => {
assert.ok(err instanceof TypeError, 'Should throw a TypeError');
assert.strictEqual(
err.message,
'Parameter `response` must be a response stream.',
'Error message must match expected stream requirement'
);
return true;
}
);
}
assert.throws(
() => cloneResponse({ pipe: 'not-a-function' }),
(err) => {
assert.ok(err instanceof TypeError, 'Should throw a TypeError when pipe is not callable');
assert.strictEqual(err.message, 'response.pipe is not a function');
return true;
}
);
}
// Contract 3: cloneResponse preserves custom properties and pipes multi-chunk payload to the clone
{
const original = new PassThrough();
original.customTraceId = 'req-12345';
original.statusCode = 206;
const clone = createResponseClone(original);
assert.strictEqual(clone.customTraceId, 'req-12345', 'Cloned stream should copy custom response properties');
assert.strictEqual(clone.statusCode, 206, 'Cloned stream should preserve statusCode 206');
const readPromise = readStreamToString(clone);
original.write('chunk1-');
original.write('chunk2-');
original.end('chunk3');
const output = await readPromise;
assert.strictEqual(output, 'chunk1-chunk2-chunk3', 'Cloned stream should stream all chunks sequentially');
}
console.log('All pkg:npm/clone-response@1.0.3 contracts passed successfully.');
}
main().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
原始种子者
匿名