trusty-mpm 1.7.3

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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
//! Unit tests for the harness-manifest schema (HR-2 / DOC-17), split out of
//! `schema.rs` (a 500-SLOC-capped production file) so coverage can grow under
//! the 1500-SLOC test cap — mirrors the `native_mcp_tests.rs` split.
//!
//! Test: this file IS the test module.

use super::*;

/// A [`GatedAgent`] fixture — stem plus its declared markers (#4765).
fn gated(stem: &str, markers: &[&str]) -> GatedAgent {
    GatedAgent {
        stem: stem.to_string(),
        markers: markers.iter().map(|m| (*m).to_string()).collect(),
    }
}

#[test]
fn manifest_roundtrip() {
    // A fully-populated manifest must survive a serialize → parse round-trip
    // unchanged, proving the schema is self-consistent.
    let manifest = HarnessManifest {
        version: Some(MANIFEST_VERSION),
        agents: Some(AgentSet {
            include: vec!["rust-engineer".into(), "qa".into()],
            exclude: vec!["*-ops".into()],
            ignore_staleness: vec!["engineer".into()],
            source: ContentSource::Catalog,
        }),
        agent_categories: Some(AgentCategories {
            universal: vec!["qa".into()],
            language: vec![gated("rust-engineer", &["Cargo.toml"])],
            framework: vec![gated("react-engineer", &["package.json::\"react\""])],
            platform: vec![gated("vercel-ops", &["vercel.json"])],
            deprecated: vec!["ops".into()],
        }),
        skill_categories: Some(SkillCategories {
            universal: vec!["tm".into()],
        }),
        skills: Some(SkillSet {
            include: vec!["example-skill".into()],
            exclude: vec![],
            source: ContentSource::Bundled,
        }),
        instructions: Some(InstructionLayers {
            system: Some(true),
            contextual: Some(true),
            domain: Some(false),
        }),
        style: Some(StyleSelection {
            active: Some("trusty-mpm-teacher".into()),
        }),
        mcp: Some(McpServers {
            trusty_memory: Some(true),
            trusty_search: Some(false),
        }),
        models: Some(ModelTiers {
            lightweight: Some("haiku".into()),
            standard: None,
            high: None,
            intensive: Some("opus".into()),
        }),
        divert: Some(DivertConfig {
            enabled: Some(true),
            min_lines: Some(350),
            worker_model: Some("claude-haiku-4-5".to_string()),
        }),
    };

    let toml = manifest.to_toml().expect("serialize");
    let parsed = HarnessManifest::from_toml(&toml).expect("parse");
    assert_eq!(manifest, parsed);
}

#[test]
fn manifest_partial_parse() {
    // A manifest that sets only one section must parse, with every other
    // section left `None` so the merge keeps the lower layer's values.
    let toml = r#"
version = 1

[style]
active = "trusty-mpm-research"
"#;
    let parsed = HarnessManifest::from_toml(toml).expect("partial parse");
    assert_eq!(parsed.version, Some(1));
    assert_eq!(
        parsed.style.as_ref().and_then(|s| s.active.as_deref()),
        Some("trusty-mpm-research")
    );
    assert!(parsed.agents.is_none());
    assert!(parsed.skills.is_none());
    assert!(parsed.mcp.is_none());
}

#[test]
fn manifest_merge_overrides() {
    // A higher-precedence layer must replace only the sections it sets and
    // leave the rest of the lower layer intact.
    let lower = HarnessManifest {
        version: Some(1),
        agents: Some(AgentSet {
            include: vec!["a".into()],
            ..AgentSet::default()
        }),
        style: Some(StyleSelection {
            active: Some("trusty-mpm".into()),
        }),
        mcp: Some(McpServers {
            trusty_memory: Some(true),
            trusty_search: Some(true),
        }),
        ..HarnessManifest::default()
    };
    let higher = HarnessManifest {
        style: Some(StyleSelection {
            active: Some("trusty-mpm-teacher".into()),
        }),
        ..HarnessManifest::default()
    };

    let merged = lower.merge(higher);
    // style replaced by the higher layer
    assert_eq!(
        merged.style.as_ref().and_then(|s| s.active.as_deref()),
        Some("trusty-mpm-teacher")
    );
    // agents + mcp kept from the lower layer (higher left them None)
    assert_eq!(
        merged.agents.as_ref().map(|a| a.include.clone()),
        Some(vec!["a".to_string()])
    );
    assert_eq!(
        merged.mcp.as_ref().and_then(|m| m.trusty_search),
        Some(true)
    );
}

