CodeSampleX

示例

undici-types 8.3.0: version

已验证示例 — npm undici-types 8.3.0: version. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: undici-types package.json declares name undici-types and…

sha256:c774bbcf46f4af3f73fec6bf351d76ecb7099991f0a35354470869b243249fa4

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
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-27

案例

HOW
目标
verify undici-types.version in pkg:npm/undici-types@8.3.0
包
符号
  • undici-types.version
创建时间
2026-08-27T11:30:38Z

契约

  1. undici-types package.json declares name undici-types and version 8.3.0
  2. undici-types package.json specifies types entry point index.d.ts
  3. undici-types package.json specifies files pattern including *.d.ts
  4. undici-types index.d.ts declares default export Undici and namespace Undici
  5. undici-types index.d.ts exports client and agent types Dispatcher, Pool, BalancedPool, RoundRobinPool, Client, Agent, and H2CClient
  6. undici-types index.d.ts exports request helpers and connection functions request, stream, pipeline, connect, upgrade, and buildConnector
  7. undici-types index.d.ts exports global dispatcher management functions setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, and getGlobalOrigin
  8. undici-types index.d.ts exports global installation function install
  9. undici-types declaration files exist on disk for all core modules including dispatcher, client, pool, agent, fetch, errors, cache, cookies, formdata, eventsource, websocket, and diagnostics-channel

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 undici-types.version in pkg:npm/undici-types@8.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/undici-types@8.3.0
Demonstrate these symbols/APIs:
  - undici-types.version

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:7bc0423f37279d02616b935b957832ec2b8443df7f2a79e06f42a74388d24493","contract":["undici-types package.json declares name undici-types and version 8.3.0","undici-types package.json specifies types entry point index.d.ts","undici-types package.json specifies files pattern including *.d.ts","undici-types index.d.ts declares default export Undici and namespace Undici","undici-types index.d.ts exports client and agent types Dispatcher, Pool, BalancedPool, RoundRobinPool, Client, Agent, and H2CClient","undici-types index.d.ts exports request helpers and connection functions request, stream, pipeline, connect, upgrade, and buildConnector","undici-types index.d.ts exports global dispatcher management functions setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, and getGlobalOrigin","undici-types index.d.ts exports global installation function install","undici-types declaration files exist on disk for all core modules including dispatcher, client, pool, agent, fetch, errors, cache, cookies, formdata, eventsource, websocket, and diagnostics-channel"],"goal":"verify undici-types.version in pkg:npm/undici-types@8.3.0","kind":"HOW","packages":["pkg:npm/undici-types@8.3.0"],"schemaVersion":1,"symbols":["undici-types.version"]},"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@8.3.0"],"schemaVersion":1,"subject":"pkg:npm/undici-types@8.3.0","symbols":["undici-types.version"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-undici-types-version",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-undici-types-version",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "undici-types": "8.3.0"
      }
    },
    "node_modules/undici-types": {
      "version": "8.3.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
      "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-undici-types-version",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for undici-types.version",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "undici-types": "8.3.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify undici-types.version in pkg:npm/undici-types@8.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/undici-types@8.3.0"
  ],
  "symbols": [
    "undici-types.version"
  ]
}
src/index.js
const fs = require('node:fs');
const path = require('node:path');

/**
 * Returns package metadata from undici-types package.json.
 * @returns {object} The parsed package.json object
 */
function getPackageMetadata() {
  const pkgJsonPath = require.resolve('undici-types/package.json');
  const raw = fs.readFileSync(pkgJsonPath, 'utf8');
  return JSON.parse(raw);
}

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

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

/**
 * Verifies version metadata and core exports from undici-types.
 * @returns {object} Validation summary
 */
