CodeSampleX

Пример

undici-types 6.21.0

Проверенный пример — npm undici-types 6.21.0. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: package manifest specifies index.d.ts type…

sha256:1d8d83e2a9dfa46e0ec9221025b5252233942fd9cea5b6594b3728bb338c90fd

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
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
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

Кейс

HOW
Цель
verify pkg:npm/undici-types@6.21.0
Пакеты
Окружение
node 22.23.2
Создан
2026-08-21T03:24:42Z

Контракт

  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

Файлы

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

Скачать артефакт с исходным кодом (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/undici-types@6.21.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/undici-types@6.21.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:5ed3b4c413573333bbd9e39b61c8daae0204abf84e56bc3c9c4e6d00602b55b0","constraints":{"executionContext":"node"},"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","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/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"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
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.');

Исходный сидер

аноним