#[test]
fn manifest_merge_keeps_lower_when_absent() {
    // Merging an all-None higher layer is the identity on the lower layer.
    let lower = HarnessManifest {
        version: Some(1),
        style: Some(StyleSelection {
            active: Some("trusty-mpm".into()),
        }),
        ..HarnessManifest::default()
    };
    let merged = lower.clone().merge(HarnessManifest::default());
    assert_eq!(lower, merged);
}

#[test]
fn manifest_merge_mcp_field_level() {
    // A partial `[mcp]` override (only trusty_search) must NOT discard the
    // lower layer's other toggle (trusty_memory) — field-level merge.
    let lower = HarnessManifest {
        mcp: Some(McpServers {
            trusty_memory: Some(true),
            trusty_search: Some(true),
        }),
        ..HarnessManifest::default()
    };
    let higher = HarnessManifest {
        mcp: Some(McpServers {
            trusty_memory: None,
            trusty_search: Some(false),
        }),
        ..HarnessManifest::default()
    };

    let merged = lower.merge(higher);
    let mcp = merged.mcp.expect("mcp section present");
    assert_eq!(
        mcp.trusty_memory,
        Some(true),
        "the unmentioned toggle must survive the partial override"
    );
    assert_eq!(
        mcp.trusty_search,
        Some(false),
        "the overridden toggle must take the higher layer's value"
    );
}

#[test]
fn instruction_layers_field_merge() {
    // A partial `[instructions]` override must merge field-by-field too.
    let lower = HarnessManifest {
        instructions: Some(InstructionLayers {
            system: Some(true),
            contextual: Some(true),
            domain: Some(true),
        }),
        ..HarnessManifest::default()
    };
    let higher = HarnessManifest {
        instructions: Some(InstructionLayers {
            system: None,
            contextual: None,
            domain: Some(false),
        }),
        ..HarnessManifest::default()
    };

    let layers = lower.merge(higher).instructions.expect("layers present");
    assert_eq!(layers.system, Some(true), "system inherited from lower");
    assert_eq!(
        layers.contextual,
        Some(true),
        "contextual inherited from lower"
    );
    assert_eq!(layers.domain, Some(false), "domain overridden by higher");
}

#[test]
fn selection_matches() {
    // Empty include → match all; exclude wins over include.
    assert!(super::selection_matches("anything", &[], &[]));
    // Exact include.
    let inc = vec!["rust-engineer".to_string()];
    assert!(super::selection_matches("rust-engineer", &inc, &[]));
    assert!(!super::selection_matches("qa", &inc, &[]));
    // Glob include.
    let glob_inc = vec!["*-engineer".to_string()];
    assert!(super::selection_matches("rust-engineer", &glob_inc, &[]));
    assert!(!super::selection_matches("rust-ops", &glob_inc, &[]));
    // Multi-`*` glob include (regression: was mis-matched by split_once).
    let multi_inc = vec!["*-engineer-*".to_string()];
    assert!(super::selection_matches(
        "rust-engineer-ops",
        &multi_inc,
        &[]
    ));
    assert!(!super::selection_matches("rust-engineer", &multi_inc, &[]));
    // Exclude wins.
    let exc = vec!["rust-engineer".to_string()];
    assert!(!super::selection_matches("rust-engineer", &[], &exc));
    let inc_and_exc = ["rust-engineer".to_string()];
    assert!(!super::selection_matches(
        "rust-engineer",
        &inc_and_exc,
        &exc
    ));
}

