pmat 3.11.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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
# Sprint 63 Kickoff: Multi-Language Mutation Testing Support

**Sprint Duration**: 3 days
**Target Version**: v2.176.0
**Start Date**: October 27, 2025 (after Sprint 62 completion)
**Focus**: Extend mutation testing from Rust-only to support Python, TypeScript, Go, and C++

---

## Sprint Goals

### Primary Goal
Expand `pmat mutate` to support **5 languages** with production-ready mutation operators:
1. **Rust** (already implemented in v2.175.0)
2. **Python** (NEW)
3. **TypeScript/JavaScript** (NEW)
4. **Go** (NEW)
5. **C++** (NEW)

### Success Criteria
- ✅ Language auto-detection from file extensions
- ✅ 5-10 mutation operators per language
- ✅ Integration tests for all 5 languages
- ✅ Documentation updated with language-specific examples
- ✅ Performance comparable to Rust implementation

---

## Architecture Overview

### Current State (v2.175.0)
```
pmat mutate
  └── server/src/services/mutation/
      ├── engine.rs                          # Generic mutation engine
      ├── types.rs                           # Mutant, MutantStatus enums
      ├── rust_tree_sitter_mutations.rs      # Rust-specific mutations
      └── rust_adapter.rs                    # Cargo test runner
```

**Rust-only**: All mutation logic hardcoded for Rust syntax

### Target State (v2.176.0)
```
pmat mutate
  └── server/src/services/mutation/
      ├── engine.rs                          # Generic mutation engine (updated)
      ├── types.rs                           # Mutant, MutantStatus enums (unchanged)
      ├── language_detector.rs               # NEW: Auto-detect language from file
      ├── operators/                         # NEW: Per-language mutation operators
      │   ├── mod.rs                         # Trait: MutationOperator
      │   ├── rust.rs                        # Rust operators (refactored from rust_tree_sitter_mutations.rs)
      │   ├── python.rs                      # Python operators
      │   ├── typescript.rs                  # TypeScript/JavaScript operators
      │   ├── go.rs                          # Go operators
      │   └── cpp.rs                         # C++ operators
      └── adapters/                          # NEW: Per-language test runners
          ├── mod.rs                         # Trait: TestAdapter
          ├── rust.rs                        # Cargo test runner (refactored from rust_adapter.rs)
          ├── python.rs                      # pytest/unittest runner
          ├── typescript.rs                  # Jest/Mocha runner
          ├── go.rs                          # go test runner
          └── cpp.rs                         # gtest/Catch2 runner
```

**Multi-language**: Plugin architecture with language-specific implementations

---

## Implementation Plan

### Day 1: Architecture Refactoring + Python Support

#### Task 1: Create Language Detection Module (1 hour)
**File**: `server/src/services/mutation/language_detector.rs`

```rust
use std::path::Path;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Language {
    Rust,
    Python,
    TypeScript,
    JavaScript,
    Go,
    Cpp,
    Unsupported,
}

impl Language {
    pub fn from_extension(path: &Path) -> Self {
        match path.extension().and_then(|e| e.to_str()) {
            Some("rs") => Language::Rust,
            Some("py") => Language::Python,
            Some("ts") => Language::TypeScript,
            Some("tsx") => Language::TypeScript,
            Some("js") => Language::JavaScript,
            Some("jsx") => Language::JavaScript,
            Some("go") => Language::Go,
            Some("cpp") | Some("cc") | Some("cxx") | Some("hpp") | Some("hxx") => Language::Cpp,
            _ => Language::Unsupported,
        }
    }

    pub fn name(&self) -> &'static str {
        match self {
            Language::Rust => "Rust",
            Language::Python => "Python",
            Language::TypeScript => "TypeScript",
            Language::JavaScript => "JavaScript",
            Language::Go => "Go",
            Language::Cpp => "C++",
            Language::Unsupported => "Unsupported",
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_rust_detection() {
        assert_eq!(Language::from_extension(Path::new("foo.rs")), Language::Rust);
    }

    #[test]
    fn test_python_detection() {
        assert_eq!(Language::from_extension(Path::new("foo.py")), Language::Python);
    }

    #[test]
    fn test_typescript_detection() {
        assert_eq!(Language::from_extension(Path::new("foo.ts")), Language::TypeScript);
        assert_eq!(Language::from_extension(Path::new("foo.tsx")), Language::TypeScript);
    }
}
```

