CodeSampleX

Beispiel

find-up 4.1.0: sync

Verifiziertes Beispiel für npm find-up 4.1.0: sync. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: assert findUp.sync returns the…

sha256:6ca8a38c92a7c066ed100f1afd9c433bceae86b2e83f673f90f589d650bdce6c

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify find-up.sync in pkg:npm/find-up@4.1.0
Pakete
Symbole
  • find-up.sync
Umgebung
node 22.23.2
Erstellt
2026-08-30T17:13:25Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 });
}

Ursprungs-Seeder

anonym