CodeSampleX

示例

mimic-response 3.1.0

已验证示例 — npm mimic-response 3.1.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: mimicResponse(fromStream, toStream) copies HTTP response properties…

sha256:3006b9956f4ebda3b8bbac54dc067cf7307117ca79ec8b97d342b993f399222a

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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@1
2026-08-21

案例

HOW
目标
verify pkg:npm/mimic-response@3.1.0
包
环境
node 22.23.2
创建时间
2026-08-21T17:59:08Z

契约

  1. mimicResponse(fromStream, toStream) copies HTTP response properties including statusCode, statusMessage, headers, and url from fromStream to toStream
  2. mimicResponse(fromStream, toStream) returns the destination toStream instance
  3. mimicResponse(fromStream, toStream) does not overwrite properties already existing on toStream
  4. mimicResponse(fromStream, toStream) throws an Error if toStream has autoDestroy enabled
  5. mimicResponse(fromStream, toStream) forwards getters and setters between fromStream and toStream
  6. mimicResponse(fromStream, toStream) propagates aborted event from fromStream to destroy toStream

文件

  • 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/mimic-response@3.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/mimic-response@3.1.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:9494774e3352fab876617a927d6de6d38871d5f3bdf9016c1ddc3a68a578aa8b","constraints":{"executionContext":"node"},"contract":["mimicResponse(fromStream, toStream) copies HTTP response properties including statusCode, statusMessage, headers, and url from fromStream to toStream","mimicResponse(fromStream, toStream) returns the destination toStream instance","mimicResponse(fromStream, toStream) does not overwrite properties already existing on toStream","mimicResponse(fromStream, toStream) throws an Error if toStream has autoDestroy enabled","mimicResponse(fromStream, toStream) forwards getters and setters between fromStream and toStream","mimicResponse(fromStream, toStream) propagates aborted event from fromStream to destroy toStream"],"goal":"verify pkg:npm/mimic-response@3.1.0","kind":"HOW","packages":["pkg:npm/mimic-response@3.1.0"],"schemaVersion":1},"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/mimic-response@3.1.0"],"schemaVersion":1,"subject":"pkg:npm/mimic-response@3.1.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-mimic-response",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-mimic-response",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "mimic-response": "3.1.0"
      }
    },
    "node_modules/mimic-response": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
      "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-mimic-response",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for mimic-response",
  "main": "test/contract.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "mimic-response": "3.1.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/mimic-response@3.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/mimic-response@3.1.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('assert');
const { PassThrough } = require('stream');
const mimicResponse = require('mimic-response');

async function runTests() {
  // Test 1: Copies HTTP response properties and returns toStream
  {
    const fromStream = new PassThrough();
    fromStream.statusCode = 200;
    fromStream.statusMessage = 'OK';
    fromStream.headers = { 'content-type': 'application/json' };
    fromStream.httpVersion = '1.1';
    fromStream.url = '/api/resource';
    fromStream.method = 'GET';

    const toStream = new PassThrough({ autoDestroy: false });
    const result = mimicResponse(fromStream, toStream);

    assert.strictEqual(result, toStream, 'mimicResponse should return toStream');
    assert.strictEqual(toStream.statusCode, 200, 'statusCode should match');
    assert.strictEqual(toStream.statusMessage, 'OK', 'statusMessage should match');
    assert.deepStrictEqual(toStream.headers, { 'content-type': 'application/json' }, 'headers should match');
    assert.strictEqual(toStream.httpVersion, '1.1', 'httpVersion should match');
    assert.strictEqual(toStream.url, '/api/resource', 'url should match');
    assert.strictEqual(toStream.method, 'GET', 'method should match');
  }

  // Test 2: Does not overwrite existing properties on toStream
  {
    const fromStream = new PassThrough();
    fromStream.statusCode = 200;
    fromStream.customProperty = 'from-source';

    const toStream = new PassThrough({ autoDestroy: false });
    toStream.customProperty = 'original-destination';

    mimicResponse(fromStream, toStream);
    assert.strictEqual(toStream.customProperty, 'original-destination', 'existing property should not be overwritten');
    assert.strictEqual(toStream.statusCode, 200, 'new property should be copied');
  }

  // Test 3: Throws an Error if toStream has autoDestroy enabled
  {
    const fromStream = new PassThrough();
    const toStream = new PassThrough({ autoDestroy: true });

    assert.throws(
      () => mimicResponse(fromStream, toStream),
      /The second stream must have the `autoDestroy` option set to `false`/,
      'should throw error when autoDestroy is true'
    );
  }

  // Test 4: Forwards getters and setters between fromStream and toStream
  {
    const fromStream = new PassThrough();
    fromStream.statusCode = 200;

    const toStream = new PassThrough({ autoDestroy: false });
    mimicResponse(fromStream, toStream);

    toStream.statusCode = 404;
    assert.strictEqual(fromStream.statusCode, 404, 'setting property on toStream should update fromStream');

    fromStream.statusMessage = 'Not Found';
    assert.strictEqual(toStream.statusMessage, 'Not Found', 'updating property on fromStream should reflect on toStream');
  }

  // Test 5: Propagates aborted event from fromStream to destroy toStream
  await new Promise((resolve, reject) => {
    const fromStream = new PassThrough();
    const toStream = new PassThrough({ autoDestroy: false });

    mimicResponse(fromStream, toStream);

    let abortedEmitted = false;
    toStream.on('aborted', () => {
      abortedEmitted = true;
    });

    toStream.on('close', () => {
      try {
        assert.strictEqual(abortedEmitted, true, 'aborted event should have been emitted on toStream');
        assert.strictEqual(toStream.destroyed, true, 'toStream should be destroyed');
        resolve();
      } catch (err) {
        reject(err);
      }
    });

    fromStream.emit('aborted');
  });

  console.log('All mimic-response contract assertions passed successfully.');
}

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

原始种子者

匿名