Commit 843aaff
committed
Merge torrust#869: feat!: Global command-line output contract (ADR-T-010)
5a6dab0 feat(cli): surface panic payloads in debug diagnostics (Peer Cat)
503e90e fix(container): decouple debug runtime binary from nextest archive (Peer Cat)
c68a626 docs(cli): consolidate ADR-T-010 implementation record (Peer Cat)
c430995 test(cli): add ADR-T-010 regression guards (Peer Cat)
d07fee7 docs(cli): refresh ADR-T-010 command examples (Peer Cat)
4089926 feat(cli)!: migrate container entry script to ADR-T-010 (Peer Cat)
0dd220b feat(cli)!: complete ADR-T-010 shared-library cleanup (Peer Cat)
685ad5a feat(cli)!: migrate maintenance commands to ADR-T-010 (Peer Cat)
b5332e1 feat(cli)!: migrate torrent helpers to ADR-T-010 (Peer Cat)
e8adbff feat(cli)!: implement ADR-T-010 root JSON logging boundary (Peer Cat)
c9faf16 feat(cli)!: implement ADR-T-010 helper control plane (Cameron Garnham)
4bbb32c feat(cli)!: implement ADR-T-010 stage-one output contract (Cameron Garnham)
ceba40e docs(adr-010): establish global CLI output contract (Cameron Garnham)
Pull request description:
## Summary
Lands ADR-T-010 end to end: every shipped, documented, or operator-facing first-party Torrust Index command-line entrypoint now follows one JSON-only stream contract.
Stdout is reserved for machine-readable result data. Stderr carries machine-readable diagnostics and control records as JSON/NDJSON. Commands that emit stdout result data refuse direct terminal stdout, so automation cannot accidentally mix data streams with human-facing diagnostics.
> ⚠ **Breaking for operators and scripts.** Any automation that scraped previous plain-text output from helper binaries, root maintenance commands, `parse_torrent`, server logs, or container startup must switch to exit codes plus JSON/NDJSON parsing.
## Why
ADR-T-009 introduced strict stream rules for container helper binaries, but the underlying problem was repository-wide: every CLI entrypoint had its own stdout/stderr behavior.
That made shell integration brittle:
- helper JSON could be corrupted by plain diagnostics;
- `clap` help/errors and Rust panic output could still leak raw text;
- server and maintenance logs were not consistently machine-readable;
- `parse_torrent` and maintenance tools mixed operator text with command results;
- container startup used plain text and `DEBUG=1` shell tracing instead of structured records;
- command-reachable libraries could still print or exit outside the command boundary.
This PR promotes the helper contract into a global CLI contract and migrates the existing command surface to match it.
## Highlights
- **ADR-T-010 becomes canonical.** [adr/010-global-command-line-output-contract.md](adr/010-global-command-line-output-contract.md) now records the completed repository-wide contract, command classifications, shared schema, implementation summary, redaction policy, and guards.
- **Shared CLI infrastructure.** `torrust-index-cli-common` now owns JSON `clap` help/version/usage handling, stderr control-plane records, baseline exit classes, JSON panic diagnostics, JSON tracing setup, TTY refusal, stdout JSON emission, command runners, locked stderr writes, and redaction helpers.
- **Helper binaries migrated.** `torrust-index-auth-keypair`, `torrust-index-config-probe`, and `torrust-index-health-check` now share the same JSON control plane. Successful stdout payloads are single JSON objects with a top-level `schema` field; help, version, argv errors, TTY refusal, panic diagnostics, and tracing go to stderr as JSON.
- **Server logging boundary migrated.** `torrust-index` now emits JSON tracing records on stderr. The configured logging threshold remains the default filter, while non-empty `RUST_LOG` takes precedence. Binary entrypoints return explicit `ExitCode` values instead of relying on Rust default termination.
- **Torrent helper commands migrated.** `parse_torrent` is now a stdout-result command emitting `schema`, `torrent`, `original_v1_info_hash`, and `input_byte_length`. `create_test_torrent` is a no-stdout side-effect command with JSON stderr diagnostics.
- **Maintenance commands migrated.** `import_tracker_statistics`, `seeder`, and `upgrade` now keep stdout empty and emit help, usage errors, status, diagnostics, tracing, and panic records as JSON/NDJSON on stderr.
- **Upgrade path hardened.** The v1-to-v2 upgrader now propagates typed errors for setup, migrations, transfer validation, torrent decoding, missing fields, and timestamp conversion instead of relying on plain output, color formatting, unwraps, or panic-driven failures.
- **Command-reachable libraries cleaned up.** Shutdown notices use structured tracing, mail template failures are returned to callers, terminal color formatting is removed from command paths, and parsing helpers leave reporting to their command callers.
- **Container entry script migrated.** Startup validation failures, status notices, expected utility failures, `jq` failures, unexpected shell exits, and `DEBUG=1` phase records now emit JSON/NDJSON on stderr. Helper stdout stays internal to command substitutions.
- **Regression guards added.** Workspace Clippy now denies accidental raw `print_stdout`, `print_stderr`, and direct `exit` usage outside approved boundaries, and [tests/cli_contract.rs](tests/cli_contract.rs) keeps in-scope binaries returning `ExitCode`.
## Breaking Changes
| Surface | Before | After |
|---|---|---|
| CLI stream contract | Per-command stdout/stderr behavior | ADR-T-010 JSON-only contract across first-party entrypoints |
| Server logs | Human-formatted tracing output | JSON records on stderr |
| Helper stdout schemas | Some payloads lacked explicit schema versioning | Successful helper payloads include top-level `schema` |
| Helper help/errors/panics | Plain `clap` or Rust panic text could reach stderr | JSON control-plane records on stderr |
| `parse_torrent` | Legacy plain-text CLI behavior | Single JSON stdout result; refuses direct terminal stdout |
| `create_test_torrent` | Plain status/diagnostic output | Empty stdout; JSON/NDJSON stderr |
| `import_tracker_statistics`, `seeder`, `upgrade` | Plain status/errors and panic/unwrap paths | Empty stdout; JSON/NDJSON stderr; explicit exit codes |
| Container entry script | Plain startup text and `DEBUG=1` / `set -x` tracing | JSON/NDJSON stderr records and explicit debug phase records |
| Command libraries | Some direct printing/exiting/color formatting | Structured diagnostics returned or logged through the command boundary |
## Operator Migration
Stdout-producing commands should be piped or redirected before inspection:
```sh
torrust-index-auth-keypair | jq .
torrust-index-config-probe | jq .
torrust-index-health-check http://127.0.0.1:3001/health_check | jq .
cargo run --quiet --bin parse_torrent -- "$fixture" | jq .'
```
## Credits
Thank-you for @da2ce7 for writing the ADR 10, and starting the work.
ACKs for top commit:
peer-cat:
ACK 5a6dab0
da2ce7:
ACK 5a6dab0
Tree-SHA512: 3253c4d6cc995fc468e730925bc7a7f59087356f30d2a2b109f69d0cc6c216c0cf8e18941549b2a78814e426963d7600a917d905e4ae3c72ed2d4445b068dd6474 files changed
Lines changed: 3898 additions & 936 deletions
File tree
- adr
- docs
- packages
- index-auth-keypair
- src
- bin
- tests
- tests
- index-cli-common
- src
- tests
- tests
- index-config-probe/src/bin
- index-config/src
- index-entry-script
- src
- tests
- index-health-check
- src
- bin
- tests
- tests
- mudlark
- src
- testing
- tests
- tests
- render-text-as-image/examples
- src
- bin
- bootstrap
- console
- commands
- seeder
- tracker_statistics_importer
- cronjobs
- tracker
- upgrades/from_v1_0_0_to_v2_0_0
- databases
- transferrers
- utils
- web/api/server
- tests
- common/contexts/torrent
- e2e/web/api/v1/contexts/torrent
- upgrades/from_v1_0_0_to_v2_0_0
- transferrer_testers
- upgrades/from_v1_0_0_to_v2_0_0
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
18 | 36 | | |
19 | 37 | | |
20 | 38 | | |
| |||
57 | 75 | | |
58 | 76 | | |
59 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
60 | 128 | | |
61 | 129 | | |
62 | 130 | | |
| |||
67 | 135 | | |
68 | 136 | | |
69 | 137 | | |
70 | | - | |
| 138 | + | |
71 | 139 | | |
72 | 140 | | |
73 | 141 | | |
| |||
126 | 194 | | |
127 | 195 | | |
128 | 196 | | |
129 | | - | |
| 197 | + | |
130 | 198 | | |
131 | 199 | | |
132 | 200 | | |
| |||
391 | 459 | | |
392 | 460 | | |
393 | 461 | | |
394 | | - | |
395 | | - | |
| 462 | + | |
| 463 | + | |
396 | 464 | | |
397 | 465 | | |
398 | 466 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | | - | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
| |||
139 | 138 | | |
140 | 139 | | |
141 | 140 | | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
| |||
98 | 104 | | |
99 | 105 | | |
100 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
101 | 114 | | |
102 | 115 | | |
103 | 116 | | |
| |||
314 | 327 | | |
315 | 328 | | |
316 | 329 | | |
| 330 | + | |
| 331 | + | |
317 | 332 | | |
318 | 333 | | |
319 | 334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
165 | 249 | | |
166 | 250 | | |
167 | 251 | | |
| |||
177 | 261 | | |
178 | 262 | | |
179 | 263 | | |
| 264 | + | |
180 | 265 | | |
181 | 266 | | |
182 | 267 | | |
| |||
0 commit comments