#### Task 2: Define Operator and Adapter Traits (1 hour)
**File**: `server/src/services/mutation/operators/mod.rs`

```rust
use crate::services::mutation::types::{Mutant, MutantStatus};
use std::path::Path;

pub mod rust;
pub mod python;
pub mod typescript;
pub mod go;
pub mod cpp;

/// Trait for language-specific mutation operators
pub trait MutationOperator {
    /// Generate mutants for a given source file
    fn generate_mutants(&self, source: &str, file_path: &Path) -> Result<Vec<Mutant>, String>;

    /// Apply a mutant to source code
    fn apply_mutant(&self, source: &str, mutant: &Mutant) -> Result<String, String>;
}

/// Trait for language-specific test adapters
pub trait TestAdapter {
    /// Run tests for a mutated file
    fn run_tests(&self, mutated_source: &str, original_file: &Path) -> Result<MutantStatus, String>;

    /// Get test timeout in seconds
    fn timeout(&self) -> u64;
}
```

#### Task 3: Refactor Rust Implementation (2 hours)
Move existing Rust code into new architecture:
- Extract from `rust_tree_sitter_mutations.rs``operators/rust.rs`
- Extract from `rust_adapter.rs``adapters/rust.rs`
- Implement `MutationOperator` and `TestAdapter` traits

#### Task 4: Implement Python Mutation Operators (4 hours)
**File**: `server/src/services/mutation/operators/python.rs`

**Mutation Operators** (5 operators for Day 1):
1. **Binary Operators**: `+``-`, `*``/`, `//``%`
2. **Comparison Operators**: `>``<`, `>=``<=`, `==``!=`
3. **Boolean Operators**: `and``or`, `not` removed
4. **Return Values**: `True``False`, `0``1`
5. **String Mutations**: `""``"<MUTANT>"`, string concatenation

**Implementation**:
```rust
use super::MutationOperator;
use crate::services::mutation::types::Mutant;
use std::path::Path;
use tree_sitter::{Parser, Query, QueryCursor};

pub struct PythonMutationOperator {
    parser: Parser,
}

impl PythonMutationOperator {
    pub fn new() -> Result<Self, String> {
        let mut parser = Parser::new();
        parser
            .set_language(tree_sitter_python::language())
            .map_err(|e| format!("Failed to set Python parser: {}", e))?;
        Ok(Self { parser })
    }
}

impl MutationOperator for PythonMutationOperator {
    fn generate_mutants(&self, source: &str, file_path: &Path) -> Result<Vec<Mutant>, String> {
        let tree = self.parser.parse(source, None)
            .ok_or("Failed to parse Python source")?;

        let mut mutants = Vec::new();

        // Binary operators
        let binary_query = Query::new(
            tree_sitter_python::language(),
            "(binary_operator left: (_) operator: _ @op right: (_))"
        ).map_err(|e| format!("Failed to create query: {}", e))?;

        let mut cursor = QueryCursor::new();
        for m in cursor.matches(&binary_query, tree.root_node(), source.as_bytes()) {
            for capture in m.captures {
                let op_text = capture.node.utf8_text(source.as_bytes()).unwrap();
                let replacement = match op_text {
                    "+" => "-",
                    "-" => "+",
                    "*" => "/",
                    "/" => "*",
                    "//" => "%",
                    _ => continue,
                };

                mutants.push(Mutant {
                    original_file: file_path.to_path_buf(),
                    location: (
                        capture.node.start_position().row + 1,
                        capture.node.start_position().column + 1,
                        capture.node.end_position().row + 1,
                        capture.node.end_position().column + 1,
                    ),
                    operator: format!("BinaryOp({} → {})", op_text, replacement),
                    original_source: op_text.to_string(),
                    mutated_source: replacement.to_string(),
                });
            }
        }

        Ok(mutants)
    }

    fn apply_mutant(&self, source: &str, mutant: &Mutant) -> Result<String, String> {
        // Apply byte-level replacement (same logic as Rust)
        let bytes = source.as_bytes();
        let start_byte = /* calculate from location */;
        let end_byte = /* calculate from location */;

        let mut mutated = Vec::new();
        mutated.extend_from_slice(&bytes[..start_byte]);
        mutated.extend_from_slice(mutant.mutated_source.as_bytes());
        mutated.extend_from_slice(&bytes[end_byte..]);

        String::from_utf8(mutated).map_err(|e| format!("Invalid UTF-8: {}", e))
    }
}
```

