CodeSampleX

샘플

fs-extra 10.1.0

검증된 샘플 — npm fs-extra 10.1.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: ensureDir creates nested directory structures if they do not exist

sha256:f0c98bf169e06d3abfccee3c5a4d926603803d4b965d36c348bb41bdc8d75602

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

케이스

HOW
목표
verify pkg:npm/fs-extra@10.1.0
패키지
환경
node 22.23.2
생성일
2026-08-20T20:13:16Z

컨트랙트

  1. ensureDir creates nested directory structures if they do not exist
  2. outputJson and readJson write and read JSON documents while automatically creating parent directories
  3. outputFile writes string data creating parent directories automatically and readFile retrieves the written content
  4. copy recursively copies directory hierarchies and supports custom filter functions
  5. emptyDir deletes all contents within a directory while leaving the directory itself intact
  6. pathExists accurately checks the existence of files and directories
  7. remove recursively removes directories and files without throwing if the target does not exist
  8. move moves files and directories across paths with optional overwrite

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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/fs-extra@10.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fs-extra@10.1.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:78e43567fa76fb3b50a4a390cb358812983664af183d35af4298771fa7a20b36","constraints":{"executionContext":"node"},"contract":["ensureDir creates nested directory structures if they do not exist","outputJson and readJson write and read JSON documents while automatically creating parent directories","outputFile writes string data creating parent directories automatically and readFile retrieves the written content","copy recursively copies directory hierarchies and supports custom filter functions","emptyDir deletes all contents within a directory while leaving the directory itself intact","pathExists accurately checks the existence of files and directories","remove recursively removes directories and files without throwing if the target does not exist","move moves files and directories across paths with optional overwrite"],"goal":"verify pkg:npm/fs-extra@10.1.0","kind":"HOW","packages":["pkg:npm/fs-extra@10.1.0"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/fs-extra@10.1.0"],"schemaVersion":1,"subject":"pkg:npm/fs-extra@10.1.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-fs-extra",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fs-extra",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "fs-extra": "10.1.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "10.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
      "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },
    "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": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-fs-extra",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of fs-extra",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "fs-extra": "10.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/fs-extra@10.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fs-extra@10.1.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const fs = require('fs-extra');

/**
 * Creates directory and writes JSON file inside nested directory structure.
 */
async function writeConfig(filePath, data) {
  await fs.outputJson(filePath, data, { spaces: 2 });
}

/**
 * Reads JSON file using fs-extra readJson.
 */
async function readConfig(filePath) {
  return await fs.readJson(filePath);
}

/**
 * Ensures directory exists, creating all intermediate directories.
 */
async function createDirectoryStructure(dirPath) {
  await fs.ensureDir(dirPath);
}

/**
 * Writes text file, automatically creating parent directories.
 */
async function writeTextFile(filePath, content) {
  await fs.outputFile(filePath, content, 'utf8');
}

/**
 * Copies a source directory or file to a destination path.
 */
async function copyPath(src, dest, options = {}) {
  await fs.copy(src, dest, options);
}

/**
 * Empties a directory without deleting the directory itself.
 */
async function emptyDirectory(dirPath) {
  await fs.emptyDir(dirPath);
}

/**
 * Checks if path exists.
 */
async function checkExists(targetPath) {
  return await fs.pathExists(targetPath);
}

/**
 * Moves file or directory from source to destination.
 */
async function movePath(src, dest, options = {}) {
  await fs.move(src, dest, options);
}

/**
 * Removes file or directory recursively.
 */
async function removePath(targetPath) {
  await fs.remove(targetPath);
}

module.exports = {
  fs,
  writeConfig,
  readConfig,
  createDirectoryStructure,
  writeTextFile,
  copyPath,
  emptyDirectory,
  checkExists,
  movePath,
  removePath
};
test/contract.mjs
import assert from 'node:assert';
import path from 'node:path';
import os from 'node:os';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  fs,
  writeConfig,
  readConfig,
  createDirectoryStructure,
  writeTextFile,
  copyPath,
  emptyDirectory,
  checkExists,
  movePath,
  removePath
} = require('../src/index.js');

