trusty-mpm 1.8.2

trusty-mpm: unified multi-agent orchestration platform (core, daemon, CLI, TUI, Telegram)
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
//! Unit tests for `daemon::doctor::doctor_output_style` — split out of
//! `doctor_output_style.rs` (test-file budget: 1500 SLOC; the inline module
//! pushed the production file over its 500-SLOC cap once issue #3453 added
//! the `.local.json` precedence-chain layers and the `legacy_ids` probe).
//! What: exercises `check_output_style`, `check_output_style_staleness`, and
//! `check_output_style_legacy_ids` across the full four-layer precedence
//! chain (`project-local` / `project` / `user-local` / `user`).
//! Test: this module IS the test suite for `super`.

use super::*;
use crate::core::content_source::test_support::rc;

/// Write `<dir>/.claude/settings.json` with the given raw JSON text.
fn write_settings(dir: &Path, json: &str) {
    let claude_dir = dir.join(".claude");
    std::fs::create_dir_all(&claude_dir).unwrap();
    std::fs::write(claude_dir.join("settings.json"), json).unwrap();
}

/// Write `<dir>/.claude/settings.local.json` with the given raw JSON text
/// (issue #3453 — the layer `check_output_style` previously never read).
fn write_local_settings(dir: &Path, json: &str) {
    let claude_dir = dir.join(".claude");
    std::fs::create_dir_all(&claude_dir).unwrap();
    std::fs::write(claude_dir.join("settings.local.json"), json).unwrap();
}

/// Deploy the default trusty-mpm style file under `<home>/.claude/output-styles/`.
fn deploy_default_style(home: &Path) {
    let styles_dir = home.join(".claude").join("output-styles");
    std::fs::create_dir_all(&styles_dir).unwrap();
    let default = OUTPUT_STYLES[0];
    std::fs::write(
        styles_dir.join(default.file_name),
        default.content(crate::core::content_source::test_support::rc()),
    )
    .unwrap();
}

/// A `FrameworkPaths` rooted under `home`, so the managed-config tier the
/// staleness probe scans is inside the temp dir rather than the real one (#7423).
fn hermetic_paths(home: &Path) -> FrameworkPaths {
    let mut paths = FrameworkPaths::under(home);
    paths.trusty_mpm_root = None;
    paths
}

/// Deploy every bundled style, byte-exact, under `<home>/.claude/output-styles/`.
fn deploy_all_styles(home: &Path) {
    let styles_dir = home.join(".claude").join("output-styles");
    std::fs::create_dir_all(&styles_dir).unwrap();
    for style in OUTPUT_STYLES {
        std::fs::write(styles_dir.join(style.file_name), style.content(rc())).unwrap();
    }
}

#[test]
fn output_style_ok_when_style_resolves() {
    let home = tempfile::tempdir().unwrap();
    deploy_default_style(home.path());
    write_settings(home.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Ok);
}

#[test]
fn output_style_fail_when_id_unknown() {
    // This is the exact incident condition: a stale/foreign style id.
    let home = tempfile::tempdir().unwrap();
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Fail);
    assert!(check.message.contains("claude_mpm"));
    assert!(
        check.message.contains("trusty-mpm"),
        "valid id list must be present"
    );
}

#[test]
fn output_style_warn_when_key_absent() {
    let home = tempfile::tempdir().unwrap();
    write_settings(home.path(), r#"{}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Warn);
}

#[test]
fn output_style_warn_when_settings_missing() {
    let home = tempfile::tempdir().unwrap();
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Warn);
}

#[test]
fn output_style_fail_when_file_missing() {
    // A known id whose deployed file was never written (or was deleted).
    let home = tempfile::tempdir().unwrap();
    write_settings(home.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Fail);
}

#[test]
fn output_style_fail_on_malformed_json() {
    let home = tempfile::tempdir().unwrap();
    write_settings(home.path(), "{not valid json");
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Fail);
    assert!(check.message.contains("not valid JSON"));
}

