CodeSampleX

Exemple

get-caller-file 2.0.5

Échantillon vérifié pour npm get-caller-file 2.0.5. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:7db40b3af8c39f559c459dbb1e0bb29459aab82c46e44bf0ed40cb4f59317b10

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/get-caller-file@2.0.5
Paquets
Créé
2026-08-23T08:22:27Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 d'origine

anonyme