function verifyPackageVersionAndExports() {
  const pkg = getPackageMetadata();
  const indexContent = readDeclarationFile('index.d.ts');

  return {
    packageName: pkg.name,
    packageVersion: pkg.version,
    typesEntry: pkg.types,
    filesPattern: pkg.files,
    hasDefaultExport: indexContent.includes('export default Undici'),
    hasNamespace: indexContent.includes('declare namespace Undici'),
    hasInstallExport: indexContent.includes('globalThisInstall as install'),
    hasDispatcher: indexContent.includes('Dispatcher'),
    hasClient: indexContent.includes('Client'),
    hasPool: indexContent.includes('Pool'),
    hasBalancedPool: indexContent.includes('BalancedPool'),
    hasRoundRobinPool: indexContent.includes('RoundRobinPool'),
    hasAgent: indexContent.includes('Agent'),
    hasH2CClient: indexContent.includes('H2CClient'),
    hasRequest: indexContent.includes('request'),
    hasStream: indexContent.includes('stream'),
    hasPipeline: indexContent.includes('pipeline'),
    hasConnect: indexContent.includes('connect'),
    hasUpgrade: indexContent.includes('upgrade'),
    hasSetGlobalDispatcher: indexContent.includes('setGlobalDispatcher'),
    hasGetGlobalDispatcher: indexContent.includes('getGlobalDispatcher'),
    hasSetGlobalOrigin: indexContent.includes('setGlobalOrigin'),
    hasGetGlobalOrigin: indexContent.includes('getGlobalOrigin')
  };
}

module.exports = {
  getPackageMetadata,
  resolvePackagePath,
  readDeclarationFile,
  verifyPackageVersionAndExports
};
test/contract.js
const assert = require('node:assert');
const fs = require('node:fs');
const {
  getPackageMetadata,
  resolvePackagePath,
  readDeclarationFile,
  verifyPackageVersionAndExports
} = require('../src/index.js');

// 1. Verify undici-types package.json declares name "undici-types" and version "8.3.0"
const pkg = getPackageMetadata();
assert.strictEqual(pkg.name, 'undici-types', 'Package name must be undici-types');
assert.strictEqual(pkg.version, '8.3.0', 'Package version must be 8.3.0');

// 2. Verify undici-types package.json specifies types entry point index.d.ts
assert.strictEqual(pkg.types, 'index.d.ts', 'Types entry point must be index.d.ts');

// 3. Verify undici-types package.json specifies files pattern including *.d.ts
assert.ok(Array.isArray(pkg.files), 'files must be an array');
assert.ok(pkg.files.includes('*.d.ts'), 'files must include *.d.ts pattern');

// 4. Verify undici-types index.d.ts declares default export Undici and namespace Undici
const indexContent = readDeclarationFile('index.d.ts');
assert.strictEqual(indexContent.includes('export default Undici'), true, 'index.d.ts must export default Undici');
assert.strictEqual(indexContent.includes('declare namespace Undici'), true, 'index.d.ts must declare namespace Undici');

// 5. Verify undici-types index.d.ts exports client and agent types Dispatcher, Pool, BalancedPool, RoundRobinPool, Client, Agent, and H2CClient
assert.strictEqual(indexContent.includes('Dispatcher,'), true, 'index.d.ts must export Dispatcher');
assert.strictEqual(indexContent.includes('Pool,'), true, 'index.d.ts must export Pool');
assert.strictEqual(indexContent.includes('BalancedPool,'), true, 'index.d.ts must export BalancedPool');
assert.strictEqual(indexContent.includes('RoundRobinPool,'), true, 'index.d.ts must export RoundRobinPool');
assert.strictEqual(indexContent.includes('Client,'), true, 'index.d.ts must export Client');
assert.strictEqual(indexContent.includes('Agent,'), true, 'index.d.ts must export Agent');
assert.strictEqual(indexContent.includes('H2CClient,'), true, 'index.d.ts must export H2CClient');

