pmat 3.16.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
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
#![cfg_attr(coverage_nightly, coverage(off))]
//! Claude Code sub-agent templates for PMAT.
//!
//! This module provides specialized sub-agent templates compatible with Claude Code's
//! sub-agent system. Each sub-agent is an AI specialist focused on a specific aspect
//! of code quality analysis.

use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::{Path, PathBuf};

/// Available PMAT sub-agents for Claude Code.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum PmatSubAgent {
    /// Complexity analysis specialist (cyclomatic & cognitive complexity).
    ComplexityAnalyst,
    /// Mutation testing expert with ML prediction.
    MutationTester,
    /// Technical debt detector (SATD - TODO, FIXME, HACK comments).
    SATDDetector,
    /// Unused code elimination specialist.
    DeadCodeEliminator,
    /// Generic description detector for documentation enforcement.
    DocumentationEnforcer,

    // Future phases (not implemented in MVP)
    /// Rust-specific quality expert.
    RustQualityExpert,
    /// Python quality expert.
    PythonQualityExpert,
    /// TypeScript/JavaScript quality expert.
    TypeScriptQualityExpert,
    /// WASM deep inspector (bytecode analysis).
    WasmDeepInspector,
    /// Refactoring advisor using pattern learning.
    RefactoringAdvisor,
    /// Test coverage analyst.
    TestCoverageAnalyst,
    /// Quality gate orchestrator.
    QualityGateOrchestrator,
}

impl PmatSubAgent {
    /// Get the display name of the sub-agent.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn name(&self) -> &'static str {
        match self {
            Self::ComplexityAnalyst => "complexity-analyst",
            Self::MutationTester => "mutation-tester",
            Self::SATDDetector => "satd-detector",
            Self::DeadCodeEliminator => "dead-code-eliminator",
            Self::DocumentationEnforcer => "documentation-enforcer",
            Self::RustQualityExpert => "rust-quality-expert",
            Self::PythonQualityExpert => "python-quality-expert",
            Self::TypeScriptQualityExpert => "typescript-quality-expert",
            Self::WasmDeepInspector => "wasm-deep-inspector",
            Self::RefactoringAdvisor => "refactoring-advisor",
            Self::TestCoverageAnalyst => "test-coverage-analyst",
            Self::QualityGateOrchestrator => "quality-gate-orchestrator",
        }
    }

    /// Get a brief description of the sub-agent.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn description(&self) -> &'static str {
        match self {
            Self::ComplexityAnalyst => {
                "Expert in cyclomatic and cognitive complexity analysis, suggests refactorings"
            }
            Self::MutationTester => {
                "Mutation testing specialist with ML prediction and test improvement suggestions"
            }
            Self::SATDDetector => {
                "Technical debt identifier tracking TODO, FIXME, and HACK comments"
            }
            Self::DeadCodeEliminator => {
                "Unused code removal specialist identifying safe-to-delete code"
            }
            Self::DocumentationEnforcer => {
                "Generic description detector enforcing documentation quality standards"
            }
            Self::RustQualityExpert => {
                "Rust-specific quality expert covering ownership, lifetimes, and idiomatic patterns"
            }
            Self::PythonQualityExpert => {
                "Python quality expert for type hints, PEP compliance, and best practices"
            }
            Self::TypeScriptQualityExpert => {
                "TypeScript/JavaScript quality expert for type safety and modern patterns"
            }
            Self::WasmDeepInspector => {
                "WebAssembly bytecode analyst for compiler debugging and optimization"
            }
            Self::RefactoringAdvisor => {
                "AI-powered refactoring advisor using historical pattern learning"
            }
            Self::TestCoverageAnalyst => {
                "Test coverage gap identifier suggesting missing test cases"
            }
            Self::QualityGateOrchestrator => {
                "Coordinates multiple quality checks and synthesizes results"
            }
        }
    }

    /// Check if this sub-agent is implemented in the MVP.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn is_mvp(&self) -> bool {
        matches!(
            self,
            Self::ComplexityAnalyst
                | Self::MutationTester
                | Self::SATDDetector
                | Self::DeadCodeEliminator
                | Self::DocumentationEnforcer
        )
    }

    /// Get the primary MCP tools used by this sub-agent.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn primary_tools(&self) -> Vec<&'static str> {
        match self {
            Self::ComplexityAnalyst => vec!["analyze_complexity", "analyze_cognitive_complexity"],
            Self::MutationTester => {
                vec!["mutation_test", "mutation_predict", "equivalent_detector"]
            }
            Self::SATDDetector => vec!["analyze_satd", "analyze_context"],
            Self::DeadCodeEliminator => vec!["analyze_dead_code", "analyze_imports"],
            Self::DocumentationEnforcer => vec!["check_generic_docs", "analyze_context"],
            Self::RustQualityExpert => vec!["analyze_complexity", "analyze_borrow_checker"],
            Self::PythonQualityExpert => vec!["analyze_complexity", "analyze_context"],
            Self::TypeScriptQualityExpert => vec!["analyze_complexity", "analyze_context"],
            Self::WasmDeepInspector => vec!["deep_wasm_analyze", "wasm_disassemble"],
            Self::RefactoringAdvisor => vec!["suggest_refactorings", "query_patterns"],
            Self::TestCoverageAnalyst => vec!["analyze_coverage", "suggest_tests"],
            Self::QualityGateOrchestrator => vec!["run_quality_gates", "aggregate_metrics"],
        }
    }

    /// Get all sub-agents (MVP only by default).
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn all_mvp() -> Vec<Self> {
        vec![
            Self::ComplexityAnalyst,
            Self::MutationTester,
            Self::SATDDetector,
            Self::DeadCodeEliminator,
            Self::DocumentationEnforcer,
        ]
    }

    /// Get all sub-agents (including future phases).
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn all() -> Vec<Self> {
        vec![
            Self::ComplexityAnalyst,
            Self::MutationTester,
            Self::SATDDetector,
            Self::DeadCodeEliminator,
            Self::DocumentationEnforcer,
            Self::RustQualityExpert,
            Self::PythonQualityExpert,
            Self::TypeScriptQualityExpert,
            Self::WasmDeepInspector,
            Self::RefactoringAdvisor,
            Self::TestCoverageAnalyst,
            Self::QualityGateOrchestrator,
        ]
    }
}

