CodeSampleX

サンプル

@types/js-yaml 4.0.9: load

検証済みサンプル — npm @types/js-yaml 4.0.9: load. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: @types/js-yaml package.json declares type definitions…

sha256:525eba58d05c229ed197acc8fc9a82196bdf1dd161f870c347340add8f1d180a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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@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-07

ケース

HOW
ゴール
verify load in pkg:npm/%40types/js-yaml@4.0.9
パッケージ
シンボル
  • load
環境
node 22.23.2
作成日
2026-08-23T17:41:19Z

コントラクト

  1. @types/js-yaml package.json declares type definitions entry point index.d.ts and version 4.0.9
  2. @types/js-yaml index.d.ts declares load function taking string input and optional LoadOptions returning unknown
  3. @types/js-yaml index.d.ts declares LoadOptions interface with filename, onWarning, schema, json, and listener properties
  4. @types/js-yaml index.d.ts declares Schema class, YAMLException class, State interface, and EventType type

ファイル

  • 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 load in pkg:npm/%40types/js-yaml@4.0.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40types/js-yaml@4.0.9
Demonstrate these symbols/APIs:
  - load
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:9886f034cb71903a282ddbfdb4af41d7d9906d4526d47146696d1ae3f60a0131","constraints":{"executionContext":"node"},"contract":["@types/js-yaml package.json declares type definitions entry point index.d.ts and version 4.0.9","@types/js-yaml index.d.ts declares load function taking string input and optional LoadOptions returning unknown","@types/js-yaml index.d.ts declares LoadOptions interface with filename, onWarning, schema, json, and listener properties","@types/js-yaml index.d.ts declares Schema class, YAMLException class, State interface, and EventType type"],"goal":"verify load in pkg:npm/%40types/js-yaml@4.0.9","kind":"HOW","packages":["pkg:npm/%40types/js-yaml@4.0.9"],"schemaVersion":1,"symbols":["load"]},"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/js-yaml@4.0.9"],"schemaVersion":1,"subject":"pkg:npm/%40types/js-yaml@4.0.9","symbols":["load"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-types-js-yaml-load",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-types-js-yaml-load",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@types/js-yaml": "4.0.9"
      }
    },
    "node_modules/@types/js-yaml": {
      "version": "4.0.9",
      "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz",
      "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-types-js-yaml-load",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for @types/js-yaml load",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@types/js-yaml": "4.0.9"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify load in pkg:npm/%40types/js-yaml@4.0.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40types/js-yaml@4.0.9"
  ],
  "symbols": [
    "load"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const fs = require('node:fs');
const path = require('node:path');

/**
 * Resolves the path to the @types/js-yaml declaration file.
 * @returns {string} Absolute path to index.d.ts
 */
function getDeclarationPath() {
  const pkgJsonPath = require.resolve('@types/js-yaml/package.json');
  const pkgDir = path.dirname(pkgJsonPath);
  return path.join(pkgDir, 'index.d.ts');
}

/**
 * Loads the declaration file content from @types/js-yaml.
 * @returns {string} The text content of index.d.ts
 */
function loadDeclarationContent() {
  const declPath = getDeclarationPath();
  return fs.readFileSync(declPath, 'utf8');
}

/**
 * Validates that the declaration file defines expected TypeScript constructs for load and its dependencies.
 * @returns {object} Summary of discovered type declarations
 */
function inspectTypeDefinitions() {
  const content = loadDeclarationContent();

  const hasNamespace = content.includes('export as namespace jsyaml;');
  const hasLoadFunction = content.includes('export function load(str: string, opts?: LoadOptions): unknown;');
  const hasLoadOptions = content.includes('export interface LoadOptions');
  const hasFilenameOption = content.includes('filename?: string | undefined;');
  const hasOnWarningOption = content.includes('onWarning?(this: null, e: YAMLException): void;');
  const hasSchemaOption = content.includes('schema?: Schema | undefined;');
  const hasJsonOption = content.includes('json?: boolean | undefined;');
  const hasListenerOption = content.includes('listener?(this: State, eventType: EventType, state: State): void;');
  const hasSchemaClass = content.includes('export class Schema');
  const hasYamlExceptionClass = content.includes('export class YAMLException extends Error');
  const hasStateInterface = content.includes('export interface State');
  const hasEventType = content.includes('export type EventType = "open" | "close";');

  return {
    hasNamespace,
    hasLoadFunction,
    hasLoadOptions,
    hasFilenameOption,
    hasOnWarningOption,
    hasSchemaOption,
    hasJsonOption,
    hasListenerOption,
    hasSchemaClass,
    hasYamlExceptionClass,
    hasStateInterface,
    hasEventType
  };
}

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('@types/js-yaml/package.json');
assert.strictEqual(pkgJson.name, '@types/js-yaml', 'package name should match @types/js-yaml');
assert.strictEqual(pkgJson.version, '4.0.9', 'package version should match 4.0.9');
assert.strictEqual(pkgJson.types, 'index.d.ts', 'package types entry should point to index.d.ts');
assert.ok(pkgJson.exports && pkgJson.exports['.'], 'exports entry point should be configured');

// 2. Verify declaration file existence
const declPath = getDeclarationPath();
assert.strictEqual(fs.existsSync(declPath), true, 'index.d.ts should exist on disk');

// 3. Verify declaration content and structure
const content = loadDeclarationContent();
assert.strictEqual(typeof content, 'string', 'declaration content should be a string');
assert.strictEqual(content.includes('export as namespace jsyaml;'), true, 'declaration should declare jsyaml namespace');

// 4. Verify load function declaration signature
assert.strictEqual(
  content.includes('export function load(str: string, opts?: LoadOptions): unknown;'),
  true,
  'index.d.ts must declare load function accepting string input and optional LoadOptions returning unknown'
);

// 5. Verify LoadOptions interface and member options
assert.strictEqual(content.includes('export interface LoadOptions'), true, 'index.d.ts must declare LoadOptions interface');
assert.strictEqual(content.includes('filename?: string | undefined;'), true, 'LoadOptions must declare optional filename property');
assert.strictEqual(content.includes('onWarning?(this: null, e: YAMLException): void;'), true, 'LoadOptions must declare onWarning hook');
assert.strictEqual(content.includes('schema?: Schema | undefined;'), true, 'LoadOptions must declare optional schema property');
assert.strictEqual(content.includes('json?: boolean | undefined;'), true, 'LoadOptions must declare optional json flag');
assert.strictEqual(content.includes('listener?(this: State, eventType: EventType, state: State): void;'), true, 'LoadOptions must declare parse event listener');

// 6. Verify supporting types used by load: Schema, YAMLException, State, EventType
assert.strictEqual(content.includes('export class Schema'), true, 'index.d.ts must declare Schema class');
assert.strictEqual(content.includes('export class YAMLException extends Error'), true, 'index.d.ts must declare YAMLException class');
assert.strictEqual(content.includes('export interface State'), true, 'index.d.ts must declare State interface');
assert.strictEqual(content.includes('export type EventType = "open" | "close";'), true, 'index.d.ts must declare EventType type');

// 7. Verify helper module inspection
const inspection = inspectTypeDefinitions();
assert.strictEqual(inspection.hasNamespace, true, 'inspection should confirm namespace');
assert.strictEqual(inspection.hasLoadFunction, true, 'inspection should confirm load function signature');
assert.strictEqual(inspection.hasLoadOptions, true, 'inspection should confirm LoadOptions interface');
assert.strictEqual(inspection.hasFilenameOption, true, 'inspection should confirm filename option');
assert.strictEqual(inspection.hasOnWarningOption, true, 'inspection should confirm onWarning option');
assert.strictEqual(inspection.hasSchemaOption, true, 'inspection should confirm schema option');
assert.strictEqual(inspection.hasJsonOption, true, 'inspection should confirm json option');
assert.strictEqual(inspection.hasListenerOption, true, 'inspection should confirm listener option');
assert.strictEqual(inspection.hasSchemaClass, true, 'inspection should confirm Schema class');
assert.strictEqual(inspection.hasYamlExceptionClass, true, 'inspection should confirm YAMLException class');
assert.strictEqual(inspection.hasStateInterface, true, 'inspection should confirm State interface');
assert.strictEqual(inspection.hasEventType, true, 'inspection should confirm EventType union');

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

オリジンシーダー

匿名