// 6. Verify undici-types index.d.ts exports request helpers and connection functions request, stream, pipeline, connect, upgrade, and buildConnector
assert.strictEqual(indexContent.includes('request,'), true, 'index.d.ts must export request');
assert.strictEqual(indexContent.includes('stream,'), true, 'index.d.ts must export stream');
assert.strictEqual(indexContent.includes('pipeline,'), true, 'index.d.ts must export pipeline');
assert.strictEqual(indexContent.includes('connect,'), true, 'index.d.ts must export connect');
assert.strictEqual(indexContent.includes('upgrade,'), true, 'index.d.ts must export upgrade');
assert.strictEqual(indexContent.includes('buildConnector,'), true, 'index.d.ts must export buildConnector');

// 7. Verify undici-types index.d.ts exports global dispatcher management functions setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, and getGlobalOrigin
assert.strictEqual(indexContent.includes('setGlobalDispatcher,'), true, 'index.d.ts must export setGlobalDispatcher');
assert.strictEqual(indexContent.includes('getGlobalDispatcher,'), true, 'index.d.ts must export getGlobalDispatcher');
assert.strictEqual(indexContent.includes('setGlobalOrigin,'), true, 'index.d.ts must export setGlobalOrigin');
assert.strictEqual(indexContent.includes('getGlobalOrigin,'), true, 'index.d.ts must export getGlobalOrigin');

// 8. Verify undici-types index.d.ts exports global installation function install
assert.strictEqual(indexContent.includes('globalThisInstall as install'), true, 'index.d.ts must export install function');

// 9. Verify undici-types declaration files exist on disk for all core modules
const expectedDeclarationFiles = [
  'index.d.ts',
  'dispatcher.d.ts',
  'client.d.ts',
  'pool.d.ts',
  'balanced-pool.d.ts',
  'round-robin-pool.d.ts',
  'agent.d.ts',
  'h2c-client.d.ts',
  'api.d.ts',
  'connector.d.ts',
  'errors.d.ts',
  'fetch.d.ts',
  'formdata.d.ts',
  'cookies.d.ts',
  'eventsource.d.ts',
  'websocket.d.ts',
  'cache.d.ts',
  'cache-interceptor.d.ts',
  'diagnostics-channel.d.ts',
  'global-dispatcher.d.ts',
  'global-origin.d.ts',
  'mock-agent.d.ts',
  'mock-client.d.ts',
  'mock-pool.d.ts',
  'proxy-agent.d.ts',
  'socks5-proxy-agent.d.ts',
  'env-http-proxy-agent.d.ts',
  'retry-agent.d.ts',
  'retry-handler.d.ts',
  'snapshot-agent.d.ts'
];

for (const declFile of expectedDeclarationFiles) {
  const fullPath = resolvePackagePath(declFile);
  assert.strictEqual(fs.existsSync(fullPath), true, `Declaration file ${declFile} must exist`);
}

// 10. Verify helper validation summary
const summary = verifyPackageVersionAndExports();
assert.strictEqual(summary.packageName, 'undici-types');
assert.strictEqual(summary.packageVersion, '8.3.0');
assert.strictEqual(summary.typesEntry, 'index.d.ts');
assert.strictEqual(summary.hasDefaultExport, true);
assert.strictEqual(summary.hasNamespace, true);
assert.strictEqual(summary.hasInstallExport, true);
assert.strictEqual(summary.hasDispatcher, true);
assert.strictEqual(summary.hasClient, true);
assert.strictEqual(summary.hasPool, true);
assert.strictEqual(summary.hasAgent, true);
assert.strictEqual(summary.hasRequest, true);
assert.strictEqual(summary.hasStream, true);
assert.strictEqual(summary.hasPipeline, true);
assert.strictEqual(summary.hasConnect, true);
assert.strictEqual(summary.hasUpgrade, true);
assert.strictEqual(summary.hasSetGlobalDispatcher, true);
assert.strictEqual(summary.hasGetGlobalDispatcher, true);
assert.strictEqual(summary.hasSetGlobalOrigin, true);
assert.strictEqual(summary.hasGetGlobalOrigin, true);

console.log('All undici-types.version contract checks passed successfully.');

原始种子者

匿名