requirements-manager 0.1.1

Plain-text requirements management tool
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
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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
# Test Traceability System Design

**Version**: 1.0
**Date**: 2025-10-25
**Status**: Proposed

## Executive Summary

This document describes a comprehensive design for automated requirement-to-test traceability in Requiem. The system automatically discovers tests in source code, creates TEST requirements linked to verified requirements, tracks test execution status, and provides project management visibility into verification coverage throughout the development lifecycle.

**Key Features**:
- Automatic synchronization between code tests and TEST requirements (no manual maintenance)
- Language-agnostic design (initial Rust support, extensible to Python, C++, etc.)
- Suspect link detection for failed tests and changed requirements
- Coverage reporting and traceability matrices
- Release snapshot capabilities for compliance documentation

## Goals and Non-Goals

### Goals
1. **Automatic synchronization**: TEST requirements auto-generated from code annotations
2. **Single source of truth**: Test annotations in code drive requirement generation
3. **Language agnostic**: Support multiple programming languages and test frameworks
4. **Change impact analysis**: Track when requirements change and which tests become suspect
5. **Test status tracking**: Record pass/fail status and link to requirement verification
6. **Project visibility**: Enable PMs to track coverage trends and generate release reports
7. **Compliance ready**: Generate documentation suitable for regulatory requirements

### Non-Goals
1. **Test execution**: This tool does not run tests, only tracks their relationship to requirements
2. **Test framework replacement**: Works alongside existing test frameworks, doesn't replace them
3. **Requirement authoring from tests**: Requirements are still manually written; tests verify existing requirements
4. **Real-time test monitoring**: Status updates require explicit import of test results

## Architecture Overview

### 1. Domain Model Extensions

#### 1.1 Test Metadata Structure

Add test-specific metadata to requirements:

```rust
pub struct TestMetadata {
    /// Location of the test in source code
    /// Format: "path/to/file.rs::test_function_name"
    pub location: String,

    /// Test framework identifier
    /// Examples: "rust-test", "pytest", "junit", "gtest"
    pub framework: String,

    /// Last known test execution status
    pub last_status: TestStatus,

    /// When the test was last executed
    pub last_run: Option<DateTime<Utc>>,

    /// Fingerprint of test status (changes when test starts failing)
    pub status_fingerprint: String,
}

pub enum TestStatus {
    Passed,
    Failed { error: String },
    NotRun,
    Skipped,
}
```

This metadata is stored in TEST requirement frontmatter:

```yaml
---
_version: '1'
uuid: a1b2c3d4-...
created: 2025-10-25T16:00:00Z
parents:
  - uuid: 4bfeb7d5-...  # USR-001
    fingerprint: abc123...
    hrid: USR-001
test_metadata:
  location: "src/domain/requirement.rs::test_requirement_creation"
  framework: "rust-test"
  last_status:
    Passed: null
  last_run: 2025-10-25T16:30:00Z
  status_fingerprint: def456...
---
```

#### 1.2 Extended Suspect Link System

Extend the existing `Parent` structure to include test-specific suspect reasons:

```rust
pub struct Parent {
    pub hrid: Hrid,
    pub fingerprint: String,
    pub suspect_reason: Option<SuspectReason>,
}

pub enum SuspectReason {
    /// Parent requirement content changed (existing)
    ParentChanged,

    /// Test failed during last execution (new)
    TestFailed {
        error: String,
        timestamp: DateTime<Utc>,
    },

    /// Test hasn't been executed recently (new)
    TestStale {
        last_run: DateTime<Utc>,
        threshold: Duration,
    },

    /// Test was skipped (new)
    TestSkipped {
        reason: Option<String>,
    },
}
```

**Suspect Link Logic**:
- For **normal requirements** with TEST children: requirement is suspect if any test fails
- For **TEST requirements** with verified parents: link is suspect if:
  - Parent requirement fingerprint changed (existing behavior)
  - Test execution failed
  - Test hasn't run within configured threshold

### 2. Test Discovery System

#### 2.1 Test Scanner Interface

Language-agnostic interface for discovering tests:

```rust
pub trait TestScanner {
    /// Scan a directory tree for tests
    fn scan(&self, root: &Path) -> Result<Vec<DiscoveredTest>>;

    /// Get the framework identifier
    fn framework_id(&self) -> &str;
}

pub struct DiscoveredTest {
    /// Unique location identifier
    /// Format depends on language: "path/to/file.ext::test_name"
    pub location: String,

    /// Test framework
    pub framework: String,

    /// Description from doc comments
    pub description: String,

    /// Requirements this test verifies (from annotations)
    pub verifies: Vec<Hrid>,

    /// Optional tags
    pub tags: BTreeSet<String>,
}
```

#### 2.2 Rust Test Scanner

Parses Rust source files for test annotations:

**Annotation Formats Supported**:

1. **Doc comment annotations** (Phase 1):
```rust
/// Verifies that requirements can be created from HRID
///
/// @verifies USR-001
/// @verifies SYS-003
#[test]
fn test_requirement_creation() {
    // test code
}
```

2. **Attribute macros** (Phase 2, future):
```rust
#[test]
#[requirement_verifies("USR-001", "SYS-003")]
fn test_requirement_creation() {
    // test code
}
```

**Implementation Approach**:
- Use `syn` crate to parse Rust syntax
- Extract `#[test]` and `#[cfg(test)]` annotated functions
- Parse doc comments for `@verifies HRID` patterns
- Support doctests by parsing doc comments on public items

