[M2] CLI: server lifecycle + auth + robot-envelope refactor for existing cmds#11
Merged
Merged
Conversation
New subcommands: - server start [--detach] [--host H] [--port P] — daemon with PID + endpoint sidecar - server stop — SIGTERM via PID file with cleanup - server status — robot envelope: PID liveness + health probe + DB summary - server init [--force] — bootstraps empty db.json, prints fresh admin key - auth login (saves profile to config.toml, optional connectivity check) - auth logout, auth whoami, auth list Auth credentials persisted to ~/.config/openproxy/config.toml. Refactor (no behaviour change for existing flags): - provider list/add, key list/add, pool list/status/create/delete, tunnel start/stop/status now emit openproxy.v1 envelopes when --robot is set. Legacy --json keeps existing pretty-print output. - route honors --robot by switching to JSON streaming mode (per-event envelope deferred to M3). Config helpers: - New save_config_file in cli/config.rs for auth login/logout. - config_file_path and load_config_file made public for reuse. Tests: - 6 unit tests in server.rs/auth.rs (pid round trip, key shape, profile slug derivation, URL normalization, login/logout round trip). - tests/server_lifecycle.rs spawns real binary, asserts PID + endpoint sidecar appear, /api/health answers, stop cleans up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second milestone of the agent-first CLI plan. Independent of #10 (M1, already merged).
Adds 8 new subcommands:
serverinit [--force]db.json+ print fresh admin keyserverstart [--detach] [--host H] [--port P]$DATA_DIR/openproxy.pidand$DATA_DIR/openproxy.endpointsidecarsserverstopserverstatus/api/healthprobe, DB summaryauthlogin --url <U> --api-key <K> [--profile P]~/.config/openproxy/config.toml, optionally activate as defaultauthlogout [--profile P]authwhoami [--verify]authlistDetached mode uses
setsid+ clean stdio redirect to$DATA_DIR/openproxy.log.server statusreads theopenproxy.endpointsidecar to auto-pick the right port.Refactor (no behaviour change for existing flags):
provider list/add,key list/add,pool list/status/create/delete,tunnel start/stop/statusnow emitopenproxy.v1.<resource>.<verb>envelopes when--robotis set.--jsonkeeps producing the same pretty-printed JSON it always did.routehonors--robotby enabling JSON streaming mode (per-event envelope deferred to M3).output::emit_error()with proper exit codes.Schemas emitted
openproxy.v1.server.{init,start,stop,status}openproxy.v1.auth.{login,logout,whoami,list}openproxy.v1.provider.{list,add}openproxy.v1.key.{list,add}openproxy.v1.pool.{list,status,create,delete}openproxy.v1.tunnel.{start,stop,status}Test coverage
op-...48 hex),default_profile_nameslug derivation, URL normalisation, login -> logout round trip writing a real TOML file.tests/server_lifecycle.rsspawns the real binary, asserts PID + endpoint sidecar appear,/api/healthanswers, andstopcleans both sidecars up.init -> start --detach -> status -> conflict-on-restart -> provider/key/pool/tunnel --robot envelopes -> auth login/logout/list -> server stopall pass.Review & Testing Checklist for Human
Risk: yellow (touches binary's process model + writes credentials to disk).
cargo testis green locally.target/debug/openproxy --data-dir /tmp/op-x server initproduces a fresh admin key, thenserver start --detach --port 4733 --host 127.0.0.1actually backgrounds andcurl http://127.0.0.1:4733/api/healthreturns{"ok":true}. Thenserver stopexits the child cleanly.auth login --url http://127.0.0.1:4733 --api-key <admin>writes~/.config/openproxy/config.tomlwithdefault_profileset and the masked-key envelope is sane.provider list --json/pool list --jsonstill see the same pretty-printed shape.Notes
~/.config/openproxy/config.toml(mirrors~/.netrc, user's explicit choice in M2 scoping).route, observability commands (usage,logs,chat), and the remaining 12 command groups in the PLAN.