trusty-mpm 1.3.5

trusty-mpm: unified multi-agent orchestration platform (core, daemon, CLI, TUI, Telegram)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//! CLI parse tests for the `tm projects` verb tree (DOC-35 §3.1/§10.8).
//!
//! Why: `tm projects` (#2115) and its `deliverables`/`milestones` subtrees
//! (#2381) build a large clap namespace; a parse test per verb pins the exact
//! flag/positional shape so a rename or a moved flag fails loudly here rather
//! than silently at runtime. Split into its own file to keep `tests.rs` under the
//! test-file line cap.
//! What: `Cli::try_parse_from` round-trips for every projects verb, asserting the
//! parsed `Command`/action variant and its salient fields.
//! Test: this file is the test.

use clap::Parser;

use crate::cli::{
    Cli, Command, DeliverableKindArg, DeliverableStatusArg, DeliverablesAction, EstimationTierArg,
    MilestonesAction, ProjectsAction,
};

/// Assert `argv` parses to a `Command::Projects` and hand its action to `check`.
///
/// `pub(crate)`: reused by the sibling `tests_projects_config_tests.rs`
/// (#2120's config-subtree tests, split out to stay under this file's
/// 500-SLOC cap — see the comment above the `config` subtree marker below).
pub(crate) fn projects_action(argv: &[&str]) -> ProjectsAction {
    let cli = Cli::try_parse_from(argv).expect("parse");
    match cli.command.expect("subcommand") {
        Command::Projects { action } => action,
        other => panic!("expected Command::Projects, got {other:?}"),
    }
}

/// #2118: `ProjectsAction` stays a MANDATORY clap subcommand — a bare
/// `tm projects` (no verb) must still fail to parse with a clap usage error,
/// unchanged from before #2118. The interactive-TTY TUI launch is intercepted
/// in `main.rs` BEFORE `Cli::try_parse()` even runs (see
/// `commands::projects::is_bare_projects_argv`), so it never reaches this
/// parse path at all.
///
/// Why this asserts `exit_code()` rather than a specific `ErrorKind`: clap's
/// internal validator (`clap_builder`'s `parser::validator::Validator::validate`)
/// checks `is_arg_required_else_help_set()` BEFORE `is_subcommand_required_set()`
/// — whichever is true first decides between
/// `ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand` and
/// `ErrorKind::MissingSubcommand`. That internal, non-`Option`-derived
/// resolution was observed to differ between this project's local dev
/// environment (always `MissingSubcommand`, confirmed via
/// `cargo test --workspace` too, not just `-p trusty-mpm`) and CI's Linux
/// runner (`DisplayHelpOnMissingArgumentOrSubcommand`) despite an identical
/// locked `clap_builder` version (4.6.0, verified via `Cargo.lock`) — i.e. it
/// is not this project's dependency resolution that differs. Both kinds are
/// `Stream::Stderr` in `clap_builder`'s `error::Error::stream()` (only
/// `DisplayHelp`/`DisplayVersion` map to `Stream::Stdout`), so both share
/// `exit_code() == 2` regardless of which one fires — that shared, portable
/// contract (a non-zero exit, not clap's internal error-kind taxonomy) is
/// what `main.rs`'s bare-invocation interception actually depends on, so it
/// is what this test pins.
/// Test: this test.
#[test]
fn cli_rejects_bare_projects_with_a_usage_error() {
    let err =
        Cli::try_parse_from(["tm", "projects"]).expect_err("bare `projects` must fail to parse");
    assert_eq!(err.exit_code(), 2);
    assert!(
        matches!(
            err.kind(),
            clap::error::ErrorKind::MissingSubcommand
                | clap::error::ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand
        ),
        "expected a 'needs a subcommand' usage error, got {:?}",
        err.kind()
    );
}

// ───────────────────────── registry verbs (#2115) ─────────────────────────

