CodeSampleX

샘플

find-up 4.1.0: sync

검증된 샘플 — npm find-up 4.1.0: sync. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert findUp.sync returns the absolute path when target file…

sha256:6ca8a38c92a7c066ed100f1afd9c433bceae86b2e83f673f90f589d650bdce6c

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-30

케이스

HOW
목표
verify find-up.sync in pkg:npm/find-up@4.1.0
패키지
심벌
  • find-up.sync
환경
node 22.23.2
생성일
2026-08-30T17:13:25Z

컨트랙트

  1. assert findUp.sync returns the absolute path when target file exists in the start directory
  2. assert findUp.sync walks up parent directories to find target file
  3. assert findUp.sync returns the first matching item when given an array of target filenames
  4. assert findUp.sync returns undefined when target file is not found in start or parent directories
  5. assert findUp.sync supports a custom synchronous matcher function to locate target path
  6. assert findUp.sync halts directory traversal when matcher returns findUp.stop

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 find-up.sync in pkg:npm/find-up@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/find-up@4.1.0
Demonstrate these symbols/APIs:
  - find-up.sync
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:d5d7b94c4dbf641f6ce9d13b63f96f986f23335026b206f8fbb6133e317d6bc2","constraints":{"executionContext":"node"},"contract":["assert findUp.sync returns the absolute path when target file exists in the start directory","assert findUp.sync walks up parent directories to find target file","assert findUp.sync returns the first matching item when given an array of target filenames","assert findUp.sync returns undefined when target file is not found in start or parent directories","assert findUp.sync supports a custom synchronous matcher function to locate target path","assert findUp.sync halts directory traversal when matcher returns findUp.stop"],"goal":"verify find-up.sync in pkg:npm/find-up@4.1.0","kind":"HOW","packages":["pkg:npm/find-up@4.1.0"],"schemaVersion":1,"symbols":["find-up.sync"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/find-up@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/find-up@4.1.0","symbols":["find-up.sync"],"verifierAdapter":"node-typescript@1"}
index.js
const findUp = require('find-up');

/**
 * Synchronously finds a file or directory by walking up parent directories.
 *
 * @param {string|string[]} name - Filename or array of filenames to search for.
 * @param {object} [options] - Options passed to findUp.sync.
 * @param {string} [options.cwd] - Directory to start looking from.
 * @param {string} [options.type] - The type of path to match ('file' or 'directory').
 * @returns {string|undefined} First path found or undefined if not found.
 */
function findFileSync(name, options = {}) {
  return findUp.sync(name, options);
}

/**
 * Synchronously finds a file or directory using a custom matcher function.
 *
 * @param {Function} matcher - Function called with each directory that returns a file path or findUp.stop.
 * @param {object} [options] - Options passed to findUp.sync.
 * @param {string} [options.cwd] - Directory to start looking from.
 * @returns {string|undefined} First path found or undefined if not found.
 */
function findWithMatcherSync(matcher, options = {}) {
  return findUp.sync(matcher, options);
}

module.exports = {
  findFileSync,
  findWithMatcherSync,
  findUp,
};
package-lock.json
{
  "name": "sample-2997937507",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-2997937507",
      "version": "1.0.0",
      "license": "ISC",
      "dependencies": {
        "find-up": "^4.1.0"
      }
    },
    "node_modules/find-up": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
      "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
      "license": "MIT",
      "dependencies": {
        "locate-path": "^5.0.0",
        "path-exists": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/locate-path": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
      "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
      "license": "MIT",
      "dependencies": {
        "p-locate": "^4.1.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/p-limit": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
      "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
      "license": "MIT",
      "dependencies": {
        "p-try": "^2.0.0"
      },
      "engines": {
        "node": ">=6"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/p-locate": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
      "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
      "license": "MIT",
      "dependencies": {
        "p-limit": "^2.2.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/p-try": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
      "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/path-exists": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
      "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-find-up-sync",
  "version": "1.0.0",
  "description": "Clean-room sample verifying find-up.sync functionality",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "find-up": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify find-up.sync in pkg:npm/find-up@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/find-up@4.1.0"
  ],
  "symbols": [
    "find-up.sync"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import findUp from 'find-up';
import { findFileSync, findWithMatcherSync } from '../index.js';

// Setup isolated temporary directory structure for offline verification
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'findup-sync-contract-'));
const level1Dir = path.join(tmpDir, 'level1');
const level2Dir = path.join(level1Dir, 'level2');
fs.mkdirSync(level2Dir, { recursive: true });

const rootFile = path.join(tmpDir, 'root-config.json');
const level1File = path.join(level1Dir, 'level1-config.json');
const level2File = path.join(level2Dir, 'level2-config.json');

fs.writeFileSync(rootFile, '{"root": true}', 'utf8');
fs.writeFileSync(level1File, '{"level1": true}', 'utf8');
fs.writeFileSync(level2File, '{"level2": true}', 'utf8');

try {
  // 1. Find file in start directory synchronously
  const directLevel2 = findUp.sync('level2-config.json', { cwd: level2Dir });
  assert.strictEqual(directLevel2, level2File, 'findUp.sync must locate file in cwd');

  const wrapperLevel2 = findFileSync('level2-config.json', { cwd: level2Dir });
  assert.strictEqual(wrapperLevel2, level2File, 'findFileSync must locate file in cwd');

  // 2. Find file in parent directory by walking upwards
  const directLevel1 = findUp.sync('level1-config.json', { cwd: level2Dir });
  assert.strictEqual(directLevel1, level1File, 'findUp.sync must walk up to parent directory');

  const directRoot = findUp.sync('root-config.json', { cwd: level2Dir });
  assert.strictEqual(directRoot, rootFile, 'findUp.sync must walk up multiple parent levels');

  // 3. Find with array of filenames (first matching)
  const arrayMatch = findUp.sync(['nonexistent.json', 'level1-config.json', 'root-config.json'], { cwd: level2Dir });
  assert.strictEqual(arrayMatch, level1File, 'findUp.sync with array must find the first existing match traversing upwards');

  // 4. Return undefined when file is not found anywhere in ancestor tree
  const notFound = findUp.sync('definitely-does-not-exist.json', { cwd: level2Dir });
  assert.strictEqual(notFound, undefined, 'findUp.sync must return undefined when file does not exist');

  // 5. Custom synchronous matcher function
  const matcherFound = findWithMatcherSync(dir => {
    const candidate = path.join(dir, 'root-config.json');
    return fs.existsSync(candidate) ? candidate : undefined;
  }, { cwd: level2Dir });
  assert.strictEqual(matcherFound, rootFile, 'findWithMatcherSync must support custom directory matcher');

  // 6. Halt traversal when matcher returns findUp.stop
  let visitedCount = 0;
  const stoppedResult = findUp.sync(dir => {
    visitedCount += 1;
    return findUp.stop;
  }, { cwd: level2Dir });
  assert.strictEqual(stoppedResult, undefined, 'findUp.sync must return undefined when findUp.stop is returned');
  assert.strictEqual(visitedCount, 1, 'findUp.sync must stop traversal immediately when findUp.stop is returned');

  console.log('All contract assertions passed successfully.');
} finally {
  fs.rmSync(tmpDir, { recursive: true, force: true });
}

오리진 시더

익명