**Example Scanner Output**:
```rust
DiscoveredTest {
    location: "src/domain/requirement.rs::test_requirement_creation",
    framework: "rust-test",
    description: "Verifies that requirements can be created from HRID",
    verifies: vec![
        Hrid::from_str("USR-001").unwrap(),
        Hrid::from_str("SYS-003").unwrap(),
    ],
    tags: BTreeSet::new(),
}
```

#### 2.3 Generic Scanner (Language-Agnostic)

For languages without dedicated scanner, parse source files as text:

```rust
pub struct GenericScanner {
    file_patterns: Vec<String>,  // e.g., ["**/*.py", "**/*.cpp"]
    annotation_pattern: Regex,   // e.g., r"@verifies\s+([A-Z]+-\d+)"
}
```

Searches for comment patterns like:
- `@verifies USR-001`
- `@requirement USR-001`
- `VERIFIES: USR-001`

#### 2.4 Future Scanner Extensions

Plugin architecture for additional languages:

```rust
pub struct ScannerRegistry {
    scanners: HashMap<String, Box<dyn TestScanner>>,
}

impl ScannerRegistry {
    pub fn register(&mut self, id: String, scanner: Box<dyn TestScanner>);
    pub fn get(&self, id: &str) -> Option<&dyn TestScanner>;
}
```

Planned scanners:
- `PytestScanner` - Python unittest/pytest with decorators
- `GTestScanner` - Google Test C++ macros
- `JUnitScanner` - Java JUnit annotations

### 3. Test Result Import System

#### 3.1 Result Parser Interface

```rust
pub trait TestResultParser {
    /// Parse test results from a file
    fn parse(&self, path: &Path) -> Result<Vec<TestResult>>;

    /// Get the format identifier
    fn format_id(&self) -> &str;
}

pub struct TestResult {
    /// Location matching DiscoveredTest location
    pub location: String,

    /// Test execution status
    pub status: TestStatus,

    /// When the test ran
    pub timestamp: DateTime<Utc>,

    /// Optional additional metadata
    pub metadata: HashMap<String, String>,
}
```

#### 3.2 Cargo Test JSON Parser

Parses output from `cargo test -- --format json`:

```json
{
  "type": "test",
  "event": "ok",
  "name": "requirement::tests::test_requirement_creation",
  "exec_time": 0.001
}
```