#### Task 5: Implement Python Test Adapter (2 hours)
**File**: `server/src/services/mutation/adapters/python.rs`

```rust
use super::TestAdapter;
use crate::services::mutation::types::MutantStatus;
use std::path::Path;
use std::process::Command;
use std::time::Duration;

pub struct PythonTestAdapter {
    timeout: u64,
}

impl PythonTestAdapter {
    pub fn new(timeout: u64) -> Self {
        Self { timeout }
    }
}

impl TestAdapter for PythonTestAdapter {
    fn run_tests(&self, mutated_source: &str, original_file: &Path) -> Result<MutantStatus, String> {
        // Write mutated source to temporary file
        let temp_file = format!("/tmp/mutant_{}.py", uuid::Uuid::new_v4());
        std::fs::write(&temp_file, mutated_source)
            .map_err(|e| format!("Failed to write temp file: {}", e))?;

        // Run pytest
        let output = Command::new("pytest")
            .arg(&temp_file)
            .arg("--tb=short")
            .arg("-q")
            .timeout(Duration::from_secs(self.timeout))
            .output()
            .map_err(|e| format!("Failed to run pytest: {}", e))?;

        // Clean up
        let _ = std::fs::remove_file(&temp_file);

        // Determine status
        if output.status.success() {
            Ok(MutantStatus::Survived)
        } else if output.status.code() == Some(1) {
            Ok(MutantStatus::Killed)
        } else {
            Ok(MutantStatus::CompileError)
        }
    }

    fn timeout(&self) -> u64 {
        self.timeout
    }
}
```

#### Task 6: Update Engine to Support Multiple Languages (1 hour)
**File**: `server/src/services/mutation/engine.rs`

```rust
use crate::services::mutation::language_detector::{Language, LanguageDetector};
use crate::services::mutation::operators::{MutationOperator, rust::RustMutationOperator, python::PythonMutationOperator};
use crate::services::mutation::adapters::{TestAdapter, rust::RustTestAdapter, python::PythonTestAdapter};

pub struct MutationEngine {
    language: Language,
    operator: Box<dyn MutationOperator>,
    adapter: Box<dyn TestAdapter>,
}

impl MutationEngine {
    pub fn new(file_path: &Path, timeout: u64) -> Result<Self, String> {
        let language = Language::from_extension(file_path);

        let (operator, adapter): (Box<dyn MutationOperator>, Box<dyn TestAdapter>) = match language {
            Language::Rust => (
                Box::new(RustMutationOperator::new()?),
                Box::new(RustTestAdapter::new(timeout)),
            ),
            Language::Python => (
                Box::new(PythonMutationOperator::new()?),
                Box::new(PythonTestAdapter::new(timeout)),
            ),
            _ => return Err(format!("Unsupported language: {:?}", language)),
        };

        Ok(Self { language, operator, adapter })
    }

    pub fn generate_mutants(&self, source: &str, file_path: &Path) -> Result<Vec<Mutant>, String> {
        self.operator.generate_mutants(source, file_path)
    }

    pub fn test_mutant(&self, source: &str, mutant: &Mutant) -> Result<MutantStatus, String> {
        let mutated_source = self.operator.apply_mutant(source, mutant)?;
        self.adapter.run_tests(&mutated_source, &mutant.original_file)
    }
}
```

