CodeSampleX

サンプル

get-caller-file 2.0.5

検証済みサンプル — npm get-caller-file 2.0.5. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: getCallerFile returns the caller file path of the invoking…

sha256:7db40b3af8c39f559c459dbb1e0bb29459aab82c46e44bf0ed40cb4f59317b10

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
verify pkg:npm/get-caller-file@2.0.5
パッケージ
作成日
2026-08-23T08:22:27Z

コントラクト

  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

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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

オリジンシーダー

匿名