CodeSampleX

Exemplo

mimic-response 3.1.0

Amostra verificada para npm mimic-response 3.1.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: mimicResponse(fromStream, toStream)…

sha256:3006b9956f4ebda3b8bbac54dc067cf7307117ca79ec8b97d342b993f399222a

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@1
2026-08-21

Caso

HOW
Objetivo
verify pkg:npm/mimic-response@3.1.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-21T17:59:08Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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);
});

Seeder de origem

anônimo