From 8ea847091dad353fba2947b7f2d8a968b45af3f6 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 05:48:05 -0600 Subject: [PATCH] fix(fleet): close the remaining fleet help gaps (#13175) Every item verified against a binary built from current main first; the bridge per-verb bullet was already fixed by #13197 and is not repeated here. - queue TOP_USAGE: release/heartbeat/checkpoint/park/block/fail/ complete lines now list [--lane ]; the fallback line lists the full subcommand set (complete included). New parity test compares each single-verb TOP_USAGE line's flags against that verb's own usage synopsis so the two cannot drift apart again. - queue fallback GROUP_USAGE: scan line corrected to scan [--repo ] [--limit <1..100>] [--lease-min ]. - queue session status/result --help: a help flag after the subcommand prints the session usage and exits 0 instead of being looked up as a session handle. - queue surfaces --help: prints a short usage instead of being ignored (it printed the registry JSON). - agent: per-verb help via verb_usage() on the #13197 bridge pattern (kinds/enroll/doctor/next/shortlist); unknown verbs keep the shared USAGE. USAGE_FOOTER pins the shared tail. - gh tiers --help prints its own usage (was exit 2); gh closures --help prints its own usage (was silent exit 0); the gh usage synopsis gains the missing closures line. - serve queue-broker/secrets-broker --help prints the role's own usage (env configuration surface); a serve list with --help prints the serve domain help instead of dying in parse_serve_list. - shell --help reaches the shell's own usage when the Agent capability is available, instead of the registry domain help that lists only targets. - built-ins: version/capabilities/help with a lone --help print their own short usage and exit 0; any other trailing argument still errors exit 2. - laptop-agent: a help token before the -- separator (not swallowed as an option value) prints USAGE and exits 0 before any transport; poll --help no longer polls a job named --help. Tests: fleet-queue 565 passed + 1 pre-existing failure on main (sweep_wiring call-shape drift, filed as #13230); fleet-agent 93; fleet-laptop-agent 20; fleet bin 122. Book chapters updated in the same change per DOC-01 (builtins, agent, gh, laptop-agent, queue-core, queue-lifecycle, queue-dispatch, queue-fallback, serve, shell, concepts/agents, concepts/placement, concepts/gh, and the dispatch tutorial); fleet-docs builds clean. --- pkgs/fleet/book/concepts/agents.md | 6 +- pkgs/fleet/book/concepts/gh.md | 4 +- pkgs/fleet/book/concepts/placement.md | 4 +- pkgs/fleet/book/reference/agent.md | 2 +- pkgs/fleet/book/reference/builtins.md | 2 +- pkgs/fleet/book/reference/gh.md | 4 +- pkgs/fleet/book/reference/laptop-agent.md | 2 +- pkgs/fleet/book/reference/queue-core.md | 2 +- pkgs/fleet/book/reference/queue-dispatch.md | 6 +- pkgs/fleet/book/reference/queue-fallback.md | 2 +- pkgs/fleet/book/reference/queue-lifecycle.md | 8 +- pkgs/fleet/book/reference/serve.md | 6 +- pkgs/fleet/book/reference/shell.md | 2 +- pkgs/fleet/book/tutorials/dispatch-a-build.md | 8 +- pkgs/fleet/crates/fleet-agent/src/lib.rs | 65 ++++++- pkgs/fleet/crates/fleet-agent/src/tests.rs | 24 ++- .../crates/fleet-laptop-agent/src/cli.rs | 44 +++++ pkgs/fleet/crates/fleet-queue/src/client.rs | 43 +++++ .../crates/fleet-queue/src/client/support.rs | 16 +- pkgs/fleet/crates/fleet-queue/src/fallback.rs | 2 +- .../fleet/crates/fleet-queue/src/placement.rs | 44 ++++- pkgs/fleet/crates/fleet/src/gh.rs | 23 +++ pkgs/fleet/crates/fleet/src/main.rs | 167 ++++++++++++++++++ 23 files changed, 443 insertions(+), 43 deletions(-) diff --git a/pkgs/fleet/book/concepts/agents.md b/pkgs/fleet/book/concepts/agents.md index c879eec0fe..dbef0dccd1 100644 --- a/pkgs/fleet/book/concepts/agents.md +++ b/pkgs/fleet/book/concepts/agents.md @@ -9,9 +9,9 @@ the same `agent` capability. Source: https://github.com/developing-today/code/blob/main/pkgs/fleet/crates/fleet-agent/src/lib.rs -As with the bridge, every per-verb `--help` prints the same shared usage -text; there is no per-verb help in source. This chapter is the per-verb -reference. +As with the bridge, every verb has its own `--help`: the verb's +synopsis and description over the shared output/exit-code footer. +This chapter is the per-verb reference. ## Kinds and seat shapes: 16 × 3 diff --git a/pkgs/fleet/book/concepts/gh.md b/pkgs/fleet/book/concepts/gh.md index 3a8c7eba26..06a00bb504 100644 --- a/pkgs/fleet/book/concepts/gh.md +++ b/pkgs/fleet/book/concepts/gh.md @@ -142,8 +142,8 @@ no daemon answered. **`fleet gh tiers`** probes _every_ rotation source and prints its core and GraphQL rate-limit headroom — labels and numbers only; token values never leave the provider. Exit 0 when every source answers, **3 when any source -is down**. Source behaviour: `tiers` takes no `--help` — `fleet gh tiers ---help` errors with "unexpected argument '--help'". +is down**. Source behaviour: `fleet gh tiers --help` prints the verb's own +usage and exits 0; any other argument errors. **`fleet gh closures []`** reads back the closure log. The policy layer behind it: `issue|pr close|reopen` through the rotation must carry a diff --git a/pkgs/fleet/book/concepts/placement.md b/pkgs/fleet/book/concepts/placement.md index 069467a8ee..a94a02c02f 100644 --- a/pkgs/fleet/book/concepts/placement.md +++ b/pkgs/fleet/book/concepts/placement.md @@ -265,5 +265,5 @@ Actions/Blacksmith surface's host repo. Session state mapping from GitHub: `queued|waiting|pending|requested` → `queued`; `in_progress` → `running`; completed with conclusion `success|skipped|neutral` → `succeeded`, `cancelled` → `cancelled`, anything else → `failed`. Note that -`session status --help` does not print help — `--help` is taken as the -handle and errors; only bare `session --help` prints the usage. +a help flag after the subcommand prints the session usage — +`session status --help` is a help request, never a handle lookup. diff --git a/pkgs/fleet/book/reference/agent.md b/pkgs/fleet/book/reference/agent.md index daf96edc06..e94a654fca 100644 --- a/pkgs/fleet/book/reference/agent.md +++ b/pkgs/fleet/book/reference/agent.md @@ -6,7 +6,7 @@ Every verb prints **one JSON object**. Exit codes for the domain: `0` ok · `2` See also [Agents: enrolment, doctor and the intake ladder](../concepts/agents.md) and [fleet bridge](bridge.md). -Known discrepancy: every per-verb help invocation returns **one shared USAGE text** for the whole domain — there is no per-verb help in source. The per-verb sections below are written from source semantics. +Help: `fleet agent --help` prints that verb's own usage — its synopsis, a short description, and the shared output/exit-code footer. An unknown verb (or no verb) falls back to the shared domain USAGE. The per-verb sections below are written from source semantics. ## fleet agent kinds diff --git a/pkgs/fleet/book/reference/builtins.md b/pkgs/fleet/book/reference/builtins.md index 53cb05467f..1fa9fd8a9d 100644 --- a/pkgs/fleet/book/reference/builtins.md +++ b/pkgs/fleet/book/reference/builtins.md @@ -4,7 +4,7 @@ The `fleet` binary has five root built-in commands that belong to no domain: `in Two rules govern all five, without exception: -- **Built-ins take no arguments.** A trailing argument is a usage error naming it, exit 2 — never silently discarded. That rule includes `--help`: `fleet version --help` and `fleet capabilities --help` are errors, not help, and `fleet help --help` answers `error: no domain named '--help'`. This is the opposite of the leaf-verb convention elsewhere in the binary, where ` --help` prints that verb's usage and exits 0. +- **Built-ins take no arguments.** A trailing argument is a usage error naming it, exit 2 — never silently discarded. The one exception is a lone help flag: `fleet version --help`, `fleet capabilities --help`, and `fleet help --help` each print that built-in's own short usage and exit 0 (#13175) — the same leaf-verb convention as elsewhere in the binary. A help flag followed by anything else is still a usage error. - **Bare `fleet` is an error.** With no subcommand at all, the binary prints a missing-subcommand message and the full help to stderr and exits 2. `fleet --help`, `fleet -h`, and `fleet help` (exactly one word) print the registry help and exit 0. `fleet --version` and `fleet -V` print the short version form (see `version` below). A domain an invocation cannot use answers with a stub on stderr and exit 69 (`EX_UNAVAILABLE`). There are four stub wordings, one per reason class: the domain is not in this build, the invocation name (`fleet-serve` / `fleet-connect`) narrowed the surface away, the `[domains]` table in fleet config disabled the domain on this host, or the domain is included but not yet implemented. Every stub's second line is `Enabled capabilities: ` (`none` when empty). Help marks unavailable domains inline — `[not in this build]`, `[narrowed out by this name]`, `[disabled by config]` — but prints the full registry on every variant: every build knows every domain. diff --git a/pkgs/fleet/book/reference/gh.md b/pkgs/fleet/book/reference/gh.md index 42d8539127..3d57797458 100644 --- a/pkgs/fleet/book/reference/gh.md +++ b/pkgs/fleet/book/reference/gh.md @@ -77,7 +77,7 @@ fleet gh tiers Probes _every_ rotation source and prints its core and GraphQL rate-limit headroom — labels and numbers only; token values never leave the provider. -Known discrepancy: `tiers` takes no `--help`: `fleet gh tiers --help` errors with `error: unexpected argument '--help' for 'fleet gh tiers'`. This verb is documented only in source. +Help: `fleet gh tiers --help` prints the verb's own usage and exits 0; any other argument is a usage error naming it. ### Exit codes @@ -171,7 +171,7 @@ fleet gh closures [] Reads back the closure log. The policy layer behind it: `issue|pr close|reopen` through the rotation must carry a `--reason` from the taxonomy — `implemented`, `superseded`, `cancelled`, `started-incorrectly` — enforced with the policy error "Please give a reason. This is required by policy." The reason is written into the close comment, and every successful close or reopen appends one `fleet-closure/v1` JSON-line record to `closure-records.jsonl` in the fleet state directory (backed up with it); `closures` prints the log, optionally filtered to one item. -Known discrepancy: this verb has **no help output at all** — its help-dump file is empty because the `--help` invocation produced nothing. Its behaviour is documented only in source (this section). +Help: `fleet gh closures --help` prints the verb's own usage and exits 0. ### Exit codes diff --git a/pkgs/fleet/book/reference/laptop-agent.md b/pkgs/fleet/book/reference/laptop-agent.md index 98ec8624d7..7d9e5fb284 100644 --- a/pkgs/fleet/book/reference/laptop-agent.md +++ b/pkgs/fleet/book/reference/laptop-agent.md @@ -4,7 +4,7 @@ See also [fleet proxy](proxy.md) and [fleet shell](shell.md). -Known discrepancy: there is **no `--help` handling anywhere in this domain**. The shared USAGE text is printed only as part of error messages, and a `--help` argument is treated as data — `laptop-agent jobs --help` errors `unknown command "jobs"` (because `jobs` accepts no trailing arguments), `poll --help` actually polls a job named `--help` and prints its real `HTTP 404: no such job`, and `kill --help` prints nothing. This chapter is written from source. A second stale-help note: the domain status line still claims "implementation lands in a later step of epic #5412"; the source is a full client mirroring the Python daemon client verb for verb. +Help: a help token anywhere before the `--` separator — and not swallowed as an option's value — prints the domain's shared USAGE and exits 0, before any transport is touched: `poll --help` asks for help; it does not poll a job named `--help` (#13175). A stale-help note: the domain status line still claims "implementation lands in a later step of epic #5412"; the source is a full client mirroring the Python daemon client verb for verb. ## Shared behaviour (all verbs) diff --git a/pkgs/fleet/book/reference/queue-core.md b/pkgs/fleet/book/reference/queue-core.md index b9e6fad521..de395a6aa6 100644 --- a/pkgs/fleet/book/reference/queue-core.md +++ b/pkgs/fleet/book/reference/queue-core.md @@ -202,7 +202,7 @@ usage: repo-queue release [--worker ] [--lane ] [--reason ]`); source makes it **required and non-empty** — missing → exit 2 `release requires --reason "" (#8217)`. This chapter documents the source behaviour. (The top-level usage line additionally omits `[--lane ]`, which the per-verb usage, the help dump, and the implementation all have.) +Help: the usage writes `--reason` bare — it is **required and non-empty** — missing → exit 2 `release requires --reason "" (#8217)`. The top-level usage line lists the same flags as the per-verb usage, `[--lane ]` included; a parity test cross-checks the two so they cannot drift apart again. Exit codes: 0 released · 2 usage / missing or empty `--reason` · 3 transport · 4 broker store failure · 5 no matching claimed row. diff --git a/pkgs/fleet/book/reference/queue-dispatch.md b/pkgs/fleet/book/reference/queue-dispatch.md index 237f3be6fb..c4ab5f5081 100644 --- a/pkgs/fleet/book/reference/queue-dispatch.md +++ b/pkgs/fleet/book/reference/queue-dispatch.md @@ -61,7 +61,7 @@ usage: repo-queue session [HANDLE|OWNER/REPO#RUN_ID] [--min **Behaviour.** Session records are a labeled **STOPGAP**: a local JSON store at `~/.local/state/fleet-place/sessions.json` (same path/shape as the reference implementation, so records migrate when the designed placement-sessions table lands). The store is lock-guarded on write. `session status ` refreshes the record from GitHub and prints `: state= surface= run=` (or the record as JSON with `--json`). -Known discrepancy: `--help` is **not** treated as help here. The token after the subcommand is taken as the HANDLE, so `session status --help` looks up a session literally named `--help` and fails with `repo-queue: no session with handle --help in …/sessions.json`. Only a bare `session --help` (no subcommand) prints usage. The flags documented here come from source. This chapter documents the source behaviour. +Help: a help flag after the subcommand prints the session usage and exits 0 — `session status --help` asks for help; it does not look up a session named `--help` (#13175). The flags documented here come from source. Exit codes: 0 ok · 2 usage / no such handle / missing handle (`session status needs a HANDLE`). @@ -85,7 +85,7 @@ usage: repo-queue session [HANDLE|OWNER/REPO#RUN_ID] [--min **Behaviour.** Same refresh as `status`; the output adds `terminal: bool` (`succeeded|failed|cancelled` are terminal) and, when not terminal, the note `not terminal yet — reconnect with the same handle`. Text form: `: (terminal=) run=`. -Known discrepancy: as with `status`, `--help` after the subcommand is treated as a handle, not as help (see `session status`). Flags are documented from source. +Help: as with `status`, a help flag after the subcommand prints the session usage (see `session status`). Flags are documented from source. Exit codes: 0 ok · 2 usage / no such handle / missing handle. @@ -126,7 +126,7 @@ usage: repo-queue surfaces [--registry PATH] | ------------ | --------- | -------------------------------- | ----------------------- | | `--registry` | file path | resolution order (see Behaviour) | Registry file to print. | -**Behaviour.** Prints the resolved placement registry verbatim as pretty JSON, exit 0. (The help-dump `queue_surfaces.txt` is exactly this output, not help text.) Registry resolution order: `--registry ` or env `FLEET_PLACE_REGISTRY` → a home copy → the source-tree relative path → the registry **embedded in the binary**. Registry shape (version 2): `{comment, version, laptop: {busy, busy_source, note}, owners: {: {concurrent_jobs_cap, concurrent_macos_cap, plan, private_minutes_monthly}}, surfaces: […]}`. +**Behaviour.** Prints the resolved placement registry verbatim as pretty JSON, exit 0. `surfaces --help` prints a short usage instead of the registry. Registry resolution order: `--registry ` or env `FLEET_PLACE_REGISTRY` → a home copy → the source-tree relative path → the registry **embedded in the binary**. Registry shape (version 2): `{comment, version, laptop: {busy, busy_source, note}, owners: {: {concurrent_jobs_cap, concurrent_macos_cap, plan, private_minutes_monthly}}, surfaces: […]}`. The shipped surfaces: `fleet-personal` (github-actions, dezren39/fleet, App installation, active), `fleet-org` (github-actions, developing-today/fleet, user-token dispatch, active; also the Blacksmith host), `fleet-forks` (github-actions, developing-today-forks/fleet, **public targets only**, active), `org-run` (standby, retained for manual use; placement prefers fleet-org), `fleet-org-blacksmith` (kind `blacksmith`, Linux-only fallback; budget 3000 free min/mo, paid cap 0 — paid overage disabled unless a dispatch explicitly supplies `--allow-paid-blacksmith`), `codespace-overflow` (kind `codespace`, status `pending-scope`, max 3 live, 180 core-hours/mo budget; uses existing codespaces only, never creates them), `laptop` (kind `laptop`, `handoff-only` — a placement record only; this adapter never runs shell commands on the laptop). Targets accept exact `owner/repo`, `owner/*`, or `*`. `sticky_queue_threshold: 2` and `selection_priority` (10 for the active runners, 20 for org-run) drive the cascade. diff --git a/pkgs/fleet/book/reference/queue-fallback.md b/pkgs/fleet/book/reference/queue-fallback.md index b760d28de0..401d5a88ce 100644 --- a/pkgs/fleet/book/reference/queue-fallback.md +++ b/pkgs/fleet/book/reference/queue-fallback.md @@ -69,7 +69,7 @@ usage: repo-queue fallback scan [--repo ] [--limit <1..100>] [--lease-min **Behaviour.** Sweeps the fallback repos' labelled issues (`queue/queued`, `queue/claimed`, `queue/blocked`) and folds each issue's claim state. Output JSON: `{"mode":"fallback", "generated_at", "lease_seconds", "items": [{"repo","number","title","url","labels","blocked","claim": }], "summary": {"total", "claimable"}, "notes": […]}`. Items are ranked claimable first (free/released/stale), then live, then contested/blocked; a blocked item never ranks claimable even if its marker fold reads free — the label is the block. Per-issue comment-read failures land in `notes` and the issue is folded with no markers rather than failing the sweep. -Known discrepancy: the group usage line in `queue_fallback.txt` (and source `GROUP_USAGE`) summarizes `scan `, but `fallback scan` takes **no positionals at all** (they are a usage error) — its repo filter is the `--repo` flag. The same top-level usage additionally **omits `complete`** from the fallback subcommand list while the fallback group usage and the implementation both include it. This chapter documents the implementation behaviour. +Help: the group usage line lists `scan [--repo ] [--limit <1..100>] [--lease-min ]` — `fallback scan` takes **no positionals at all** (they are a usage error); its repo filter is the `--repo` flag. The top-level usage lists the full fallback subcommand set, `complete` included. This chapter documents the implementation behaviour. Exit codes: 0 ok · 2 usage (including positionals, out-of-range `--limit`) · 3 GitHub transport failed. diff --git a/pkgs/fleet/book/reference/queue-lifecycle.md b/pkgs/fleet/book/reference/queue-lifecycle.md index 14f3c2fd9f..b3aef3c076 100644 --- a/pkgs/fleet/book/reference/queue-lifecycle.md +++ b/pkgs/fleet/book/reference/queue-lifecycle.md @@ -101,7 +101,7 @@ usage: repo-queue checkpoint [--worker ] [--lane ] [--stage ') = {stage, progress, at}`; writes a `checkpoint` event. Fallback-switch path, like heartbeat: a primary-store failure switches, exit 6. Prints row + `mode_line`. -Known discrepancy: help brackets `--stage` as optional (`[--stage ]`); source makes it **required** — missing → exit 2 `checkpoint: --stage is required`. This chapter documents the source behaviour. +Help: the usage writes `--stage` bare — it is **required** — missing → exit 2 `checkpoint: --stage is required`. Exit codes: 0 ok · 2 usage / missing `--stage` / both progress flags · 3 transport · 4 broker store failure · 5 no matching claimed row · 6 fallback switch. @@ -296,7 +296,7 @@ usage: repo-queue cancel [--worker ] [--reason ] **Behaviour.** For a task that will never be worked (issue closed, self-assigned elsewhere, superseded). Sets status `cancelled`, clears worker/lease, deletes the lease row, records `result.reason_class = "cancelled"` + `result.cancel_reason`, writes a `cancelled` event. The original function only accepted `queued` or `parked` rows. Output: the row; cancel closes the timeline binding window. -Known discrepancy: help brackets `--reason` as optional (`[--reason ]`); source makes it **required** (exit 2 without it). Source-only fact: cancel's `--worker` default is `fleet-monitor`, not `repo-worker-code`. This chapter documents the source behaviour. +Help: the usage writes `--reason` bare — it is **required** (exit 2 without it) — and its description names cancel's `--worker` default: `fleet-monitor`, not `repo-worker-code`. Exit codes: 0 cancelled · 2 usage / missing `--reason` · 3 transport · 4 broker store failure · 5 no matching row. @@ -344,7 +344,7 @@ usage: repo-queue fail [--worker ] [--lane ] [--error ] **Behaviour.** Terminal `failed`. Broker route `/fail`. Output: row or `{task, lane_ledger}`; fail closes the timeline binding window. -Known discrepancy: help brackets `--error` as optional; source makes it **required** (exit 2 without it), and `--reason-class` is a closed enum (default `transient`) that help never mentions. This chapter documents the source behaviour. +Help: the usage writes `--error` bare — it is **required** (exit 2 without it) — and its description names the `--reason-class` closed enum: `transient` (the default), `deterministic`, `blocked`. Exit codes: 0 failed · 2 usage / missing `--error` / invalid `--reason-class` · 3 transport · 4 broker store failure · 5 no matching claimed row. @@ -385,7 +385,7 @@ Client-side completion dressing (all fail-soft, explicit caller values win): The gate is pure (no network): it parses the record, checks freshness (≤ **1800 s** old by default; >300 s in the future is unreadable clock skew), checks it describes the task's issue, checks the verdict against the readback, checks every PR the completion result links (`pr`/`pr_url`/`merged_pr` fields) appears in the readback, and checks any follow-up. **Every rejection leaves the task claimed** and names the defect ("…; the task remains claimed"). The five verdicts and their per-verdict rules are specified under `verify-disposition` below. -Known discrepancy: `--queue` is present in help and in the client's flag list, but the source **never reads it** — it reaches no request body field. A dead flag. This chapter documents the source behaviour. +Help: `complete` takes no `--queue` flag — an earlier dead `--queue` (parsed but never read by the source) was removed from the parser and the usage (#13174). Exit codes: 0 completed · 1 disposition gate rejection (task remains claimed) · 2 usage / non-object result / unknown telemetry field · 3 transport · 4 broker store failure · 5 no matching claimed row · 6 fallback switch. diff --git a/pkgs/fleet/book/reference/serve.md b/pkgs/fleet/book/reference/serve.md index b5f76bc1bf..b613b56371 100644 --- a/pkgs/fleet/book/reference/serve.md +++ b/pkgs/fleet/book/reference/serve.md @@ -29,7 +29,7 @@ fleet serve [ ...] - Supervision is fail-fast: the supervisor polls the threads on a 100 ms tick; **the first role thread to return or panic takes the whole process down** (the external supervisor restarts the unit). The process exit code is the role's own code, except that a role exiting cleanly (code 0) is converted to exit **1** — a daemon role returning at all is abnormal — and a panic is also exit 1. The role is named on stderr either way. - One composition subtlety: the `proxy` role inside a list runs co-hosted, which **disables the proxy's idle-exit**, so an idle proxy cannot exit the shared process and kill its siblings. -Known discrepancy: a serve list has **no `--help` form at all** — appending `--help` to a two-role list is the hard error above, not help. Single-role `--help` works, but for the two brokers it returns only the generic serve domain help (see below). +Help: appending `--help` to a two-role list prints the serve domain help and exits 0 — a list has no single role to name. Single-role `--help` prints that role's own usage, for the two brokers as well (see below). If the invocation cannot use a role at all (not in this build, narrowed out by the invocation name, or disabled by config), `serve` answers with the capability stub on stderr, always **exit 69**. @@ -59,7 +59,7 @@ Runs the repo work queue as a resident service. Any trailing argument is rejecte - **Secrets dependency:** `QUEUE_BROKER_SECRETS_URL` (default `http://100.99.113.103:4800`, or `unix://` for the secrets broker's socket) and `QUEUE_BROKER_SECRETS_TOKEN_FILE` (default `~/.config/secrets-broker/token`). - **Startup ordering:** the listener binds _first_, then the Turso backend comes up on a startup thread, so `/healthz` answers immediately and queue verbs answer exit 3 with a `turso_pending` reason until the backend is ready. A backend that cannot come up within its retry budget still exits the broker with 3 so the supervisor restarts it. -Known discrepancy: there is no role-specific help for this role; `fleet serve queue-broker --help` prints the generic serve domain help. +Help: `fleet serve queue-broker --help` prints this role's own usage — the environment configuration surface below — and exits 0. ### Exit codes @@ -101,7 +101,7 @@ The broker's full semantics — the serving gate, cache-first reads, read-throug Endpoints (header `X-Agent-Token` required on everything except `/health`; identical over TCP and the Unix socket): `GET /health`, `GET /secrets` (names only, sorted), `GET /secret/`, `POST /refresh`. -Known discrepancy: there is no role-specific help for this role; `fleet serve secrets-broker --help` prints the generic serve domain help. +Help: `fleet serve secrets-broker --help` prints this role's own usage — the environment configuration surface below — and exits 0. ### Exit codes diff --git a/pkgs/fleet/book/reference/shell.md b/pkgs/fleet/book/reference/shell.md index 275a15f903..bc789454df 100644 --- a/pkgs/fleet/book/reference/shell.md +++ b/pkgs/fleet/book/reference/shell.md @@ -2,7 +2,7 @@ `fleet shell` runs a command, or opens a shell, where builds belong: the laptop, a codespace, or here. A limited sandbox is the wrong place to compile. It adds no transport; it builds the argv for the verb that already knows how to get there. The domain rides on the `agent` capability. -Known discrepancy: the top-level help for this domain lists only `targets` and hides every flag below. The flags are documented here from source (they appear only in the domain's `--help` text). A second discrepancy: the `--detach` usage error for local/codespace says "it needs --target laptop", but the actions target also accepts `--detach` with different semantics — the error string predates the actions target. +Help: `fleet shell --help` prints the shell's own usage, with every flag below. (The registry's domain help — `fleet help shell` — names only the `targets` subcommand; the flags live in the shell usage.) A standing discrepancy: the `--detach` usage error for local/codespace says "it needs --target laptop", but the actions target also accepts `--detach` with different semantics — the error string predates the actions target. See also [fleet agent](agent.md) and [fleet laptop-agent](laptop-agent.md). diff --git a/pkgs/fleet/book/tutorials/dispatch-a-build.md b/pkgs/fleet/book/tutorials/dispatch-a-build.md index 54f668fcd2..9f5bebf2d4 100644 --- a/pkgs/fleet/book/tutorials/dispatch-a-build.md +++ b/pkgs/fleet/book/tutorials/dispatch-a-build.md @@ -182,11 +182,9 @@ What can go wrong, and the fix: the handle is not in this seat's local store. Handles are local — another seat's store does not have your record. Use the portable reference instead (Step 4), which resolves live without the store. -- Do not pass `--help` to `session status` or `session result`: those - subcommands do not special-case it, so the token after the subcommand - is taken as the handle and you get exactly the "no session with handle - --help" error above. Only a bare `fleet queue session --help` prints - the usage. +- Passing `--help` to `session status` or `session result` is safe: + a help flag after the subcommand prints the session usage and exits 0 + — it is never taken as a handle. ## Step 4: Refer to a run portably diff --git a/pkgs/fleet/crates/fleet-agent/src/lib.rs b/pkgs/fleet/crates/fleet-agent/src/lib.rs index 4e85a9debc..2dcee04af9 100644 --- a/pkgs/fleet/crates/fleet-agent/src/lib.rs +++ b/pkgs/fleet/crates/fleet-agent/src/lib.rs @@ -73,6 +73,60 @@ usage: fleet agent [options] Every verb prints one JSON object. Exit: 0 ok, 2 usage, 3 a needed leg is down, 5 no work on any rung."; +/// The shared tail of every per-verb usage: how output and exit +/// codes work, whatever the verb. It is USAGE's own tail, pinned by +/// test so the two cannot drift apart. +const USAGE_FOOTER: &str = "\ +Every verb prints one JSON object. Exit: 0 ok, 2 usage, 3 a needed leg +is down, 5 no work on any rung."; + +/// Per-verb usage for `fleet agent --help` (#13175): every +/// verb used to print the one shared USAGE, so a help request for a +/// single verb answered with all of them. Unknown verbs return +/// None and the caller falls back to the shared USAGE. +pub fn verb_usage(verb: &str) -> Option { + let section = match verb { + "kinds" => { + "\ +usage: fleet agent kinds + +The agent kinds this fleet can enrol." + } + "enroll" => { + "\ +usage: fleet agent enroll --kind K --name N [--groups a,b] [--dry-run] [--profile PATH] + +Register an agent and save its profile." + } + "doctor" => { + "\ +usage: fleet agent doctor [--agent N] + +Which legs answer from this seat." + } + "next" => { + "\ +usage: fleet agent next [--agent N] [--lane L] [--repo OWNER/NAME] [--low-water N] + [--shortlist PATH] [--platform P] [--pool P] + [--remaining-budget-minutes N] [--filter EXPR] [--queue Q] + [--no-push] [--no-queue] [--no-shortlist] [--no-priority] + +The next piece of work, down the ladder: pushed command, queue, +local shortlist, highest priority." + } + "shortlist" => { + "\ +usage: fleet agent shortlist status|take|clear + fleet agent shortlist add --issue N --title T [--repo R] [--rank N] [--why TEXT] + fleet agent shortlist fill [--repo R] [--target N] + +The local list `next` draws on." + } + _ => return None, + }; + Some(format!("{section}\n\n{USAGE_FOOTER}")) +} + /// A verb's failure: a usage error or a leg that is down. #[derive(Debug, Clone, PartialEq)] pub enum AgentError { @@ -526,9 +580,16 @@ pub fn execute(world: &dyn World, args: &[String]) -> R<(Value, i32)> { /// The domain entry point: `fleet agent ...`. pub fn run(config: &Config, args: &[String]) -> i32 { - if args.is_empty() || wants_help(args) { + if args.is_empty() { println!("{USAGE}"); - return if args.is_empty() { EXIT_USAGE } else { EXIT_OK }; + return EXIT_USAGE; + } + if wants_help(args) { + match args.first().and_then(|verb| verb_usage(verb)) { + Some(text) => println!("{text}"), + None => println!("{USAGE}"), + } + return EXIT_OK; } // The sub-invocations load fleet config themselves; this domain // has no settings of its own yet. diff --git a/pkgs/fleet/crates/fleet-agent/src/tests.rs b/pkgs/fleet/crates/fleet-agent/src/tests.rs index 5ac5c94645..27e0556107 100644 --- a/pkgs/fleet/crates/fleet-agent/src/tests.rs +++ b/pkgs/fleet/crates/fleet-agent/src/tests.rs @@ -24,7 +24,10 @@ use serde_json::{Value, json}; use crate::shell::{self, Options, Target}; use crate::shortlist::{self, Entry, Shortlist}; -use crate::{AgentError, EXIT_DOWN, EXIT_NO_WORK, EXIT_OK, Out, World, argv, execute}; +use crate::{ + AgentError, EXIT_DOWN, EXIT_NO_WORK, EXIT_OK, Out, USAGE, USAGE_FOOTER, World, argv, execute, + verb_usage, +}; static NEXT_DIR: AtomicU32 = AtomicU32::new(0); @@ -3190,3 +3193,22 @@ fn the_step_limit_is_a_positive_number_of_seconds_or_the_default() { std::time::Duration::from_secs(7) ); } + +/// #13175 oracle: every agent verb has its own help — it starts +/// with the verb's own usage line, ends with the shared footer, +/// and is not the shared USAGE; USAGE itself ends with the footer +/// so the two cannot drift apart. +#[test] +fn every_agent_verb_has_its_own_help() { + for verb in ["kinds", "enroll", "doctor", "next", "shortlist"] { + let text = verb_usage(verb).unwrap_or_else(|| panic!("{verb} must have usage")); + assert!( + text.starts_with(&format!("usage: fleet agent {verb}")), + "{verb} help must open with its own usage line: {text}" + ); + assert!(text.ends_with(USAGE_FOOTER), "{verb}: {text}"); + assert_ne!(text, USAGE, "{verb} help must not be the shared text"); + } + assert!(verb_usage("bogus").is_none()); + assert!(USAGE.ends_with(USAGE_FOOTER)); +} diff --git a/pkgs/fleet/crates/fleet-laptop-agent/src/cli.rs b/pkgs/fleet/crates/fleet-laptop-agent/src/cli.rs index 62e7db13d0..2426c92b26 100644 --- a/pkgs/fleet/crates/fleet-laptop-agent/src/cli.rs +++ b/pkgs/fleet/crates/fleet-laptop-agent/src/cli.rs @@ -182,8 +182,37 @@ fn command_words(shell: bool, cmd: &[String]) -> Vec { } } +/// True when `args` asks for help: a help token before the first +/// `--` that is not the value of an option. This domain had no help +/// path at all — `poll --help` parsed `--help` as a job id and +/// polled it live (#13175). Help wins, the fleet-wide convention +/// (#10838); everything after `--` is the remote command, and an +/// option's value is the option's, even when it reads as a flag. +pub fn wants_help(args: &[String]) -> bool { + let mut i = 0; + while i < args.len() { + let a = args[i].as_str(); + if a == "--" { + break; + } + if matches!(a, "--help" | "-h" | "help") { + return true; + } + if matches!(a, "--cwd" | "--timeout" | "--wait") { + i += 2; + continue; + } + i += 1; + } + false +} + /// Entry point for `fleet laptop-agent …`: returns the process exit code. pub fn run(config: &fleet_config::Config, args: &[String]) -> i32 { + if wants_help(args) { + println!("{USAGE}"); + return 0; + } let command = match parse(args) { Ok(c) => c, Err(message) => { @@ -291,6 +320,21 @@ mod tests { assert!(parse(&v("poll job1 --wait")).is_err()); } + #[test] + fn help_tokens_win_before_any_transport() { + // The #13175 shapes: per-verb help used to fall through to + // live behaviour (a poll of a job named `--help`). + assert!(wants_help(&v("poll --help"))); + assert!(wants_help(&v("--help"))); + assert!(wants_help(&v("health --help"))); + assert!(wants_help(&v("exec --help -- ls"))); + // Not help: an option's value, and the command after `--`. + assert!(!wants_help(&v("exec --cwd --help -- ls"))); + assert!(!wants_help(&v("exec -- ls --help"))); + assert!(!wants_help(&v("poll job1 --wait 30"))); + assert!(!wants_help(&v("health"))); + } + #[test] fn unknown_verbs_and_stray_arguments_are_refused() { assert!(parse(&v("frobnicate")).is_err()); diff --git a/pkgs/fleet/crates/fleet-queue/src/client.rs b/pkgs/fleet/crates/fleet-queue/src/client.rs index 408babc136..d618314de4 100644 --- a/pkgs/fleet/crates/fleet-queue/src/client.rs +++ b/pkgs/fleet/crates/fleet-queue/src/client.rs @@ -2536,6 +2536,49 @@ esac assert!(checked >= 30, "scanned only {checked} verbs"); } + /// #13175: the parity test above cross-checks the per-verb + /// usages against the parsers, but TOP_USAGE — the text a cold + /// session reads first — drifted on its own (its fallback line + /// omitted `complete`; its lifecycle lines omitted `[--lane + /// ]`). Every single-verb TOP_USAGE line must list exactly + /// the flags of that verb's own usage synopsis. Group lines + /// (ending in `...`) summarize multi-verb surfaces whose own + /// usages carry the flags, and stay out of this check. + #[test] + fn top_usage_lines_match_per_verb_usage() { + let flags = |text: &str| -> Vec { + let mut out: Vec = text + .split(|c: char| c == ' ' || c == '[' || c == ']' || c == '|') + .filter_map(|w| w.strip_prefix("--")) + .map(|w| w.split('=').next().unwrap().to_string()) + .collect(); + out.sort(); + out.dedup(); + out + }; + let mut checked = 0; + for line in TOP_USAGE.lines() { + let line = line.trim(); + if line.is_empty() || line.ends_with("...") { + continue; + } + let verb = line.split_whitespace().next().unwrap_or(""); + let text = usage(verb); + if text == TOP_USAGE { + // Not a verb with its own usage (header lines). + continue; + } + let synopsis = text.lines().next().unwrap(); + assert_eq!( + flags(line), + flags(synopsis), + "TOP_USAGE line for {verb:?} must list exactly the flags of its usage: {line}" + ); + checked += 1; + } + assert!(checked >= 25, "checked only {checked} TOP_USAGE lines"); + } + #[test] fn bare_list_note_fires_only_on_unfiltered_list() { let bare = parse_args_inner(&[], &["queue", "status", "limit"], &[]).unwrap(); diff --git a/pkgs/fleet/crates/fleet-queue/src/client/support.rs b/pkgs/fleet/crates/fleet-queue/src/client/support.rs index 68c401f6ab..1e1426d179 100644 --- a/pkgs/fleet/crates/fleet-queue/src/client/support.rs +++ b/pkgs/fleet/crates/fleet-queue/src/client/support.rs @@ -191,21 +191,21 @@ Run `repo-queue --help` for flags:\n\ enqueue [--queue ] [--platform

] [--dry-run] [--shadow-intent]\n\ list [--queue ] [--status ] [--limit ] [--not-before ] [--lane ] [--worker ] [--task ]\n\ claim [--queue ] [--worker ] [--lease-seconds ] [--lane ] [--task ] [--count ] [--from-session ] [--platform

] [--session-id ] [--model-provider

] [--model-id ] [--model-variant ] [--filter ] [--pool

] [--launched-by ] [--remaining-budget-minutes ] [--handoff] [--bind]\n\ - release [--worker ] --reason \n\ + release [--worker ] [--lane ] --reason \n\ lane [--worker ] [--exclusion-reason ] [--opencode-reason ] [--limit-platform

] [--limit-reason ] [--clear-platform-limit]\n\ bind [--worker ] --session-id [--launched-by ] [--model-provider

] [--model-id ] [--model-variant ]\n\ - heartbeat [--worker ] [--extend-seconds ] [--progress

] [--progress-file ]\n\ - checkpoint [--worker ] --stage [--progress

] [--progress-file ]\n\ - park [--worker ] --reason [--delay-seconds ] [--not-before ] [--progress

] [--progress-file ] [--ready-condition ] [--execution ] [--required-budget-minutes ] [--hands --action ]\n\ + heartbeat [--worker ] [--lane ] [--extend-seconds ] [--progress

] [--progress-file ]\n\ + checkpoint [--worker ] [--lane ] --stage [--progress

] [--progress-file ]\n\ + park [--worker ] [--lane ] --reason [--delay-seconds ] [--not-before ] [--progress

] [--progress-file ] [--ready-condition ] [--execution ] [--required-budget-minutes ] [--hands --action ]\n\ wake [--worker ] [--reason ]\n\ - block [--worker ] --reason-class --blocker [--progress

] [--progress-file ] [--ledger-id ] [--question ] [--context ] [--options-json ] [--links-json ] [--blocked-by-pr ] [--blocked-by-issue ] [--blocked-by-task ] [--blocked-by-ci ] [--dep-recheck-seconds ] [--dep-max-ttl-seconds ] [--hands --action ]\n\ + block [--worker ] [--lane ] --reason-class --blocker [--progress

] [--progress-file ] [--ledger-id ] [--question ] [--context ] [--options-json ] [--links-json ] [--blocked-by-pr ] [--blocked-by-issue ] [--blocked-by-task ] [--blocked-by-ci ] [--dep-recheck-seconds ] [--dep-max-ttl-seconds ] [--hands --action ]\n\ unblock [--worker ] [--reason ] [--drop-dep ]\n\ dep-recheck [--task ] [--limit ]\n\ quarantine-recheck [--task ] [--limit ]\n\ cancel [--worker ] --reason \n\ revive [--worker ] [--reason ] [--not-before ]\n\ - fail [--worker ] --error [--reason-class ] [--execution ]\n\ - complete [--worker ] [--result ] [--result-file ] [--telemetry ] [--execution ]\n\ + fail [--worker ] [--lane ] --error [--reason-class ] [--execution ]\n\ + complete [--worker ] [--lane ] [--result ] [--result-file ] [--telemetry ] [--execution ]\n\ verify-disposition --repo [--pr ] [--follow-up-task | --follow-up-issue | --follow-up-pr ] [--reason ] [--staleness-seconds ] [--json]\n\ timeline [--worker ] [--json]\n\ history [--worker ] [--json] (alias of timeline)\n\ @@ -213,7 +213,7 @@ Run `repo-queue --help` for flags:\n\ models [--days ] [--json]\n\ health [--queue ] [--worker ]\n\ signal [--queue ] [--reason ]\n\ - fallback ...\n\ + fallback ...\n\ outbox ...\n\ dispatch|session|surfaces ...\n\ stack ..."; diff --git a/pkgs/fleet/crates/fleet-queue/src/fallback.rs b/pkgs/fleet/crates/fleet-queue/src/fallback.rs index 8e9cf31bf8..4574150b49 100644 --- a/pkgs/fleet/crates/fleet-queue/src/fallback.rs +++ b/pkgs/fleet/crates/fleet-queue/src/fallback.rs @@ -810,7 +810,7 @@ usage: repo-queue fallback --help`\n\ for flags:\n\ - scan (--repo/--limit/--lease-min live on scan)\n\ + scan [--repo ] [--limit <1..100>] [--lease-min ]\n\ status \n\ claim --worker \n\ heartbeat --worker \n\ diff --git a/pkgs/fleet/crates/fleet-queue/src/placement.rs b/pkgs/fleet/crates/fleet-queue/src/placement.rs index 439b8e2e6c..49a2f9aac9 100644 --- a/pkgs/fleet/crates/fleet-queue/src/placement.rs +++ b/pkgs/fleet/crates/fleet-queue/src/placement.rs @@ -1866,9 +1866,23 @@ fn run_dispatch(args: &[String]) -> R { const SESSION_USAGE: &str = "usage: repo-queue session [HANDLE|OWNER/REPO#RUN_ID] \ [--mine] [--json] [--registry PATH]"; +/// True when a session subcommand's tail asks for help. A help flag +/// is never a session handle: `session status --help` used to look +/// up a session literally named `--help` and error (#13175). +fn session_help_requested(sub: &str, rest: &[String]) -> bool { + matches!(sub, "status" | "result" | "list") + && rest + .get(1..) + .is_some_and(|tail| tail.iter().any(|a| matches!(a.as_str(), "--help" | "-h"))) +} + fn run_session(args: &[String]) -> R { let (cli, rest) = extract_common(args)?; let sub = rest.first().map(|s| s.as_str()).unwrap_or(""); + if session_help_requested(sub, &rest) { + println!("{SESSION_USAGE}"); + return Ok(0); + } let gh = RealGh::new(); // #13146: the session mirror to the queue backend (best-effort). let remote = remote::session_remote(); @@ -2007,8 +2021,14 @@ fn run_session(args: &[String]) -> R { } } +const SURFACES_USAGE: &str = "usage: repo-queue surfaces [--json] [--registry PATH]\n\nPrints the placement surface registry as JSON."; + fn run_surfaces(args: &[String]) -> R { - let (cli, _rest) = extract_common(args)?; + let (cli, rest) = extract_common(args)?; + if rest.iter().any(|a| matches!(a.as_str(), "--help" | "-h")) { + println!("{SURFACES_USAGE}"); + return Ok(0); + } let registry = registry_value(&cli)?; println!( "{}", @@ -3248,4 +3268,26 @@ mod tests { assert_eq!(jobs[0]["cache"]["actions_restore_keys"][1], "rust-code-"); assert_eq!(inputs["dispatch_id"], "fp_test"); } + + /// #13175 oracle: a help flag after a session subcommand is a + /// help request, never a handle; a real handle is not. + #[test] + fn session_help_flag_is_not_a_handle() { + let args = |xs: &[&str]| xs.iter().map(|x| x.to_string()).collect::>(); + assert!(session_help_requested( + "status", + &args(&["status", "--help"]) + )); + assert!(session_help_requested("result", &args(&["result", "-h"]))); + assert!(session_help_requested("list", &args(&["list", "--help"]))); + assert!(!session_help_requested( + "status", + &args(&["status", "fp_abc123"]) + )); + assert!(!session_help_requested("status", &args(&["status"]))); + assert!(!session_help_requested( + "bogus", + &args(&["bogus", "--help"]) + )); + } } diff --git a/pkgs/fleet/crates/fleet/src/gh.rs b/pkgs/fleet/crates/fleet/src/gh.rs index 2951e40261..c9ab50110e 100644 --- a/pkgs/fleet/crates/fleet/src/gh.rs +++ b/pkgs/fleet/crates/fleet/src/gh.rs @@ -168,6 +168,7 @@ Usage: fleet gh fleet gh tiers fleet gh cache-serve [--bind ] fleet gh cache-status + fleet gh closures [] fleet gh [--cache-addr ...] [--no-cache] fleet gh --raw @@ -1355,6 +1356,20 @@ fn emit(attempt: &Attempt) { let _ = err.flush(); } +const TIERS_USAGE: &str = "\ +Usage: fleet gh tiers + +Probe every token-rotation source (the personal token, then the +fleet's three GitHub Apps' installation tokens) and print each +one's rate-limit headroom. Takes no arguments."; + +const CLOSURES_USAGE: &str = "\ +Usage: fleet gh closures [] + +Print the close-guard closure records, one JSON object per line, +optionally only those for one item number. Takes no other +arguments."; + /// `fleet gh tiers`: probe every rotation source and print its /// core and GraphQL rate-limit headroom. Labels and numbers only — /// token values never leave the provider. Exit 0 when every source @@ -1483,6 +1498,10 @@ pub fn run(config: &Config, args: &[String]) -> i32 { // subcommands: real `gh` has no such verbs, so intercepting // them cannot shadow a passthrough call. if args.first().is_some_and(|a| a == "tiers") { + if args.len() == 2 && matches!(args[1].as_str(), "--help" | "-h") { + println!("{TIERS_USAGE}"); + return EXIT_OK; + } if args.len() > 1 { return usage_error(&format!( "unexpected argument '{}' for 'fleet gh tiers'", @@ -1638,6 +1657,10 @@ pub fn run(config: &Config, args: &[String]) -> i32 { /// `fleet gh closures []`: print closure records, one JSON /// object per line, optionally only those for one item number. fn run_closures(tail: &[String]) -> i32 { + if tail.len() == 1 && matches!(tail[0].as_str(), "--help" | "-h") { + println!("{CLOSURES_USAGE}"); + return EXIT_OK; + } if tail.len() > 1 { return usage_error(&format!( "unexpected argument '{}' for 'fleet gh closures'", diff --git a/pkgs/fleet/crates/fleet/src/main.rs b/pkgs/fleet/crates/fleet/src/main.rs index ef9a9073a1..bf07a8812b 100644 --- a/pkgs/fleet/crates/fleet/src/main.rs +++ b/pkgs/fleet/crates/fleet/src/main.rs @@ -787,6 +787,48 @@ fn run_domain_with_initializer( println!("{SERVE_PROXY_USAGE}"); return EXIT_OK; } + // The broker roles have their own usage too (#13175): `fleet + // serve queue-broker --help` asks for the role's help, not the + // serve domain's — the same carve-out the proxy role gets above. + if d.name == "serve" && args.get(1).is_some_and(|a| is_help_flag(a)) { + match args.first().map(|s| s.as_str()) { + Some("queue-broker") => { + println!("{SERVE_QUEUE_BROKER_USAGE}"); + return EXIT_OK; + } + Some("secrets-broker") => { + println!("{SERVE_SECRETS_BROKER_USAGE}"); + return EXIT_OK; + } + _ => {} + } + } + // A serve LIST has no single role to name: `fleet serve + // queue-broker secrets-broker --help` used to die in the list + // parser ("a serve list is role tokens only"). The serve + // domain help answers it (#13175). + if d.name == "serve" + && args.len() > 2 + && ServeRole::from_token(&args[0]).is_some() + && ServeRole::from_token(&args[1]).is_some() + && args[2..].iter().any(|a| is_help_flag(a)) + { + print_domain_help(surface, d); + return EXIT_OK; + } + // The shell domain's own usage answers `fleet shell --help` + // (#13175): the registry's domain help names only the `targets` + // subcommand and hides every flag, while fleet-agent's shell + // usage is the documented surface — the same carve-out the + // search client gets above (#12782). Routing through run_shell + // lets its own help handling print that usage. + #[cfg(feature = "agent")] + if d.name == "shell" + && args.first().is_some_and(|a| is_help_flag(a)) + && surface.cap_state(Capability::Agent, d.name) == CapState::Available + { + return fleet_agent::run_shell(&surface.config, args); + } // Domain help is registry data: always available, even where the // domain itself is not (§3). if wants_domain_help(d, args) { @@ -963,6 +1005,23 @@ fn run_domain_with_initializer( } } +const SERVE_QUEUE_BROKER_USAGE: &str = "\ +Usage: fleet serve queue-broker + +Run the queue broker in the foreground. The role takes no +arguments; configuration is by environment: QUEUE_BROKER_BIND +(default 100.99.113.103:4801), QUEUE_BROKER_TOKEN_FILE, +QUEUE_BROKER_BACKEND and the QUEUE_BROKER_TURSO_URL / +QUEUE_BROKER_TURSO_TOKEN_FILE pair for the Turso backend."; + +const SERVE_SECRETS_BROKER_USAGE: &str = "\ +Usage: fleet serve secrets-broker + +Run the secrets broker in the foreground. The role takes no +arguments; configuration is by environment: SECRETS_BROKER_BIND +(default 100.99.113.103:4800), SECRETS_BROKER_TOKEN_FILE and +SECRETS_BROKER_TTL_S."; + const SERVE_PROXY_USAGE: &str = "\ Usage: fleet serve proxy @@ -1398,6 +1457,33 @@ fn reject_extra_args(args: &[String]) -> Option { }) } +const VERSION_USAGE: &str = "\ +usage: fleet version + +Print the version, build, source revision and enabled +capabilities of this fleet binary. Takes no arguments."; + +const CAPABILITIES_USAGE: &str = "\ +usage: fleet capabilities + +Print this invocation's capability report as JSON: every domain +with its state in this build, and the usable capability set. +Takes no arguments."; + +const HELP_USAGE: &str = "\ +usage: fleet help + +Print one domain's registry help: its summary, commands and +status in this build. With no argument, `fleet --help` prints +the full registry."; + +/// True when a built-in's tail is exactly one help flag: `fleet +/// version --help` asks what the built-in does (#13175) — it is +/// not an unexpected argument. +fn is_help_only_tail(tail: &[String]) -> bool { + tail.len() == 1 && is_help_flag(&tail[0]) +} + fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { let first = args.first().map(|s| s.as_str()); match first { @@ -1413,6 +1499,10 @@ fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { print_help(surface); EXIT_OK } + Some("help") if is_help_only_tail(&args[1..]) => { + println!("{HELP_USAGE}"); + EXIT_OK + } Some("help") => match args.get(1).and_then(|name| domain(name)) { Some(d) => { // `help` takes exactly one argument — the domain name. @@ -1440,6 +1530,10 @@ fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { EXIT_OK } Some("version") => { + if is_help_only_tail(&args[1..]) { + println!("{VERSION_USAGE}"); + return EXIT_OK; + } if let Some(code) = reject_extra_args(args) { return code; } @@ -1447,6 +1541,10 @@ fn run_root(surface: &Surface, args: &[String], invoked_as: &str) -> i32 { EXIT_OK } Some("capabilities") => { + if is_help_only_tail(&args[1..]) { + println!("{CAPABILITIES_USAGE}"); + return EXIT_OK; + } if let Some(code) = reject_extra_args(args) { return code; } @@ -1924,6 +2022,75 @@ mod tests { ); } + #[test] + fn builtin_help_flags_print_usage_instead_of_erroring() { + // #13175: the root built-ins rejected --help as an unexpected + // argument (exit 2). A lone help flag now prints the built-in's + // own usage and exits 0; a further argument still errors. + let surface = Surface::new(None, fleet_config::Config::default()); + for cmd in ["version", "capabilities", "help"] { + assert_eq!( + run_root(&surface, &args(&[cmd, "--help"]), "fleet"), + EXIT_OK, + "{cmd} --help must print its usage" + ); + assert_eq!( + run_root(&surface, &args(&[cmd, "--help", "extra"]), "fleet"), + EXIT_USAGE, + "{cmd} --help with a further argument still errors" + ); + } + } + + #[test] + fn serve_broker_role_help_prints_the_role_usage() { + // #13175: `fleet serve --help` used to print the + // generic serve domain help; the role's own usage now answers, + // like the proxy and search roles. + let serve = domain("serve").expect("serve domain exists"); + let surface = Surface::new(None, fleet_config::Config::default()); + for role in ["queue-broker", "secrets-broker"] { + assert_eq!( + run_domain(&surface, serve, &args(&[role, "--help"]), "fleet"), + EXIT_OK, + "fleet serve {role} --help must print the role usage" + ); + } + } + + #[test] + fn shell_help_prints_the_shell_usage() { + // #13175: `fleet shell --help` used to print the registry's + // domain help, which names only the `targets` subcommand and + // hides every flag; the shell's own usage now answers. + let shell = domain("shell").expect("shell domain exists"); + let surface = Surface::new(None, fleet_config::Config::default()); + assert_eq!( + run_domain(&surface, shell, &args(&["--help"]), "fleet"), + EXIT_OK, + "fleet shell --help must print the shell usage" + ); + } + + #[test] + fn serve_list_help_prints_domain_help_instead_of_erroring() { + // #13175: a role list plus --help was the list parser's hard + // error ("a serve list is role tokens only"); the serve + // domain help now answers it. + let serve = domain("serve").expect("serve domain exists"); + let surface = Surface::new(None, fleet_config::Config::default()); + assert_eq!( + run_domain( + &surface, + serve, + &args(&["queue-broker", "secrets-broker", "--help"]), + "fleet" + ), + EXIT_OK, + "a serve list with --help must print help, not the list error" + ); + } + #[test] fn serve_list_parses_two_or_more_distinct_roles() { let list = parse_serve_list(&args(&["queue-broker", "secrets-broker"]))