CodeSampleX

Sample

fs_extra 1.3.0: fs_extra

Verified sample for cargo fs_extra 1.3.0: fs_extra. The contract ran on rust 1 · linux alpine/x64 · docker and passed: fs_extra::file::write_all…

sha256:bb1ac6bc6cedb47d1d2eeb1b39d742c2310c716043d1675eb4b59e45569621d1

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux x64 cargo

Verification-run environments

Environment Contract Stages Run
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-22

Case

HOW
Goal
verify fs_extra in pkg:cargo/fs_extra@1.3.0
Packages
Symbols
  • fs_extra
Created
2026-11-22T15:42:56Z

Contract

  1. fs_extra::file::write_all, read_to_string, and copy write, read, and copy files, returning ErrorKind::AlreadyExists when overwrite is false and ErrorKind::NotFound for missing files
  2. fs_extra::dir::create_all, get_dir_content, get_size, and copy traverse and recursively copy directories with default and content_only CopyOptions (dir::get_size returns exact file byte sum while get_dir_content.dir_size includes directory metadata sizes; dir::copy returns exact copied file bytes and ErrorKind::AlreadyExists on duplicate destination without overwrite)
  3. fs_extra::copy_items, move_items, and remove_items copy, move, and delete batches of files and directories while returning exact transferred byte counts

Files

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • tests/contract.rs

Download the source artifact (tar.gz)

Source

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"

[[package]]
name = "sample-fs-extra"
version = "0.1.0"
dependencies = [
 "fs_extra",
]
Cargo.toml
[package]
name = "sample-fs-extra"
version = "0.1.0"
edition = "2021"

[dependencies]
fs_extra = "=1.3.0"
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 in pkg:cargo/fs_extra@1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/fs_extra@1.3.0
Demonstrate these symbols/APIs:
  - fs_extra

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:58e0b993c061451b84e71cbf0d56af2962e69bea13a2befc1f84edd1d8595583","contract":["fs_extra::file::write_all, read_to_string, and copy write, read, and copy files, returning ErrorKind::AlreadyExists when overwrite is false and ErrorKind::NotFound for missing files","fs_extra::dir::create_all, get_dir_content, get_size, and copy traverse and recursively copy directories with default and content_only CopyOptions (dir::get_size returns exact file byte sum while get_dir_content.dir_size includes directory metadata sizes; dir::copy returns exact copied file bytes and ErrorKind::AlreadyExists on duplicate destination without overwrite)","fs_extra::copy_items, move_items, and remove_items copy, move, and delete batches of files and directories while returning exact transferred byte counts"],"goal":"verify fs_extra in pkg:cargo/fs_extra@1.3.0","kind":"HOW","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"symbols":["fs_extra"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"subject":"pkg:cargo/fs_extra@1.3.0","symbols":["fs_extra"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fs_extra in pkg:cargo/fs_extra@1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/fs_extra@1.3.0"
  ],
  "symbols": [
    "fs_extra"
  ]
}
src/main.rs
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};

use fs_extra::dir;
use fs_extra::error::ErrorKind;
use fs_extra::file;

static COUNTER: AtomicU64 = AtomicU64::new(0);

struct TempDirGuard(PathBuf);

impl TempDirGuard {
    fn new(prefix: &str) -> Self {
        let id = COUNTER.fetch_add(1, Ordering::Relaxed);
        let path = std::env::temp_dir().join(format!(
            "csx-{}-{}-{}",
            prefix,
            std::process::id(),
            id
        ));
        dir::create_all(&path, true).expect("create temp workspace");
        Self(path)
    }

    fn path(&self) -> &Path {
        &self.0
    }
}

impl Drop for TempDirGuard {
    fn drop(&mut self) {
        let _ = dir::remove(&self.0);
    }
}

