CodeSampleX

Ejemplo

get-caller-file 2.0.5

Muestra verificada para npm get-caller-file 2.0.5. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: getCallerFile returns the caller…

sha256:7db40b3af8c39f559c459dbb1e0bb29459aab82c46e44bf0ed40cb4f59317b10

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

Caso

HOW
Objetivo
verify pkg:npm/get-caller-file@2.0.5
Paquetes
Creado
2026-08-23T08:22:27Z

Contrato

  1. getCallerFile returns the caller file path of the invoking function at default position 2
  2. getCallerFile inspects callers at custom stack depth positions
  3. getCallerFile throws TypeError when position depth exceeds or equals Error.stackTraceLimit
  4. getCallerFile preserves existing Error.prepareStackTrace handler across invocations
  5. getCallerFile returns undefined when requested stack position exceeds stack depth within limits

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 pkg:npm/get-caller-file@2.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/get-caller-file@2.0.5

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:bd427d4cca7e34f8cccfe0b0591517cb275e78be87ee3c13c9c712630c9ea74d","contract":["getCallerFile returns the caller file path of the invoking function at default position 2","getCallerFile inspects callers at custom stack depth positions","getCallerFile throws TypeError when position depth exceeds or equals Error.stackTraceLimit","getCallerFile preserves existing Error.prepareStackTrace handler across invocations","getCallerFile returns undefined when requested stack position exceeds stack depth within limits"],"goal":"verify pkg:npm/get-caller-file@2.0.5","kind":"HOW","packages":["pkg:npm/get-caller-file@2.0.5"],"schemaVersion":1},"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/get-caller-file@2.0.5"],"schemaVersion":1,"subject":"pkg:npm/get-caller-file@2.0.5","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-get-caller-file",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-caller-file",
      "version": "1.0.0",
      "dependencies": {
        "get-caller-file": "2.0.5"
      }
    },
    "node_modules/get-caller-file": {
      "version": "2.0.5",
      "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
      "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
      "license": "ISC",
      "engines": {
        "node": "6.* || 8.* || >= 10.*"
      }
    }
  }
}
package.json
{
  "name": "sample-get-caller-file",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "description": "Clean-room code sample for get-caller-file@2.0.5",
  "main": "src/index.mjs",
  "license": "MIT-0",
  "dependencies": {
    "get-caller-file": "2.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/get-caller-file@2.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-caller-file@2.0.5"
  ]
}
src/index.mjs
import getCallerFile from 'get-caller-file';

/**
 * Returns the caller file of the immediate invocation.
 *
 * @param {number} [position=2] - The stack frame position to inspect.
 * @returns {string|undefined} Caller file path or undefined if out of range.
 */
export function whoCalledMe(position) {
  return getCallerFile(position);
}

/**
 * Returns the caller of the outer caller using an increased stack position depth.
 *
 * @returns {string|undefined} Caller file path.
 */
export function nestedCaller() {
  return whoCalledMe(3);
}

export default getCallerFile;
test/contract.mjs
import assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
import getCallerFile, { whoCalledMe, nestedCaller } from '../src/index.mjs';

// 1. getCallerFile returns the caller file path of the invoking function at default position 2
function directCaller() {
  return getCallerFile();
}
const thisFilePath = fileURLToPath(import.meta.url);
const callerResult = directCaller();
assert.ok(callerResult, 'callerResult should be non-empty string');
assert.ok(
  callerResult === import.meta.url || callerResult === thisFilePath || callerResult.includes('contract.mjs'),
  `callerResult (${callerResult}) should match contract.mjs`
);

// Helper function whoCalledMe correctly resolves caller to test/contract.mjs
const helperCaller = whoCalledMe();
assert.ok(helperCaller, 'helperCaller should be non-empty string');
assert.ok(
  helperCaller === import.meta.url || helperCaller === thisFilePath || helperCaller.includes('contract.mjs'),
  `helperCaller (${helperCaller}) should reference contract.mjs`
);

// 2. getCallerFile inspects callers at custom stack depth positions
function outerCaller() {
  return nestedCaller();
}
const nestedResult = outerCaller();
assert.ok(nestedResult, 'nestedResult should be non-empty string');
assert.ok(
  nestedResult === import.meta.url || nestedResult === thisFilePath || nestedResult.includes('contract.mjs'),
  `nestedResult (${nestedResult}) should resolve to contract.mjs`
);

// 3. getCallerFile throws TypeError when position depth exceeds or equals Error.stackTraceLimit
assert.throws(
  () => getCallerFile(Error.stackTraceLimit),
  {
    name: 'TypeError'
  },
  'getCallerFile should throw TypeError when position >= Error.stackTraceLimit'
);

// 4. getCallerFile preserves existing Error.prepareStackTrace handler across invocations
const customPrepareStackTrace = (_, stack) => stack;
Error.prepareStackTrace = customPrepareStackTrace;
try {
  directCaller();
  assert.equal(Error.prepareStackTrace, customPrepareStackTrace, 'prepareStackTrace handler should be preserved');
} finally {
  Error.prepareStackTrace = undefined;
}

// 5. getCallerFile returns undefined when requested stack position exceeds stack depth within limits
const originalLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 50;
try {
  const outOfRange = getCallerFile(40);
  assert.equal(outOfRange, undefined, 'out of range position should return undefined');
} finally {
  Error.stackTraceLimit = originalLimit;
}

console.log('All pkg:npm/get-caller-file@2.0.5 contract assertions passed successfully.');

Seeder de origen

anónimo