CodeSampleX

샘플

@humanfs/node 0.16.8: hfs

검증된 샘플 — npm @humanfs/node 0.16.8: hfs. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: hfs is exported as a pre-configured instance of NodeHfs

sha256:e510217dc08baa90d5fd149524d9d0d9c90c0763496d750be88205709b1cab67

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify @humanfs/node.hfs in pkg:npm/%40humanfs/node@0.16.8
패키지
심벌
  • @humanfs/node.hfs
환경
node 22.23.2
생성일
2026-09-05T16:56:05Z

컨트랙트

  1. hfs is exported as a pre-configured instance of NodeHfs
  2. hfs provides asynchronous methods to write and read text and parsed JSON files
  3. hfs reads and writes binary data via Uint8Array and appends text to files
  4. hfs inspects file and directory existence, file size, and last modified date
  5. hfs creates nested directories and recursively walks directory entries
  6. hfs performs copy, move, and recursive delete operations on files and directories

파일

  • 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 @humanfs/node.hfs in pkg:npm/%40humanfs/node@0.16.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40humanfs/node@0.16.8
Demonstrate these symbols/APIs:
  - @humanfs/node.hfs

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:04ace24d4b6017ce3ae2468c5982e7a915a8e8e75ef62bf8e0f0870f36625201","contract":["hfs is exported as a pre-configured instance of NodeHfs","hfs provides asynchronous methods to write and read text and parsed JSON files","hfs reads and writes binary data via Uint8Array and appends text to files","hfs inspects file and directory existence, file size, and last modified date","hfs creates nested directories and recursively walks directory entries","hfs performs copy, move, and recursive delete operations on files and directories"],"goal":"verify @humanfs/node.hfs in pkg:npm/%40humanfs/node@0.16.8","kind":"HOW","packages":["pkg:npm/%40humanfs/node@0.16.8"],"schemaVersion":1,"symbols":["@humanfs/node.hfs"]},"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/%40humanfs/node@0.16.8"],"schemaVersion":1,"subject":"pkg:npm/%40humanfs/node@0.16.8","symbols":["@humanfs/node.hfs"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-humanfs-node-hfs",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-humanfs-node-hfs",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@humanfs/node": "0.16.8"
      }
    },
    "node_modules/@humanfs/core": {
      "version": "0.19.2",
      "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz",
      "integrity": "sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==",
      "license": "Apache-2.0",
      "dependencies": {
        "@humanfs/types": "^0.15.0"
      },
      "engines": {
        "node": ">=18.18.0"
      }
    },
    "node_modules/@humanfs/node": {
      "version": "0.16.8",
      "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.8.tgz",
      "integrity": "sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ==",
      "license": "Apache-2.0",
      "dependencies": {
        "@humanfs/core": "^0.19.2",
        "@humanfs/types": "^0.15.0",
        "@humanwhocodes/retry": "^0.4.0"
      },
      "engines": {
        "node": ">=18.18.0"
      }
    },
    "node_modules/@humanfs/types": {
      "version": "0.15.0",
      "resolved": "https://registry.npmjs.org/@humanfs/types/-/types-0.15.0.tgz",
      "integrity": "sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q==",
      "license": "Apache-2.0",
      "engines": {
        "node": ">=18.18.0"
      }
    },
    "node_modules/@humanwhocodes/retry": {
      "version": "0.4.3",
      "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz",
      "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==",
      "license": "Apache-2.0",
      "engines": {
        "node": ">=18.18"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/nzakas"
      }
    }
  }
}
package.json
{
  "name": "sample-humanfs-node-hfs",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @humanfs/node.hfs",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@humanfs/node": "0.16.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @humanfs/node.hfs in pkg:npm/%40humanfs/node@0.16.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40humanfs/node@0.16.8"
  ],
  "symbols": [
    "@humanfs/node.hfs"
  ]
}
src/index.js
/**
 * Clean-room wrapper for @humanfs/node.hfs operations.
 */

/**
 * Dynamically loads the @humanfs/node module.
 * @returns {Promise<typeof import('@humanfs/node')>}
 */
async function loadHumanfsNode() {
  return await import('@humanfs/node');
}

/**
 * Retrieves the pre-configured hfs instance from @humanfs/node.
 * @returns {Promise<import('@humanfs/node').NodeHfs>}
 */
async function getHfsInstance() {
  const { hfs } = await import('@humanfs/node');
  return hfs;
}

module.exports = {
  loadHumanfsNode,
  getHfsInstance
};
test/contract.mjs
import assert from 'node:assert/strict';
import path from 'node:path';
import fsp from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import { hfs, NodeHfs } from '@humanfs/node';

const require = createRequire(import.meta.url);
const { loadHumanfsNode, getHfsInstance } = require('../src/index.js');

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const testDir = path.join(__dirname, 'temp_contract_workspace');

async function cleanup() {
  try {
    await fsp.rm(testDir, { recursive: true, force: true });
  } catch {}
}

await cleanup();
await fsp.mkdir(testDir, { recursive: true });

