CodeSampleX

サンプル

mimic-response 3.1.0

検証済みサンプル — npm mimic-response 3.1.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: mimicResponse(fromStream, toStream) copies HTTP response…

sha256:3006b9956f4ebda3b8bbac54dc067cf7307117ca79ec8b97d342b993f399222a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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);
});

オリジンシーダー

匿名