64 lines
2.2 KiB
Markdown
64 lines
2.2 KiB
Markdown
# Unit Test Audit Extension Design
|
|
|
|
## Goal
|
|
|
|
Extend the PortTracker `audit` command to classify unit tests (not just features) by inspecting .NET test source code with Roslyn.
|
|
|
|
## Architecture
|
|
|
|
Parameterize the existing audit pipeline (`AuditCommand` + `SourceIndexer` + `FeatureClassifier`) to support both `features` and `unit_tests` tables. No new files — the same indexer and classifier logic applies to test methods.
|
|
|
|
## CLI Interface
|
|
|
|
```
|
|
dotnet run -- audit --type features|tests|all [--source <path>] [--module <id>] [--execute]
|
|
```
|
|
|
|
| Flag | Default (features) | Default (tests) |
|
|
|------|-------------------|-----------------|
|
|
| `--type` | `features` | — |
|
|
| `--source` | `dotnet/src/ZB.MOM.NatsNet.Server` | `dotnet/tests/ZB.MOM.NatsNet.Server.Tests` |
|
|
| `--output` | `reports/audit-results.csv` | `reports/audit-results-tests.csv` |
|
|
|
|
- `--type all` runs both sequentially.
|
|
- `--source` override works for either type.
|
|
|
|
## Changes Required
|
|
|
|
### AuditCommand.cs
|
|
|
|
1. Add `--type` option with values `features`, `tests`, `all`.
|
|
2. Thread an `AuditTarget` (table name + default source + default output + display label) through `RunAudit` and `ApplyUpdates`.
|
|
3. `--type all` calls `RunAudit` twice with different targets.
|
|
4. `ApplyUpdates` uses the target's table name in UPDATE SQL.
|
|
|
|
### FeatureClassifier.cs
|
|
|
|
No changes. Same N/A lookup and classification logic applies to unit tests.
|
|
|
|
### SourceIndexer.cs
|
|
|
|
No changes. Already generic — just pass a different directory path.
|
|
|
|
## Pre-audit DB Reset
|
|
|
|
Before running the test audit, manually reset deferred tests to `unknown`:
|
|
|
|
```sql
|
|
sqlite3 porting.db "UPDATE unit_tests SET status = 'unknown' WHERE status = 'deferred';"
|
|
```
|
|
|
|
## Execution Sequence
|
|
|
|
1. Reset deferred tests: `sqlite3 porting.db "UPDATE unit_tests SET status = 'unknown' WHERE status = 'deferred';"`
|
|
2. Run audit: `dotnet run -- audit --type tests --db porting.db --execute`
|
|
3. Verify results and generate report.
|
|
|
|
## Classification Behavior for Tests
|
|
|
|
Same priority as features:
|
|
1. **N/A**: Go method matches logging/signal patterns → `n_a`
|
|
2. **Method found**: Test class + method exists in test project → `verified` or `stub`
|
|
3. **Class exists, method missing**: → `deferred` ("method not found")
|
|
4. **Class not found**: → `deferred` ("class not found")
|