try {
  // 1. hfs is exported as a pre-configured instance of NodeHfs
  {
    assert.ok(hfs, 'hfs must be exported');
    assert.ok(hfs instanceof NodeHfs, 'hfs must be an instance of NodeHfs');
    assert.equal(typeof loadHumanfsNode, 'function', 'loadHumanfsNode helper must be a function');
    assert.equal(typeof getHfsInstance, 'function', 'getHfsInstance helper must be a function');

    const mod = await loadHumanfsNode();
    assert.equal(mod.hfs, hfs, 'loadHumanfsNode must export the singleton hfs instance');

    const instance = await getHfsInstance();
    assert.equal(instance, hfs, 'getHfsInstance must return the singleton hfs instance');
  }

  // 2. hfs provides asynchronous methods to write and read text and parsed JSON files
  {
    const textFile = path.join(testDir, 'contract_sample.txt');
    await hfs.write(textFile, 'Humanfs Node Hfs Contract Text');
    const content = await hfs.text(textFile);
    assert.equal(content, 'Humanfs Node Hfs Contract Text', 'text() must return written string content');

    const jsonFile = path.join(testDir, 'contract_config.json');
    const payload = { service: 'storage', symbol: 'hfs', active: true, count: 42 };
    await hfs.write(jsonFile, JSON.stringify(payload));
    const parsed = await hfs.json(jsonFile);
    assert.deepEqual(parsed, payload, 'json() must parse and return stored JSON object');
  }

  // 3. hfs reads and writes binary data via Uint8Array and appends text to files
  {
    const binFile = path.join(testDir, 'contract_binary.dat');
    const binaryData = new Uint8Array([0x48, 0x46, 0x53, 0x5f, 0x42, 0x49, 0x4e]);
    await hfs.write(binFile, binaryData);
    const readBytes = await hfs.bytes(binFile);
    assert.deepEqual(readBytes, binaryData, 'bytes() must return exact written byte array');

    const appendFile = path.join(testDir, 'contract_append.txt');
    await hfs.write(appendFile, 'Part1');
    await hfs.append(appendFile, '-Part2');
    const fullText = await hfs.text(appendFile);
    assert.equal(fullText, 'Part1-Part2', 'append() must append text to the file');
  }

  // 4. hfs inspects file and directory existence, file size, and last modified date
  {
    const sampleFile = path.join(testDir, 'contract_sample.txt');
    assert.equal(await hfs.isFile(sampleFile), true, 'isFile() must return true for regular file');
    assert.equal(await hfs.isDirectory(sampleFile), false, 'isDirectory() must return false for regular file');
    assert.equal(await hfs.isDirectory(testDir), true, 'isDirectory() must return true for directory');
    assert.equal(await hfs.isFile(testDir), false, 'isFile() must return false for directory');

    const missingFile = path.join(testDir, 'does_not_exist.txt');
    assert.equal(await hfs.isFile(missingFile), false, 'isFile() must return false for missing file');
    assert.equal(await hfs.isDirectory(missingFile), false, 'isDirectory() must return false for missing directory');

    const fileSize = await hfs.size(sampleFile);
    assert.equal(fileSize, Buffer.byteLength('Humanfs Node Hfs Contract Text'), 'size() must return correct file byte count');

    const mtime = await hfs.lastModified(sampleFile);
    assert.ok(mtime instanceof Date, 'lastModified() must return a Date instance');
  }

  // 5. hfs creates nested directories and recursively walks directory entries
  {
    const subFolder = path.join(testDir, 'level1', 'level2');
    await hfs.createDirectory(subFolder);
    assert.equal(await hfs.isDirectory(subFolder), true, 'createDirectory() must create nested folders');

    const nestedFile = path.join(subFolder, 'nested.txt');
    await hfs.write(nestedFile, 'nested file content');

    const walkedNames = [];
    for await (const entry of hfs.walk(testDir)) {
      walkedNames.push(entry.name);
    }
    assert.ok(walkedNames.includes('nested.txt'), 'walk() must discover deeply nested files');
    assert.ok(walkedNames.includes('level1'), 'walk() must discover intermediate directories');
  }

  // 6. hfs performs copy, move, and recursive delete operations on files and directories
  {
    const origFile = path.join(testDir, 'to_copy.txt');
    const destFile = path.join(testDir, 'copied.txt');
    const movedFile = path.join(testDir, 'moved.txt');

    await hfs.write(origFile, 'Data to move and copy');
    await hfs.copy(origFile, destFile);
    assert.equal(await hfs.isFile(destFile), true, 'copy() must create destination copy');

    await hfs.move(destFile, movedFile);
    assert.equal(await hfs.isFile(destFile), false, 'move() must remove old file');
    assert.equal(await hfs.isFile(movedFile), true, 'move() must create file at destination');

    const deleted = await hfs.delete(movedFile);
    assert.equal(deleted, true, 'delete() must return true when removing a file');
    assert.equal(await hfs.isFile(movedFile), false, 'deleted file must no longer exist');

    const treeDir = path.join(testDir, 'level1');
    const deletedAll = await hfs.deleteAll(treeDir);
    assert.equal(deletedAll, true, 'deleteAll() must return true when deleting directory tree');
    assert.equal(await hfs.isDirectory(treeDir), false, 'deleteAll() must remove full folder structure');
  }

  console.log('hfs contract assertions passed.');
} finally {
  await cleanup();
}

오리진 시더

익명