async function runContract() {
  const tmpBase = path.join(os.tmpdir(), `csx-contract-fs-extra-${Date.now()}-${Math.random().toString(36).slice(2)}`);
  await fs.ensureDir(tmpBase);

  try {
    // 1. ensureDir creates nested directory structures if they do not exist
    const nestedDir = path.join(tmpBase, 'a', 'b', 'c', 'nested');
    assert.strictEqual(await checkExists(nestedDir), false, 'Nested dir should not exist initially');
    await createDirectoryStructure(nestedDir);
    assert.strictEqual(await checkExists(nestedDir), true, 'Nested dir should exist after ensureDir');

    // 2. outputJson and readJson write and read JSON documents while automatically creating parent directories
    const jsonPath = path.join(tmpBase, 'configs', 'app', 'settings.json');
    const testData = { name: 'sample-app', port: 8080, features: ['logging', 'metrics'], active: true };
    await writeConfig(jsonPath, testData);
    assert.strictEqual(await checkExists(jsonPath), true, 'JSON file should exist');
    const readData = await readConfig(jsonPath);
    assert.deepStrictEqual(readData, testData, 'readJson must match written json data');

    // 3. outputFile writes string data creating parent directories automatically and readFile retrieves the written content
    const textPath = path.join(tmpBase, 'docs', 'readme.txt');
    const textContent = 'Hello from clean-room contract verification!';
    await writeTextFile(textPath, textContent);
    assert.strictEqual(await checkExists(textPath), true, 'Text file should exist');
    const readText = await fs.readFile(textPath, 'utf8');
    assert.strictEqual(readText, textContent, 'readFile must return the written string');

    // 4. copy recursively copies directory hierarchies and supports custom filter functions
    const srcDir = path.join(tmpBase, 'source-tree');
    const destDir = path.join(tmpBase, 'dest-tree');
    await fs.outputFile(path.join(srcDir, 'file1.txt'), 'content-1');
    await fs.outputFile(path.join(srcDir, 'ignored.tmp'), 'ignore-me');
    await fs.outputFile(path.join(srcDir, 'sub', 'file2.txt'), 'content-2');

    await copyPath(srcDir, destDir, {
      filter: (src) => !src.endsWith('.tmp')
    });
    assert.strictEqual(await checkExists(path.join(destDir, 'file1.txt')), true, 'Copied file1 must exist');
    assert.strictEqual(await checkExists(path.join(destDir, 'sub', 'file2.txt')), true, 'Copied file2 must exist');
    assert.strictEqual(await checkExists(path.join(destDir, 'ignored.tmp')), false, 'Filtered file must not be copied');

    // 5. emptyDir deletes all contents within a directory while leaving the directory itself intact
    const dirToEmpty = path.join(tmpBase, 'to-empty');
    await fs.outputFile(path.join(dirToEmpty, 'nested', 'data.bin'), 'data');
    assert.strictEqual(await checkExists(path.join(dirToEmpty, 'nested', 'data.bin')), true);
    await emptyDirectory(dirToEmpty);
    assert.strictEqual(await checkExists(dirToEmpty), true, 'Directory itself must still exist after emptyDir');
    const dirEntries = await fs.readdir(dirToEmpty);
    assert.strictEqual(dirEntries.length, 0, 'Directory should have 0 entries after emptyDir');

    // 6. pathExists accurately checks the existence of files and directories
    assert.strictEqual(await checkExists(dirToEmpty), true, 'pathExists must return true for existing dir');
    assert.strictEqual(await checkExists(path.join(tmpBase, 'non-existent-path')), false, 'pathExists must return false for missing path');

    // 7. remove recursively removes directories and files without throwing if the target does not exist
    await removePath(destDir);
    assert.strictEqual(await checkExists(destDir), false, 'Directory must be removed');
    await removePath(path.join(tmpBase, 'non-existent-file-12345.xyz')); // should not throw

    // 8. move moves files and directories across paths with optional overwrite
    const moveSrc = path.join(tmpBase, 'move-source.txt');
    const moveDest = path.join(tmpBase, 'moved', 'target.txt');
    await fs.outputFile(moveSrc, 'to-be-moved');
    await movePath(moveSrc, moveDest);
    assert.strictEqual(await checkExists(moveSrc), false, 'Source must no longer exist after move');
    assert.strictEqual(await checkExists(moveDest), true, 'Destination must exist after move');
    assert.strictEqual(await fs.readFile(moveDest, 'utf8'), 'to-be-moved', 'Moved content must match');

    console.log('Contract tests passed successfully.');
  } finally {
    await fs.remove(tmpBase);
  }
}

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

오리진 시더

익명