CodeSampleX

Exemple

@humanfs/node 0.16.8: NodeHfsImpl

Échantillon vérifié pour npm @humanfs/node 0.16.8: NodeHfsImpl. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:3c9e8e5ee6b0ee182eb5998341a0af3894bdc8121780a74da3b364ab85fec266

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify @humanfs/node.NodeHfsImpl in pkg:npm/%40humanfs/node@0.16.8
Paquets
Symboles
  • @humanfs/node.NodeHfsImpl
Environnement
node 22.23.2
Créé
2026-09-05T15:33:34Z

Contrat

  1. NodeHfsImpl instances can be constructed with default or custom file system options
  2. NodeHfsImpl writes and reads binary data via Uint8Array and appends bytes to files
  3. NodeHfsImpl inspects file and directory existence, file size, and last modified date
  4. NodeHfsImpl creates directories and lists directory entries with entry metadata
  5. NodeHfsImpl copies and moves individual files as well as directory hierarchies
  6. NodeHfsImpl deletes individual files and recursively removes directory trees

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.NodeHfsImpl 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.NodeHfsImpl

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:419b13b8973e4e4be9409b53b300c9b87af41d3753f5a1432ccadfd6bfaa16bf","contract":["NodeHfsImpl instances can be constructed with default or custom file system options","NodeHfsImpl writes and reads binary data via Uint8Array and appends bytes to files","NodeHfsImpl inspects file and directory existence, file size, and last modified date","NodeHfsImpl creates directories and lists directory entries with entry metadata","NodeHfsImpl copies and moves individual files as well as directory hierarchies","NodeHfsImpl deletes individual files and recursively removes directory trees"],"goal":"verify @humanfs/node.NodeHfsImpl in pkg:npm/%40humanfs/node@0.16.8","kind":"HOW","packages":["pkg:npm/%40humanfs/node@0.16.8"],"schemaVersion":1,"symbols":["@humanfs/node.NodeHfsImpl"]},"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.NodeHfsImpl"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-humanfs-node-impl",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-humanfs-node-impl",
      "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-impl",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @humanfs/node.NodeHfsImpl",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@humanfs/node": "0.16.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @humanfs/node.NodeHfsImpl in pkg:npm/%40humanfs/node@0.16.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40humanfs/node@0.16.8"
  ],
  "symbols": [
    "@humanfs/node.NodeHfsImpl"
  ]
}
src/index.js
/**
 * Clean-room wrapper for @humanfs/node.NodeHfsImpl operations.
 */

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

/**
 * Creates a new NodeHfsImpl instance.
 * @param {object} [options]
 * @returns {Promise<import('@humanfs/node').NodeHfsImpl>}
 */
async function createNodeHfsImpl(options) {
  const { NodeHfsImpl } = await import('@humanfs/node');
  return new NodeHfsImpl(options);
}

module.exports = {
  loadHumanfsNode,
  createNodeHfsImpl
};
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 { NodeHfsImpl } from '@humanfs/node';

