Skip to content

Deepen engine architecture + seed CONTEXT.md#243

Open
timopruesse wants to merge 1 commit into
mainfrom
refactor/deepen-engine-architecture
Open

Deepen engine architecture + seed CONTEXT.md#243
timopruesse wants to merge 1 commit into
mainfrom
refactor/deepen-engine-architecture

Conversation

@timopruesse

Copy link
Copy Markdown
Owner

Summary

Five architectural deepening refactors that concentrate behavior behind smaller interfaces and make the engine testable without touching disk, sudo, or the network — plus a CONTEXT.md that names the resulting vocabulary. No user-facing behavior change (one cosmetic log line dropped, noted below).

Net: +706 / −650 across 16 files, 4 new modules. Tests grew from ~50 lib + 31 integration to 78 lib + 37 integration.

What changed

1. Mode, distinct from the CLI Command (src/engine/mode.rs)
Mode {Install, Update, Uninstall} is mapped once from the CLI verb; list/validate/completions never reach the engine, so the dead match arms disappear from run_command, update_history, and commands_for_mode. The CommandExecutor trait collapsed from three methods to one execute(ctx) reading ctx.mode, eliminating the double mode dispatch.

2. FileOps privilege seam (src/engine/commands/fs_ops.rs)
A FileOps trait with two real adapters — DirectFs (std::fs) and SudoFs (sudo) — selected once per command. The if use_sudo {…} fork and platform-specific symlink/removal logic move behind the interface. A test-only RecordingFs lets executor tests assert which operations ran without disk I/O.

3. Tree-materialization module (src/engine/commands/tree.rs)
resolve_single_file_dest (the file-vs-dir target rule, now a pure table-tested function) plus install_tree/uninstall_tree parameterized by a per-file op. copy/symlink shrink to their genuine differences.

4. TaskGraph (src/config/graph.rs)
One home for topo_order, layers, find_cycle, missing_dependencies. The runner's two traversals and the validator's separate cycle DFS now share it.

5. Unified runner execution (src/engine/runner.rs, −190 lines)
Parallel and sequential collapse into one layer loop (sequential = one task per layer) with a single run_layer lifecycle helper.

CONTEXT.md documents the domain + architecture vocabulary and resolves the overloaded "command" into Command entry / Mode / CLI command.

Testing

  • make lint — clean (fmt + clippy -D warnings)
  • make test — 78 lib + 37 integration tests pass
  • New tests: Mode mapping/display, FileOps adapters + recording fake, dest resolution, tree apply/remove, TaskGraph (diamond/cycle/missing/layers), and integration tests for copy & symlink uninstall, symlink force-vs-skip, parallel-respecting-dependency-layers, single-file-into-directory copy.

Behavior note

copy in update mode no longer emits the cosmetic "Copy update: re-running install" log line; it still re-applies identically. Nothing else changes observably.

🤖 Generated with Claude Code

Five deepening refactors that concentrate behavior behind smaller interfaces
and make the engine testable without touching disk, sudo, or the network:

1. Introduce engine::Mode {Install,Update,Uninstall}, distinct from the CLI
   Command. Collapse CommandExecutor's three methods into one execute(ctx)
   reading ctx.mode. Removes dead list/validate/completions match arms and the
   double mode dispatch.
2. Add a FileOps privilege seam (DirectFs / SudoFs adapters) selected once per
   command, replacing the per-call sudo fork and platform-specific symlink and
   removal logic.
3. Extract a tree-materialization module shared by copy and symlink: dest
   resolution (now a pure, table-tested function) plus the install/uninstall
   walk, parameterized by a per-file operation.
4. Build a TaskGraph module owning topo order, layers, cycle and missing-edge
   detection. Runner and validator now share one implementation.
5. Unify the parallel and sequential run_tasks branches into one layer loop
   (sequential = one task per layer) with a single per-task lifecycle helper.

Hardening: new unit tests for Mode, FileOps adapters + a recording fake, dest
resolution, tree apply/remove, and TaskGraph; new integration tests for copy
and symlink uninstall, symlink force vs skip, parallel-respecting-dependency
layers, and single-file-into-directory copy.

Add CONTEXT.md documenting the domain and architecture vocabulary, resolving the
overloaded "command" into Command entry / Mode / CLI command.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant