CodeSampleX

Exemple

undici-types 7.18.2

Échantillon vérifié pour npm undici-types 7.18.2. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:2c7f87f11a86804b242228352661fed99013c9af857ca0c2804fe138f6a2b6ea

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/undici-types@7.18.2
Paquets
Créé
2026-08-23T13:31:51Z

Contrat

  1. undici-types package.json declares type definitions entry point index.d.ts and version 7.18.2
  2. undici-types index.d.ts exports Dispatcher, Client, Pool, Agent, fetch, and Undici namespace
  3. undici-types dispatcher.d.ts declares Dispatcher class with dispatch, request, stream, pipeline, connect, upgrade, close, and destroy methods
  4. undici-types client.d.ts, pool.d.ts, and agent.d.ts declare Client, Pool, and Agent classes extending Dispatcher
  5. undici-types fetch.d.ts declares fetch function, Headers, Request, and Response types
  6. undici-types errors.d.ts declares UndiciError and error hierarchy
  7. undici-types cache-interceptor.d.ts declares MemoryCacheStore and SqliteCacheStore classes

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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@7.18.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/undici-types@7.18.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:e1424fb6f33c2cca0f5ab8a279b58405f2361668577adbf090b411f271747f6e","contract":["undici-types package.json declares type definitions entry point index.d.ts and version 7.18.2","undici-types index.d.ts exports Dispatcher, Client, Pool, Agent, fetch, and Undici namespace","undici-types dispatcher.d.ts declares Dispatcher class with dispatch, request, stream, pipeline, connect, upgrade, close, and destroy methods","undici-types client.d.ts, pool.d.ts, and agent.d.ts declare Client, Pool, and Agent classes extending Dispatcher","undici-types fetch.d.ts declares fetch function, Headers, Request, and Response types","undici-types errors.d.ts declares UndiciError and error hierarchy","undici-types cache-interceptor.d.ts declares MemoryCacheStore and SqliteCacheStore classes"],"goal":"verify pkg:npm/undici-types@7.18.2","kind":"HOW","packages":["pkg:npm/undici-types@7.18.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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@7.18.2"],"schemaVersion":1,"subject":"pkg:npm/undici-types@7.18.2","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": "7.18.2"
      }
    },
    "node_modules/undici-types": {
      "version": "7.18.2",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
      "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-undici-types",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for undici-types",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "undici-types": "7.18.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/undici-types@7.18.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/undici-types@7.18.2"
  ]
}
src/index.js
const fs = require('node:fs');
const path = require('node:path');

/**
 * Resolves the path to the undici-types package or a declaration file within it.
 * @param {string} [subPath='index.d.ts'] - Relative declaration file path
 * @returns {string} Absolute path to the declaration file
 */
function getDeclarationPath(subPath = 'index.d.ts') {
  const pkgJsonPath = require.resolve('undici-types/package.json');
  const pkgDir = path.dirname(pkgJsonPath);
  return path.join(pkgDir, subPath);
}

/**
 * Loads the text content of a declaration file from undici-types.
 * @param {string} [subPath='index.d.ts'] - Relative declaration file path
 * @returns {string} The text content of the declaration file
 */
function loadDeclarationContent(subPath = 'index.d.ts') {
  const declPath = getDeclarationPath(subPath);
  return fs.readFileSync(declPath, 'utf8');
}

/**
 * Validates that the undici-types declaration files define expected TypeScript constructs and signatures.
 * @returns {object} Summary of discovered type definitions
 */
function inspectTypeDefinitions() {
  const indexContent = loadDeclarationContent('index.d.ts');
  const dispatcherContent = loadDeclarationContent('dispatcher.d.ts');
  const clientContent = loadDeclarationContent('client.d.ts');
  const poolContent = loadDeclarationContent('pool.d.ts');
  const fetchContent = loadDeclarationContent('fetch.d.ts');
  const errorsContent = loadDeclarationContent('errors.d.ts');
  const agentContent = loadDeclarationContent('agent.d.ts');
  const cacheInterceptorContent = loadDeclarationContent('cache-interceptor.d.ts');

  return {
    indexHasDefaultExport: indexContent.includes('export default Undici'),
    indexHasNamespace: indexContent.includes('declare namespace Undici'),
    indexHasDispatcherExport: indexContent.includes('Dispatcher'),
    indexHasClientExport: indexContent.includes('Client'),
    indexHasPoolExport: indexContent.includes('Pool'),
    indexHasAgentExport: indexContent.includes('Agent'),
    dispatcherHasClass: dispatcherContent.includes('declare class Dispatcher extends EventEmitter'),
    dispatcherHasDispatch: dispatcherContent.includes('dispatch (options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean'),
    dispatcherHasRequest: dispatcherContent.includes('request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>): Promise<Dispatcher.ResponseData<TOpaque>>'),
    dispatcherHasClose: dispatcherContent.includes('close (): Promise<void>'),
    dispatcherHasDestroy: dispatcherContent.includes('destroy (): Promise<void>'),
    clientExtendsDispatcher: clientContent.includes('class Client extends Dispatcher'),
    poolExtendsDispatcher: poolContent.includes('class Pool extends Dispatcher'),
    agentExtendsDispatcher: agentContent.includes('class Agent extends Dispatcher'),
    fetchHasFunction: fetchContent.includes('export declare function fetch ('),
    fetchHasHeaders: fetchContent.includes('export declare class Headers'),
    fetchHasRequest: fetchContent.includes('export declare class Request extends BodyMixin'),
    fetchHasResponse: fetchContent.includes('export declare class Response extends BodyMixin'),
    errorsHasUndiciError: errorsContent.includes('class UndiciError extends Error'),
    cacheInterceptorHasStores: cacheInterceptorContent.includes('class MemoryCacheStore') && cacheInterceptorContent.includes('class SqliteCacheStore')
  };
}