#### Task 7: Add Integration Tests (1 hour)
**File**: `server/tests/mutation_multi_language_tests.rs`

```rust
#[test]
fn test_python_mutation_generation() {
    let python_code = r#"
def add(a, b):
    return a + b

def is_positive(x):
    return x > 0
"#;

    let temp_file = std::env::temp_dir().join("test_python.py");
    std::fs::write(&temp_file, python_code).unwrap();

    let engine = MutationEngine::new(&temp_file, 30).unwrap();
    let mutants = engine.generate_mutants(python_code, &temp_file).unwrap();

    assert!(mutants.len() >= 2); // At least + → - and > → <
    assert!(mutants.iter().any(|m| m.operator.contains("BinaryOp(+ → -)")));
    assert!(mutants.iter().any(|m| m.operator.contains("ComparisonOp(> → <)")));
}

#[test]
fn test_python_test_execution() {
    let python_code = r#"
def divide(a, b):
    if b == 0:
        raise ValueError("Division by zero")
    return a / b

def test_divide():
    assert divide(10, 2) == 5
    assert divide(20, 4) == 5
"#;

    let temp_file = std::env::temp_dir().join("test_python_exec.py");
    std::fs::write(&temp_file, python_code).unwrap();

    let engine = MutationEngine::new(&temp_file, 30).unwrap();
    let mutants = engine.generate_mutants(python_code, &temp_file).unwrap();

    // Test first mutant (likely == → !=)
    let mutant = &mutants[0];
    let status = engine.test_mutant(python_code, mutant).unwrap();
    assert_eq!(status, MutantStatus::Killed); // Should be caught by tests
}
```

---

### Day 2: TypeScript and Go Support

#### Task 1: Implement TypeScript Mutation Operators (4 hours)
**File**: `server/src/services/mutation/operators/typescript.rs`

**Mutation Operators** (8 operators):
1. **Binary Operators**: Same as Rust/Python
2. **Comparison Operators**: Same as Rust/Python
3. **Boolean Operators**: `&&``||`, `!` removed
4. **Ternary Operators**: `? :` condition flipped
5. **Template Literals**: Mutate `${var}` interpolation
6. **Arrow Functions**: Mutate return expressions
7. **Type Assertions**: Remove/modify `as Type`
8. **Optional Chaining**: Remove `?.``.`

**Dependencies**:
```toml
# Cargo.toml
tree-sitter-typescript = "0.20"  # Add to dependencies
```

#### Task 2: Implement TypeScript Test Adapter (2 hours)
**File**: `server/src/services/mutation/adapters/typescript.rs`

Support multiple test frameworks:
- Jest (default)
- Mocha
- Vitest

Detection logic:
```rust
fn detect_test_framework(project_dir: &Path) -> TestFramework {
    let package_json = project_dir.join("package.json");
    if package_json.exists() {
        let content = std::fs::read_to_string(&package_json).unwrap_or_default();
        if content.contains("\"jest\"") {
            return TestFramework::Jest;
        } else if content.contains("\"mocha\"") {
            return TestFramework::Mocha;
        } else if content.contains("\"vitest\"") {
            return TestFramework::Vitest;
        }
    }
    TestFramework::Jest // Default
}
```

#### Task 3: Implement Go Mutation Operators (4 hours)
**File**: `server/src/services/mutation/operators/go.rs`

**Mutation Operators** (7 operators):
1. **Binary Operators**: Same as other languages
2. **Comparison Operators**: Same as other languages
3. **Boolean Operators**: `&&``||`, `!` removed
4. **Slice Operations**: Mutate slice bounds `[:]`, `[1:]`, `[:len]`
5. **Channel Operations**: `<-ch` timing mutations
6. **Goroutines**: Remove `go` keyword (make synchronous)
7. **Defer Statements**: Remove `defer` keyword

