Skip to content

feat(minimal): finish client interface — lib/main split, CLI subcommands, test harness, stop - #612

Merged
0chroma merged 4 commits into
mainfrom
0chroma/feat-finish-client-interface
Jul 8, 2026
Merged

feat(minimal): finish client interface — lib/main split, CLI subcommands, test harness, stop#612
0chroma merged 4 commits into
mainfrom
0chroma/feat-finish-client-interface

Conversation

@0chroma

@0chroma 0chroma commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Completes the minimal CLI by splitting the monolithic main.rs into a testable library, adding the remaining subcommands, and wiring up a full integration test suite against a real in-process daemon.

Lib/main split

  • lib.rs (new, ~1535 lines): all CLI argument structs, the run() dispatcher, and every cmd_* function are now pub, enabling integration tests to call commands directly
  • main.rs: reduced to 26 lines — tracing init, Cli::parse(), and minimal::run(cli)
  • client.rs: error type changed from String to anyhow::Error for proper error chaining throughout

New subcommands

  • stop [--force] — sends a Shutdown RPC to minimald; refuses if active sessions exist unless --force is passed
  • version — prints CLI version and, if the daemon is reachable, daemon + stdlib versions (does not autospawn)
  • rename <session> <new-name> — resolves by UUID or name, issues RenameSession RPC
  • init, add, update — ports the build-system commands from the legacy binary; operates locally against mctx/op/graph (no daemon RPC)
  • --json flag on ls — three output modes: default table, --raw (IDs only), --json (pretty-printed ListSessionsResponse)

Test infrastructure

  • minimald test-support feature: compiles test_harness as pub mod so external crates can spin up a real minimald server over UDS without a separate binary
  • 17 integration tests covering version, ls (all three modes, empty and with sessions), activate, destroy (by UUID/name, unknown), stop (no-sessions/live/force), rename (by UUID/name), and session policy — all against a real TestServer on a UDS
  • 12 unit tests for ingress parsing and the policy-hook decision logic
  • format_ls extracted from cmd_ls so tests capture and assert on actual JSON/raw/table output

Code review refactors

  • Extracted SessionLookup enum with From impls for both GetSessionRecordRequest and GetSessionPolicyRequest, eliminating duplicated UUID-or-name parsing
  • Extracted ensure_daemon() helper, replacing 9 copies of the autospawn boilerplate
  • Changed parse_ingress_mapping/parse_ingress_proto from Result<_, String> to Result<_, anyhow::Error>
  • Made shell_quote private (internal only)
  • Test create_session helper reuses unwrap_ready from the harness instead of duplicating the match

Changed files

File Change
crates/minimal/src/lib.rs New — all CLI types, dispatcher, and cmd_* functions
crates/minimal/src/main.rs Reduced to thin entrypoint (26 lines)
crates/minimal/src/client.rs Stringanyhow::Error error types
crates/minimal/tests/cli.rs New — 17 integration tests
crates/minimal/tests/common/mod.rs New — shared TestDaemon harness
crates/minimal/Cargo.toml Added anyhow, mctx, op, paths deps + test-support dev-dep
crates/minimald/Cargo.toml Added test-support feature
crates/minimald/src/lib.rs test_harness gated on test or test-support
crates/minimald/src/test_harness.rs pub(crate)pub + bring_session_up helper

Test plan

  • cargo test -p minimal — 12 unit + 17 integration tests pass
  • cargo test -p minimald — 106 tests pass (unaffected)
  • cargo clippy -p minimal -p minimald --all-targets -- -D warnings — clean
  • cargo fmt -- --check — clean
  • ./target/debug/minimal --help — all subcommands visible
  • ./target/debug/minimal version — prints client + daemon version

Summary by CodeRabbit

  • New Features
    • Expanded CLI capabilities for session lifecycle, mesh management (join/leave/status), login (mTLS cert issuance), SSH proxying/forwarding, and local project commands (init/add/update/version, completions).
    • Improved session listing with multiple output formats, including JSON.
  • Bug Fixes
    • More informative error messages for daemon connection and RPC/SSH command failures.
  • Tests
    • Added end-to-end CLI integration tests using a real daemon test harness, covering core commands and listing output modes.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: f1a9a310-f33d-402a-9646-924176cc009c

📥 Commits

Reviewing files that changed from the base of the PR and between 78aa8e0 and 8628f87.

📒 Files selected for processing (2)
  • crates/minimal/Cargo.toml
  • crates/minimal/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/minimal/Cargo.toml
  • crates/minimal/src/lib.rs

📝 Walkthrough

Walkthrough

The minimal CLI now lives in a library entrypoint with typed command dispatch, richer RPC error context, exposed daemon test harness APIs, and real integration tests that exercise the CLI against a running minimald.

Changes

