CodeSampleX

Ejemplo

source-map-support 0.5.21: sourceMapSupport.install

Muestra verificada para npm source-map-support 0.5.21: sourceMapSupport.install. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:538be996e4848ae80667e27ec77f4129821af67b64457af004c41cfb4c596ce3

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-01

Caso

HOW
Objetivo
verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21
Paquetes
Símbolos
  • sourceMapSupport.install
Creado
2026-09-01T11:51:22Z

Contrato

  1. sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping
  2. sourceMapSupport.install rewrites stack traces to map generated positions back to original source files
  3. sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps
  4. sourceMapSupport.install preserves standard stack trace structure when no source map is found

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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: verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/source-map-support@0.5.21
Demonstrate these symbols/APIs:
  - sourceMapSupport.install

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:5046590449b2dfd1c98ea3da01e34f5959b466640c9ac3098f2d932ae84d8491","contract":["sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping","sourceMapSupport.install rewrites stack traces to map generated positions back to original source files","sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps","sourceMapSupport.install preserves standard stack trace structure when no source map is found"],"goal":"verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21","kind":"HOW","packages":["pkg:npm/source-map-support@0.5.21"],"schemaVersion":1,"symbols":["sourceMapSupport.install"]},"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/source-map-support@0.5.21"],"schemaVersion":1,"subject":"pkg:npm/source-map-support@0.5.21","symbols":["sourceMapSupport.install"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-source-map-support-install",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-support-install",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "source-map-support": "0.5.21"
      }
    },
    "node_modules/buffer-from": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
      "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
      "license": "MIT"
    },
    "node_modules/source-map": {
      "version": "0.6.1",
      "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
      "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/source-map-support": {
      "version": "0.5.21",
      "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
      "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
      "license": "MIT",
      "dependencies": {
        "buffer-from": "^1.0.0",
        "source-map": "^0.6.0"
      }
    }
  }
}
package.json
{
  "name": "sample-source-map-support-install",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of sourceMapSupport.install in source-map-support",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "license": "MIT-0",
  "dependencies": {
    "source-map-support": "0.5.21"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map-support@0.5.21"
  ],
  "symbols": [
    "sourceMapSupport.install"
  ]
}
src/index.js
const sourceMapSupport = require("source-map-support");

/**
 * Installs source map support into Node.js stack trace handling.
 * @param {object} [options]
 * @returns {void}
 */
function install(options) {
  return sourceMapSupport.install(options);
}

/**
 * Resets custom retrieve handlers to defaults if available.
 * @returns {void}
 */
function resetRetrieveHandlers() {
  if (typeof sourceMapSupport.resetRetrieveHandlers === "function") {
    sourceMapSupport.resetRetrieveHandlers();
  }
}

module.exports = {
  sourceMapSupport,
  install,
  resetRetrieveHandlers,
};
test/contract.mjs
import assert from "node:assert";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
const { sourceMapSupport, install, resetRetrieveHandlers } = require("../src/index.js");

async function runContract() {
  // 1. sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping
  assert.strictEqual(typeof sourceMapSupport.install, "function", "sourceMapSupport.install must be a function");
  assert.strictEqual(typeof install, "function", "install wrapper must be a function");

  let hookInvocations = 0;
  const sampleSourceMap = {
    version: 3,
    file: "compiled-bundle.js",
    sources: ["src/original-module.ts"],
    sourcesContent: [
      "export function executeTask(value: number): number {\n  if (value < 0) throw new Error(\"negative value\");\n  return value * 2;\n}\n"
    ],
    names: ["executeTask", "value"],
    mappings: "AAAA,gBAAsBA,YAAY,CAACC,KAAa;IAC9C,IAAIA,KAAK,GAAG,CAAC;MAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACjD,OAAOA,KAAK,GAAG,CAAC,CAAC;AACnB,CAAC"
  };

  install({
    emptyCacheBetweenOperations: true,
    handleUncaughtExceptions: false,
    environment: "node",
    retrieveSourceMap(source) {
      if (source === "compiled-bundle.js" || source.endsWith("/compiled-bundle.js")) {
        hookInvocations++;
        return {
          url: "compiled-bundle.js",
          map: sampleSourceMap,
        };
      }
      return null;
    },
  });

  assert.strictEqual(typeof Error.prepareStackTrace, "function", "Error.prepareStackTrace must be a function after install()");

  // 2. sourceMapSupport.install rewrites stack traces to map generated positions back to original source files
  const fnWithSourceURL = new Function(
    "//# sourceURL=compiled-bundle.js\nthrow new Error(\"error inside compiled bundle\");"
  );
  let caughtError = null;
  try {
    fnWithSourceURL();
  } catch (err) {
    caughtError = err;
  }

  assert.ok(caughtError instanceof Error, "Expected error to be thrown");
  assert.ok(
    caughtError.stack.includes("src/original-module.ts"),
    `Expected stack trace to contain mapped original file "src/original-module.ts", got:\n${caughtError.stack}`
  );

  // 3. sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps
  assert.ok(hookInvocations > 0, "Expected custom retrieveSourceMap hook to be invoked when formatting stack trace");

  // 4. sourceMapSupport.install preserves standard stack trace structure when no source map is found
  const fnUnmapped = new Function(
    "//# sourceURL=unmapped-file.js\nthrow new Error(\"unmapped error message\");"
  );
  let unmappedErr = null;
  try {
    fnUnmapped();
  } catch (err) {
    unmappedErr = err;
  }
  assert.ok(unmappedErr instanceof Error, "Expected unmapped error");
  assert.ok(typeof unmappedErr.stack === "string", "Stack trace must be a string");
  assert.ok(unmappedErr.stack.includes("unmapped error message"), "Stack trace must contain original error message");
  assert.ok(unmappedErr.stack.includes("unmapped-file.js"), "Stack trace must contain unmapped source URL");

  resetRetrieveHandlers();
  console.log("Contract assertions passed successfully.");
}

runContract().catch((err) => {
  console.error("Contract test failed:", err);
  process.exit(1);
});

Seeder de origen

anónimo