**Dependencies**:
```toml
# Cargo.toml
tree-sitter-go = "0.20"  # Add to dependencies
```

#### Task 4: Implement Go Test Adapter (2 hours)
**File**: `server/src/services/mutation/adapters/go.rs`

```rust
impl TestAdapter for GoTestAdapter {
    fn run_tests(&self, mutated_source: &str, original_file: &Path) -> Result<MutantStatus, String> {
        // Write mutated source to temp file
        let temp_file = format!("/tmp/mutant_{}.go", uuid::Uuid::new_v4());
        std::fs::write(&temp_file, mutated_source)
            .map_err(|e| format!("Failed to write temp file: {}", e))?;

        // Run go test
        let output = Command::new("go")
            .arg("test")
            .arg(&temp_file)
            .arg("-v")
            .timeout(Duration::from_secs(self.timeout))
            .output()
            .map_err(|e| format!("Failed to run go test: {}", e))?;

        // Parse output
        let stdout = String::from_utf8_lossy(&output.stdout);
        if stdout.contains("PASS") {
            Ok(MutantStatus::Survived)
        } else if stdout.contains("FAIL") {
            Ok(MutantStatus::Killed)
        } else {
            Ok(MutantStatus::CompileError)
        }
    }

    fn timeout(&self) -> u64 {
        self.timeout
    }
}
```

#### Task 5: Integration Tests for TypeScript and Go (2 hours)
Add comprehensive test coverage for both languages

---

### Day 3: C++ Support, Documentation, and Release

#### Task 1: Implement C++ Mutation Operators (4 hours)
**File**: `server/src/services/mutation/operators/cpp.rs`

**Mutation Operators** (8 operators):
1. **Binary Operators**: Same as other languages
2. **Comparison Operators**: Same as other languages
3. **Boolean Operators**: `&&``||`, `!` removed
4. **Pointer Operations**: `*ptr``ptr`, `&var` removed
5. **Increment/Decrement**: `++``--`, `+=``-=`
6. **Member Access**: `.``->`
7. **Template Arguments**: Mutate template parameters
8. **Move Semantics**: `std::move()` removed

**Dependencies**:
```toml
# Cargo.toml
tree-sitter-cpp = "0.20"  # Add to dependencies
```

#### Task 2: Implement C++ Test Adapter (2 hours)
**File**: `server/src/services/mutation/adapters/cpp.rs`

Support multiple test frameworks:
- Google Test (gtest) - default
- Catch2
- Boost.Test

Detection logic similar to TypeScript (check CMakeLists.txt or Makefile)

#### Task 3: Update CLI Handler (1 hour)
**File**: `server/src/cli/handlers/mutate.rs`

Update to show language information:
```rust
println!("Detected language: {}", language.name());
println!("Mutation operators: {} loaded", operator_count);
```

#### Task 4: Update Documentation (2 hours)

**Update files**:
1. `server/README.md` - Add multi-language examples
2. `CHANGELOG.md` - Add v2.176.0 release notes
3. `pmat-book/src/ch28-00-mutation-testing.md` - Add language-specific sections
4. `docs/execution/SPRINT-63-PROGRESS.md` - Track implementation status

**Example additions to Chapter 28**:
```markdown
## Multi-Language Support (v2.176.0+)

### Python Mutation Testing

\`\`\`bash
# Mutate Python file
pmat mutate --target src/calculator.py

# With pytest
pmat mutate --target tests/test_math.py --timeout 30
\`\`\`

### TypeScript Mutation Testing

\`\`\`bash
# Mutate TypeScript file (auto-detects Jest/Mocha)
pmat mutate --target src/utils.ts

# React component mutation
pmat mutate --target src/components/Button.tsx
\`\`\`

### Go Mutation Testing

\`\`\`bash
# Mutate Go file
pmat mutate --target pkg/calculator.go

# Test package
pmat mutate --target pkg/ --timeout 60
\`\`\`

### C++ Mutation Testing

\`\`\`bash
# Mutate C++ file (auto-detects gtest/Catch2)
pmat mutate --target src/calculator.cpp

# Header file mutation
pmat mutate --target include/utils.hpp
\`\`\`
```