impl std::str::FromStr for PmatSubAgent {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "complexity-analyst" => Ok(Self::ComplexityAnalyst),
            "mutation-tester" => Ok(Self::MutationTester),
            "satd-detector" => Ok(Self::SATDDetector),
            "dead-code-eliminator" => Ok(Self::DeadCodeEliminator),
            "documentation-enforcer" => Ok(Self::DocumentationEnforcer),
            "rust-quality-expert" => Ok(Self::RustQualityExpert),
            "python-quality-expert" => Ok(Self::PythonQualityExpert),
            "typescript-quality-expert" => Ok(Self::TypeScriptQualityExpert),
            "wasm-deep-inspector" => Ok(Self::WasmDeepInspector),
            "refactoring-advisor" => Ok(Self::RefactoringAdvisor),
            "test-coverage-analyst" => Ok(Self::TestCoverageAnalyst),
            "quality-gate-orchestrator" => Ok(Self::QualityGateOrchestrator),
            _ => bail!("Unknown sub-agent: {}", s),
        }
    }
}

impl std::fmt::Display for PmatSubAgent {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}

/// Sub-agent generator for Claude Code.
pub struct SubAgentGenerator {
    _template_dir: PathBuf,
}

impl SubAgentGenerator {
    /// Create a new sub-agent generator.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn new() -> Self {
        Self {
            _template_dir: PathBuf::from("server/src/scaffold/agent/subagent_templates"),
        }
    }

    /// Create a generator with custom template directory.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub fn with_template_dir(template_dir: PathBuf) -> Self {
        Self {
            _template_dir: template_dir,
        }
    }

    /// Generate a sub-agent definition in markdown format.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn generate_subagent(&self, agent: PmatSubAgent) -> Result<String> {
        if !agent.is_mvp() {
            bail!(
                "Sub-agent {} is not yet implemented (future phase)",
                agent.name()
            );
        }

        match agent {
            PmatSubAgent::ComplexityAnalyst => self.generate_complexity_analyst(),
            PmatSubAgent::MutationTester => self.generate_mutation_tester(),
            PmatSubAgent::SATDDetector => self.generate_satd_detector(),
            PmatSubAgent::DeadCodeEliminator => self.generate_dead_code_eliminator(),
            PmatSubAgent::DocumentationEnforcer => self.generate_documentation_enforcer(),
            _ => bail!("Sub-agent {} not implemented in MVP", agent.name()),
        }
    }

    /// Export sub-agent to a file compatible with Claude Code.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub fn export_for_claude_code(
        &self,
        agent: PmatSubAgent,
        output_dir: &Path,
    ) -> Result<PathBuf> {
        let content = self.generate_subagent(agent)?;
        let filename = format!("{}.md", agent.name());
        let output_path = output_dir.join(filename);

        // Create output directory if it doesn't exist
        std::fs::create_dir_all(output_dir)?;

        // Write the sub-agent definition
        std::fs::write(&output_path, content)?;

        Ok(output_path)
    }

    /// Export all MVP sub-agents.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub fn export_all_mvp(&self, output_dir: &Path) -> Result<Vec<PathBuf>> {
        let mut paths = Vec::new();
        for agent in PmatSubAgent::all_mvp() {
            let path = self.export_for_claude_code(agent, output_dir)?;
            paths.push(path);
        }
        Ok(paths)
    }

    /// Get MCP tool mapping for all sub-agents.
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    pub fn get_tool_mapping() -> HashMap<PmatSubAgent, Vec<&'static str>> {
        let mut mapping = HashMap::new();
        for agent in PmatSubAgent::all() {
            mapping.insert(agent, agent.primary_tools());
        }
        mapping
    }

    // Template generation methods (to be implemented)
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    fn generate_complexity_analyst(&self) -> Result<String> {
        Ok(include_str!("subagent_templates/complexity_analyst.md.tmpl").to_string())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    fn generate_mutation_tester(&self) -> Result<String> {
        Ok(include_str!("subagent_templates/mutation_tester.md.tmpl").to_string())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    fn generate_satd_detector(&self) -> Result<String> {
        Ok(include_str!("subagent_templates/satd_detector.md.tmpl").to_string())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    fn generate_dead_code_eliminator(&self) -> Result<String> {
        Ok(include_str!("subagent_templates/dead_code_eliminator.md.tmpl").to_string())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    fn generate_documentation_enforcer(&self) -> Result<String> {
        Ok(include_str!("subagent_templates/documentation_enforcer.md.tmpl").to_string())
    }
}

impl Default for SubAgentGenerator {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_subagent_name() {
        assert_eq!(PmatSubAgent::ComplexityAnalyst.name(), "complexity-analyst");
        assert_eq!(PmatSubAgent::MutationTester.name(), "mutation-tester");
    }

    #[test]
    fn test_subagent_from_str() {
        let agent: PmatSubAgent = "complexity-analyst".parse().unwrap();
        assert_eq!(agent, PmatSubAgent::ComplexityAnalyst);

        let agent: PmatSubAgent = "mutation-tester".parse().unwrap();
        assert_eq!(agent, PmatSubAgent::MutationTester);
    }

    #[test]
    fn test_subagent_from_str_invalid() {
        let result: Result<PmatSubAgent> = "invalid-agent".parse();
        assert!(result.is_err());
    }

    #[test]
    fn test_all_mvp_agents() {
        let agents = PmatSubAgent::all_mvp();
        assert_eq!(agents.len(), 5);
        assert!(agents.iter().all(|a| a.is_mvp()));
    }

    #[test]
    fn test_primary_tools() {
        let tools = PmatSubAgent::ComplexityAnalyst.primary_tools();
        assert!(tools.contains(&"analyze_complexity"));

        let tools = PmatSubAgent::MutationTester.primary_tools();
        assert!(tools.contains(&"mutation_test"));
        assert!(tools.contains(&"mutation_predict"));
    }

    #[test]
    fn test_tool_mapping() {
        let mapping = SubAgentGenerator::get_tool_mapping();
        assert!(!mapping.is_empty());

        let complexity_tools = mapping.get(&PmatSubAgent::ComplexityAnalyst).unwrap();
        assert!(complexity_tools.contains(&"analyze_complexity"));
    }

    #[test]
    fn test_generator_creation() {
        let gen = SubAgentGenerator::new();
        assert!(gen
            ._template_dir
            .to_string_lossy()
            .contains("subagent_templates"));
    }

    #[test]
    fn test_non_mvp_agent_generates_error() {
        let gen = SubAgentGenerator::new();
        let result = gen.generate_subagent(PmatSubAgent::RustQualityExpert);
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("not yet implemented"));
    }

    // --- PMAT-634 additions: cover untested surface area for Phase-1 tactic #3 ---

    #[test]
    fn test_name_covers_all_variants() {
        // Every variant returns a kebab-case identifier matching FromStr round-trip.
        for agent in PmatSubAgent::all() {
            let name = agent.name();
            assert!(!name.is_empty(), "variant name is empty");
            let parsed: PmatSubAgent = name.parse().expect("round-trip parse");
            assert_eq!(parsed, agent, "FromStr inverse of name failed");
        }
    }

    #[test]
    fn test_description_non_empty_and_unique_across_variants() {
        let descs: Vec<&'static str> = PmatSubAgent::all()
            .iter()
            .map(|a| a.description())
            .collect();
        assert_eq!(descs.len(), 12);
        for d in &descs {
            assert!(!d.is_empty(), "description is empty");
        }
        let mut sorted = descs.clone();
        sorted.sort();
        sorted.dedup();
        assert_eq!(sorted.len(), descs.len(), "descriptions not unique");
    }

    #[test]
    fn test_is_mvp_false_for_future_variants() {
        let future = [
            PmatSubAgent::RustQualityExpert,
            PmatSubAgent::PythonQualityExpert,
            PmatSubAgent::TypeScriptQualityExpert,
            PmatSubAgent::WasmDeepInspector,
            PmatSubAgent::RefactoringAdvisor,
            PmatSubAgent::TestCoverageAnalyst,
            PmatSubAgent::QualityGateOrchestrator,
        ];
        for a in future {
            assert!(!a.is_mvp(), "{} should not be MVP", a.name());
        }
    }

    #[test]
    fn test_primary_tools_non_empty_for_all_variants() {
        for agent in PmatSubAgent::all() {
            let tools = agent.primary_tools();
            assert!(
                !tools.is_empty(),
                "primary_tools empty for {}",
                agent.name()
            );
            for t in tools {
                assert!(!t.is_empty());
            }
        }
    }

    #[test]
    fn test_primary_tools_specific_mappings() {
        assert_eq!(
            PmatSubAgent::SATDDetector.primary_tools(),
            vec!["analyze_satd", "analyze_context"]
        );
        assert_eq!(
            PmatSubAgent::DeadCodeEliminator.primary_tools(),
            vec!["analyze_dead_code", "analyze_imports"]
        );
        assert_eq!(
            PmatSubAgent::DocumentationEnforcer.primary_tools(),
            vec!["check_generic_docs", "analyze_context"]
        );
        assert_eq!(
            PmatSubAgent::WasmDeepInspector.primary_tools(),
            vec!["deep_wasm_analyze", "wasm_disassemble"]
        );
        assert_eq!(
            PmatSubAgent::QualityGateOrchestrator.primary_tools(),
            vec!["run_quality_gates", "aggregate_metrics"]
        );
    }

    #[test]
    fn test_all_returns_full_roster() {
        let all = PmatSubAgent::all();
        assert_eq!(all.len(), 12);
        // The first 5 must match all_mvp() in order (contract relied on by all_mvp).
        assert_eq!(&all[..5], &PmatSubAgent::all_mvp()[..]);
        // No duplicates.
        let mut sorted = all.clone();
        sorted.sort_by_key(|a| a.name());
        sorted.dedup();
        assert_eq!(sorted.len(), 12);
    }

    #[test]
    fn test_from_str_round_trip_all_variants() {
        // name() → FromStr → name() should be a fixed point for all 12 variants.
        for a in PmatSubAgent::all() {
            let parsed: PmatSubAgent = a.name().parse().expect("parse");
            assert_eq!(parsed.name(), a.name());
        }
    }

    #[test]
    fn test_display_matches_name() {
        for a in PmatSubAgent::all() {
            assert_eq!(format!("{}", a), a.name());
        }
    }

    #[test]
    fn test_from_str_error_message_names_input() {
        let err = "not-a-real-agent"
            .parse::<PmatSubAgent>()
            .unwrap_err()
            .to_string();
        assert!(err.contains("not-a-real-agent"), "err was: {err}");
    }

    #[test]
    fn test_with_template_dir_sets_field() {
        let dir = std::path::PathBuf::from("/tmp/custom-subagent-templates");
        let gen = SubAgentGenerator::with_template_dir(dir.clone());
        assert_eq!(gen._template_dir, dir);
    }

    #[test]
    fn test_default_matches_new() {
        let a = SubAgentGenerator::default();
        let b = SubAgentGenerator::new();
        assert_eq!(a._template_dir, b._template_dir);
    }

    #[test]
    fn test_generate_subagent_returns_non_empty_for_all_mvp() {
        let gen = SubAgentGenerator::new();
        for agent in PmatSubAgent::all_mvp() {
            let content = gen.generate_subagent(agent).expect("MVP generate ok");
            assert!(!content.is_empty(), "empty content for {}", agent.name());
        }
    }

    #[test]
    fn test_export_for_claude_code_writes_file_and_returns_path() {
        let tmp = tempfile::TempDir::new().expect("tmp");
        let gen = SubAgentGenerator::new();
        let path = gen
            .export_for_claude_code(PmatSubAgent::ComplexityAnalyst, tmp.path())
            .expect("export");
        assert_eq!(path, tmp.path().join("complexity-analyst.md"));
        let disk = std::fs::read_to_string(&path).expect("read");
        let expected = gen
            .generate_subagent(PmatSubAgent::ComplexityAnalyst)
            .unwrap();
        assert_eq!(disk, expected);
    }

    #[test]
    fn test_export_for_claude_code_creates_missing_directory() {
        let tmp = tempfile::TempDir::new().expect("tmp");
        let nested = tmp.path().join("does/not/exist/yet");
        assert!(!nested.exists());
        let gen = SubAgentGenerator::new();
        let path = gen
            .export_for_claude_code(PmatSubAgent::SATDDetector, &nested)
            .expect("export with nested");
        assert!(path.exists());
        assert!(nested.is_dir());
    }

    #[test]
    fn test_export_for_claude_code_non_mvp_propagates_error() {
        let tmp = tempfile::TempDir::new().expect("tmp");
        let gen = SubAgentGenerator::new();
        let err = gen
            .export_for_claude_code(PmatSubAgent::RefactoringAdvisor, tmp.path())
            .unwrap_err()
            .to_string();
        assert!(err.contains("not yet implemented"), "err was: {err}");
        // No file should have been written on the error path.
        assert!(!tmp.path().join("refactoring-advisor.md").exists());
    }

    #[test]
    fn test_export_all_mvp_writes_five_files() {
        let tmp = tempfile::TempDir::new().expect("tmp");
        let gen = SubAgentGenerator::new();
        let paths = gen.export_all_mvp(tmp.path()).expect("export all");
        assert_eq!(paths.len(), 5);
        for p in &paths {
            assert!(p.exists(), "missing {}", p.display());
            assert!(p.starts_with(tmp.path()));
        }
        for agent in PmatSubAgent::all_mvp() {
            let expected = tmp.path().join(format!("{}.md", agent.name()));
            assert!(
                paths.contains(&expected),
                "missing path for {}",
                agent.name()
            );
        }
    }

    #[test]
    fn test_get_tool_mapping_covers_every_variant() {
        let mapping = SubAgentGenerator::get_tool_mapping();
        assert_eq!(mapping.len(), 12);
        for agent in PmatSubAgent::all() {
            let tools = mapping.get(&agent).expect("entry");
            assert_eq!(tools, &agent.primary_tools());
        }
    }
}