CodeSampleX

Ejemplo

@types/stack-utils 2.0.3: clean stack trace and parse line with StackUtils

Muestra verificada para npm @types/stack-utils 2.0.3: clean stack trace and parse line with StackUtils. El contrato se ejecutó en node 22 · linux alpine/x64…

sha256:296cb5a337d2e20ee0879f3a52d1996dcdaccdda2f7b1e2b9f5aadb1e9f1c917

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-27

Caso

HOW
Objetivo
clean stack trace and parse line with StackUtils
Paquetes
Símbolos
  • StackUtils
Creado
2026-08-27T15:29:35Z

Contrato

  1. package manifest specifies index.d.ts type declarations and TypeScript version
  2. declares StackUtils class with constructor, static nodeInternals, and methods clean, capture, captureString, at, parseLine
  3. declares Options interface with internals, ignoredPackages, cwd, and wrapCallSite
  4. declares CallSite and CallSiteLike interfaces with location and inspection methods
  5. declares StackLineData and StackData interfaces with line, column, file, and eval details

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

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: clean stack trace and parse line with StackUtils
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40types/stack-utils@2.0.3
Demonstrate these symbols/APIs:
  - StackUtils

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:15dba7b3b974ba667f57b387ed75c37fa6cd86111421202ded076a046ae19037","contract":["package manifest specifies index.d.ts type declarations and TypeScript version","declares StackUtils class with constructor, static nodeInternals, and methods clean, capture, captureString, at, parseLine","declares Options interface with internals, ignoredPackages, cwd, and wrapCallSite","declares CallSite and CallSiteLike interfaces with location and inspection methods","declares StackLineData and StackData interfaces with line, column, file, and eval details"],"goal":"clean stack trace and parse line with StackUtils","kind":"HOW","packages":["pkg:npm/%40types/stack-utils@2.0.3"],"schemaVersion":1,"symbols":["StackUtils"]},"contractCommand":["node","test/contract.mjs"],"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/stack-utils@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/%40types/stack-utils@2.0.3","symbols":["StackUtils"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-types-stack-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-types-stack-utils",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@types/stack-utils": "2.0.3"
      }
    },
    "node_modules/@types/stack-utils": {
      "version": "2.0.3",
      "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz",
      "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-types-stack-utils",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@types/stack-utils": "2.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "clean stack trace and parse line with StackUtils",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40types/stack-utils@2.0.3"
  ],
  "symbols": [
    "StackUtils"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve @types/stack-utils package manifest and verify type declaration entry points
const pkgPath = require.resolve('@types/stack-utils/package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, '@types/stack-utils', 'Package name must be @types/stack-utils');
assert.equal(pkg.version, '2.0.3', 'Package version must be 2.0.3');
assert.equal(pkg.types, 'index.d.ts', 'Package types entry must point to index.d.ts');
assert.equal(pkg.typeScriptVersion, '4.5', 'TypeScript version must be 4.5');

const typesDir = path.dirname(pkgPath);
const dtsContent = fs.readFileSync(path.join(typesDir, 'index.d.ts'), 'utf8');

// 2. Verify StackUtils class declaration and methods
assert.ok(
  dtsContent.includes('export = StackUtils;'),
  'Must export StackUtils as CommonJS default export'
);
assert.ok(
  dtsContent.includes('declare class StackUtils {'),
  'Must declare StackUtils class'
);
assert.ok(
  dtsContent.includes('static nodeInternals(): RegExp[];'),
  'Must declare static nodeInternals method returning RegExp array'
);
assert.ok(
  dtsContent.includes('constructor(options?: StackUtils.Options);'),
  'Must declare constructor accepting optional StackUtils.Options'
);
assert.ok(
  dtsContent.includes('clean(stack: string | string[]): string;'),
  'Must declare clean method accepting string or string array'
);
assert.ok(
  dtsContent.includes('capture(limit?: number, startStackFunction?: Function): StackUtils.CallSite[];') &&
  dtsContent.includes('capture(startStackFunction: Function): StackUtils.CallSite[];'),
  'Must declare capture overloads returning CallSite array'
);
assert.ok(
  dtsContent.includes('captureString(limit?: number, startStackFunction?: Function): string;') &&
  dtsContent.includes('captureString(startStackFunction: Function): string;'),
  'Must declare captureString overloads returning string'
);
assert.ok(
  dtsContent.includes('at(startStackFunction?: Function): StackUtils.CallSiteLike;'),
  'Must declare at method returning CallSiteLike'
);
assert.ok(
  dtsContent.includes('parseLine(line: string): StackUtils.StackLineData | null;'),
  'Must declare parseLine method returning StackLineData or null'
);

// 3. Verify Options interface
assert.ok(
  dtsContent.includes('interface Options {') &&
  dtsContent.includes('internals?: RegExp[] | undefined;') &&
  dtsContent.includes('ignoredPackages?: string[] | undefined;') &&
  dtsContent.includes('cwd?: string | undefined;') &&
  dtsContent.includes('wrapCallSite?(callSite: CallSite): CallSite;'),
  'Options interface must define internals, ignoredPackages, cwd, and wrapCallSite'
);

// 4. Verify CallSite and CallSiteLike interfaces
assert.ok(
  dtsContent.includes('interface CallSite {') &&
  dtsContent.includes('getThis(): object | undefined;') &&
  dtsContent.includes('getTypeName(): string;') &&
  dtsContent.includes('getFunction(): Function | undefined;') &&
  dtsContent.includes('getFunctionName(): string;') &&
  dtsContent.includes('getMethodName(): string | null;') &&
  dtsContent.includes('getFileName(): string | undefined;') &&
  dtsContent.includes('getLineNumber(): number;') &&
  dtsContent.includes('getColumnNumber(): number;') &&
  dtsContent.includes('getEvalOrigin(): CallSite | string;') &&
  dtsContent.includes('isToplevel(): boolean;') &&
  dtsContent.includes('isEval(): boolean;') &&
  dtsContent.includes('isNative(): boolean;') &&
  dtsContent.includes('isConstructor(): boolean;'),
  'CallSite interface must define V8 CallSite accessor methods'
);

assert.ok(
  dtsContent.includes('interface CallSiteLike extends StackData {') &&
  dtsContent.includes('type?: string | undefined;'),
  'CallSiteLike interface must extend StackData and include optional type property'
);

// 5. Verify StackLineData and StackData interfaces
assert.ok(
  dtsContent.includes('interface StackLineData extends StackData {') &&
  dtsContent.includes('evalLine?: number | undefined;') &&
  dtsContent.includes('evalColumn?: number | undefined;') &&
  dtsContent.includes('evalFile?: string | undefined;'),
  'StackLineData interface must extend StackData and include evalLine, evalColumn, evalFile'
);

assert.ok(
  dtsContent.includes('interface StackData {') &&
  dtsContent.includes('line?: number | undefined;') &&
  dtsContent.includes('column?: number | undefined;') &&
  dtsContent.includes('file?: string | undefined;') &&
  dtsContent.includes('constructor?: boolean | undefined;') &&
  dtsContent.includes('evalOrigin?: string | undefined;') &&
  dtsContent.includes('native?: boolean | undefined;') &&
  dtsContent.includes('function?: string | undefined;') &&
  dtsContent.includes('method?: string | undefined;'),
  'StackData interface must define line, column, file, constructor, evalOrigin, native, function, method'
);

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

Seeder de origen

anónimo