Maps to `TestResult`:
- `location`: Extract from `name` field
- `status`: Map `event` (ok → Passed, failed → Failed)
- `timestamp`: Current time (cargo test doesn't include timestamps)

#### 3.3 JUnit XML Parser

Parses standard JUnit XML format (used by pytest, many CI systems):

```xml
<testsuite name="suite" tests="1" failures="0">
  <testcase name="test_requirement_creation"
            classname="domain.test_requirement"
            time="0.001">
  </testcase>
</testsuite>
```

Maps to `TestResult`:
- `location`: Combine `classname` and `name`
- `status`: Check for `<failure>` or `<error>` elements
- `timestamp`: From testsuite `timestamp` attribute if present

### 4. CLI Commands

#### 4.1 Test Sync Command

**Command**: `req test sync [OPTIONS]`

**Purpose**: Discover tests in source code and create/update TEST requirements

**Options**:
- `--test-root <PATH>`: Where to scan for tests (default: `src/`)
- `--framework <ID>`: Test framework (default: from config or auto-detect)
- `--dry-run`: Show what would be created without making changes
- `--force`: Regenerate all TEST requirements from scratch

**Behavior**:
1. Scan source tree using configured scanner
2. For each discovered test:
   - Check if TEST requirement exists (by location)
   - If exists: update description, verify parent links
   - If not exists: create new TEST requirement with next available ID
3. Mark TEST requirements with no matching code as "orphaned"

**Output**:
```
Scanning for tests in src/...
Found 47 tests

TEST-001 ✓ up-to-date (src/domain/requirement.rs::test_creation)
TEST-002 + created (src/domain/hrid.rs::test_hrid_parsing)
TEST-003 ~ updated (src/storage/tree.rs::test_add_requirement)
TEST-004 ⚠ orphaned (no matching test found)

Summary: 1 created, 1 updated, 1 orphaned, 44 unchanged
```

#### 4.2 Test Import Results Command

**Command**: `req test import-results <FILE> [OPTIONS]`

**Purpose**: Import test execution results and update TEST requirement status

**Options**:
- `--format <FORMAT>`: Result format (cargo-json, junit-xml, auto-detect)
- `--timestamp <ISO8601>`: Override timestamp (default: file mtime or current time)
- `--mark-stale`: Mark tests not in results as stale

**Behavior**:
1. Parse test results file using appropriate parser
2. For each result:
   - Find TEST requirement by location
   - Update `test_metadata.last_status`
   - Update `test_metadata.last_run`
   - Recalculate `status_fingerprint`
   - Update suspect status on parent links
3. Optionally mark other tests as stale

**Output**:
```
Importing results from target/test-results.json...

TEST-001 ✓ passed (src/domain/requirement.rs::test_creation)
TEST-002 ✗ failed (src/domain/hrid.rs::test_hrid_parsing)
  Error: assertion failed: hrid.id() == 1
TEST-003 ✓ passed (src/storage/tree.rs::test_add_requirement)

Summary: 45 passed, 2 failed, 0 skipped

Suspect links created: 2
  - SYS-003 ← TEST-002 (test failed)
```

#### 4.3 Test Coverage Command

**Command**: `req test coverage [OPTIONS]`

**Purpose**: Show requirement verification coverage

**Options**:
- `--kind <KIND>`: Filter by requirement kind (USR, SYS, etc.)
- `--untested-only`: Show only requirements without tests
- `--format <FORMAT>`: Output format (text, json, csv, markdown)
- `--threshold <PERCENT>`: Warn if coverage below threshold

**Output (text format)**:
```
Requirement Test Coverage
==========================

USR Requirements: 5 total
  ✓ Tested: 5 (100%)
  ⚠ Suspect: 1 (20%)
  ✗ Failed: 0 (0%)

SYS Requirements: 15 total
  ✓ Tested: 12 (80%)
  ⚠ Suspect: 2 (13%)
  ✗ Failed: 1 (7%)
  ! Untested: 3 (20%)
    - SYS-008 (List suspect links command)
    - SYS-013 (Configuration validation)
    - SYS-014 (Parallel loading)

Overall: 17/20 tested (85%)

Legend:
  ✓ Tested - Has passing tests
  ⚠ Suspect - Tests need re-running (parent changed)
  ✗ Failed - Has failing tests
  ! Untested - No test coverage
```

**Output (JSON format)**:
```json
{
  "timestamp": "2025-10-25T16:00:00Z",
  "summary": {
    "total_requirements": 20,
    "tested": 17,
    "untested": 3,
    "passing": 14,
    "suspect": 2,
    "failing": 1,
    "coverage_percent": 85.0
  },
  "by_kind": {
    "USR": { "total": 5, "tested": 5, "coverage": 100.0 },
    "SYS": { "total": 15, "tested": 12, "coverage": 80.0 }
  },
  "untested_requirements": [
    { "hrid": "SYS-008", "title": "List suspect links command" },
    { "hrid": "SYS-013", "title": "Configuration validation" },
    { "hrid": "SYS-014", "title": "Parallel loading" }
  ]
}
```

#### 4.4 Test Matrix Command

**Command**: `req test matrix [OPTIONS]`

**Purpose**: Generate full traceability matrix

**Options**:
- `--kind <KIND>`: Filter by requirement kind
- `--format <FORMAT>`: Output format (text, markdown, html, csv)
- `--output <FILE>`: Write to file instead of stdout

**Output (text format)**:
```
Requirement Traceability Matrix
================================
Generated: 2025-10-25 16:00:00 UTC

Requirement | Title                    | Tests    | Status      | Last Run
------------|--------------------------|----------|-------------|----------
USR-001     | Plain text storage       | TEST-001 | ✓ Passed    | 2025-10-25
            |                          | TEST-005 | ✓ Passed    | 2025-10-25
USR-002     | HRID format              | TEST-002 | ✗ Failed    | 2025-10-25
SYS-001     | Markdown with frontmatter| TEST-003 | ✓ Passed    | 2025-10-25
SYS-002     | UUID stability           | TEST-004 | ↻ Suspect   | 2025-10-24
SYS-003     | Multiple parents         | (none)   | ! Untested  | N/A

Summary: 4 passed, 1 failed, 1 suspect, 1 untested

Legend:
  ✓ Passed   - All tests passing
  ✗ Failed   - One or more tests failed
  ↻ Suspect  - Requirement changed or test stale
  ! Untested - No test coverage
```

**Output (HTML format)**: Interactive table with:
- Sorting by any column
- Filtering by status
- Expandable test details showing error messages
- Links to requirement and test files

#### 4.5 Test Suspect Command

**Command**: `req test suspect [OPTIONS]`

**Purpose**: Show all suspect test links (failed tests and changed requirements)

**Options**:
- `--kind <KIND>`: Filter by requirement kind
- `--reason <REASON>`: Filter by suspect reason (failed, stale, changed)
- `--exit-code`: Exit with non-zero if suspects found (CI integration)

**Output**:
```
Suspect Test Links
==================

SYS-003: Multiple parents support
  ✗ TEST-002 FAILED (2025-10-25 15:30:00)
    Location: src/domain/requirement.rs::test_multiple_parents
    Error: assertion failed: parents.len() == 2

SYS-002: UUID stability
  ↻ TEST-004 SUSPECT (parent changed)
    Location: src/domain/requirement.rs::test_uuid_stability
    Parent fingerprint changed: abc123... → def456...
    Last run: 2025-10-24 10:00:00 (1 day ago)

USR-003: Parent relationships
  ⏰ TEST-007 STALE (not run recently)
    Location: src/storage/tree.rs::test_parent_links
    Last run: 2025-10-10 09:00:00 (15 days ago)
    Threshold: 7 days

Summary: 3 suspect links (1 failed, 1 changed, 1 stale)
Exit code: 1
```

#### 4.6 Test Validate Command

**Command**: `req test validate [OPTIONS]`

**Purpose**: Verify TEST requirements match actual code

**Options**:
- `--fix`: Automatically fix discrepancies
- `--check`: Exit with non-zero if validation fails (CI mode)

**Behavior**:
1. Scan for tests in code
2. Load TEST requirements
3. Compare:
   - TEST requirements with no matching code (orphaned)
   - Tests with no TEST requirement (undocumented)
   - TEST requirements with wrong parent links
   - TEST requirements with stale descriptions

**Output**:
```
Validating test traceability...

✗ Orphaned TEST requirements (no matching code):
  - TEST-023: src/cli.rs::test_version (file moved?)

⚠ Tests without TEST requirements:
  - src/domain/config.rs::test_default_config
  - src/storage/directory.rs::test_load_error

⚠ Mismatched parent links:
  - TEST-005: Claims to verify USR-002, but code says USR-003

Run 'req test sync' to fix these issues.
Exit code: 1
```

#### 4.7 Test Lookup Command

**Command**: `req test lookup <LOCATION>`

**Purpose**: Reverse lookup - find which requirements a test verifies

**Example**:
```bash
$ req test lookup src/domain/requirement.rs::test_creation

Test: test_creation
Location: src/domain/requirement.rs::test_creation
Framework: rust-test
Status: ✓ Passed (2025-10-25 16:00:00)

Verifies:
  - USR-001: Plain text storage
  - SYS-003: Multiple parents

Tracked by:
  - TEST-001: Created 2025-07-22
```

### 5. Configuration

Extend `config.toml` with test traceability settings:

```toml
_version = "1"
allowed_kinds = ["USR", "SYS", "TEST"]

[test_traceability]
# Enable test traceability features
enabled = true

# Test framework identifier
# Options: "rust-test", "pytest", "junit", "generic"
framework = "rust-test"

# Where to scan for tests
test_root = "src/"

# Where to scan for test results
result_path = "target/test-results.json"

# Result file format
# Options: "cargo-json", "junit-xml", "auto"
result_format = "cargo-json"

# Auto-sync TEST requirements when validating
auto_sync = true

# Mark tests as stale after this many days
stale_threshold_days = 7

# Annotation pattern for generic scanner
annotation_pattern = "@verifies"

# Require all requirements to have tests
require_coverage = false

# Minimum coverage threshold (percent)
coverage_threshold = 80.0

# Generate HTML reports
html_reports = true
html_output_dir = "target/traceability/"
```

### 6. Storage and Persistence

#### 6.1 TEST Requirement Files

TEST requirements are stored as markdown files like other requirements:

**File**: `reqs/TEST-001.md`
```markdown
---
_version: '1'
uuid: a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d
created: 2025-10-25T16:00:00Z
parents:
  - uuid: 4bfeb7d5-d168-44a7-b0f1-e292c1c89b9a  # USR-001
    fingerprint: c8f9e2b1a3d4c5e6f7a8b9c0d1e2f3a4
    hrid: USR-001
test_metadata:
  location: "src/domain/requirement.rs::test_requirement_creation"
  framework: "rust-test"
  last_status:
    Passed: null
  last_run: 2025-10-25T16:30:00Z
  status_fingerprint: abc123def456...
---

# Test: Requirement Creation

Verifies that requirements can be created from HRID and content.

**Test Location**: `src/domain/requirement.rs::test_requirement_creation`

**Framework**: Rust test

**Verified Requirements**:
- USR-001: Plain text storage

**Status**: ✓ Passed

**Last Run**: 2025-10-25 16:30:00 UTC

## Test Description

This test ensures that:
1. A requirement can be created from an HRID string
2. The requirement has a valid UUID
3. The content is stored correctly
```

#### 6.2 Traceability Cache

To improve performance, maintain an in-memory cache:

```rust
pub struct TraceabilityCache {
    /// Map from test location to TEST requirement UUID
    location_to_test: HashMap<String, Uuid>,

    /// Map from requirement UUID to verifying TEST UUIDs
    requirement_to_tests: HashMap<Uuid, Vec<Uuid>>,

    /// Map from TEST requirement UUID to verified requirement UUIDs
    test_to_requirements: HashMap<Uuid, Vec<Uuid>>,

    /// Last sync timestamp
    last_sync: DateTime<Utc>,
}
```

Cache invalidation:
- Rebuild when TEST requirements are added/removed
- Update when test results are imported
- Persist to `.req-cache/traceability.json` for faster startup

## Project Management Lifecycle

### 7. Development Phase Workflow

#### 7.1 Continuous Coverage Monitoring

**Scenario**: PM wants to track verification progress during sprint

**Setup**:
1. Configure CI to run tests and import results
2. Generate coverage report after each build
3. Track coverage trends over time

**CI Integration** (.github/workflows/test.yml):
```yaml
name: Test Coverage

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Run tests with JSON output
        run: cargo test -- --format json > test-results.json
        continue-on-error: true

      - name: Import test results
        run: cargo run -- test import-results test-results.json

      - name: Generate coverage report
        run: |
          cargo run -- test coverage --format json > coverage.json
          cargo run -- test coverage --format markdown > coverage.md

      - name: Check coverage threshold
        run: cargo run -- test coverage --threshold 80

      - name: Comment PR with coverage
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const coverage = fs.readFileSync('coverage.md', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: coverage
            });

      - name: Upload coverage report
        uses: actions/upload-artifact@v3
        with:
          name: coverage-report
          path: |
            coverage.json
            coverage.md
```

**Developer Dashboard** (local):
```bash
# Watch mode - regenerate coverage on file changes
watch -n 10 'cargo test && cargo run -- test import-results target/test-results.json && cargo run -- test coverage'

# Quick status check before committing
cargo run -- test validate && cargo run -- test suspect
```

#### 7.2 Coverage Trend Tracking

**Historical Coverage Database**:

Store coverage snapshots for trend analysis:

**File**: `.req-cache/coverage-history.jsonl`
```jsonl
{"timestamp":"2025-10-01T00:00:00Z","commit":"abc123","total":20,"tested":15,"coverage":75.0}
{"timestamp":"2025-10-08T00:00:00Z","commit":"def456","total":22,"tested":18,"coverage":81.8}
{"timestamp":"2025-10-15T00:00:00Z","commit":"ghi789","total":23,"tested":20,"coverage":87.0}
```

**Command**: `req test trends [OPTIONS]`

**Purpose**: Show coverage trends over time

**Options**:
- `--since <DATE>`: Show trends since date
- `--commits <N>`: Show last N commits
- `--format <FORMAT>`: Output format (text, json, chart)

**Output**:
```
Coverage Trends
===============

Date       | Commit  | Requirements | Tested | Coverage | Change
-----------|---------|--------------|--------|----------|-------
2025-10-01 | abc123  | 20          | 15     | 75.0%    | -
2025-10-08 | def456  | 22          | 18     | 81.8%    | +6.8%
2025-10-15 | ghi789  | 23          | 20     | 87.0%    | +5.2%
2025-10-22 | jkl012  | 25          | 22     | 88.0%    | +1.0%

Trend: ↗ Improving (13% increase over 21 days)
Velocity: +0.62% per day

Projection:
  90% coverage: 2025-10-25 (3 days)
  95% coverage: 2025-11-01 (10 days)
  100% coverage: 2025-11-09 (18 days)
```

**Chart Output** (ASCII):
```
Coverage over time
100% |                                              ▓
 90% |                                          ▓▓▓▓
 80% |                              ▓▓▓▓▓▓▓▓▓▓▓▓
 70% |                  ▓▓▓▓▓▓▓▓▓▓▓▓
 60% |      ▓▓▓▓▓▓▓▓▓▓▓▓
 50% |  ▓▓▓▓
     |___________________________________________________
      Oct 1          Oct 15          Nov 1         Nov 15
```

### 8. Pre-Release Workflow

#### 8.1 Release Readiness Check

**Command**: `req test release-check [OPTIONS]`

**Purpose**: Validate traceability is ready for release

**Options**:
- `--require-coverage <PERCENT>`: Minimum coverage required
- `--allow-suspect`: Allow suspect links (otherwise fail)
- `--allow-untested <KIND>`: Allow untested requirements of specific kinds

**Behavior**:
1. Run validation checks
2. Check for suspect links
3. Verify coverage threshold
4. Generate release checklist

**Output**:
```
Release Readiness Check
=======================
Release: v1.0.0
Date: 2025-10-25

✓ Test synchronization up-to-date
✓ No orphaned TEST requirements
✓ Coverage threshold met (88% ≥ 80%)
✗ Suspect links found (2)
  - SYS-003 ← TEST-002 (test failed)
  - SYS-007 ← TEST-008 (parent changed)
✗ Untested requirements (3)
  - SYS-013: Configuration validation
  - SYS-014: Parallel loading
  - SYS-015: Error recovery

BLOCKERS: 2 failed tests, 3 untested requirements

Release Status: NOT READY

Action Items:
1. Fix failing tests:
   - TEST-002: src/domain/requirement.rs::test_multiple_parents
2. Add test coverage for:
   - SYS-013, SYS-014, SYS-015
3. Re-run release-check when fixed
```

#### 8.2 Release Candidate Process

**Workflow**:

1. **Create release branch**:
```bash
git checkout -b release-v1.0.0
```

2. **Run release readiness check**:
```bash
cargo run -- test release-check --require-coverage 80
```

3. **Fix blockers**:
```bash
# Fix failing tests
cargo test

# Import results
cargo test -- --format json > test-results.json
cargo run -- test import-results test-results.json

# Verify suspect links cleared
cargo run -- test suspect
```

4. **Generate pre-release snapshot**:
```bash
cargo run -- test snapshot --tag v1.0.0-rc1 --output docs/release-v1.0.0-rc1/
```

5. **Review with stakeholders**:
- Share generated traceability matrix
- Review untested requirements
- Approve any exceptions

6. **Final release preparation** (see next section)

### 9. Release Snapshot and Archival

#### 9.1 Snapshot Generation

**Command**: `req test snapshot [OPTIONS]`

**Purpose**: Capture point-in-time traceability state for release documentation

**Options**:
- `--tag <TAG>`: Git tag or version identifier
- `--output <DIR>`: Output directory for snapshot files
- `--format <FORMAT>`: Formats to generate (all, html, pdf, json, markdown)
- `--include-source`: Include full requirement and test source
- `--sign`: Cryptographically sign snapshot for compliance

**Behavior**:
1. Validate current state (no uncommitted changes)
2. Run test sync and import latest results
3. Generate comprehensive reports
4. Create snapshot metadata
5. Optional: Generate cryptographic signature

**Output Structure**:
```
docs/release-v1.0.0/
├── snapshot.json              # Machine-readable snapshot metadata
├── snapshot.json.sig          # Digital signature (if --sign)
├── traceability-matrix.html   # Interactive HTML matrix
├── traceability-matrix.pdf    # PDF for printing/archival
├── coverage-report.html       # Detailed coverage report
├── coverage-report.json       # Machine-readable coverage
├── requirements/              # Full requirement text (if --include-source)
│   ├── USR-001.md
│   ├── SYS-001.md
│   └── TEST-001.md
└── README.md                  # Human-readable summary
```

**snapshot.json** format:
```json
{
  "version": "1.0",
  "release": {
    "tag": "v1.0.0",
    "date": "2025-10-25T18:00:00Z",
    "commit": "abc123def456",
    "branch": "main"
  },
  "coverage": {
    "total_requirements": 25,
    "tested_requirements": 22,
    "coverage_percent": 88.0,
    "by_kind": {
      "USR": { "total": 5, "tested": 5, "coverage": 100.0 },
      "SYS": { "total": 20, "tested": 17, "coverage": 85.0 }
    }
  },
  "test_summary": {
    "total_tests": 47,
    "passing": 47,
    "failing": 0,
    "skipped": 0
  },
  "traceability": [
    {
      "requirement": {
        "hrid": "USR-001",
        "uuid": "4bfeb7d5-d168-44a7-b0f1-e292c1c89b9a",
        "title": "Plain text storage",
        "fingerprint": "c8f9e2b1a3d4c5e6f7a8b9c0d1e2f3a4"
      },
      "tests": [
        {
          "hrid": "TEST-001",
          "uuid": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
          "location": "src/domain/requirement.rs::test_creation",
          "status": "passed",
          "last_run": "2025-10-25T17:30:00Z"
        }
      ]
    }
  ],
  "untested_requirements": [
    {
      "hrid": "SYS-013",
      "uuid": "...",
      "title": "Configuration validation",
      "rationale": "Manual testing sufficient for MVP"
    }
  ],
  "signature": {
    "algorithm": "ed25519",
    "public_key": "...",
    "signature": "..."
  }
}
```

#### 9.2 Release Documentation Generation

**README.md** (auto-generated):
```markdown
# Traceability Report: Release v1.0.0

**Date**: 2025-10-25
**Commit**: abc123def456
**Coverage**: 88% (22/25 requirements)

## Summary

This release includes 25 requirements verified by 47 automated tests.
All tests passed at the time of release.

### Coverage by Type

| Kind | Total | Tested | Coverage |
|------|-------|--------|----------|
| USR  | 5     | 5      | 100%     |
| SYS  | 20    | 17     | 85%      |

### Test Execution

- **Total Tests**: 47
- **Passing**: 47 (100%)
- **Failing**: 0
- **Skipped**: 0

Last test run: 2025-10-25 17:30:00 UTC

### Untested Requirements

The following requirements have no automated test coverage:

- **SYS-013**: Configuration validation
  - Rationale: Manual testing sufficient for MVP
- **SYS-014**: Parallel loading
  - Rationale: Performance verified via benchmarks
- **SYS-015**: Error recovery
  - Planned for v1.1.0

## Compliance Statement

All critical requirements (USR-*) have automated test coverage.
System requirements are 85% covered by automated tests.
This traceability report was generated automatically from source code
and verified at release time.

## Files

- `traceability-matrix.html` - Interactive traceability matrix
- `traceability-matrix.pdf` - Printable traceability matrix
- `coverage-report.html` - Detailed coverage report
- `snapshot.json` - Machine-readable traceability data
- `requirements/` - Full requirement text at release time

## Verification

This snapshot can be cryptographically verified:
```bash
req test verify-snapshot snapshot.json snapshot.json.sig
```

Public key: [key fingerprint]
```

#### 9.3 Release Tagging Integration

**Git Hook** (.git/hooks/pre-push):
```bash
#!/bin/bash
# Check if pushing a release tag
if [[ $ref == refs/tags/v* ]]; then
  echo "Release tag detected: generating snapshot..."

  cargo run -- test release-check --require-coverage 80 || {
    echo "❌ Release check failed"
    exit 1
  }

  TAG=$(basename $ref)
  cargo run -- test snapshot --tag $TAG --output "docs/release-$TAG/" || {
    echo "❌ Snapshot generation failed"
    exit 1
  }

  git add "docs/release-$TAG/"
  git commit --amend --no-edit

  echo "✓ Snapshot generated and committed"
fi
```

**Automated Release Process**:
```bash
# 1. Create release candidate
git checkout -b release-v1.0.0

# 2. Run release checks
cargo run -- test release-check --require-coverage 80

# 3. Generate snapshot
cargo run -- test snapshot --tag v1.0.0 --output docs/release-v1.0.0/

# 4. Commit snapshot
git add docs/release-v1.0.0/
git commit -m "docs: add traceability snapshot for v1.0.0"

# 5. Create tag
git tag -a v1.0.0 -m "Release v1.0.0"

# 6. Push (triggers CI to publish)
git push origin v1.0.0
```

### 10. Post-Release Workflow

#### 10.1 Release Comparison

**Command**: `req test diff-releases <TAG1> <TAG2>`

**Purpose**: Compare traceability between releases

**Output**:
```
Traceability Diff: v0.9.0 → v1.0.0
====================================

Requirements:
  +5 added (USR-006, SYS-016, SYS-017, SYS-018, SYS-019)
  -0 removed
  ~3 modified (SYS-001, SYS-007, USR-003)

Tests:
  +12 added
  -2 removed
  ~5 modified

Coverage:
  v0.9.0: 75% (15/20)
  v1.0.0: 88% (22/25)
  Change: +13% (7 more requirements tested)

Notable changes:
  - All USR requirements now have test coverage
  - SYS-013, SYS-014, SYS-015 remain untested
  - 2 tests removed due to refactoring (TEST-017, TEST-019)
```

#### 10.2 Compliance Reporting

For regulatory/compliance purposes, generate formal reports:

**Command**: `req test compliance-report <TAG> [OPTIONS]`

**Options**:
- `--standard <STANDARD>`: Compliance standard (ISO-26262, DO-178C, etc.)
- `--format <FORMAT>`: Output format (pdf, docx, html)
- `--template <PATH>`: Custom report template

**Output**: Formal document with:
- Executive summary
- Traceability matrix
- Coverage statistics
- Test results
- Change history
- Signatures and approvals

### 11. Ongoing Maintenance

#### 11.1 Test Debt Tracking

Track requirements that need better test coverage:

**Command**: `req test debt [OPTIONS]`

**Options**:
- `--priority`: Order by requirement priority/risk
- `--age`: Show how long requirements have been untested

**Output**:
```
Test Debt Report
================

High Priority Untested:
  SYS-013 - Configuration validation (untested 45 days)
  SYS-015 - Error recovery (untested 38 days)

Medium Priority Untested:
  SYS-014 - Parallel loading (untested 22 days)

Recommendations:
  1. Add tests for SYS-013 (critical path)
  2. Add integration test for SYS-015
  3. Consider manual test procedure for SYS-014
```

#### 11.2 Test Maintenance Alerts

Monitor test health over time:

**Alerts**:
- Tests failing intermittently (flaky tests)
- Tests not run in X days
- Requirements changed but tests not updated
- TEST requirements orphaned (test deleted)

**Command**: `req test health`

**Output**:
```
Test Health Report
==================

⚠ Flaky Tests (passed < 90% in last 10 runs):
  TEST-007: Passes 7/10 times (70%)

⏰ Stale Tests (not run in 14+ days):
  TEST-015: Last run 2025-10-01 (24 days ago)

🔄 Changed Requirements (tests may need updates):
  SYS-003: Changed 2025-10-20, tests last run 2025-10-15

👻 Orphaned Tests:
  TEST-023: No matching test found in code
```

## Implementation Phases

### Phase 1: Core Foundation (Weeks 1-2)

**Goals**: Basic structure and Rust test discovery

**Deliverables**:
1. Add `test_metadata` field to Requirement domain model
2. Implement `TestScanner` trait
3. Implement `RustTestScanner` (doc comment parsing)
4. Implement `req test sync` command
5. Basic TEST requirement creation

**Success Criteria**:
- Can discover Rust tests with `@verifies` annotations
- Can create TEST-XXX.md files automatically
- TEST requirements link to parent requirements

### Phase 2: Status Tracking (Weeks 3-4)

**Goals**: Import test results and track status

**Deliverables**:
1. Implement `TestResultParser` trait
2. Implement `CargoTestJsonParser`
3. Implement `req test import-results` command
4. Extend suspect link system with test failures
5. Add status to TEST requirement metadata

**Success Criteria**:
- Can import cargo test JSON output
- TEST requirements show pass/fail status
- Suspect links created when tests fail

### Phase 3: Reporting (Weeks 5-6)

**Goals**: Visibility and coverage reporting

**Deliverables**:
1. Implement `req test coverage` command
2. Implement `req test matrix` command
3. Implement `req test suspect` command
4. Add JSON/CSV/Markdown output formats
5. Basic HTML report generation

**Success Criteria**:
- Can see which requirements lack tests
- Can generate traceability matrix
- Reports suitable for stakeholder review

### Phase 4: Release Management (Weeks 7-8)

**Goals**: Snapshot and release workflows

**Deliverables**:
1. Implement `req test snapshot` command
2. Implement `req test release-check` command
3. Coverage trend tracking
4. Release documentation generation
5. Snapshot verification

**Success Criteria**:
- Can generate release snapshots
- Snapshots include all traceability data
- Can compare releases

### Phase 5: Language Extensions (Weeks 9-10)

**Goals**: Support beyond Rust

**Deliverables**:
1. Implement `GenericScanner` (comment-based)
2. Add JUnit XML parser
3. Plugin architecture for scanners
4. Documentation for adding languages
5. Example: Python/pytest support

**Success Criteria**:
- Can scan Python files for `@verifies` comments
- Can import pytest results
- Clear path to add more languages

### Phase 6: Polish & Compliance (Weeks 11-12)

**Goals**: Production readiness

**Deliverables**:
1. Implement `req test trends` command
2. Implement `req test debt` command
3. Implement `req test health` command
4. CI/CD integration examples
5. Compliance report templates
6. Comprehensive documentation

**Success Criteria**:
- CI integration examples work
- Documentation complete
- Ready for production use

## Testing Strategy

### Unit Tests

Test each component in isolation:
- `RustTestScanner`: Parse various annotation formats
- `CargoTestJsonParser`: Parse test result JSON
- `TraceabilityCache`: Cache operations
- Requirement with `test_metadata`: Serialization/deserialization

### Integration Tests

Test end-to-end workflows:
- Sync workflow: Scan → Create TEST reqs → Verify parent links
- Import workflow: Run tests → Parse results → Update status
- Coverage workflow: Calculate coverage → Generate reports

### Compliance Tests

Verify correctness:
- All discovered tests have TEST requirements
- All TEST requirements have matching code
- Parent links match `@verifies` annotations
- Fingerprints detect changes correctly

### Performance Tests

Ensure scalability:
- Scan 1000+ test files in <5 seconds
- Import 10000+ test results in <10 seconds
- Generate matrix for 500+ requirements in <30 seconds

## Open Questions

1. **Test granularity**: Should we support multiple test assertions verifying different aspects of one requirement?
   - Proposal: Yes, one test can verify multiple requirements, multiple tests can verify one requirement

2. **Integration tests**: How to handle integration tests that verify multiple requirements?
   - Proposal: Annotate with all verified requirements

3. **Manual tests**: Should we support manual test case documents?
   - Proposal: Phase 7 feature - separate MANUAL-XXX requirements

4. **Test parameters**: How to handle parameterized tests?
   - Proposal: Treat each parameter set as separate test instance

5. **Partial verification**: Can a test partially verify a requirement?
   - Proposal: Add optional `@verifies USR-001[partial]` annotation

6. **Historical test results**: Should we store history beyond "last run"?
   - Proposal: Store last 10 runs for flaky test detection

## Future Enhancements

### Phase 7+: Advanced Features

1. **Manual test integration**: Support for manual test procedures
2. **Test case detail linking**: Link to specific test sections/assertions
3. **Requirement verification levels**: Full vs. partial verification
4. **Risk-based testing**: Prioritize tests based on requirement criticality
5. **Real-time dashboards**: Web UI for live coverage monitoring
6. **Test result timeline**: Historical view of test status over time
7. **AI-powered suggestions**: Suggest which tests to write based on requirements
8. **Coverage heatmaps**: Visual representation of tested vs. untested areas
9. **Multi-repo support**: Track tests across multiple repositories
10. **Requirements change notifications**: Alert when verified requirements change

## Appendix A: Example Scenarios

### Scenario 1: New Feature Development

1. PM creates requirement: `USR-006: Export requirements as JSON`
2. Dev implements feature in `src/export.rs`
3. Dev writes test:
   ```rust
   /// @verifies USR-006
   #[test]
   fn test_json_export() { ... }
   ```
4. CI runs: `req test sync` → Creates TEST-025
5. CI runs tests, imports results
6. PM sees coverage increase: 88% → 92%
7. At sprint review, PM shows passing test for USR-006

### Scenario 2: Bug Fix

1. Bug found: HRID parsing fails on edge case
2. Dev identifies SYS-002 (HRID format requirement)
3. Dev checks: `req test lookup SYS-002`
4. Finds TEST-003 is supposed to verify this
5. Dev improves TEST-003 to catch bug
6. Test fails (as expected)
7. Dev fixes bug in `src/domain/hrid.rs`
8. Test passes
9. `req test import-results` clears suspect link

### Scenario 3: Pre-Release Audit

1. PM runs: `req test release-check --require-coverage 85`
2. Finds 3 untested requirements
3. Team decides: 2 need tests, 1 is OK (benchmarks instead)
4. Devs write 2 new tests
5. PM runs release-check again: passes
6. PM generates snapshot: `req test snapshot --tag v1.0.0`
7. PM reviews HTML matrix with stakeholders
8. Tag created, snapshot archived

### Scenario 4: Post-Release Analysis

1. After v1.0.0 release, v1.1.0 planning begins
2. PM runs: `req test debt`
3. Identifies high-priority untested requirements
4. Creates backlog items for test coverage
5. Team adds tests incrementally
6. PM runs: `req test trends` weekly
7. Observes coverage trending toward 95%
8. At v1.1.0: `req test diff-releases v1.0.0 v1.1.0`
9. Shows +10% coverage improvement in release notes

## Appendix B: Data Model Diagram

```
┌─────────────────────┐
│   Requirement       │
│   (USR/SYS)         │
│                     │
│ - uuid              │
│ - hrid              │
│ - content           │
│ - fingerprint       │
└──────────┬──────────┘
           │
           │ verified by
           ├───────────────────────┐
           │                       │
           ▼                       ▼
┌──────────────────┐    ┌──────────────────┐
│  TEST            │    │  TEST            │
│  Requirement     │    │  Requirement     │
│                  │    │                  │
│ - uuid           │    │ - uuid           │
│ - hrid: TEST-001 │    │ - hrid: TEST-002 │
│ - parents: [USR] │    │ - parents: [USR] │
│ - test_metadata  │    │ - test_metadata  │
│   - location     │    │   - location     │
│   - status       │    │   - status       │
│   - last_run     │    │   - last_run     │
└────────┬─────────┘    └────────┬─────────┘
         │                       │
         │ corresponds to        │
         │ (auto-synced)         │
         ▼                       ▼
┌──────────────────┐    ┌──────────────────┐
│  Test Code       │    │  Test Code       │
│                  │    │                  │
│ /// @verifies    │    │ /// @verifies    │
│ ///   USR-001    │    │ ///   USR-001    │
│ #[test]          │    │ #[test]          │
│ fn test_foo()    │    │ fn test_bar()    │
└──────────────────┘    └──────────────────┘
```

## Appendix C: Configuration Reference

Complete configuration options:

```toml
[test_traceability]
# Core settings
enabled = true
framework = "rust-test"
test_root = "src/"

# Scanning
scan_ignore = ["target/", "vendor/"]
annotation_pattern = "@verifies"
include_doctests = true

# Results
result_path = "target/test-results.json"
result_format = "cargo-json"
store_history = true
history_limit = 10

# Synchronization
auto_sync = true
auto_create_tests = true
warn_orphaned = true

# Status tracking
stale_threshold_days = 7
mark_stale_on_import = true
require_recent_results = false

# Coverage
require_coverage = false
coverage_threshold = 80.0
coverage_by_kind = { USR = 100.0, SYS = 80.0 }

# Reporting
html_reports = true
html_output_dir = "target/traceability/"
html_template = "default"
generate_pdf = false

# Release
snapshot_sign = false
snapshot_include_source = true
snapshot_compress = false

# Advanced
cache_traceability = true
parallel_scan = true
scan_threads = 0  # 0 = auto-detect
```

---

**End of Design Document**