#[test]
fn output_style_prefers_project_over_global() {
    let home = tempfile::tempdir().unwrap();
    let project = tempfile::tempdir().unwrap();
    deploy_default_style(home.path());
    // Global settings carry the bad incident value...
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#);
    // ...but the project-local settings (written by `prepare_session`)
    // carry the correct one and must take precedence.
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok);
}

#[test]
fn output_style_falls_back_to_global_when_project_silent() {
    // Issue #1863: the exact incident condition. A project settings file
    // EXISTS (so the old `effective_settings_path` would stop looking
    // there) but does not set `outputStyle` — Claude Code itself falls
    // back to the global value in that case, and so must this check. The
    // global value here is the bad incident id, so this must Fail, not
    // silently report Warn/Ok from the project scope.
    let home = tempfile::tempdir().unwrap();
    let project = tempfile::tempdir().unwrap();
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#);
    write_settings(project.path(), r#"{"theme": "dark"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Fail);
    assert!(check.message.contains("claude_mpm"));
    assert!(
        check.message.contains("user"),
        "message must name the resolved scope: {}",
        check.message
    );
}

#[test]
fn output_style_falls_back_to_global_when_project_missing() {
    // No project settings file at all (e.g. `tm doctor` run before the
    // project has ever launched a session) must still catch a bad global
    // value.
    let home = tempfile::tempdir().unwrap();
    let project = tempfile::tempdir().unwrap();
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Fail);
    assert!(check.message.contains("claude_mpm"));
}

#[test]
fn output_style_reports_project_scope_on_success() {
    // The `Ok` message must name which scope ("project") supplied the
    // resolved value, so operators can tell the two apart.
    let home = tempfile::tempdir().unwrap();
    let project = tempfile::tempdir().unwrap();
    deploy_default_style(home.path());
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok);
    assert!(
        check.message.contains("project"),
        "message must name the resolved scope: {}",
        check.message
    );
}