#[test]
fn glob_matching() {
    // Bare `*` matches everything.
    assert!(super::glob_matches("*", "anything"));
    assert!(super::glob_matches("*", ""));

    // Exact (no wildcard) is equality.
    assert!(super::glob_matches("rust-engineer", "rust-engineer"));
    assert!(!super::glob_matches("rust-engineer", "qa"));
    assert!(!super::glob_matches("rust-engineer", "rust-engineer-2"));

    // Trailing `*` = prefix; leading `*` = suffix.
    assert!(super::glob_matches("*-engineer", "rust-engineer"));
    assert!(!super::glob_matches("*-engineer", "rust-engineer-ops"));
    assert!(super::glob_matches("engineer-*", "engineer-rust"));
    assert!(!super::glob_matches("engineer-*", "rust-engineer"));
    assert!(super::glob_matches("rust-*", "rust-engineer"));

    // Single interior `*` = prefix + suffix.
    assert!(super::glob_matches("a*b", "axxb"));
    assert!(super::glob_matches("a*b", "ab"), "interior * matches empty");
    assert!(!super::glob_matches("a*b", "axx"));

    // Multi-`*` patterns: the previously-broken cases.
    // `*-engineer-*` = "contains -engineer-".
    assert!(super::glob_matches("*-engineer-*", "rust-engineer-ops"));
    assert!(super::glob_matches("*-engineer-*", "x-engineer-y"));
    assert!(
        !super::glob_matches("*-engineer-*", "rust-engineer"),
        "no trailing segment after -engineer- → no match"
    );
    // `a*b*c` = a-prefix, then b, then c-suffix in order.
    assert!(super::glob_matches("a*b*c", "aXbYc"));
    assert!(super::glob_matches("a*b*c", "abc"));
    assert!(
        !super::glob_matches("a*b*c", "acb"),
        "segments must appear in order"
    );
    assert!(
        !super::glob_matches("a*b*c", "aXbY"),
        "missing the trailing c suffix"
    );
}

#[test]
fn content_source_roundtrip() {
    // ContentSource serializes lowercase and round-trips.
    let serialized = toml::to_string(&AgentSet {
        source: ContentSource::Catalog,
        ..AgentSet::default()
    })
    .unwrap();
    assert!(serialized.contains("catalog"));
}

#[test]
fn agent_set_source_default_is_bundled() {
    // An [agents] section that omits `source` must default to Bundled, so
    // the default manifest reproduces today's bundled-asset behavior.
    let toml = "[agents]\ninclude = []\n";
    let parsed = HarnessManifest::from_toml(toml).unwrap();
    assert_eq!(parsed.agents.unwrap().source, ContentSource::Bundled);
}

#[test]
fn a_custom_mcp_table_parses_and_is_dropped() {
    // #7894: `[mcp.custom.<name>]` used to deserialize into `McpServers.custom`,
    // merge by name across layers, and land in `HarnessPlan.custom_mcp_servers`
    // — where it stopped. ADR-0042 deleted its only reader,
    // `session_launch::custom_mcp`, with every other workspace `.mcp.json`
    // injector, so the field is gone. A manifest still carrying the table must
    // keep PARSING (serde ignores the unknown key) and must leave the `[mcp]`
    // toggles it declares alongside intact.
    let toml = r#"
[mcp]
trusty_search = false

[mcp.custom.my-local-tool]
type = "stdio"
command = "my-tool"
args = ["serve"]
"#;

    let parsed = HarnessManifest::from_toml(toml).expect("parse");

    let mcp = parsed.mcp.expect("mcp section present");
    assert_eq!(mcp.trusty_search, Some(false));
    assert_eq!(mcp.trusty_memory, None);
}

#[test]
fn agent_categories_roundtrip() {
    // #4760: the framework tier's five category lists must survive a TOML
    // round-trip through the SAME parser every other manifest layer uses —
    // that shared parser is the whole point of extending `manifest.toml`
    // rather than inventing a second format. #4765: each gated entry now
    // carries its own markers, in the array-of-tables form the shipped asset
    // uses.
    let raw = r#"
version = 1

[agent_categories]
universal = ["qa"]
deprecated = ["ops"]

[[agent_categories.language]]
stem = "rust-engineer"
markers = ["Cargo.toml"]

[[agent_categories.platform]]
stem = "vercel-ops"
markers = ["vercel.json", ".vercelignore"]

[skill_categories]
universal = ["tm"]
"#;
    let parsed = HarnessManifest::from_toml(raw).expect("parses");
    let cats = parsed.agent_categories.clone().expect("section present");
    assert_eq!(cats.universal, vec!["qa".to_string()]);
    assert_eq!(cats.deprecated, vec!["ops".to_string()]);
    assert_eq!(cats.language, vec![gated("rust-engineer", &["Cargo.toml"])]);
    assert_eq!(
        cats.platform,
        vec![gated("vercel-ops", &["vercel.json", ".vercelignore"])]
    );
    assert_eq!(
        parsed
            .skill_categories
            .clone()
            .expect("skill section present")
            .universal,
        vec!["tm".to_string()]
    );

    let round =
        HarnessManifest::from_toml(&parsed.to_toml().expect("serializes")).expect("re-parses");
    assert_eq!(round, parsed);
}