#### Task 5: Integration Tests and Quality Gates (2 hours)
```bash
# Run all mutation tests
cargo test --test mutation_multi_language_tests

# Verify language detection
cargo test --lib mutation::language_detector

# Run clippy
cargo clippy --all-targets --all-features

# Build release binary
cargo build --release --bin pmat
```

#### Task 6: Version Bump and Release (1 hour)
```bash
# Update version 2.175.0 → 2.176.0
# Update CHANGELOG.md
# Commit, tag, and push
git commit -m "feat: Add multi-language mutation testing support (Python, TypeScript, Go, C++)"
git tag -a v2.176.0 -m "v2.176.0: Multi-language mutation testing"
git push && git push --tags

# Publish to crates.io
cd server && cargo publish
```

---

## Dependencies

### Rust Crates (Add to `server/Cargo.toml`)
```toml
[dependencies]
tree-sitter = "0.20"
tree-sitter-rust = "0.20"
tree-sitter-python = "0.20"       # NEW
tree-sitter-typescript = "0.20"   # NEW
tree-sitter-go = "0.20"           # NEW
tree-sitter-cpp = "0.20"          # NEW
uuid = { version = "1.0", features = ["v4"] }  # For temp files
```

### External Tools (System Requirements)
Users must have these installed for respective languages:
- **Python**: `pytest` or `unittest`
- **TypeScript**: `npm`, `jest`, or `mocha`
- **Go**: `go` toolchain
- **C++**: `g++`, `cmake`, `gtest` or `catch2`

**Detection Logic**: Warn user if tools are missing
```rust
fn check_prerequisites(language: Language) -> Result<(), String> {
    match language {
        Language::Python => {
            Command::new("pytest").arg("--version").status()
                .map_err(|_| "pytest not found. Install with: pip install pytest")?;
        },
        Language::TypeScript => {
            Command::new("npm").arg("--version").status()
                .map_err(|_| "npm not found. Install Node.js from: https://nodejs.org")?;
        },
        // ... etc
    }
    Ok(())
}
```

---

## Testing Strategy

### Unit Tests (30 tests)
- Language detection (5 tests)
- Operator trait implementations (10 tests per language = 50 tests)
- Adapter trait implementations (10 tests per language = 50 tests)
- **Total**: ~100 unit tests

### Integration Tests (20 tests)
- End-to-end mutation testing per language (4 tests per language = 20 tests)
- Multi-file projects (5 tests)
- Error handling (5 tests)
- **Total**: ~30 integration tests

### Property-Based Tests (10 tests)
- Mutant generation properties (all languages)
- Test adapter properties (all languages)
- Language detection properties

### Manual Testing
Test on real-world projects:
- **Rust**: `pmat` itself (server/src)
- **Python**: `paiml` packages
- **TypeScript**: Interactive platform (if available)
- **Go**: Any internal Go projects
- **C++**: `paiml-mcp-agent-toolkit` C++ examples

---

## Performance Targets

| Metric | Target | Measurement |
|--------|--------|-------------|
| **Mutant Generation** | <100ms per file | Time to parse and generate mutants |
| **Test Execution** | <30s per mutant | Default timeout, configurable |
| **Memory Usage** | <500MB total | Peak RSS during execution |
| **Throughput** | >10 mutants/sec | Parallel execution efficiency |

**Benchmark Script**:
```bash
#!/bin/bash
# Sprint 63 performance benchmark

echo "=== Multi-Language Performance Benchmark ==="

for lang in rust python typescript go cpp; do
    echo ""
    echo "Testing $lang..."
    time pmat mutate --target examples/$lang/sample.$lang --timeout 30
done
```

---

## Risk Mitigation

### Risk 1: Tree-Sitter Parser Compatibility
**Mitigation**: Use well-maintained tree-sitter grammars with stable APIs
**Fallback**: Implement basic regex-based mutation if parser fails