fn verify_fs_extra_contract() {
    let root = TempDirGuard::new("fs-extra-main");
    let src_dir = root.path().join("src_tree");
    let nested_dir = src_dir.join("nested");
    dir::create_all(&nested_dir, false).expect("create nested dirs");

    let alpha_path = src_dir.join("alpha.txt");
    let beta_path = nested_dir.join("beta.txt");
    file::write_all(&alpha_path, "hello fs_extra").expect("write alpha");
    file::write_all(&beta_path, "nested payload").expect("write beta");

    assert_eq!(
        file::read_to_string(&alpha_path).expect("read alpha"),
        "hello fs_extra"
    );

    let dir_content = dir::get_dir_content(&src_dir).expect("get_dir_content");
    assert_eq!(dir_content.files.len(), 2);
    assert_eq!(dir_content.directories.len(), 2);
    let expected_file_bytes = ("hello fs_extra".len() + "nested payload".len()) as u64;
    let total_size = dir::get_size(&src_dir).expect("get_size");
    assert_eq!(total_size, expected_file_bytes);
    assert!(dir_content.dir_size >= expected_file_bytes);

    let dest_parent = root.path().join("dest_parent");
    dir::create_all(&dest_parent, false).expect("create dest_parent");
    let mut dir_opts = dir::CopyOptions::new();
    let copied = dir::copy(&src_dir, &dest_parent, &dir_opts).expect("dir::copy");
    assert_eq!(copied, expected_file_bytes);
    assert_eq!(
        file::read_to_string(dest_parent.join("src_tree").join("nested").join("beta.txt"))
            .expect("read copied beta"),
        "nested payload"
    );

    let duplicate_err = dir::copy(&src_dir, &dest_parent, &dir_opts)
        .expect_err("dir::copy without overwrite should fail on existing target");
    assert!(matches!(duplicate_err.kind, ErrorKind::AlreadyExists));

    dir_opts.content_only = true;
    dir_opts.overwrite = true;
    let flat_dest = root.path().join("flat_dest");
    dir::create_all(&flat_dest, false).expect("create flat_dest");
    dir::copy(&src_dir, &flat_dest, &dir_opts).expect("content_only dir::copy");
    assert!(flat_dest.join("alpha.txt").exists());
    assert!(flat_dest.join("nested").join("beta.txt").exists());

    let default_dir_opts = dir::CopyOptions::new();
    let items_dest = root.path().join("items_dest");
    dir::create_all(&items_dest, false).expect("create items_dest");
    let copied_items =
        fs_extra::copy_items(&[&alpha_path, &nested_dir], &items_dest, &default_dir_opts)
            .expect("copy_items");
    assert_eq!(copied_items, expected_file_bytes);
    assert!(items_dest.join("alpha.txt").exists());
    assert!(items_dest.join("nested").join("beta.txt").exists());

    let moved_dest = root.path().join("moved_dest");
    dir::create_all(&moved_dest, false).expect("create moved_dest");
    let moved_alpha = items_dest.join("alpha.txt");
    let moved_bytes = fs_extra::move_items(&[&moved_alpha], &moved_dest, &default_dir_opts)
        .expect("move_items");
    assert_eq!(moved_bytes, "hello fs_extra".len() as u64);
    assert!(!moved_alpha.exists());
    assert_eq!(
        file::read_to_string(moved_dest.join("alpha.txt")).expect("read moved alpha"),
        "hello fs_extra"
    );

    let mut file_opts = file::CopyOptions::new();
    let file_copy_target = root.path().join("copied_single.txt");
    file::copy(&alpha_path, &file_copy_target, &file_opts).expect("file::copy");
    let file_dup_err = file::copy(&alpha_path, &file_copy_target, &file_opts)
        .expect_err("file::copy without overwrite should fail");
    assert!(matches!(file_dup_err.kind, ErrorKind::AlreadyExists));
    file_opts.overwrite = true;
    file::copy(&alpha_path, &file_copy_target, &file_opts).expect("file::copy with overwrite");
    assert_eq!(
        file::read_to_string(&file_copy_target).expect("read single copy"),
        "hello fs_extra"
    );

    fs_extra::remove_items(&[&file_copy_target, &moved_dest]).expect("remove_items");
    assert!(!file_copy_target.exists());
    assert!(!moved_dest.exists());

    let missing_err = file::read_to_string(root.path().join("does_not_exist.txt"))
        .expect_err("reading missing file should fail");
    assert!(matches!(missing_err.kind, ErrorKind::NotFound));
}

fn main() {
    verify_fs_extra_contract();
    println!("CONTRACT_OK");
}
tests/contract.rs
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};

use fs_extra::dir;
use fs_extra::error::ErrorKind;
use fs_extra::file;

static TEST_COUNTER: AtomicU64 = AtomicU64::new(0);

struct TempDirGuard(PathBuf);

impl TempDirGuard {
    fn new(label: &str) -> Self {
        let id = TEST_COUNTER.fetch_add(1, Ordering::Relaxed);
        let path = std::env::temp_dir().join(format!(
            "csx-test-{}-{}-{}",
            label,
            std::process::id(),
            id
        ));
        dir::create_all(&path, true).expect("create temp dir");
        Self(path)
    }

    fn path(&self) -> &Path {
        &self.0
    }
}

impl Drop for TempDirGuard {
    fn drop(&mut self) {
        let _ = dir::remove(&self.0);
    }
}