#[test]
fn skill_categories_roundtrip() {
    // #4765: the skill roster is a manifest section like any other — it parses
    // through the shared parser and survives a serialize round-trip. Absent, it
    // stays `None` so every non-framework layer is unaffected.
    let raw = "[skill_categories]\nuniversal = [\"tm\", \"tm-doctor\"]\n";
    let parsed = HarnessManifest::from_toml(raw).expect("parses");
    let skills = parsed
        .skill_categories
        .clone()
        .expect("section present")
        .universal;
    assert_eq!(skills, vec!["tm".to_string(), "tm-doctor".to_string()]);

    let round =
        HarnessManifest::from_toml(&parsed.to_toml().expect("serializes")).expect("re-parses");
    assert_eq!(round, parsed);

    let without = HarnessManifest::from_toml("[agents]\ninclude = [\"qa\"]\n").expect("parses");
    assert!(
        without.skill_categories.is_none(),
        "the section is additive — every other layer omits it"
    );
}

#[test]
fn agent_categories_absent_parses_as_none() {
    // Every other manifest layer omits `[agent_categories]`; that must stay a
    // clean parse, not an error, so the new section is genuinely additive.
    let parsed = HarnessManifest::from_toml("[agents]\ninclude = [\"qa\"]\n").expect("parses");
    assert!(parsed.agent_categories.is_none());
}

#[test]
fn agent_categories_merge_is_whole_section() {
    // A higher layer's section replaces the lower one outright, matching the
    // documented merge mode for the list-like sections.
    let lower = HarnessManifest {
        agent_categories: Some(AgentCategories {
            universal: vec!["qa".into()],
            ..AgentCategories::default()
        }),
        ..HarnessManifest::default()
    };
    let higher = HarnessManifest {
        agent_categories: Some(AgentCategories {
            universal: vec!["engineer".into()],
            ..AgentCategories::default()
        }),
        ..HarnessManifest::default()
    };
    let merged = lower.clone().merge(higher);
    assert_eq!(
        merged.agent_categories.unwrap().universal,
        vec!["engineer".to_string()]
    );
    // An absent higher section inherits the lower one.
    let inherited = lower.merge(HarnessManifest::default());
    assert_eq!(
        inherited.agent_categories.unwrap().universal,
        vec!["qa".to_string()]
    );
}

/// Why (#6887): a project that overrides only `min_lines` must not silently
/// turn the feature off. Whole-section replacement — the shape `[agents]` and
/// `[style]` use — would do exactly that, because the higher layer's
/// `enabled` is `None`.
/// What: lower sets `enabled = true` + `min_lines = 350`; higher sets only
/// `min_lines = 500`; asserts the merged section keeps `enabled = Some(true)`
/// and takes the higher `min_lines`.
#[test]
fn divert_config_merge_field_level() {
    let lower = HarnessManifest {
        divert: Some(DivertConfig {
            enabled: Some(true),
            min_lines: Some(350),
            worker_model: Some("claude-haiku-4-5".to_string()),
        }),
        ..HarnessManifest::default()
    };
    let higher = HarnessManifest {
        divert: Some(DivertConfig {
            min_lines: Some(500),
            ..DivertConfig::default()
        }),
        ..HarnessManifest::default()
    };

    let divert = lower.merge(higher).divert.expect("divert section present");
    assert_eq!(
        divert.enabled,
        Some(true),
        "a partial override must not reset the lower layer's `enabled`"
    );
    assert_eq!(divert.min_lines, Some(500), "higher wins the field it sets");
    assert_eq!(
        divert.worker_model.as_deref(),
        Some("claude-haiku-4-5"),
        "an unmentioned field inherits the lower layer"
    );
}

/// Why (#6887): the section must survive the TOML round-trip the resolver
/// performs on every layer, or a project's `[divert]` table is silently
/// dropped.
/// What: serializes a fully-populated `[divert]` and parses it back.
#[test]
fn divert_config_roundtrip() {
    let manifest = HarnessManifest {
        version: Some(MANIFEST_VERSION),
        divert: Some(DivertConfig {
            enabled: Some(true),
            min_lines: Some(400),
            worker_model: Some("claude-haiku-4-5-20251001".to_string()),
        }),
        ..HarnessManifest::default()
    };
    let toml = manifest.to_toml().expect("serialize");
    let parsed = HarnessManifest::from_toml(&toml).expect("parse");
    assert_eq!(parsed.divert, manifest.divert);
}