#[test]
fn output_style_project_local_wins_even_when_project_settings_correct() {
    // The exact live-repro shape from issue #3453: `settings.json` was
    // already correct (rewritten by a repair pass), but the co-located
    // `settings.local.json` still carries the pre-rebrand id and Claude
    // Code applies IT, not the plain file, at the project scope. Before
    // this fix, `check_output_style` never even read `.local.json` and
    // reported a false `Ok` from `settings.json` alone.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    deploy_default_style(home.path());
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#); // correct
    write_local_settings(project.path(), r#"{"outputStyle": "claude_mpm"}"#); // stale, wins
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(
        check.status,
        CheckStatus::Fail,
        "message: {}",
        check.message
    );
    assert!(check.message.contains("claude_mpm"));
    assert!(
        check.message.contains("project-local"),
        "message must name the resolved scope: {}",
        check.message
    );
}

#[test]
fn output_style_project_local_overrides_project() {
    // Precedence must hold even when BOTH layers resolve to known,
    // deployed styles — proving the winner is genuinely selected by
    // precedence, not merely by which one happens to be valid.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    deploy_all_styles(home.path());
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    write_local_settings(project.path(), r#"{"outputStyle": "trusty-mpm-teacher"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
    assert!(check.message.contains("trusty-mpm-teacher"));
    assert!(check.message.contains("project-local"));
}

#[test]
fn output_style_user_local_overrides_user() {
    // Same format-precedence rule applied at the user scope (no project
    // dir at all): `settings.local.json` under `home` must win over
    // `settings.json` under the same `home`.
    let home = crate::test_support::hermetic_temp_dir();
    deploy_all_styles(home.path());
    write_settings(home.path(), r#"{"outputStyle": "trusty-mpm"}"#);
    write_local_settings(home.path(), r#"{"outputStyle": "trusty-mpm-teacher"}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
    assert!(check.message.contains("trusty-mpm-teacher"));
    assert!(check.message.contains("user-local"));
}

#[test]
fn output_style_project_scope_still_outranks_user_local() {
    // Project (plain) settings must still beat a `.local` value at the
    // USER scope — scope (project vs. user) is the primary sort key,
    // format (`.local` vs. plain) only breaks ties WITHIN a scope.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    deploy_default_style(home.path());
    write_local_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#); // user-local, bad
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#); // project, good
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
    assert!(check.message.contains("project"));
}

/// A project style `fixture-voice` under `project`, optionally with its composite.
fn write_project_style(project: &Path, with_composite: bool) -> PathBuf {
    let styles = project.join(crate::core::output_style::PROJECT_STYLES_DIR);
    std::fs::create_dir_all(&styles).unwrap();
    let style = styles.join("fixture-voice.md");
    std::fs::write(&style, "---\nname: fixture-voice\n---\nProject voice.\n").unwrap();
    if with_composite {
        std::fs::write(styles.join("fixture-voice.tm-floor.md"), "composite").unwrap();
    }
    style
}

#[test]
fn output_style_ok_for_a_project_style_and_its_composite() {
    // #8533 critic round 3: a project style id and its `.tm-floor` composite
    // are valid values, not unknown ids.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    let style = write_project_style(project.path(), true);
    for id in ["fixture-voice", "fixture-voice.tm-floor"] {
        write_local_settings(project.path(), &format!(r#"{{"outputStyle": "{id}"}}"#));
        let check = check_output_style(Some(project.path()), home.path());
        assert_eq!(check.status, CheckStatus::Ok, "{id}: {}", check.message);
        assert!(
            check.message.contains(&style.display().to_string()),
            "{id}: the project style path is named: {}",
            check.message
        );
        assert!(check.message.contains("project-local"), "{}", check.message);
    }
    // An id that names no project style is still unknown.
    write_local_settings(project.path(), r#"{"outputStyle": "nope.tm-floor"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Fail, "{}", check.message);
    assert!(check.message.contains("is not a known trusty-mpm style"));
}

#[test]
fn output_style_project_style_without_composite_is_reported() {
    // #8533: a composite id with no composite file names nothing Claude Code
    // can load; a raw id with no composite loads without the floor.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    write_project_style(project.path(), false);
    write_settings(
        project.path(),
        r#"{"outputStyle": "fixture-voice.tm-floor"}"#,
    );
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Fail, "{}", check.message);
    assert!(
        check.message.contains("fixture-voice.tm-floor.md"),
        "{}",
        check.message
    );
    write_settings(project.path(), r#"{"outputStyle": "fixture-voice"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Warn, "{}", check.message);
    // With no project dir, a project style id is unknown.
    write_settings(home.path(), r#"{"outputStyle": "fixture-voice"}"#);
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Fail, "{}", check.message);
}

#[test]
fn output_style_warn_names_all_checked_layers_when_none_configured() {
    // The no-`outputStyle`-key-anywhere case (the writing project's real
    // `settings.json` shape) must Warn, not Fail, and must name every
    // layer it checked so the operator can see the full resolution chain.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    write_settings(project.path(), r#"{"theme": "dark"}"#);
    let check = check_output_style(Some(project.path()), home.path());
    assert_eq!(
        check.status,
        CheckStatus::Warn,
        "message: {}",
        check.message
    );
    assert!(check.message.contains("settings.local.json"));
    assert!(check.message.contains("settings.json"));
}

#[test]
fn staleness_ok_when_in_sync() {
    // All three bundled styles deployed byte-exact must be Ok.
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());
    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}

#[test]
fn doctor_recognises_the_supervisor_style() {
    // #8453: the supervisor style is a bundled style — its deployed file is no
    // orphan, and a project naming it passes the resolution check.
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());
    let supervisor = crate::core::session_profile::SUPERVISOR_OUTPUT_STYLE_ID;
    assert!(
        home.path()
            .join(".claude/output-styles")
            .join(format!("{supervisor}.md"))
            .is_file()
    );
    let stale = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(stale.status, CheckStatus::Ok, "message: {}", stale.message);

    write_settings(
        home.path(),
        &format!(r#"{{"outputStyle": "{supervisor}"}}"#),
    );
    let check = check_output_style(None, home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}

#[test]
fn staleness_warns_on_drift() {
    // This is the exact incident condition (issue #2333): PR #2328
    // corrected the bundled content, but the deployed copy never got
    // refreshed. A byte-level mismatch must Warn and point at a command that
    // actually redeploys — #5866: it used to name `tm install`, which has no
    // output-style step at all, so the remedy was a no-op.
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());
    let styles_dir = home.path().join(".claude").join("output-styles");
    let first = &OUTPUT_STYLES[0];
    std::fs::write(
        styles_dir.join(first.file_name),
        "stale pre-#2328 identity text",
    )
    .unwrap();

    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Warn);
    assert!(check.message.contains(first.file_name));
    assert!(
        check
            .message
            .contains(crate::core::doctor_repair::OUTPUT_STYLE_REMEDY),
        "the remedy must name the command that redeploys: {}",
        check.message
    );
    assert!(
        !check.message.contains("tm install"),
        "#5866: `tm install` has no output-style step — naming it sends the \
         operator to a no-op: {}",
        check.message
    );
}

#[test]
fn staleness_warns_on_orphan() {
    // A dormant foreign file (issue #2333's `claude-mpm.md` example) must
    // be flagged, but never deleted.
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());
    let styles_dir = home.path().join(".claude").join("output-styles");
    std::fs::write(styles_dir.join("claude-mpm.md"), "pre-rebrand lineage").unwrap();

    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Warn);
    assert!(check.message.contains("claude-mpm.md"));
    assert!(
        styles_dir.join("claude-mpm.md").exists(),
        "orphan detection must never delete the foreign file"
    );
}

#[test]
fn staleness_ok_when_dir_missing() {
    // Nothing deployed yet is not staleness — `check_output_style` already
    // reports on that state (Warn/Fail depending on configuration).
    let home = tempfile::tempdir().unwrap();
    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Ok);
}

#[test]
fn staleness_ok_when_file_never_deployed() {
    // A style present in the bundle but never written to disk (a subset
    // deploy, or a deletion) must be skipped, not reported as drift —
    // that state is `check_output_style`'s Fail, not this probe's Warn.
    let home = tempfile::tempdir().unwrap();
    deploy_default_style(home.path()); // only OUTPUT_STYLES[0]
    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}

#[test]
fn staleness_orphan_exempts_configured_custom_id() {
    // A deliberately configured custom style id (unknown to OUTPUT_STYLES,
    // already `Fail`ed by `check_output_style` itself) is the operator's
    // own file, not a foreign leftover — orphan detection must not also
    // flag it.
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());
    write_settings(home.path(), r#"{"outputStyle": "my-custom-style"}"#);
    let styles_dir = home.path().join(".claude").join("output-styles");
    std::fs::write(
        styles_dir.join("my-custom-style.md"),
        "operator's own style",
    )
    .unwrap();

    let check = check_output_style_staleness(None, home.path(), &hermetic_paths(home.path()));
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}

/// #7423: a DRIFTED copy in the managed `$CLAUDE_CONFIG_DIR` tier must Warn
/// even when `~/.claude/output-styles/` is byte-perfect.
///
/// Why: that is the measured 2026-09-11 state after `tm doctor --fix --yes` on
/// 1.5.29 — the home copy redeployed, the managed copy left at the old 12,012
/// bytes, and the probe reported `Ok`. The managed copy is the one a tm-launched
/// session reads (`SETTING_SOURCES_FLAG_RELOCATED`), so `Ok` there is the
/// report that matters being wrong. Fails on `origin/main`, which scanned
/// `<home>/.claude` and nothing else.
/// Test: this test.
#[test]
fn staleness_warns_on_managed_config_drift() {
    let home = tempfile::tempdir().unwrap();
    deploy_all_styles(home.path());

    let paths = hermetic_paths(home.path());
    let managed_styles = paths.managed_claude_config_dir().join("output-styles");
    std::fs::create_dir_all(&managed_styles).unwrap();
    let first = &OUTPUT_STYLES[0];
    for style in OUTPUT_STYLES {
        std::fs::write(managed_styles.join(style.file_name), style.content(rc())).unwrap();
    }
    std::fs::write(
        managed_styles.join(first.file_name),
        "stale pre-1.5.29 managed copy",
    )
    .unwrap();

    let check = check_output_style_staleness(None, home.path(), &paths);
    assert_eq!(
        check.status,
        CheckStatus::Warn,
        "message: {}",
        check.message
    );
    assert!(
        check.message.contains("managed config"),
        "the finding must name the tier: {}",
        check.message
    );
    assert!(
        check.message.contains(first.file_name),
        "the finding must name the file: {}",
        check.message
    );
    assert!(
        !check.message.contains("operator home"),
        "the operator's own copy is in sync and must not be reported: {}",
        check.message
    );
}

#[test]
fn legacy_ids_warns_on_shadowed_layer() {
    // The effective layer (project, since no project-local file exists)
    // resolves fine — `check_output_style` alone would report `Ok` — but
    // the USER-scope `settings.json` underneath carries the pre-rebrand
    // id. It never wins today, but it is a landmine the moment the
    // project file's key is ever removed; this probe must still Warn.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    deploy_default_style(home.path());
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#); // effective, fine
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#); // shadowed, stale

    let effective = check_output_style(Some(project.path()), home.path());
    assert_eq!(
        effective.status,
        CheckStatus::Ok,
        "sanity: effective layer must resolve fine, message: {}",
        effective.message
    );

    let check = check_output_style_legacy_ids(Some(project.path()), home.path());
    assert_eq!(
        check.status,
        CheckStatus::Warn,
        "message: {}",
        check.message
    );
    assert!(check.message.contains("claude_mpm"));
    assert!(
        check.message.contains(
            &home
                .path()
                .join(".claude")
                .join("settings.json")
                .display()
                .to_string()
        ),
        "message must name the exact offending file: {}",
        check.message
    );
}

#[test]
fn legacy_ids_does_not_double_report_the_effective_layer() {
    // Both the effective (project-local) layer AND a shadowed (user)
    // layer carry the same stale id. `check_output_style` already Fails
    // on the effective one by name — this probe must report ONLY the
    // shadowed offender, not re-list the effective layer's file too.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    write_local_settings(project.path(), r#"{"outputStyle": "claude_mpm"}"#); // effective
    write_settings(home.path(), r#"{"outputStyle": "claude_mpm"}"#); // shadowed

    let check = check_output_style_legacy_ids(Some(project.path()), home.path());
    assert_eq!(
        check.status,
        CheckStatus::Warn,
        "message: {}",
        check.message
    );
    let user_path = home.path().join(".claude").join("settings.json");
    let project_local_path = project.path().join(".claude").join("settings.local.json");
    assert!(
        check.message.contains(&user_path.display().to_string()),
        "must name the shadowed offender: {}",
        check.message
    );
    assert!(
        !check
            .message
            .contains(&project_local_path.display().to_string()),
        "must NOT double-report the effective layer (already `Fail`ed by \
         check_output_style): {}",
        check.message
    );
}

#[test]
fn legacy_ids_ok_when_all_known() {
    // Both the effective AND a shadowed layer resolve to known, deployed
    // ids — no legacy id anywhere, so this must be `Ok`.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    deploy_all_styles(home.path());
    write_settings(project.path(), r#"{"outputStyle": "trusty-mpm"}"#); // effective
    write_settings(home.path(), r#"{"outputStyle": "trusty-mpm-teacher"}"#); // shadowed, valid

    let check = check_output_style_legacy_ids(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}

#[test]
fn legacy_ids_ok_when_none_configured() {
    // No `outputStyle` key anywhere — nothing to flag.
    let home = crate::test_support::hermetic_temp_dir();
    let project = crate::test_support::hermetic_temp_dir();
    let check = check_output_style_legacy_ids(Some(project.path()), home.path());
    assert_eq!(check.status, CheckStatus::Ok, "message: {}", check.message);
}