module.exports = {
  getDeclarationPath,
  loadDeclarationContent,
  inspectTypeDefinitions
};
test/contract.js
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const {
  getDeclarationPath,
  loadDeclarationContent,
  inspectTypeDefinitions
} = require('../src/index.js');

// 1. Verify package manifest exports and metadata
const pkgJson = require('undici-types/package.json');
assert.strictEqual(pkgJson.name, 'undici-types', 'package name should match undici-types');
assert.strictEqual(pkgJson.version, '7.18.2', 'package version should match 7.18.2');
assert.strictEqual(pkgJson.types, 'index.d.ts', 'package types entry should point to index.d.ts');

// 2. Verify declaration files existence
const indexDeclPath = getDeclarationPath('index.d.ts');
assert.strictEqual(fs.existsSync(indexDeclPath), true, 'index.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('dispatcher.d.ts')), true, 'dispatcher.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('client.d.ts')), true, 'client.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('pool.d.ts')), true, 'pool.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('agent.d.ts')), true, 'agent.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('fetch.d.ts')), true, 'fetch.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('errors.d.ts')), true, 'errors.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('cache-interceptor.d.ts')), true, 'cache-interceptor.d.ts should exist on disk');
assert.strictEqual(fs.existsSync(getDeclarationPath('global-dispatcher.d.ts')), true, 'global-dispatcher.d.ts should exist on disk');

// 3. Verify index.d.ts structure and exports
const indexContent = loadDeclarationContent('index.d.ts');
assert.strictEqual(typeof indexContent, 'string', 'index.d.ts content should be a string');
assert.strictEqual(indexContent.includes('export default Undici'), true, 'index.d.ts should have default export Undici');
assert.strictEqual(indexContent.includes('declare namespace Undici'), true, 'index.d.ts should declare namespace Undici');
assert.strictEqual(indexContent.includes('export * from \'./fetch\''), true, 'index.d.ts should re-export fetch');
assert.strictEqual(indexContent.includes('export * from \'./cookies\''), true, 'index.d.ts should re-export cookies');
assert.strictEqual(indexContent.includes('export * from \'./formdata\''), true, 'index.d.ts should re-export formdata');
assert.strictEqual(indexContent.includes('export * from \'./websocket\''), true, 'index.d.ts should re-export websocket');

// 4. Verify dispatcher.d.ts declarations
const dispatcherContent = loadDeclarationContent('dispatcher.d.ts');
assert.strictEqual(dispatcherContent.includes('declare class Dispatcher extends EventEmitter'), true, 'Dispatcher must extend EventEmitter');
assert.strictEqual(dispatcherContent.includes('dispatch (options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean'), true, 'Dispatcher must declare dispatch');
assert.strictEqual(dispatcherContent.includes('request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>): Promise<Dispatcher.ResponseData<TOpaque>>'), true, 'Dispatcher must declare request');
assert.strictEqual(dispatcherContent.includes('connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>): Promise<Dispatcher.ConnectData<TOpaque>>'), true, 'Dispatcher must declare connect');
assert.strictEqual(dispatcherContent.includes('pipeline<TOpaque = null>(options: Dispatcher.PipelineOptions<TOpaque>, handler: Dispatcher.PipelineHandler<TOpaque>): Duplex'), true, 'Dispatcher must declare pipeline');
assert.strictEqual(dispatcherContent.includes('stream<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, factory: Dispatcher.StreamFactory<TOpaque>): Promise<Dispatcher.StreamData<TOpaque>>'), true, 'Dispatcher must declare stream');
assert.strictEqual(dispatcherContent.includes('upgrade (options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>'), true, 'Dispatcher must declare upgrade');
assert.strictEqual(dispatcherContent.includes('close (): Promise<void>'), true, 'Dispatcher must declare close');
assert.strictEqual(dispatcherContent.includes('destroy (): Promise<void>'), true, 'Dispatcher must declare destroy');

// 5. Verify client, pool, and agent declarations extending Dispatcher
const clientContent = loadDeclarationContent('client.d.ts');
assert.strictEqual(clientContent.includes('class Client extends Dispatcher'), true, 'Client must extend Dispatcher');

