CodeSampleX

샘플

@types/ms 2.1.0

검증된 샘플 — npm @types/ms 2.1.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: @types/ms package.json declares type definitions entry point…

sha256:8f40547eea5883dcc7bce981ed0057b19f7e637b281b6280631095167e443b5e

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-23

케이스

HOW
목표
verify pkg:npm/%40types/ms@2.1.0
패키지
생성일
2026-08-23T13:55:28Z

컨트랙트

  1. @types/ms package.json declares type definitions entry point index.d.ts and version 2.1.0
  2. @types/ms index.d.ts declares overloaded function ms for formatting numbers and parsing StringValue
  3. @types/ms index.d.ts declares namespace ms with Unit, UnitAnyCase, and StringValue types
  4. @types/ms index.d.ts exports ms function using export assignment

파일

  • 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 pkg:npm/%40types/ms@2.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40types/ms@2.1.0

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:e9329bc4a762aea34fd2b0f7f0747d4d40d6a235bef54bf6366b3adedc3618f7","contract":["@types/ms package.json declares type definitions entry point index.d.ts and version 2.1.0","@types/ms index.d.ts declares overloaded function ms for formatting numbers and parsing StringValue","@types/ms index.d.ts declares namespace ms with Unit, UnitAnyCase, and StringValue types","@types/ms index.d.ts exports ms function using export assignment"],"goal":"verify pkg:npm/%40types/ms@2.1.0","kind":"HOW","packages":["pkg:npm/%40types/ms@2.1.0"],"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/%40types/ms@2.1.0"],"schemaVersion":1,"subject":"pkg:npm/%40types/ms@2.1.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ms-types",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ms-types",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@types/ms": "2.1.0"
      }
    },
    "node_modules/@types/ms": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
      "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-ms-types",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for @types/ms",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@types/ms": "2.1.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40types/ms@2.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40types/ms@2.1.0"
  ]
}
src/index.js
const fs = require('node:fs');
const path = require('node:path');

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

/**
 * Loads the declaration file content from @types/ms.
 * @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 and signatures.
 * @returns {object} Summary of discovered type declarations
 */
function inspectTypeDefinitions() {
  const content = loadDeclarationContent();

  const hasFormatOverload = content.includes('declare function ms(value: number, options?: { long: boolean }): string;');
  const hasParseOverload = content.includes('declare function ms(value: ms.StringValue): number;');
  const hasNamespace = content.includes('declare namespace ms');
  const hasUnitType = content.includes('type Unit =');
  const hasUnitAnyCaseType = content.includes('type UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>;');
  const hasStringValueType = content.includes('type StringValue =');
  const hasExportAssignment = content.includes('export = ms;');

  return {
    hasFormatOverload,
    hasParseOverload,
    hasNamespace,
    hasUnitType,
    hasUnitAnyCaseType,
    hasStringValueType,
    hasExportAssignment
  };
}

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/ms/package.json');
assert.strictEqual(pkgJson.name, '@types/ms', 'package name should match @types/ms');
assert.strictEqual(pkgJson.version, '2.1.0', 'package version should match 2.1.0');
assert.strictEqual(pkgJson.types, 'index.d.ts', 'package types entry should point to index.d.ts');

// 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');

// 4. Verify function overload signatures
assert.strictEqual(
  content.includes('declare function ms(value: number, options?: { long: boolean }): string;'),
  true,
  'index.d.ts must declare number formatting overload with optional long boolean option'
);
assert.strictEqual(
  content.includes('declare function ms(value: ms.StringValue): number;'),
  true,
  'index.d.ts must declare string duration parsing overload returning number'
);

// 5. Verify namespace and type aliases
assert.strictEqual(content.includes('declare namespace ms'), true, 'index.d.ts must declare ms namespace');
assert.strictEqual(content.includes('type Unit ='), true, 'index.d.ts must declare Unit type alias');
assert.strictEqual(content.includes('"Milliseconds"'), true, 'Unit type must include Milliseconds');
assert.strictEqual(content.includes('"Seconds"'), true, 'Unit type must include Seconds');
assert.strictEqual(content.includes('"Minutes"'), true, 'Unit type must include Minutes');
assert.strictEqual(content.includes('"Hours"'), true, 'Unit type must include Hours');
assert.strictEqual(content.includes('"Days"'), true, 'Unit type must include Days');
assert.strictEqual(
  content.includes('type UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>;'),
  true,
  'index.d.ts must declare UnitAnyCase type'
);
assert.strictEqual(
  content.includes('type StringValue ='),
  true,
  'index.d.ts must declare StringValue type template literals'
);

// 6. Verify export assignment
assert.strictEqual(content.includes('export = ms;'), true, 'index.d.ts must export ms function via export = ms');

// 7. Verify helper module inspection
const inspection = inspectTypeDefinitions();
assert.strictEqual(inspection.hasFormatOverload, true, 'inspection should confirm format overload');
assert.strictEqual(inspection.hasParseOverload, true, 'inspection should confirm parse overload');
assert.strictEqual(inspection.hasNamespace, true, 'inspection should confirm namespace');
assert.strictEqual(inspection.hasUnitType, true, 'inspection should confirm Unit type');
assert.strictEqual(inspection.hasUnitAnyCaseType, true, 'inspection should confirm UnitAnyCase type');
assert.strictEqual(inspection.hasStringValueType, true, 'inspection should confirm StringValue type');
assert.strictEqual(inspection.hasExportAssignment, true, 'inspection should confirm export assignment');

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

오리진 시더

익명