#[test]
fn cli_parses_projects_list_bare() {
    match projects_action(&["trusty-mpm", "projects", "list"]) {
        ProjectsAction::List { json, tag } => {
            assert!(!json);
            assert_eq!(tag, None);
        }
        other => panic!("expected list, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_list_json_and_tag() {
    match projects_action(&[
        "trusty-mpm",
        "projects",
        "list",
        "--json",
        "--tag",
        "backend",
    ]) {
        ProjectsAction::List { json, tag } => {
            assert!(json);
            assert_eq!(tag.as_deref(), Some("backend"));
        }
        other => panic!("expected list, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_register_full() {
    let action = projects_action(&[
        "trusty-mpm",
        "projects",
        "register",
        "widget",
        "--repo-url",
        "https://github.com/acme/widget",
        "--default-branch",
        "develop",
        "--description",
        "the widget",
        "--tags",
        "backend,oss",
        "--stack-hint",
        "rust",
        "--gh-user",
        "acme-bot",
        "--gh-account",
        "acme-bot",
    ]);
    match action {
        ProjectsAction::Register {
            name,
            repo_url,
            default_branch,
            description,
            tags,
            stack_hint,
            gh_user,
            gh_account,
        } => {
            assert_eq!(name, "widget");
            assert_eq!(repo_url, "https://github.com/acme/widget");
            assert_eq!(default_branch.as_deref(), Some("develop"));
            assert_eq!(description.as_deref(), Some("the widget"));
            assert_eq!(tags, vec!["backend".to_string(), "oss".to_string()]);
            assert_eq!(stack_hint.as_deref(), Some("rust"));
            assert_eq!(gh_user.as_deref(), Some("acme-bot"));
            assert_eq!(gh_account.as_deref(), Some("acme-bot"));
        }
        other => panic!("expected register, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_register_minimal() {
    match projects_action(&[
        "trusty-mpm",
        "projects",
        "register",
        "minimal",
        "--repo-url",
        "https://github.com/acme/minimal",
    ]) {
        ProjectsAction::Register {
            name,
            repo_url,
            default_branch,
            tags,
            ..
        } => {
            assert_eq!(name, "minimal");
            assert_eq!(repo_url, "https://github.com/acme/minimal");
            assert_eq!(default_branch, None);
            assert!(tags.is_empty());
        }
        other => panic!("expected register, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_show() {
    match projects_action(&["trusty-mpm", "projects", "show", "widget", "--json"]) {
        ProjectsAction::Show { name, json } => {
            assert_eq!(name, "widget");
            assert!(json);
        }
        other => panic!("expected show, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_status() {
    match projects_action(&["trusty-mpm", "projects", "status", "widget"]) {
        ProjectsAction::Status { name, json } => {
            assert_eq!(name, "widget");
            assert!(!json);
        }
        other => panic!("expected status, got {other:?}"),
    }
}

// `config` subtree (§3.1/§6, #2120) parse + shared-suite tests live in the
// sibling `tests_projects_config_tests.rs` (split out to stay under this
// file's 500-SLOC production cap — that file's `_tests.rs` suffix gives it
// the 1500-SLOC test-file cap instead; see its module doc).

// ─────────────────────── deliverables subtree (#2381) ──────────────────────

fn deliverables_action(argv: &[&str]) -> DeliverablesAction {
    match projects_action(argv) {
        ProjectsAction::Deliverables { action } => action,
        other => panic!("expected deliverables, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_deliverables_list_with_status() {
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "list",
        "widget",
        "--status",
        "in-progress",
        "--json",
    ]) {
        DeliverablesAction::List {
            project,
            json,
            status,
        } => {
            assert_eq!(project, "widget");
            assert!(json);
            assert_eq!(status, Some(DeliverableStatusArg::InProgress));
        }
        other => panic!("expected list, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_deliverables_add() {
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "add",
        "widget",
        "--name",
        "OAuth2 flow",
        "--kind",
        "feature",
        "--estimate",
        "L",
        "--spec-ref",
        "docs/specs/tm-project-control-plane.md",
        "--ticket-ref",
        "#2117",
    ]) {
        DeliverablesAction::Add {
            project,
            name,
            kind,
            estimate,
            spec_ref,
            ticket_ref,
            ..
        } => {
            assert_eq!(project, "widget");
            assert_eq!(name, "OAuth2 flow");
            assert_eq!(kind, DeliverableKindArg::Feature);
            assert_eq!(estimate, EstimationTierArg::L);
            assert_eq!(
                spec_ref.as_deref(),
                Some("docs/specs/tm-project-control-plane.md")
            );
            assert_eq!(ticket_ref.as_deref(), Some("#2117"));
        }
        other => panic!("expected add, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_deliverables_create_alias() {
    // `create` is an accepted alias of `add` (the prompt's spelling).
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "create",
        "widget",
        "--name",
        "x",
        "--kind",
        "bugfix",
        "--estimate",
        "S",
    ]) {
        DeliverablesAction::Add { kind, estimate, .. } => {
            assert_eq!(kind, DeliverableKindArg::Bugfix);
            assert_eq!(estimate, EstimationTierArg::S);
        }
        other => panic!("expected add (via create alias), got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_deliverables_show() {
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "show",
        "widget",
        "00000000-0000-0000-0000-000000000001",
    ]) {
        DeliverablesAction::Show { project, id, json } => {
            assert_eq!(project, "widget");
            assert_eq!(id, "00000000-0000-0000-0000-000000000001");
            assert!(!json);
        }
        other => panic!("expected show, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_deliverables_set_status() {
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "set-status",
        "widget",
        "00000000-0000-0000-0000-000000000001",
        "complete",
    ]) {
        DeliverablesAction::SetStatus {
            project,
            id,
            status,
        } => {
            assert_eq!(project, "widget");
            assert_eq!(id, "00000000-0000-0000-0000-000000000001");
            assert_eq!(status, DeliverableStatusArg::Complete);
        }
        other => panic!("expected set-status, got {other:?}"),
    }
}

#[test]
fn cli_parses_estimate_xl_uppercase() {
    // The estimation tier value names are the exact uppercase letters.
    match deliverables_action(&[
        "trusty-mpm",
        "projects",
        "deliverables",
        "add",
        "widget",
        "--name",
        "x",
        "--kind",
        "chore",
        "--estimate",
        "XL",
    ]) {
        DeliverablesAction::Add { estimate, .. } => {
            assert_eq!(estimate, EstimationTierArg::Xl);
        }
        other => panic!("expected add, got {other:?}"),
    }
}

// ──────────────────────── milestones subtree (#2381) ───────────────────────

fn milestones_action(argv: &[&str]) -> MilestonesAction {
    match projects_action(argv) {
        ProjectsAction::Milestones { action } => action,
        other => panic!("expected milestones, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_milestones_list() {
    match milestones_action(&["trusty-mpm", "projects", "milestones", "list", "widget"]) {
        MilestonesAction::List { project, json } => {
            assert_eq!(project, "widget");
            assert!(!json);
        }
        other => panic!("expected list, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_milestones_add() {
    match milestones_action(&[
        "trusty-mpm",
        "projects",
        "milestones",
        "add",
        "widget",
        "--name",
        "v1.0 Alpha",
        "--target-date",
        "2026-09-01T00:00:00Z",
    ]) {
        MilestonesAction::Add {
            project,
            name,
            target_date,
            ..
        } => {
            assert_eq!(project, "widget");
            assert_eq!(name, "v1.0 Alpha");
            assert_eq!(target_date, "2026-09-01T00:00:00Z");
        }
        other => panic!("expected add, got {other:?}"),
    }
}

#[test]
fn cli_parses_projects_milestones_show() {
    match milestones_action(&[
        "trusty-mpm",
        "projects",
        "milestones",
        "show",
        "widget",
        "00000000-0000-0000-0000-000000000002",
        "--json",
    ]) {
        MilestonesAction::Show { project, id, json } => {
            assert_eq!(project, "widget");
            assert_eq!(id, "00000000-0000-0000-0000-000000000002");
            assert!(json);
        }
        other => panic!("expected show, got {other:?}"),
    }
}