const poolContent = loadDeclarationContent('pool.d.ts');
assert.strictEqual(poolContent.includes('class Pool extends Dispatcher'), true, 'Pool must extend Dispatcher');

const agentContent = loadDeclarationContent('agent.d.ts');
assert.strictEqual(agentContent.includes('class Agent extends Dispatcher'), true, 'Agent must extend Dispatcher');

// 6. Verify fetch.d.ts declarations
const fetchContent = loadDeclarationContent('fetch.d.ts');
assert.strictEqual(fetchContent.includes('export declare function fetch ('), true, 'fetch.d.ts must declare fetch function');
assert.strictEqual(fetchContent.includes('export declare class Headers'), true, 'fetch.d.ts must declare Headers class');
assert.strictEqual(fetchContent.includes('export declare class Request extends BodyMixin'), true, 'fetch.d.ts must declare Request class');
assert.strictEqual(fetchContent.includes('export declare class Response extends BodyMixin'), true, 'fetch.d.ts must declare Response class');

// 7. Verify errors.d.ts declarations
const errorsContent = loadDeclarationContent('errors.d.ts');
assert.strictEqual(errorsContent.includes('declare namespace Errors'), true, 'errors.d.ts must declare Errors namespace');
assert.strictEqual(errorsContent.includes('export class UndiciError extends Error'), true, 'errors.d.ts must declare UndiciError');
assert.strictEqual(errorsContent.includes('export class ConnectTimeoutError extends UndiciError'), true, 'errors.d.ts must declare ConnectTimeoutError');
assert.strictEqual(errorsContent.includes('export class HeadersTimeoutError extends UndiciError'), true, 'errors.d.ts must declare HeadersTimeoutError');
assert.strictEqual(errorsContent.includes('export class BodyTimeoutError extends UndiciError'), true, 'errors.d.ts must declare BodyTimeoutError');
assert.strictEqual(errorsContent.includes('export class InvalidArgumentError extends UndiciError'), true, 'errors.d.ts must declare InvalidArgumentError');
assert.strictEqual(errorsContent.includes('export class RequestAbortedError extends UndiciError'), true, 'errors.d.ts must declare RequestAbortedError');

// 8. Verify cache-interceptor.d.ts declarations
const cacheInterceptorContent = loadDeclarationContent('cache-interceptor.d.ts');
assert.strictEqual(cacheInterceptorContent.includes('export interface CacheStore'), true, 'cache-interceptor.d.ts must declare CacheStore');
assert.strictEqual(cacheInterceptorContent.includes('export class MemoryCacheStore implements CacheStore'), true, 'cache-interceptor.d.ts must declare MemoryCacheStore');
assert.strictEqual(cacheInterceptorContent.includes('export class SqliteCacheStore implements CacheStore'), true, 'cache-interceptor.d.ts must declare SqliteCacheStore');

// 9. Verify helper inspection module
const inspection = inspectTypeDefinitions();
assert.strictEqual(inspection.indexHasDefaultExport, true, 'inspection should confirm default export');
assert.strictEqual(inspection.indexHasNamespace, true, 'inspection should confirm namespace');
assert.strictEqual(inspection.indexHasDispatcherExport, true, 'inspection should confirm Dispatcher export');
assert.strictEqual(inspection.indexHasClientExport, true, 'inspection should confirm Client export');
assert.strictEqual(inspection.indexHasPoolExport, true, 'inspection should confirm Pool export');
assert.strictEqual(inspection.indexHasAgentExport, true, 'inspection should confirm Agent export');
assert.strictEqual(inspection.dispatcherHasClass, true, 'inspection should confirm Dispatcher class');
assert.strictEqual(inspection.dispatcherHasDispatch, true, 'inspection should confirm dispatch method');
assert.strictEqual(inspection.dispatcherHasRequest, true, 'inspection should confirm request method');
assert.strictEqual(inspection.dispatcherHasClose, true, 'inspection should confirm close method');
assert.strictEqual(inspection.dispatcherHasDestroy, true, 'inspection should confirm destroy method');
assert.strictEqual(inspection.clientExtendsDispatcher, true, 'inspection should confirm Client extends Dispatcher');
assert.strictEqual(inspection.poolExtendsDispatcher, true, 'inspection should confirm Pool extends Dispatcher');
assert.strictEqual(inspection.agentExtendsDispatcher, true, 'inspection should confirm Agent extends Dispatcher');
assert.strictEqual(inspection.fetchHasFunction, true, 'inspection should confirm fetch function');
assert.strictEqual(inspection.fetchHasHeaders, true, 'inspection should confirm Headers class');
assert.strictEqual(inspection.fetchHasRequest, true, 'inspection should confirm Request class');
assert.strictEqual(inspection.fetchHasResponse, true, 'inspection should confirm Response class');
assert.strictEqual(inspection.errorsHasUndiciError, true, 'inspection should confirm UndiciError');
assert.strictEqual(inspection.cacheInterceptorHasStores, true, 'inspection should confirm CacheStore implementations');

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

Seeder d'origine

anonyme