Minimal CLI library extraction and testing

Layer / File(s) Summary
Client error handling
crates/minimal/Cargo.toml, crates/minimal/src/client.rs
Adds anyhow and Linux-only dependencies, and changes client RPC/connect errors to anyhow::Error with context.
main.rs delegation
crates/minimal/src/main.rs
main now parses minimal::Cli and calls minimal::run(cli).await.
CLI schema and dispatcher
crates/minimal/src/lib.rs
Defines the CLI types, ingress parsing, command dispatcher, daemon connection, proxy piping, and session listing.
Activation and attach flow
crates/minimal/src/lib.rs
Adds activation gating, pending-session handling, cmd_activate, and SSH attach via ProxyCommand.
Session, mesh, and login commands
crates/minimal/src/lib.rs
Adds session policy, mesh, destroy/stop, rename, SSH forwarding, and client certificate issuance commands.
Local build commands and unit tests
crates/minimal/src/lib.rs
Adds Linux-only build commands and unit tests for ingress parsing and policy decisions.
minimald test harness made public
crates/minimald/Cargo.toml, crates/minimald/src/lib.rs, crates/minimald/src/test_harness.rs
Adds test-support and exposes the test harness types and helpers as public APIs.
Shared test harness and CLI tests
crates/minimal/tests/common/mod.rs, crates/minimal/tests/cli.rs
Adds a real-daemon test harness and integration tests for the CLI commands.

Estimated code review effort: 4 (Complex) | ~60 minutes

Poem

I’m a rabbit with a tidy plan,
hopping through CLI land. 🐇
Errors speak with clearer light,
tests now run against the right.
One small burrow, many paths —
crisp commands and softer crashes.


Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

Comment @coderabbitai help to get the list of available commands.

@twitchyliquid64

Copy link
Copy Markdown
Member

WRT to the rebase conflict, minimal/minimal2 crates were moved, but you can get a clanker to fix it if you tell em that the minimal crate is now the mip crate and the minimal2 crate is now the minimal crate

@0chroma
0chroma force-pushed the 0chroma/feat-finish-client-interface branch from 1920bd2 to d29ec86 Compare July 6, 2026 17:35
0chroma added 3 commits July 8, 2026 09:10
Rebase the minimal2 CLI work onto main, adapting to the crate rename
(minimal2 → minimal, minimal → mip). Combines the following features:

- version, rename, init, add, and update subcommands
- --json and --raw output flags for the ls command
- anyhow-based error handling replacing ad-hoc eprintln!+Err(())
- resolve_session helper for UUID/name session lookups
- integration test harness with 14 CLI tests exercising real daemon
- lib/main split so integration tests can call cmd_* functions directly
- minimald test-support feature exposing TestServer/TestClient externally
- merged main's session-creation flow (SessionConfig, Pending/Ready,
  AbortOnUnapproved, drive_pending_to_active, send_abort) into the
  anyhow-based error handling
- client.rs socket path now uses paths::minimal_state_dir()
Adds a `minimal stop` command that sends the Shutdown RPC (PR #613)
to the running minimald daemon. With no flags it requests a graceful
shutdown — the daemon refuses if any session is live. Pass --force to
tear down live sessions and shut down regardless.

Includes three integration tests covering the no-sessions, refused,
and forced paths. Also adds a bring_session_up helper to the test
harness so tests can make sessions "live" for shutdown scenarios.
Reduce duplication and improve test coverage after the lib/main
split: extract SessionLookup/ensure_daemon helpers, make
parse_ingress return anyhow::Error, privatize shell_quote, and
capture stdout in ls integration tests via a new format_ls function.
@0chroma
0chroma force-pushed the 0chroma/feat-finish-client-interface branch from d29ec86 to a24d00a Compare July 8, 2026 16:37
@0chroma 0chroma changed the title feat(minimal2): finish #159 client interface — version, rename, init/add/update, error handling, tests feat(minimal): finish client interface — lib/main split, CLI subcommands, test harness, stop Jul 8, 2026
@0chroma
0chroma marked this pull request as ready for review July 8, 2026 16:40
…lity

The init/add/update subcommands depend on mctx → hakoniwa → libcgroups
→ procfs, which only compiles on Linux. Gating mctx/op behind
target_os = "linux" keeps the minimal binary buildable on macOS, fixing
the autospawn-e2e CI lane that builds and runs minimal on the self-hosted
Apple Silicon runner.
@0chroma
0chroma force-pushed the 0chroma/feat-finish-client-interface branch from 78aa8e0 to 8628f87 Compare July 8, 2026 21:32
@0chroma
0chroma merged commit 53afd9c into main Jul 8, 2026
15 checks passed
@0chroma
0chroma deleted the 0chroma/feat-finish-client-interface branch July 8, 2026 22:06
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.

3 participants