4.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Covenant-Setup is a Windows installer engine written in Rust. It deterministically tracks all system mutations (files, directories, registry keys, shortcuts, scripts) via a journaling model, enabling exact rollback on uninstall. Windows-only; all system operations use Win32 APIs directly.
Build & Run Commands
cargo fmt # Format code
cargo check # Type-check without building
cargo build # Debug build
cargo build --release # Release build
# Package: bundle manifest + payload into a single-file installer EXE
cargo run -- package examples/install.toml --output dist
# Install: apply a manifest directly (or from embedded bundle)
cargo run -- install examples/install.toml --json
# Uninstall: reverse all journaled actions
cargo run -- uninstall examples/journal.json --json
No Rust automated test suite exists yet beyond the in-tree #[cfg(test)]
unit tests (cargo test, 96 tests). C# UI unit tests live in a sibling
project and run via:
dotnet test ui/Covenant.Setup.Ui.Tests/Covenant.Setup.Ui.Tests.csproj
Real Win32/UAC/registry boundaries are validated by the Vagrant harness
(scripts/run-windows-vm-coverage.ps1) — see
docs/integration-tests-architecture.md. Manual interactive testing uses
the example manifest (examples/install.toml).
Architecture
Three source files:
src/main.rs— CLI (clap derive), manifest parsing, install/uninstall/package logic, journaling, UI (TUI/GUI/JSON), elevation handlingsrc/sys.rs—Systrait abstracting every external boundary (Win32 elevation/registry/MoveFileEx fallback, reboot, cleanup-helper spawn, embedded-bundle probe, GUI prompts, optionalProgressSinkinjection).WinSysis the production implementation that delegates tocrate::win::*,crate::ui::*, and the local helpers;MockSys(inmod tests) records every call for unit tests.src/win.rs— All Win32 FFI isolated here. Everyunsafeblock is bracketed withlogger.unsafe_enter()/unsafe_exit()calls. ContainsPathResolverfor known-folder token resolution, file/directory/registry/shortcut operations, Restart Manager queries, and elevation checks.
Three operational modes (CLI subcommands):
package— Reads TOML manifest, embeds it + payload files into the EXE binary using an append format (JSON payload + u64 size + magic footerCOVENANT_SETUP_BUNDLE_V1)install— Parses manifest (from file or embedded bundle), executes mutations in order, writesjournal.json, registers in Add/Remove Programsuninstall— Readsjournal.json, reverses actions in LIFO order, handles locked files via Restart Manager +MoveFileExreboot fallback, spawns cleanup helper for self-deletion
Key types:
InstallManifest— Declarative TOML contract: directories, files, registry, shortcuts, scripts, purge specJournal/JournalAction— Serialized record of every mutation for deterministic rollbackMutationTrackertrait — Extensibility point (MVP usesDeclaredTracker; future:ObservedTrackerfor ETW-based capture)PathResolver— Resolves{ProgramFilesX64},{LocalAppData},{Desktop}tokens viaSHGetKnownFolderPathLogger— Dual-mode output: structured JSON (--jsonflag) for IPC or human-readable text
Elevation: Manifest/journal is scanned for HKLM registry or ProgramFiles paths to determine if admin is needed. Auto-relaunches via ShellExecuteW with runas when --elevate flag is set. Exit code 33 signals elevation required.
UI modes: --headless forces TUI, --headed forces GUI (PowerShell-hosted WinForms), auto-detected from parent process otherwise. JSON mode (--json) is for programmatic consumers.
Conventions
- All Win32 calls go in
src/win.rs, never inmain.rs - All external boundaries (
win::*,ui::*prompts, reboot/cleanup-helper spawning, embedded-bundle probe) flow through theSystrait insrc/sys.rsso orchestration code can be unit-tested withMockSys - UTF-16 conversion uses the
Utf16Argwrapper type - Registry always uses
KEY_WOW64_64KEYfor explicit 64-bit access - Path tokens (
{ProgramFilesX64}, etc.) are resolved at runtime, never hardcoded - Subprocess calls use
CREATE_NO_WINDOWflag - Rust edition 2024
VM coverage harness
scripts\run-windows-vm-coverage.ps1 walks every scenario directory under vm\<scenario>\install.toml and delegates per-scenario in-guest assertions to scripts\windows-vm\coverage\<scenario>.ps1. The bundled scenarios (self-test, uac, hklm-registry, reboot, bundled-exec) exercise the elevation, MoveFileEx pending-rename, HKLM-registry, and embedded-bundle code paths. The harness builds the release binary and dispatches scenarios in-place; pass -SkipBuild to reuse a prior build.