#[test]
fn file_write_read_copy_and_not_found_error() {
    let root = TempDirGuard::new("file-ops");
    let src = root.path().join("source.txt");
    let dst = root.path().join("copied.txt");

    file::write_all(&src, "alpha-content").expect("write source");
    assert_eq!(
        file::read_to_string(&src).expect("read source"),
        "alpha-content"
    );

    let mut opts = file::CopyOptions::new();
    let bytes = file::copy(&src, &dst, &opts).expect("copy file");
    assert_eq!(bytes, "alpha-content".len() as u64);
    assert_eq!(
        file::read_to_string(&dst).expect("read copied"),
        "alpha-content"
    );

    let err = file::copy(&src, &dst, &opts).expect_err("second copy without overwrite fails");
    assert!(matches!(err.kind, ErrorKind::AlreadyExists));

    opts.overwrite = true;
    file::write_all(&src, "updated-content").expect("rewrite source");
    file::copy(&src, &dst, &opts).expect("copy with overwrite succeeds");
    assert_eq!(
        file::read_to_string(&dst).expect("read overwritten"),
        "updated-content"
    );

    let missing = file::read_to_string(root.path().join("missing.txt"))
        .expect_err("missing file returns NotFound");
    assert!(matches!(missing.kind, ErrorKind::NotFound));
}

#[test]
fn dir_copy_content_and_size_contract() {
    let root = TempDirGuard::new("dir-ops");
    let src = root.path().join("tree");
    let sub = src.join("sub");
    dir::create_all(&sub, false).expect("create tree");

    file::write_all(src.join("a.txt"), "12345").expect("write a");
    file::write_all(sub.join("b.txt"), "67890").expect("write b");

    let content = dir::get_dir_content(&src).expect("get_dir_content");
    assert_eq!(content.files.len(), 2);
    assert_eq!(content.directories.len(), 2);
    let dir_size = dir::get_size(&src).expect("get_size");
    assert_eq!(dir_size, 10);
    assert!(content.dir_size >= dir_size);
    assert_eq!(
        dir::get_size(src.join("a.txt")).expect("get_size on single file"),
        5
    );

    let out = root.path().join("out");
    dir::create_all(&out, false).expect("create out");
    let mut opts = dir::CopyOptions::new();
    let copied = dir::copy(&src, &out, &opts).expect("dir::copy");
    assert_eq!(copied, 10);
    assert_eq!(
        file::read_to_string(out.join("tree").join("sub").join("b.txt")).expect("read copied b"),
        "67890"
    );

    let dup_err = dir::copy(&src, &out, &opts).expect_err("duplicate dir::copy fails");
    assert!(matches!(dup_err.kind, ErrorKind::AlreadyExists));

    opts.content_only = true;
    opts.overwrite = true;
    let flat_out = root.path().join("flat_out");
    dir::create_all(&flat_out, false).expect("create flat_out");
    dir::copy(&src, &flat_out, &opts).expect("content_only dir::copy");
    assert!(flat_out.join("a.txt").exists());
    assert!(flat_out.join("sub").join("b.txt").exists());
}

#[test]
fn top_level_copy_move_and_remove_items_contract() {
    let root = TempDirGuard::new("items-ops");
    let item_file = root.path().join("doc.txt");
    let item_dir = root.path().join("bundle");
    dir::create_all(&item_dir, false).expect("create bundle");
    file::write_all(&item_file, "doc-data").expect("write doc");
    file::write_all(item_dir.join("inner.txt"), "inner").expect("write inner");

    let stage = root.path().join("stage");
    let moved = root.path().join("moved");
    dir::create_all(&stage, false).expect("create stage");
    dir::create_all(&moved, false).expect("create moved");

    let opts = dir::CopyOptions::new();
    let copied = fs_extra::copy_items(&[&item_file, &item_dir], &stage, &opts)
        .expect("copy_items");
    assert_eq!(copied, ("doc-data".len() + "inner".len()) as u64);
    assert!(stage.join("doc.txt").exists());
    assert!(stage.join("bundle").join("inner.txt").exists());

    let staged_doc = stage.join("doc.txt");
    let moved_bytes = fs_extra::move_items(&[&staged_doc], &moved, &opts).expect("move_items");
    assert_eq!(moved_bytes, "doc-data".len() as u64);
    assert!(!staged_doc.exists());
    assert_eq!(
        file::read_to_string(moved.join("doc.txt")).expect("read moved doc"),
        "doc-data"
    );

    fs_extra::remove_items(&[&stage, &moved]).expect("remove_items");
    assert!(!stage.exists());
    assert!(!moved.exists());
}

Origin Seeder

anonymous