# aphoria-code-patterns ## AUDIT (2026-02-06) ### Pattern 1: Unwrap/Expect Isolation **Finding:** NOT APPLICABLE - **Total unwrap() calls:** 72 - **Total expect() calls:** 890 (mostly from stemedb crates, not aphoria) - **In test code:** ALL 72 unwrap() calls are within `#[test]` functions - **In production code:** 0 Analysis: - `promotion/version.rs:490` - test function `test_changelog_entry_with_metrics` - `research/gap_store.rs:365-390` - test functions `test_gap_store_*` - `research/tests.rs` - all test code - `types/language.rs:220-230` - test assertions **Decision:** No fix needed. Clippy's `clippy::unwrap_used` is at `warn` level for crates, but test code is exempt by design. All 72 instances are in test functions where unwrap is acceptable for test assertions. ### Pattern 2: JSON Construction Consistency **Finding:** 27 instances of `serde_json::json!` macro **Categories:** 1. **Source metadata construction (5 files):** - `bridge.rs:52` - claim_to_assertion - `episteme/corpus.rs:191` - corpus building - `llm/extractor.rs:431` - LLM extraction - `llm/prompt.rs:97` - prompt building - `llm/ontology.rs:243` - ontology extraction 2. **Report generation (10 instances):** - `report/sarif.rs` - 5 instances (SARIF format requires specific structure) - `report/json.rs` - 5 instances (dynamic conflict reports) 3. **Other (7 instances):** - `policy_ops.rs:238` - ack payload (recent addition) - `report/mod.rs:56` - single value conversion - `eval/matcher.rs:328` - test fixture - `eval/harness.rs` - 4 test fixtures **Analysis:** The `json!` macro is used appropriately for: - Dynamic JSON construction where struct serialization doesn't apply - SARIF format which has strict schema requirements - Test fixtures where convenience matters This is NOT tech debt - it's appropriate usage. The audit finding was overly aggressive.