### Risk 2: Test Framework Detection Failures
**Mitigation**: Support multiple frameworks per language with auto-detection
**Fallback**: Allow users to specify test command manually: `--test-command "pytest {}"`

### Risk 3: Timeout Handling Across Languages
**Mitigation**: Use Rust's `std::process::Command` timeout consistently
**Fallback**: OS-level timeout as last resort

### Risk 4: Temporary File Management
**Mitigation**: Use `uuid` for unique temp files, clean up in `Drop` trait
**Fallback**: Log temp file paths for manual cleanup if needed

---

## Documentation Checklist

- [ ] Update `server/README.md` with multi-language examples
- [ ] Update `pmat-book/src/ch28-00-mutation-testing.md` with language sections
- [ ] Add `docs/guides/mutation-testing-python.md`
- [ ] Add `docs/guides/mutation-testing-typescript.md`
- [ ] Add `docs/guides/mutation-testing-go.md`
- [ ] Add `docs/guides/mutation-testing-cpp.md`
- [ ] Update `CHANGELOG.md` with v2.176.0 notes
- [ ] Update `docs/execution/SPRINT-63-PROGRESS.md` daily
- [ ] Create `examples/` directory with sample projects per language

---

## Success Metrics

### Day 1 Success
- ✅ Python mutation operators implemented (5 operators)
- ✅ Python test adapter working with pytest
- ✅ At least 10 unit tests passing
- ✅ 1 end-to-end Python integration test passing

### Day 2 Success
- ✅ TypeScript mutation operators implemented (8 operators)
- ✅ Go mutation operators implemented (7 operators)
- ✅ Both test adapters working
- ✅ 20+ unit tests passing
- ✅ 2 end-to-end integration tests passing (TS + Go)

### Day 3 Success
- ✅ C++ mutation operators implemented (8 operators)
- ✅ C++ test adapter working with gtest
- ✅ All 5 languages fully tested
- ✅ Documentation complete
- ✅ v2.176.0 released to crates.io and GitHub

### Sprint 63 Success (Overall)
- ✅ 5 languages supported (Rust, Python, TypeScript, Go, C++)
- ✅ 100+ unit tests passing
- ✅ 30+ integration tests passing
- ✅ Performance targets met
- ✅ Documentation complete
- ✅ v2.176.0 released and published

---

## Follow-Up Work (Sprint 64+)

### Sprint 64: Advanced Mutation Testing
- Incremental mutation testing (only changed files)
- Mutation caching (skip equivalent mutants)
- Mutation score trending over time
- Badge generation for READMEs

### Sprint 65: IDE Integration
- VS Code extension for inline mutation indicators
- IntelliJ plugin
- Real-time mutation score display

### Future Enhancements
- Java mutation testing (JUnit)
- Ruby mutation testing (RSpec)
- PHP mutation testing (PHPUnit)
- Swift mutation testing (XCTest)

---

## References

### Related Sprints
- **Sprint 61**: Mutation Testing CLI Implementation (v2.174.0)
- **Sprint 62**: Output Refinement and Testing (v2.175.0)
- **Sprint 64**: Advanced Features (v2.177.0)

### Existing Code References
- `server/src/services/mutation/engine.rs:1-250` - Current engine
- `server/src/services/mutation/types.rs:1-100` - Mutant types
- `server/src/services/mutation/rust_tree_sitter_mutations.rs:1-400` - Rust operators
- `server/src/cli/handlers/mutate.rs:1-280` - CLI handler

### External Tools
- **Tree-Sitter**: https://tree-sitter.github.io/tree-sitter/
- **cargo-mutants**: https://github.com/sourcefrog/cargo-mutants (reference implementation)
- **mutation-testing.io**: https://mutation-testing.io (industry standards)

---

**Document Version**: 1.0
**Last Updated**: October 27, 2025
**Status**: DRAFT - Ready for Sprint 63 kickoff after Sprint 62 completion