CodeSampleX

Beispiel

fs-extra 8.1.0: pathExists

Verifiziertes Beispiel für npm fs-extra 8.1.0: pathExists. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:69d3ea8bf3a0bc0e0684b1293691c9fd188825c943d3045adf785757d148908b

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

Fall

HOW
Ziel
verify fs-extra.pathExists in pkg:npm/fs-extra@8.1.0
Pakete
Symbole
  • fs-extra.pathExists
Umgebung
node 22.23.2
Erstellt
2026-08-23T04:42:10Z

Contract

  1. fs-extra.pathExists asynchronously checks if a file or directory exists and returns a Promise resolving to a boolean
  2. fs-extra.pathExistsSync synchronously checks if a file or directory exists and returns a boolean
  3. fs-extra.pathExists returns false for non-existent paths without throwing an error

Dateien

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

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 fs-extra.pathExists in pkg:npm/fs-extra@8.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fs-extra@8.1.0
Demonstrate these symbols/APIs:
  - fs-extra.pathExists
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:eb68cff4d47c8b29090d5f430f863849debc7a603b6fcd19b356efbf5020c549","constraints":{"executionContext":"node"},"contract":["fs-extra.pathExists asynchronously checks if a file or directory exists and returns a Promise resolving to a boolean","fs-extra.pathExistsSync synchronously checks if a file or directory exists and returns a boolean","fs-extra.pathExists returns false for non-existent paths without throwing an error"],"goal":"verify fs-extra.pathExists in pkg:npm/fs-extra@8.1.0","kind":"HOW","packages":["pkg:npm/fs-extra@8.1.0"],"schemaVersion":1,"symbols":["fs-extra.pathExists"]},"contractCommand":["node","test/contract.cjs"],"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/fs-extra@8.1.0"],"schemaVersion":1,"subject":"pkg:npm/fs-extra@8.1.0","symbols":["fs-extra.pathExists"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const fse = require('fs-extra');

async function doesPathExist(targetPath) {
  return await fse.pathExists(targetPath);
}

function doesPathExistSync(targetPath) {
  return fse.pathExistsSync(targetPath);
}

module.exports = {
  doesPathExist,
  doesPathExistSync,
  fse
};
package-lock.json
{
  "name": "sample-fs-extra-pathexists",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fs-extra-pathexists",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "fs-extra": "8.1.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "8.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
      "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^4.0.0",
        "universalify": "^0.1.0"
      },
      "engines": {
        "node": ">=6 <7 || >=8"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/jsonfile": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
      "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==",
      "license": "MIT",
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/universalify": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
      "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
      "license": "MIT",
      "engines": {
        "node": ">= 4.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-fs-extra-pathexists",
  "version": "1.0.0",
  "private": true,
  "description": "verify fs-extra.pathExists in pkg:npm/fs-extra@8.1.0",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "fs-extra": "8.1.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fs-extra.pathExists in pkg:npm/fs-extra@8.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fs-extra@8.1.0"
  ],
  "symbols": [
    "fs-extra.pathExists"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
const fse = require('fs-extra');
const { doesPathExist, doesPathExistSync } = require('../index.js');

async function run() {
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'fse-pathexists-test-'));
  const testFile = path.join(tmpDir, 'test-file.txt');
  const testSubDir = path.join(tmpDir, 'sub-dir');
  const nonExistentFile = path.join(tmpDir, 'does-not-exist.txt');
  const nonExistentDir = path.join(tmpDir, 'non-existent-directory');

  try {
    fs.writeFileSync(testFile, 'hello fs-extra', 'utf8');
    fs.mkdirSync(testSubDir, { recursive: true });

    // 1. Asynchronous fse.pathExists
    const fileExistsAsync = await fse.pathExists(testFile);
    assert.strictEqual(fileExistsAsync, true, 'fse.pathExists must return true for existing file');

    const dirExistsAsync = await fse.pathExists(testSubDir);
    assert.strictEqual(dirExistsAsync, true, 'fse.pathExists must return true for existing directory');

    const missingFileAsync = await fse.pathExists(nonExistentFile);
    assert.strictEqual(missingFileAsync, false, 'fse.pathExists must return false for non-existent file');

    const missingDirAsync = await fse.pathExists(nonExistentDir);
    assert.strictEqual(missingDirAsync, false, 'fse.pathExists must return false for non-existent directory');

    // 2. Synchronous fse.pathExistsSync
    const fileExistsSync = fse.pathExistsSync(testFile);
    assert.strictEqual(fileExistsSync, true, 'fse.pathExistsSync must return true for existing file');

    const dirExistsSync = fse.pathExistsSync(testSubDir);
    assert.strictEqual(dirExistsSync, true, 'fse.pathExistsSync must return true for existing directory');

    const missingFileSync = fse.pathExistsSync(nonExistentFile);
    assert.strictEqual(missingFileSync, false, 'fse.pathExistsSync must return false for non-existent file');

    const missingDirSync = fse.pathExistsSync(nonExistentDir);
    assert.strictEqual(missingDirSync, false, 'fse.pathExistsSync must return false for non-existent directory');

    // 3. Helper functions from index.js
    const helperFileAsync = await doesPathExist(testFile);
    assert.strictEqual(helperFileAsync, true, 'doesPathExist must return true for existing file');

    const helperMissingAsync = await doesPathExist(nonExistentFile);
    assert.strictEqual(helperMissingAsync, false, 'doesPathExist must return false for non-existent file');

    const helperFileSync = doesPathExistSync(testFile);
    assert.strictEqual(helperFileSync, true, 'doesPathExistSync must return true for existing file');

    const helperMissingSync = doesPathExistSync(nonExistentFile);
    assert.strictEqual(helperMissingSync, false, 'doesPathExistSync must return false for non-existent file');

    // 4. Verify no exceptions thrown on non-existent paths
    assert.doesNotThrow(() => {
      fse.pathExistsSync(path.join(tmpDir, 'never-created', 'deep', 'path.txt'));
    }, 'fse.pathExistsSync must not throw for deeply non-existent path');

    console.log('Contract tests passed successfully.');
    process.exit(0);
  } finally {
    try {
      if (fs.existsSync(tmpDir)) {
        fs.rmSync(tmpDir, { recursive: true, force: true });
      }
    } catch (e) {
      // Ignore cleanup error
    }
  }
}

run().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Ursprungs-Seeder

anonym