CodeSampleX

Пример

@types/node 17.0.45

Проверенный пример — npm @types/node 17.0.45. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: @types/node@17.0.45 package.json sets…

sha256:8ad4bdd67c0a0ffd8dda0b5baf5ac0626ed83c8c42df28937c115ae9148ea645

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

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

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

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-11-29

Кейс

HOW
Цель
verify pkg:npm/%40types/node@17.0.45
Пакеты
Окружение
node 22.23.2
Создан
2026-11-29T00:05:48Z

Контракт

  1. @types/node@17.0.45 package.json sets version 17.0.45, types index.d.ts, empty main, typeScriptVersion 4.0, empty dependencies, and no typesVersions
  2. require('@types/node') throws MODULE_NOT_FOUND because the package provides only TypeScript declarations and no runtime entrypoint
  3. index.d.ts references es2020/esnext libs and every referenced declaration path resolves to an existing non-empty .d.ts file on disk including subpath modules
  4. globals.d.ts declares Node 17 structuredClone, AbortController, AbortSignal, RelativeIndexable.at, and NodeJS namespace types without global fetch
  5. stream/consumers.d.ts, timers/promises.d.ts, assert/strict.d.ts, fs/promises.d.ts, and diagnostics_channel.d.ts each declare both bare and node:-prefixed modules with their core exports

Файлы

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/%40types/node@17.0.45
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40types/node@17.0.45
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:7d5a10ac2ebd0724c63b05132ecfcbebc035cdc450153dd27b30edb4a7bb06b2","constraints":{"executionContext":"node"},"contract":["@types/node@17.0.45 package.json sets version 17.0.45, types index.d.ts, empty main, typeScriptVersion 4.0, empty dependencies, and no typesVersions","require('@types/node') throws MODULE_NOT_FOUND because the package provides only TypeScript declarations and no runtime entrypoint","index.d.ts references es2020/esnext libs and every referenced declaration path resolves to an existing non-empty .d.ts file on disk including subpath modules","globals.d.ts declares Node 17 structuredClone, AbortController, AbortSignal, RelativeIndexable.at, and NodeJS namespace types without global fetch","stream/consumers.d.ts, timers/promises.d.ts, assert/strict.d.ts, fs/promises.d.ts, and diagnostics_channel.d.ts each declare both bare and node:-prefixed modules with their core exports"],"goal":"verify pkg:npm/%40types/node@17.0.45","kind":"HOW","packages":["pkg:npm/%40types/node@17.0.45"],"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/%40types/node@17.0.45"],"schemaVersion":1,"subject":"pkg:npm/%40types/node@17.0.45","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const fs = require('node:fs');
const path = require('node:path');

function getPackageDir() {
  const pkgJsonPath = require.resolve('@types/node/package.json');
  return path.dirname(pkgJsonPath);
}

function readPackageMetadata() {
  const pkgDir = getPackageDir();
  const raw = fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8');
  return JSON.parse(raw);
}

function readDeclaration(relativePath) {
  const pkgDir = getPackageDir();
  return fs.readFileSync(path.join(pkgDir, relativePath), 'utf8');
}

function parseIndexReferences() {
  const indexContent = readDeclaration('index.d.ts');
  const libRefs = [];
  const pathRefs = [];

  for (const match of indexContent.matchAll(/\/\/\/\s*<reference\s+lib="([^"]+)"\s*\/>/g)) {
    libRefs.push(match[1]);
  }
  for (const match of indexContent.matchAll(/\/\/\/\s*<reference\s+path="([^"]+)"\s*\/>/g)) {
    pathRefs.push(match[1]);
  }

  return {
    libRefs,
    pathRefs: [...new Set(pathRefs)],
  };
}

function listDeclaredModules(relativePath) {
  const content = readDeclaration(relativePath);
  const modules = [];
  for (const match of content.matchAll(/declare\s+module\s+['"]([^'"]+)['"]/g)) {
    modules.push(match[1]);
  }
  return modules;
}

module.exports = {
  getPackageDir,
  readPackageMetadata,
  readDeclaration,
  parseIndexReferences,
  listDeclaredModules,
};
package-lock.json
{
  "name": "verify-types-node-17",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-types-node-17",
      "version": "1.0.0",
      "dependencies": {
        "@types/node": "17.0.45"
      }
    },
    "node_modules/@types/node": {
      "version": "17.0.45",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz",
      "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "verify-types-node-17",
  "version": "1.0.0",
  "private": true,
  "description": "Verify @types/node@17.0.45 package layout, reference graph, and declarations",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@types/node": "17.0.45"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40types/node@17.0.45",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40types/node@17.0.45"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const {
  getPackageDir,
  readPackageMetadata,
  readDeclaration,
  parseIndexReferences,
  listDeclaredModules,
} = require('../index.js');

