fabricatio_sandbox.rust

Classes

SandboxSession

High-level sandbox: in-memory upper layer + optional read-only real-dir mounts.

VirtualFS

Thin wrapper around [VfsPath] exposing filesystem operations to Python.

Package Contents

class fabricatio_sandbox.rust.SandboxSession

High-level sandbox: in-memory upper layer + optional read-only real-dir mounts.

Tracks original file content on first mutation so diff() produces per-file unified diffs and apply() can flush changes to the real FS.

static with_mounts(mounts: Mapping[str, str]) SandboxSession

Create a sandbox session with read-only real-directory mounts.

mounts maps virtual paths (e.g. "/project") to real directories. All writes go to the in-memory upper layer; reads fall through to the mounted real directories.

read_text(path: str) str

Read a text file from the sandbox, resolving mount prefixes.

write_text(path: str, content: str) None

Write text to a file, snapshotting the original before first mutation.

read_bytes(path: str) list[int]

Read a file and return its content as bytes.

write_bytes(path: str, content: Sequence[int]) None

Write raw bytes to a file, snapshotting the original before first mutation.

list_dir(path: str) list[str]

List immediate children of a directory.

walk_dir(path: str) list[str]

Recursively walk a directory, returning all descendant paths.

exists(path: str) bool

Check whether a path exists in the sandbox.

is_file(path: str) bool

Check whether a path is a file.

is_dir(path: str) bool

Check whether a path is a directory.

create_dir(path: str) None

Create a single directory level.

create_dir_all(path: str) None

Create a directory and all missing ancestors.

remove_file(path: str) None

Remove a single file, snapshotting its content first.

remove_dir_all(path: str) None

Remove a directory and all its contents.

copy_file(src: str, dst: str) None

Copy a file from src to dst, snapshotting dst first.

rename(src: str, dst: str) None

Move a file from src to dst, snapshotting both first.

abs_path(path: str) str

Return the resolved absolute path string within the VFS.

diff() dict

Return {virtual_path: unified_diff, ...} for every mutated file.

apply() None

Flush mutations from the in-memory layer back to the real filesystem using the mount mappings.

Only files that were written through the session are flushed. New files are created under the matching mount’s real directory; existing files are overwritten.

reset() None

Clear tracked originals and written paths so the next diff() captures only fresh changes.

root_path() str

The virtual root path string. Returns "/" when the overlay root has no explicit path.

mounts() dict[str, str]

Copy of the current mount mappings.

class fabricatio_sandbox.rust.VirtualFS

Thin wrapper around [VfsPath] exposing filesystem operations to Python.

static from_memory() VirtualFS

Create an empty in-memory virtual filesystem.

static from_physical(root: str) VirtualFS

Wrap a real directory as a read-only virtual filesystem.

static from_overlay(real_roots: Sequence[str]) VirtualFS

Layer an in-memory upper layer over read-only real directories.

Writes go to the in-memory layer; reads fall through to the real dirs.

read_text(path: str) str

Read a text file and return its content as a string.

write_text(path: str, content: str) None

Write text content to a file, creating parent directories as needed.

read_bytes(path: str) list[int]

Read a file and return its content as bytes.

write_bytes(path: str, content: Sequence[int]) None

Write raw bytes to a file, creating parent directories as needed.

list_dir(path: str) list[str]

List immediate children of a directory, returning filenames.

walk_dir(path: str) list[str]

Recursively walk a directory, returning all descendant paths.

exists(path: str) bool

Check whether a path exists.

is_file(path: str) bool

Check whether a path is a file.

is_dir(path: str) bool

Check whether a path is a directory.

create_dir(path: str) None

Create a single directory level at the given path.

create_dir_all(path: str) None

Create a directory and all missing ancestors.

remove_file(path: str) None

Remove a single file.

remove_dir_all(path: str) None

Remove a directory and all its contents.

copy_file(src: str, dst: str) None

Copy a file from src to dst, creating parent dirs for dst.

rename(src: str, dst: str) None

Move (rename) a file from src to dst.

abs_path(path: str) str

Return the resolved absolute path string within the VFS.