const require = createRequire(import.meta.url);
const { loadHumanfsNode, createNodeHfsImpl } = 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. NodeHfsImpl instances can be constructed with default or custom file system options
  {
    assert.equal(typeof NodeHfsImpl, 'function', 'NodeHfsImpl must be a class constructor');
    assert.equal(typeof createNodeHfsImpl, 'function', 'createNodeHfsImpl helper must be a function');
    assert.equal(typeof loadHumanfsNode, 'function', 'loadHumanfsNode helper must be a function');

    const mod = await loadHumanfsNode();
    assert.equal(mod.NodeHfsImpl, NodeHfsImpl, 'loadHumanfsNode must export NodeHfsImpl');

    const defaultImpl = new NodeHfsImpl();
    assert.ok(defaultImpl instanceof NodeHfsImpl, 'default constructor must create a NodeHfsImpl instance');

    const customImpl = await createNodeHfsImpl({ fsp });
    assert.ok(customImpl instanceof NodeHfsImpl, 'createNodeHfsImpl with options must create a NodeHfsImpl instance');
  }

  // 2. NodeHfsImpl writes and reads binary data via Uint8Array and appends bytes to files
  {
    const impl = new NodeHfsImpl();
    const binFile = path.join(testDir, 'contract_sample.bin');
    const initialBytes = new Uint8Array([0x4e, 0x6f, 0x64, 0x65, 0x48, 0x66, 0x73]);
    await impl.write(binFile, initialBytes);

    const readBytes = await impl.bytes(binFile);
    assert.deepEqual(readBytes, initialBytes, 'bytes() must return exact written byte array');

    const appendBytes = new Uint8Array([0x49, 0x6d, 0x70, 0x6c]);
    await impl.append(binFile, appendBytes);

    const fullBytes = await impl.bytes(binFile);
    const expected = new Uint8Array([0x4e, 0x6f, 0x64, 0x65, 0x48, 0x66, 0x73, 0x49, 0x6d, 0x70, 0x6c]);
    assert.deepEqual(fullBytes, expected, 'append() must append bytes to file');
  }

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

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

    const fileSize = await impl.size(sampleFile);
    assert.equal(fileSize, 11, 'size() must return correct file byte count');

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

  // 4. NodeHfsImpl creates directories and lists directory entries with entry metadata
  {
    const impl = new NodeHfsImpl();
    const subFolder = path.join(testDir, 'entries_dir');
    await impl.createDirectory(subFolder);
    assert.equal(await impl.isDirectory(subFolder), true, 'createDirectory() must create folder');

    const fileA = path.join(subFolder, 'file_a.txt');
    const fileB = path.join(subFolder, 'file_b.txt');
    await impl.write(fileA, new Uint8Array([1]));
    await impl.write(fileB, new Uint8Array([2]));

    const entries = [];
    for await (const entry of impl.list(subFolder)) {
      entries.push(entry);
    }
    assert.equal(entries.length, 2, 'list() must yield all directory entries');
    const entryNames = entries.map(e => e.name).sort();
    assert.deepEqual(entryNames, ['file_a.txt', 'file_b.txt'], 'list() must include correct entry names');
    for (const entry of entries) {
      assert.equal(entry.isFile, true, 'entry.isFile must be true');
      assert.equal(entry.isDirectory, false, 'entry.isDirectory must be false');
    }
  }

  // 5. NodeHfsImpl copies and moves individual files as well as directory hierarchies
  {
    const impl = new NodeHfsImpl();
    const origFile = path.join(testDir, 'single_orig.txt');
    const copyFile = path.join(testDir, 'single_copy.txt');
    const moveFile = path.join(testDir, 'single_move.txt');

    await impl.write(origFile, new Uint8Array([10, 20, 30]));
    await impl.copy(origFile, copyFile);
    assert.equal(await impl.isFile(copyFile), true, 'copy() must create copy');

    await impl.move(copyFile, moveFile);
    assert.equal(await impl.isFile(copyFile), false, 'move() must remove source file');
    assert.equal(await impl.isFile(moveFile), true, 'move() must create destination file');

    const treeSrc = path.join(testDir, 'tree_src');
    const treeDstCopy = path.join(testDir, 'tree_dst_copy');
    const treeDstMove = path.join(testDir, 'tree_dst_move');

    await impl.createDirectory(path.join(treeSrc, 'nested'));
    await impl.write(path.join(treeSrc, 'nested', 'data.txt'), new Uint8Array([99]));

    await impl.copyAll(treeSrc, treeDstCopy);
    assert.equal(await impl.isFile(path.join(treeDstCopy, 'nested', 'data.txt')), true, 'copyAll() must copy hierarchy');

    await impl.moveAll(treeDstCopy, treeDstMove);
    assert.equal(await impl.isFile(path.join(treeDstCopy, 'nested', 'data.txt')), false, 'moveAll() must remove source hierarchy');
    assert.equal(await impl.isFile(path.join(treeDstMove, 'nested', 'data.txt')), true, 'moveAll() must move hierarchy to destination');
  }

  // 6. NodeHfsImpl deletes individual files and recursively removes directory trees
  {
    const impl = new NodeHfsImpl();
    const tempFile = path.join(testDir, 'to_remove.txt');
    await impl.write(tempFile, new Uint8Array([1, 2, 3]));
    assert.equal(await impl.isFile(tempFile), true);

    const deletedFile = await impl.delete(tempFile);
    assert.equal(deletedFile, true, 'delete() must return true');
    assert.equal(await impl.isFile(tempFile), false, 'deleted file must no longer exist');

    const tempFolder = path.join(testDir, 'tree_dst_move');
    assert.equal(await impl.isDirectory(tempFolder), true);

    const deletedTree = await impl.deleteAll(tempFolder);
    assert.equal(deletedTree, true, 'deleteAll() must return true');
    assert.equal(await impl.isDirectory(tempFolder), false, 'deleted directory tree must no longer exist');
  }

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

Seeder d'origine

anonyme