CodeSampleX

Ejemplo

@types/ms 2.1.0

Muestra verificada para npm @types/ms 2.1.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: @types/ms package.json declares type…

sha256:8f40547eea5883dcc7bce981ed0057b19f7e637b281b6280631095167e443b5e

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:npm/%40types/ms@2.1.0
Paquetes
Creado
2026-08-23T13:55:28Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

Seeder de origen

anónimo