// 1. Package metadata and type-only layout
const pkgDir = getPackageDir();
const meta = readPackageMetadata();
assert.equal(meta.name, '@types/node');
assert.equal(meta.version, '17.0.45');
assert.equal(meta.main, '');
assert.equal(meta.types, 'index.d.ts');
assert.equal(meta.typeScriptVersion, '4.0');
assert.deepEqual(meta.dependencies, {});
assert.equal(meta.typesVersions, undefined);

// 2. Runtime require fails with MODULE_NOT_FOUND because @types/node has no JS entry point
assert.throws(
  () => {
    require('@types/node');
  },
  (err) => err && err.code === 'MODULE_NOT_FOUND',
  'Expected require("@types/node") to throw MODULE_NOT_FOUND for type-only package'
);

// 3. index.d.ts reference graph resolves cleanly on disk
const { libRefs, pathRefs } = parseIndexReferences();
for (const expectedLib of ['es2020', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint']) {
  assert.ok(libRefs.includes(expectedLib), `Expected lib reference ${expectedLib}`);
}
assert.ok(pathRefs.length >= 45, `Expected at least 45 referenced declaration files, got ${pathRefs.length}`);
for (const refPath of pathRefs) {
  const fullPath = path.join(pkgDir, refPath);
  const stat = fs.statSync(fullPath);
  assert.ok(stat.isFile() && stat.size > 0, `Expected non-empty declaration file for ${refPath}`);
}
for (const expectedSubpath of [
  'assert/strict.d.ts',
  'dns/promises.d.ts',
  'fs/promises.d.ts',
  'stream/consumers.d.ts',
  'stream/promises.d.ts',
  'stream/web.d.ts',
  'timers/promises.d.ts',
  'globals.d.ts',
  'globals.global.d.ts',
]) {
  assert.ok(pathRefs.includes(expectedSubpath), `Expected index.d.ts to reference ${expectedSubpath}`);
}

// 4. Node 17 global declarations in globals.d.ts
const globalsDts = readDeclaration('globals.d.ts');
assert.match(globalsDts, /declare function structuredClone<T>\(/);
assert.match(globalsDts, /interface AbortController\s*\{/);
assert.match(globalsDts, /interface AbortSignal\s*\{/);
assert.match(globalsDts, /interface RelativeIndexable<T>\s*\{[\s\S]*at\(index:\s*number\):\s*T \| undefined;/);
assert.match(globalsDts, /declare namespace NodeJS\s*\{/);
assert.match(globalsDts, /interface ErrnoException extends Error/);
assert.match(globalsDts, /type TypedArray\s*=/);
assert.doesNotMatch(globalsDts, /declare function fetch\(/);

// 5. Dual bare and node:-prefixed module declarations for modern core/subpath modules
const dualModuleChecks = [
  {
    file: 'stream/consumers.d.ts',
    modules: ['stream/consumers', 'node:stream/consumers'],
    patterns: [
      /function buffer\(/,
      /function text\(/,
      /function arrayBuffer\(/,
      /function blob\(/,
      /function json\(/,
    ],
  },
  {
    file: 'timers/promises.d.ts',
    modules: ['timers/promises', 'node:timers/promises'],
    patterns: [
      /function setTimeout<T = void>\(/,
      /function setImmediate<T = void>\(/,
      /function setInterval<T = void>\(/,
    ],
  },
  {
    file: 'assert/strict.d.ts',
    modules: ['assert/strict', 'node:assert/strict'],
    patterns: [/import \{ strict \} from 'node:assert';/],
  },
  {
    file: 'fs/promises.d.ts',
    modules: ['fs/promises', 'node:fs/promises'],
    patterns: [/function readFile\(/, /function writeFile\(/, /function cp\(/],
  },
  {
    file: 'diagnostics_channel.d.ts',
    modules: ['diagnostics_channel', 'node:diagnostics_channel'],
    patterns: [
      /function hasSubscribers\(name:\s*string\):\s*boolean;/,
      /function channel\(name:\s*string\):\s*Channel;/,
      /class Channel\s*\{/,
    ],
  },
];

for (const check of dualModuleChecks) {
  const declared = listDeclaredModules(check.file);
  for (const modName of check.modules) {
    assert.ok(
      declared.includes(modName),
      `Expected ${check.file} to declare module '${modName}', found: ${declared.join(', ')}`
    );
  }
  const source = readDeclaration(check.file);
  for (const pattern of check.patterns) {
    assert.match(source, pattern, `Expected ${check.file} to match ${pattern}`);
  }
}

console.log('PASS: @types/node@17.0.45 contract verified');

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

аноним