CodeSampleX

Exemplo

undici-types 6.21.0

Amostra verificada para npm undici-types 6.21.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: package manifest specifies index.d.ts type…

sha256:a27d1695b53a6623d54a19af9146444822263b6a41c1749915ef356803fcf08b

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
2
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

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-23
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-08

Caso

HOW
Objetivo
verify pkg:npm/undici-types@6.21.0
Pacotes
Criado
2026-08-23T07:07:41Z

Contrato

  1. package manifest specifies index.d.ts type declarations and files field
  2. declares Dispatcher base class with dispatch, request, stream, pipeline, connect, and compose methods
  3. declares Client, Pool, BalancedPool, and Agent classes extending Dispatcher
  4. declares high-level request, stream, pipeline, connect, and upgrade API functions
  5. declares fetch, Headers, Request, Response, FormData, File, and FileReader web standards declarations
  6. declares Errors namespace with UndiciError base class and specific error subtypes

Arquivos

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

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/undici-types@6.21.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/undici-types@6.21.0

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:f2720aa946c27b20cc2e60091b8dea4ed845633aebf19dd04cf1950db563d121","contract":["package manifest specifies index.d.ts type declarations and files field","declares Dispatcher base class with dispatch, request, stream, pipeline, connect, and compose methods","declares Client, Pool, BalancedPool, and Agent classes extending Dispatcher","declares high-level request, stream, pipeline, connect, and upgrade API functions","declares fetch, Headers, Request, Response, FormData, File, and FileReader web standards declarations","declares Errors namespace with UndiciError base class and specific error subtypes"],"goal":"verify pkg:npm/undici-types@6.21.0","kind":"HOW","packages":["pkg:npm/undici-types@6.21.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/undici-types@6.21.0"],"schemaVersion":1,"subject":"pkg:npm/undici-types@6.21.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-undici-types",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-undici-types",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "undici-types": "6.21.0"
      }
    },
    "node_modules/undici-types": {
      "version": "6.21.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
      "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-undici-types",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "undici-types": "6.21.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/undici-types@6.21.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/undici-types@6.21.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve undici-types package manifest and verify type declaration entry points
const pkgPath = require.resolve('undici-types/package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'undici-types', 'Package name must be undici-types');
assert.equal(pkg.version, '6.21.0', 'Package version must be 6.21.0');
assert.equal(pkg.types, 'index.d.ts', 'Package types entry must point to index.d.ts');
assert.ok(Array.isArray(pkg.files) && pkg.files.includes('*.d.ts'), 'Package files must include *.d.ts');

const typesDir = path.dirname(pkgPath);
const indexDts = fs.readFileSync(path.join(typesDir, 'index.d.ts'), 'utf8');
const dispatcherDts = fs.readFileSync(path.join(typesDir, 'dispatcher.d.ts'), 'utf8');
const clientDts = fs.readFileSync(path.join(typesDir, 'client.d.ts'), 'utf8');
const poolDts = fs.readFileSync(path.join(typesDir, 'pool.d.ts'), 'utf8');
const agentDts = fs.readFileSync(path.join(typesDir, 'agent.d.ts'), 'utf8');
const apiDts = fs.readFileSync(path.join(typesDir, 'api.d.ts'), 'utf8');
const fetchDts = fs.readFileSync(path.join(typesDir, 'fetch.d.ts'), 'utf8');
const errorsDts = fs.readFileSync(path.join(typesDir, 'errors.d.ts'), 'utf8');

// 2. Verify Dispatcher base class declaration and methods
assert.ok(
  dispatcherDts.includes('declare class Dispatcher extends EventEmitter'),
  'Dispatcher class must extend EventEmitter'
);
assert.ok(
  dispatcherDts.includes('dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;') &&
  dispatcherDts.includes('request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;') &&
  dispatcherDts.includes('stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory): Promise<Dispatcher.StreamData>;') &&
  dispatcherDts.includes('pipeline(options: Dispatcher.PipelineOptions, handler: Dispatcher.PipelineHandler): Duplex;') &&
  dispatcherDts.includes('connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;') &&
  dispatcherDts.includes('compose(dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;'),
  'Dispatcher must declare dispatch, request, stream, pipeline, connect, and compose methods'
);

// 3. Verify Client, Pool, BalancedPool, and Agent classes extending Dispatcher
assert.ok(
  clientDts.includes('export class Client extends Dispatcher') &&
  clientDts.includes('constructor(url: string | URL, options?: Client.Options);'),
  'Client class must extend Dispatcher'
);
assert.ok(
  poolDts.includes('declare class Pool extends Dispatcher') &&
  poolDts.includes('constructor(url: string | URL, options?: Pool.Options)'),
  'Pool class must extend Dispatcher'
);
assert.ok(
  agentDts.includes('declare class Agent extends Dispatcher') &&
  agentDts.includes('constructor(opts?: Agent.Options)'),
  'Agent class must extend Dispatcher'
);
assert.ok(
  indexDts.includes('export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent'),
  'index.d.ts must export Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, and Agent'
);

// 4. Verify high-level request, stream, pipeline, connect, and upgrade API functions
assert.ok(
  apiDts.includes('declare function request(') &&
  apiDts.includes('declare function stream(') &&
  apiDts.includes('declare function pipeline(') &&
  apiDts.includes('declare function connect(') &&
  apiDts.includes('declare function upgrade('),
  'api.d.ts must declare request, stream, pipeline, connect, and upgrade functions'
);

// 5. Verify fetch, Headers, Request, Response, FormData, File, and FileReader web standards declarations
assert.ok(
  fetchDts.includes('export declare function fetch (') &&
  fetchDts.includes('export type RequestInfo = string | URL | Request') &&
  fetchDts.includes('export class BodyMixin'),
  'fetch.d.ts must declare fetch function, RequestInfo, and BodyMixin'
);
assert.ok(
  indexDts.includes("export * from './fetch'") &&
  indexDts.includes("export * from './formdata'") &&
  indexDts.includes("export * from './file'") &&
  indexDts.includes("export * from './filereader'"),
  'index.d.ts must re-export fetch, formdata, file, and filereader types'
);

// 6. Verify Errors namespace with UndiciError and error subtypes
assert.ok(
  errorsDts.includes('export class UndiciError extends Error') &&
  errorsDts.includes('export class ConnectTimeoutError extends UndiciError') &&
  errorsDts.includes('export class HeadersTimeoutError extends UndiciError') &&
  errorsDts.includes('export class BodyTimeoutError extends UndiciError') &&
  errorsDts.includes('export class ResponseStatusCodeError extends UndiciError'),
  'errors.d.ts must declare UndiciError and specific error subtypes'
);

console.log('Contract tests passed successfully.');

Seeder de origem

anônimo