{
  "timestamp": "2026-05-25T06:11:52.519Z",
  "mode": "headless",
  "workerType": "testgaps",
  "model": "sonnet",
  "durationMs": 259124,
  "executionId": "testgaps_1779689253395_srltd5",
  "success": true,
  "findings": {
    "sections": [
      {
        "title": "Test Coverage Gap Analysis — wifi-densepose",
        "content": "\n",
        "level": 2
      },
      {
        "title": "Coverage Summary by Crate",
        "content": "\n| Crate | Tests Found | Status | Priority |\n|-------|-------------|--------|----------|\n| `wifi-densepose-core` | 26 inline | Good | Low |\n| `wifi-densepose-signal` | ~60 (validation only) | Moderate | **High** |\n| `wifi-densepose-nn` | **0** | Critical | **P1** |\n| `wifi-densepose-train` | ~60 (config/dataset) | Moderate | High |\n| `wifi-densepose-mat` | 1 integration test | Critical | **P1** |\n| `wifi-densepose-ruvector` | **0** | Critical | **P1** |\n| `wifi-densepose-sensing-server` | 4 integration tests | Moderate | High |\n| `wifi-densepose-wasm` | 3 compliance tests | Low | Low |\n\n---\n\n",
        "level": 3
      },
      {
        "title": "Tier 1: Critical Gaps",
        "content": "\n",
        "level": 2
      },
      {
        "title": "1. `wifi-densepose-nn` — Zero test coverage",
        "content": "\nEvery public API is untested. Place these at `v2/crates/wifi-densepose-nn/tests/inference_tests.rs`:\n\n```rust\n// v2/crates/wifi-densepose-nn/tests/inference_tests.rs\n\n#[cfg(test)]\nmod tensor_tests {\n    use wifi_densepose_nn::tensor::Tensor;\n\n    #[test]\n    fn tensor_shape_mismatch_returns_error() {\n        // data has 6 elements but shape claims 3×3=9\n        let result = Tensor::new(vec![1.0f32; 6], &[3, 3]);\n        assert!(result.is_err(), \"shape mismatch must be rejected\");\n    }\n\n    #[test]\n    fn tensor_empty_data_returns_error() {\n        let result = Tensor::new(vec![], &[0]);\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn tensor_nan_values_are_detected() {\n        let t = Tensor::new(vec![f32::NAN, 1.0, 2.0], &[3]).unwrap();\n        assert!(t.has_nan(), \"NaN in data must be detectable\");\n    }\n\n    #[test]\n    fn tensor_inf_values_are_detected() {\n        let t = Tensor::new(vec![f32::INFINITY, 1.0], &[2]).unwrap();\n        assert!(t.has_inf());\n    }\n}\n\n#[cfg(test)]\nmod modality_translator_tests {\n    use wifi_densepose_nn::translator::ModalityTranslator;\n\n    #[test]\n    fn translator_rejects_wrong_subcarrier_count() {\n        // standard expects 56 subcarriers; feed 57\n        let csi = vec![0.0f32; 57 * 3]; // 57 subcarriers × 3 antennas\n        let translator = ModalityTranslator::default();\n        let result = translator.translate(&csi, 57, 3);\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn translator_handles_all_zeros() {\n        let csi = vec![0.0f32; 56 * 3];\n        let translator = ModalityTranslator::default();\n        let result = translator.translate(&csi, 56, 3);\n        // zero input should produce some output without panic\n        assert!(result.is_ok());\n    }\n}\n\n#[cfg(test)]\nmod inference_engine_tests {\n    use wifi_densepose_nn::inference::InferenceEngine;\n\n    #[test]\n    fn load_nonexistent_model_returns_error() {\n        let result = InferenceEngine::from_path(\"/nonexistent/model.onnx\");\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn load_corrupted_bytes_returns_error() {\n        let tmp = tempfile::NamedTempFile::new().unwrap();\n        std::fs::write(tmp.path(), b\"not a valid onnx file\").unwrap();\n        let result = InferenceEngine::from_path(tmp.path());\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn batch_size_zero_returns_error() {\n        // can't run inference on an empty batch\n        // requires a valid model; skip if no model file in test fixtures\n        // use #[ignore] or a feature flag for CI\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "2. `wifi-densepose-mat` — Disaster response safety gaps",
        "content": "\nPlace at `v2/crates/wifi-densepose-mat/tests/`:\n\n```rust\n// v2/crates/wifi-densepose-mat/tests/detection_edge_cases.rs\n\n#[cfg(test)]\nmod breathing_rate_edge_cases {\n    use wifi_densepose_mat::detection::breathing::BreathingDetector;\n\n    #[test]\n    fn zero_bpm_is_classified_critical() {\n        let detector = BreathingDetector::default();\n        // flat-line signal — no breathing detected\n        let signal = vec![0.0f32; 1000];\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Immediate);\n    }\n\n    #[test]\n    fn agonal_breathing_rate_triggers_immediate() {\n        // < 6 BPM is agonal; simulate 3 BPM signal\n        let detector = BreathingDetector::default();\n        let signal = generate_breathing_signal(3.0, 1000, 100.0); // 3 BPM, 1000 samples @ 100 Hz\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Immediate);\n    }\n\n    #[test]\n    fn normal_breathing_is_classified_minor() {\n        let detector = BreathingDetector::default();\n        let signal = generate_breathing_signal(15.0, 1000, 100.0); // 15 BPM\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Minor);\n    }\n\n    #[test]\n    fn all_nan_signal_returns_error_not_panic() {\n        let detector = BreathingDetector::default();\n        let signal = vec![f32::NAN; 1000];\n        let result = detector.classify(&signal);\n        assert!(result.is_err(), \"NaN input must be caught, not panic\");\n    }\n\n    fn generate_breathing_signal(bpm: f32, samples: usize, sample_rate: f32) -> Vec<f32> {\n        let freq = bpm / 60.0;\n        (0..samples)\n            .map(|i| (2.0 * std::f32::consts::PI * freq * i as f32 / sample_rate).sin())\n            .collect()\n    }\n}\n\n#[cfg(test)]\nmod alert_deduplication {\n    use wifi_densepose_mat::alerting::{AlertDispatcher, Alert, TriageCategory};\n    use std::time::Duration;\n\n    #[test]\n    fn duplicate_alerts_within_window_are_suppressed() {\n        let mut dispatcher = AlertDispatcher::new();\n        let alert = Alert::new(\"survivor-1\", TriageCategory::Immediate);\n        dispatcher.dispatch(alert.clone());\n        dispatcher.dispatch(alert.clone()); // same survivor, same category\n        assert_eq!(dispatcher.queued_count(), 1, \"duplicate must be deduplicated\");\n    }\n\n    #[test]\n    fn escalation_from_minor_to_immediate_is_forwarded() {\n        let mut dispatcher = AlertDispatcher::new();\n        dispatcher.dispatch(Alert::new(\"survivor-1\", TriageCategory::Minor));\n        dispatcher.dispatch(Alert::new(\"survivor-1\", TriageCategory::Immediate));\n        // escalation is not a duplicate — must pass through\n        assert!(dispatcher.last_alert_for(\"survivor-1\").map(|a| a.category) == Some(TriageCategory::Immediate));\n    }\n}\n\n#[cfg(test)]\nmod kalman_tracker_edge_cases {\n    use wifi_densepose_mat::tracking::KalmanTracker;\n\n    #[test]\n    fn position_jump_does_not_corrupt_state() {\n        let mut tracker = KalmanTracker::new();\n        tracker.update([1.0, 1.0, 0.5]);  // initial position\n        tracker.update([50.0, 50.0, 0.5]); // physically impossible jump\n        let pos = tracker.estimated_position();\n        // should not panic; should clamp or flag anomaly\n        assert!(pos.iter().all(|v| v.is_finite()));\n    }\n\n    #[test]\n    fn lost_track_resumes_on_re_detection() {\n        let mut tracker = KalmanTracker::new();\n        tracker.update([1.0, 1.0, 0.5]);\n        // simulate 10 missed frames\n        for _ in 0..10 { tracker.predict(); }\n        assert_eq!(tracker.state(), TrackState::Lost);\n        tracker.update([1.1, 1.1, 0.5]); // re-detected nearby\n        assert_eq!(tracker.state(), TrackState::Confirmed);\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "3. `wifi-densepose-ruvector` — Zero coverage on all 5 integration modules",
        "content": "\n```rust\n// v2/crates/wifi-densepose-ruvector/tests/viewpoint_tests.rs\n\n#[cfg(test)]\nmod attention_tests {\n    use wifi_densepose_ruvector::viewpoint::attention::CrossViewpointAttention;\n\n    #[test]\n    fn attention_weights_sum_to_one() {\n        let attn = CrossViewpointAttention::new(3); // 3 viewpoints\n        let features = vec![[1.0f32; 64], [2.0f32; 64], [3.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        let sum: f32 = weights.iter().sum();\n        assert!((sum - 1.0).abs() < 1e-5, \"attention must be a probability distribution\");\n    }\n\n    #[test]\n    fn single_viewpoint_gets_full_weight() {\n        let attn = CrossViewpointAttention::new(1);\n        let features = vec![[1.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        assert!((weights[0] - 1.0).abs() < 1e-6);\n    }\n\n    #[test]\n    fn zero_feature_vectors_do_not_produce_nan() {\n        let attn = CrossViewpointAttention::new(2);\n        let features = vec![[0.0f32; 64], [0.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        assert!(weights.iter().all(|w| w.is_finite()));\n    }\n}\n\n#[cfg(test)]\nmod sketch_tests {\n    use wifi_densepose_ruvector::sketch::WireSketch;\n\n    #[test]\n    fn round_trip_serialization() {\n        let sketch = WireSketch::from_keypoints(&[[0.5f32, 0.5], [0.3, 0.7]]);\n        let bytes = sketch.to_bytes();\n        let restored = WireSketch::from_bytes(&bytes).unwrap();\n        assert_eq!(sketch, restored);\n    }\n\n    #[test]\n    fn deserialize_truncated_bytes_returns_error() {\n        let sketch = WireSketch::from_keypoints(&[[0.5f32, 0.5]]);\n        let mut bytes = sketch.to_bytes();\n        bytes.truncate(bytes.len() / 2); // truncate halfway\n        assert!(WireSketch::from_bytes(&bytes).is_err());\n    }\n\n    #[test]\n    fn empty_keypoint_list_is_handled() {\n        let sketch = WireSketch::from_keypoints(&[]);\n        assert_eq!(sketch.keypoint_count(), 0);\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "Tier 2: Signal Processing Gaps",
        "content": "\n",
        "level": 2
      },
      {
        "title": "4. `wifi-densepose-signal` — RuvSense module untested",
        "content": "\n```rust\n// v2/crates/wifi-densepose-signal/tests/ruvsense_tests.rs\n\n#[cfg(test)]\nmod coherence_gate_tests {\n    use wifi_densepose_signal::ruvsense::coherence_gate::{CoherenceGate, GateDecision};\n\n    #[test]\n    fn high_coherence_signal_is_accepted() {\n        let gate = CoherenceGate::new(0.7); // threshold = 0.7\n        let decision = gate.evaluate(0.95);\n        assert_eq!(decision, GateDecision::Accept);\n    }\n\n    #[test]\n    fn low_coherence_signal_is_rejected() {\n        let gate = CoherenceGate::new(0.7);\n        let decision = gate.evaluate(0.3);\n        assert_eq!(decision, GateDecision::Reject);\n    }\n\n    #[test]\n    fn borderline_coherence_triggers_recalibrate() {\n        let gate = CoherenceGate::new(0.7);\n        let decision = gate.evaluate(0.68); // just below threshold\n        assert_eq!(decision, GateDecision::Recalibrate);\n    }\n}\n\n#[cfg(test)]\nmod phase_align_tests {\n    use wifi_densepose_signal::ruvsense::phase_align::PhaseAligner;\n\n    #[test]\n    fn phase_at_plus_pi_does_not_wrap_incorrectly() {\n        let aligner = PhaseAligner::new();\n        let phases = vec![std::f32::consts::PI - 0.001, std::f32::consts::PI + 0.001];\n        let aligned = aligner.align(&phases);\n        // jump across ±π boundary must be handled continuously\n        let diff = (aligned[1] - aligned[0]).abs();\n        assert!(diff < 0.01, \"phase jump at ±π must be < 0.01 rad after alignment\");\n    }\n\n    #[test]\n    fn single_phase_value_aligns_to_itself() {\n        let aligner = PhaseAligner::new();\n        let phases = vec![1.5f32];\n        let aligned = aligner.align(&phases);\n        assert_eq!(aligned.len(), 1);\n        assert!((aligned[0] - 1.5).abs() < 1e-6);\n    }\n\n    #[test]\n    fn empty_phase_array_returns_empty() {\n        let aligner = PhaseAligner::new();\n        let aligned = aligner.align(&[]);\n        assert!(aligned.is_empty());\n    }\n}\n\n#[cfg(test)]\nmod adversarial_detection_tests {\n    use wifi_densepose_signal::ruvsense::adversarial::AdversarialDetector;\n\n    #[test]\n    fn physically_impossible_amplitude_is_flagged() {\n        let detector = AdversarialDetector::new();\n        // WiFi amplitude cannot exceed hardware saturation level\n        let frame = vec![1e9f32; 56]; // absurdly large\n        assert!(detector.is_suspicious(&frame));\n    }\n\n    #[test]\n    fn normal_amplitude_range_passes() {\n        let detector = AdversarialDetector::new();\n        let frame = vec![0.5f32; 56]; // typical normalized value\n        assert!(!detector.is_suspicious(&frame));\n    }\n\n    #[test]\n    fn multi_link_inconsistency_is_detected() {\n        // link A reports body moving right; link B reports no motion\n        // physically inconsistent — flag as adversarial\n        let detector = AdversarialDetector::new();\n        let result = detector.check_multi_link_consistency(\n            &[1.0, 2.0, 3.0], // link A\n            &[0.0, 0.0, 0.0], // link B (no motion)\n        );\n        assert!(result.is_inconsistent());\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "Tier 2: Training Pipeline Gaps",
        "content": "\n",
        "level": 2
      },
      {
        "title": "5. `wifi-densepose-train` — Geometry encoder and rapid adaptation untested",
        "content": "\n```rust\n// v2/crates/wifi-densepose-train/tests/test_geometry.rs\n\n#[cfg(test)]\nmod film_layer_tests {\n    use wifi_densepose_train::geometry::FilmLayer;\n\n    #[test]\n    fn film_layer_output_shape_matches_input() {\n        let film = FilmLayer::new(64, 32); // 64-dim features, 32-dim condition\n        let features = vec![0.5f32; 64];\n        let condition = vec![1.0f32; 32];\n        let output = film.forward(&features, &condition).unwrap();\n        assert_eq!(output.len(), 64, \"FiLM output must match feature dimensionality\");\n    }\n\n    #[test]\n    fn film_layer_zero_condition_acts_as_identity() {\n        let film = FilmLayer::new(64, 32);\n        let features = vec![1.0f32; 64];\n        let zero_condition = vec![0.0f32; 32];\n        let output = film.forward(&features, &zero_condition).unwrap();\n        // scale=1, shift=0 → identity; output ≈ input\n        for (o, f) in output.iter().zip(features.iter()) {\n            assert!((o - f).abs() < 0.1, \"zero condition should approximate identity\");\n        }\n    }\n}\n\n// v2/crates/wifi-densepose-train/tests/test_rapid_adapt.rs\n\n#[cfg(test)]\nmod rapid_adaptation_tests {\n    use wifi_densepose_train::rapid_adapt::RapidAdapter;\n\n    #[test]\n    fn adapter_updates_on_single_sample() {\n        let mut adapter = RapidAdapter::new(5); // 5 adaptation steps\n        let csi_sample = vec![0.1f32; 56 * 3];\n        let pose_label = vec![0.5f32; 17 * 2]; // 17 keypoints × (x, y)\n        let result = adapter.adapt_step(&csi_sample, &pose_label);\n        assert!(result.is_ok());\n    }\n\n    #[test]\n    fn adapter_with_zero_steps_is_no_op() {\n        let adapter = RapidAdapter::new(0);\n        // 0 adaptation steps → weights unchanged\n        let initial_weights = adapter.clone_weights();\n        let _ = adapter.adapt_step(&vec![0.1f32; 168], &vec![0.5f32; 34]);\n        assert_eq!(adapter.clone_weights(), initial_weights);\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "Tier 3: Server Integration Gaps",
        "content": "\n",
        "level": 2
      },
      {
        "title": "6. `wifi-densepose-sensing-server` — Auth and semantic analyzers",
        "content": "\n```rust\n// v2/crates/wifi-densepose-sensing-server/tests/auth_tests.rs\n\n#[cfg(test)]\nmod bearer_auth_tests {\n    use wifi_densepose_sensing_server::auth::{BearerValidator, TokenError};\n\n    #[test]\n    fn missing_authorization_header_returns_unauthorized() {\n        let validator = BearerValidator::new(\"secret-token\");\n        let result = validator.validate(None);\n        assert!(matches!(result, Err(TokenError::Missing)));\n    }\n\n    #[test]\n    fn wrong_token_is_rejected() {\n        let validator = BearerValidator::new(\"correct-token\");\n        let result = validator.validate(Some(\"Bearer wrong-token\"));\n        assert!(matches!(result, Err(TokenError::Invalid)));\n    }\n\n    #[test]\n    fn malformed_header_without_bearer_prefix_is_rejected() {\n        let validator = BearerValidator::new(\"token\");\n        let result = validator.validate(Some(\"token\")); // missing \"Bearer \" prefix\n        assert!(matches!(result, Err(TokenError::Malformed)));\n    }\n\n    #[test]\n    fn correct_token_is_accepted() {\n        let validator = BearerValidator::new(\"correct-token\");\n        let result = validator.validate(Some(\"Bearer correct-token\"));\n        assert!(result.is_ok());\n    }\n}\n\n// v2/crates/wifi-densepose-sensing-server/tests/semantic_tests.rs\n\n#[cfg(test)]\nmod fall_detection_tests {\n    use wifi_densepose_sensing_server::semantic::fall_detector::FallDetector;\n\n    #[test]\n    fn no_motion_does_not_trigger_fall() {\n        let mut detector = FallDetector::new();\n        for _ in 0..30 { // 30 frames of stillness\n            detector.update_pose(stationary_pose());\n        }\n        assert!(!detector.fall_detected());\n    }\n\n    #[test]\n    fn rapid_downward_velocity_triggers_fall() {\n        let mut detector = FallDetector::new();\n        // simulate person going from standing (y=1.7m) to prone (y=0.3m) in 3 frames\n        for (frame, y) in [(0, 1.7f32), (1, 1.0), (2, 0.3)] {\n            detector.update_pose(pose_at_height(y));\n        }\n        assert!(detector.fall_detected());\n    }\n\n    #[test]\n    fn sitting_down_slowly_does_not_trigger_fall() {\n        let mut detector = FallDetector::new();\n        // gradual height decrease over 30 frames is sitting, not falling\n        for i in 0..30 {\n            let y = 1.7f32 - (i as f32 * 0.04); // ~1.2m drop over 30 frames\n            detector.update_pose(pose_at_height(y));\n        }\n        assert!(!detector.fall_detected());\n    }\n}\n```\n\n---\n\n",
        "level": 3
      },
      {
        "title": "Cross-Cutting Gap Summary",
        "content": "| Gap Category | Severity | Affects | Recommended Action |\n|---|---|---|---|\n| `wifi-densepose-nn` has 0 tests | **Critical** | Inference pipeline | Add `tests/inference_tests.rs` per skeleton above |\n| `wifi-densepose-ruvector` has 0 tests | **Critical** | Viewpoint fusion, sketches | Add `tests/viewpoint_tests.rs` |\n| MAT disaster response missing edge cases | **Critical** | 0 BPM, agonal breathing, dedup | Add `tests/detection_edge_cases.rs` |\n| Signal RuvSense 28 modules untested | High | Core sensing logic | Add `tests/ruvsense_tests.rs` |\n| NN error paths (bad model files, OOM) | High | Production reliability | Add error path tests to nn |\n| Train geometry + rapid adapt = 0 tests | High | Domain adaptation | Add `tests/test_geometry.rs` |\n| Server auth token validation | High | Security boundary | Add `tests/auth_tests.rs` |\n| NaN/Inf propagation in f32 pipelines | High | All numeric crates | Add boundary tests per module |\n| Concurrent state under Arc<Mutex> | Medium | sensing-server, mat | Add contention tests |\n\nThe highest-ROI starting point is `wifi-densepose-nn` and `wifi-densepose-mat` — the nn crate has zero tests on the core inference pipeline, and mat covers life-safety scenarios where classification errors have real consequences.",
        "level": 2
      }
    ],
    "codeBlocks": [
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-nn/tests/inference_tests.rs\n\n#[cfg(test)]\nmod tensor_tests {\n    use wifi_densepose_nn::tensor::Tensor;\n\n    #[test]\n    fn tensor_shape_mismatch_returns_error() {\n        // data has 6 elements but shape claims 3×3=9\n        let result = Tensor::new(vec![1.0f32; 6], &[3, 3]);\n        assert!(result.is_err(), \"shape mismatch must be rejected\");\n    }\n\n    #[test]\n    fn tensor_empty_data_returns_error() {\n        let result = Tensor::new(vec![], &[0]);\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn tensor_nan_values_are_detected() {\n        let t = Tensor::new(vec![f32::NAN, 1.0, 2.0], &[3]).unwrap();\n        assert!(t.has_nan(), \"NaN in data must be detectable\");\n    }\n\n    #[test]\n    fn tensor_inf_values_are_detected() {\n        let t = Tensor::new(vec![f32::INFINITY, 1.0], &[2]).unwrap();\n        assert!(t.has_inf());\n    }\n}\n\n#[cfg(test)]\nmod modality_translator_tests {\n    use wifi_densepose_nn::translator::ModalityTranslator;\n\n    #[test]\n    fn translator_rejects_wrong_subcarrier_count() {\n        // standard expects 56 subcarriers; feed 57\n        let csi = vec![0.0f32; 57 * 3]; // 57 subcarriers × 3 antennas\n        let translator = ModalityTranslator::default();\n        let result = translator.translate(&csi, 57, 3);\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn translator_handles_all_zeros() {\n        let csi = vec![0.0f32; 56 * 3];\n        let translator = ModalityTranslator::default();\n        let result = translator.translate(&csi, 56, 3);\n        // zero input should produce some output without panic\n        assert!(result.is_ok());\n    }\n}\n\n#[cfg(test)]\nmod inference_engine_tests {\n    use wifi_densepose_nn::inference::InferenceEngine;\n\n    #[test]\n    fn load_nonexistent_model_returns_error() {\n        let result = InferenceEngine::from_path(\"/nonexistent/model.onnx\");\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn load_corrupted_bytes_returns_error() {\n        let tmp = tempfile::NamedTempFile::new().unwrap();\n        std::fs::write(tmp.path(), b\"not a valid onnx file\").unwrap();\n        let result = InferenceEngine::from_path(tmp.path());\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn batch_size_zero_returns_error() {\n        // can't run inference on an empty batch\n        // requires a valid model; skip if no model file in test fixtures\n        // use #[ignore] or a feature flag for CI\n    }\n}"
      },
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-mat/tests/detection_edge_cases.rs\n\n#[cfg(test)]\nmod breathing_rate_edge_cases {\n    use wifi_densepose_mat::detection::breathing::BreathingDetector;\n\n    #[test]\n    fn zero_bpm_is_classified_critical() {\n        let detector = BreathingDetector::default();\n        // flat-line signal — no breathing detected\n        let signal = vec![0.0f32; 1000];\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Immediate);\n    }\n\n    #[test]\n    fn agonal_breathing_rate_triggers_immediate() {\n        // < 6 BPM is agonal; simulate 3 BPM signal\n        let detector = BreathingDetector::default();\n        let signal = generate_breathing_signal(3.0, 1000, 100.0); // 3 BPM, 1000 samples @ 100 Hz\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Immediate);\n    }\n\n    #[test]\n    fn normal_breathing_is_classified_minor() {\n        let detector = BreathingDetector::default();\n        let signal = generate_breathing_signal(15.0, 1000, 100.0); // 15 BPM\n        let result = detector.classify(&signal).unwrap();\n        assert_eq!(result.triage_category, TriageCategory::Minor);\n    }\n\n    #[test]\n    fn all_nan_signal_returns_error_not_panic() {\n        let detector = BreathingDetector::default();\n        let signal = vec![f32::NAN; 1000];\n        let result = detector.classify(&signal);\n        assert!(result.is_err(), \"NaN input must be caught, not panic\");\n    }\n\n    fn generate_breathing_signal(bpm: f32, samples: usize, sample_rate: f32) -> Vec<f32> {\n        let freq = bpm / 60.0;\n        (0..samples)\n            .map(|i| (2.0 * std::f32::consts::PI * freq * i as f32 / sample_rate).sin())\n            .collect()\n    }\n}\n\n#[cfg(test)]\nmod alert_deduplication {\n    use wifi_densepose_mat::alerting::{AlertDispatcher, Alert, TriageCategory};\n    use std::time::Duration;\n\n    #[test]\n    fn duplicate_alerts_within_window_are_suppressed() {\n        let mut dispatcher = AlertDispatcher::new();\n        let alert = Alert::new(\"survivor-1\", TriageCategory::Immediate);\n        dispatcher.dispatch(alert.clone());\n        dispatcher.dispatch(alert.clone()); // same survivor, same category\n        assert_eq!(dispatcher.queued_count(), 1, \"duplicate must be deduplicated\");\n    }\n\n    #[test]\n    fn escalation_from_minor_to_immediate_is_forwarded() {\n        let mut dispatcher = AlertDispatcher::new();\n        dispatcher.dispatch(Alert::new(\"survivor-1\", TriageCategory::Minor));\n        dispatcher.dispatch(Alert::new(\"survivor-1\", TriageCategory::Immediate));\n        // escalation is not a duplicate — must pass through\n        assert!(dispatcher.last_alert_for(\"survivor-1\").map(|a| a.category) == Some(TriageCategory::Immediate));\n    }\n}\n\n#[cfg(test)]\nmod kalman_tracker_edge_cases {\n    use wifi_densepose_mat::tracking::KalmanTracker;\n\n    #[test]\n    fn position_jump_does_not_corrupt_state() {\n        let mut tracker = KalmanTracker::new();\n        tracker.update([1.0, 1.0, 0.5]);  // initial position\n        tracker.update([50.0, 50.0, 0.5]); // physically impossible jump\n        let pos = tracker.estimated_position();\n        // should not panic; should clamp or flag anomaly\n        assert!(pos.iter().all(|v| v.is_finite()));\n    }\n\n    #[test]\n    fn lost_track_resumes_on_re_detection() {\n        let mut tracker = KalmanTracker::new();\n        tracker.update([1.0, 1.0, 0.5]);\n        // simulate 10 missed frames\n        for _ in 0..10 { tracker.predict(); }\n        assert_eq!(tracker.state(), TrackState::Lost);\n        tracker.update([1.1, 1.1, 0.5]); // re-detected nearby\n        assert_eq!(tracker.state(), TrackState::Confirmed);\n    }\n}"
      },
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-ruvector/tests/viewpoint_tests.rs\n\n#[cfg(test)]\nmod attention_tests {\n    use wifi_densepose_ruvector::viewpoint::attention::CrossViewpointAttention;\n\n    #[test]\n    fn attention_weights_sum_to_one() {\n        let attn = CrossViewpointAttention::new(3); // 3 viewpoints\n        let features = vec![[1.0f32; 64], [2.0f32; 64], [3.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        let sum: f32 = weights.iter().sum();\n        assert!((sum - 1.0).abs() < 1e-5, \"attention must be a probability distribution\");\n    }\n\n    #[test]\n    fn single_viewpoint_gets_full_weight() {\n        let attn = CrossViewpointAttention::new(1);\n        let features = vec![[1.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        assert!((weights[0] - 1.0).abs() < 1e-6);\n    }\n\n    #[test]\n    fn zero_feature_vectors_do_not_produce_nan() {\n        let attn = CrossViewpointAttention::new(2);\n        let features = vec![[0.0f32; 64], [0.0f32; 64]];\n        let weights = attn.compute_weights(&features);\n        assert!(weights.iter().all(|w| w.is_finite()));\n    }\n}\n\n#[cfg(test)]\nmod sketch_tests {\n    use wifi_densepose_ruvector::sketch::WireSketch;\n\n    #[test]\n    fn round_trip_serialization() {\n        let sketch = WireSketch::from_keypoints(&[[0.5f32, 0.5], [0.3, 0.7]]);\n        let bytes = sketch.to_bytes();\n        let restored = WireSketch::from_bytes(&bytes).unwrap();\n        assert_eq!(sketch, restored);\n    }\n\n    #[test]\n    fn deserialize_truncated_bytes_returns_error() {\n        let sketch = WireSketch::from_keypoints(&[[0.5f32, 0.5]]);\n        let mut bytes = sketch.to_bytes();\n        bytes.truncate(bytes.len() / 2); // truncate halfway\n        assert!(WireSketch::from_bytes(&bytes).is_err());\n    }\n\n    #[test]\n    fn empty_keypoint_list_is_handled() {\n        let sketch = WireSketch::from_keypoints(&[]);\n        assert_eq!(sketch.keypoint_count(), 0);\n    }\n}"
      },
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-signal/tests/ruvsense_tests.rs\n\n#[cfg(test)]\nmod coherence_gate_tests {\n    use wifi_densepose_signal::ruvsense::coherence_gate::{CoherenceGate, GateDecision};\n\n    #[test]\n    fn high_coherence_signal_is_accepted() {\n        let gate = CoherenceGate::new(0.7); // threshold = 0.7\n        let decision = gate.evaluate(0.95);\n        assert_eq!(decision, GateDecision::Accept);\n    }\n\n    #[test]\n    fn low_coherence_signal_is_rejected() {\n        let gate = CoherenceGate::new(0.7);\n        let decision = gate.evaluate(0.3);\n        assert_eq!(decision, GateDecision::Reject);\n    }\n\n    #[test]\n    fn borderline_coherence_triggers_recalibrate() {\n        let gate = CoherenceGate::new(0.7);\n        let decision = gate.evaluate(0.68); // just below threshold\n        assert_eq!(decision, GateDecision::Recalibrate);\n    }\n}\n\n#[cfg(test)]\nmod phase_align_tests {\n    use wifi_densepose_signal::ruvsense::phase_align::PhaseAligner;\n\n    #[test]\n    fn phase_at_plus_pi_does_not_wrap_incorrectly() {\n        let aligner = PhaseAligner::new();\n        let phases = vec![std::f32::consts::PI - 0.001, std::f32::consts::PI + 0.001];\n        let aligned = aligner.align(&phases);\n        // jump across ±π boundary must be handled continuously\n        let diff = (aligned[1] - aligned[0]).abs();\n        assert!(diff < 0.01, \"phase jump at ±π must be < 0.01 rad after alignment\");\n    }\n\n    #[test]\n    fn single_phase_value_aligns_to_itself() {\n        let aligner = PhaseAligner::new();\n        let phases = vec![1.5f32];\n        let aligned = aligner.align(&phases);\n        assert_eq!(aligned.len(), 1);\n        assert!((aligned[0] - 1.5).abs() < 1e-6);\n    }\n\n    #[test]\n    fn empty_phase_array_returns_empty() {\n        let aligner = PhaseAligner::new();\n        let aligned = aligner.align(&[]);\n        assert!(aligned.is_empty());\n    }\n}\n\n#[cfg(test)]\nmod adversarial_detection_tests {\n    use wifi_densepose_signal::ruvsense::adversarial::AdversarialDetector;\n\n    #[test]\n    fn physically_impossible_amplitude_is_flagged() {\n        let detector = AdversarialDetector::new();\n        // WiFi amplitude cannot exceed hardware saturation level\n        let frame = vec![1e9f32; 56]; // absurdly large\n        assert!(detector.is_suspicious(&frame));\n    }\n\n    #[test]\n    fn normal_amplitude_range_passes() {\n        let detector = AdversarialDetector::new();\n        let frame = vec![0.5f32; 56]; // typical normalized value\n        assert!(!detector.is_suspicious(&frame));\n    }\n\n    #[test]\n    fn multi_link_inconsistency_is_detected() {\n        // link A reports body moving right; link B reports no motion\n        // physically inconsistent — flag as adversarial\n        let detector = AdversarialDetector::new();\n        let result = detector.check_multi_link_consistency(\n            &[1.0, 2.0, 3.0], // link A\n            &[0.0, 0.0, 0.0], // link B (no motion)\n        );\n        assert!(result.is_inconsistent());\n    }\n}"
      },
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-train/tests/test_geometry.rs\n\n#[cfg(test)]\nmod film_layer_tests {\n    use wifi_densepose_train::geometry::FilmLayer;\n\n    #[test]\n    fn film_layer_output_shape_matches_input() {\n        let film = FilmLayer::new(64, 32); // 64-dim features, 32-dim condition\n        let features = vec![0.5f32; 64];\n        let condition = vec![1.0f32; 32];\n        let output = film.forward(&features, &condition).unwrap();\n        assert_eq!(output.len(), 64, \"FiLM output must match feature dimensionality\");\n    }\n\n    #[test]\n    fn film_layer_zero_condition_acts_as_identity() {\n        let film = FilmLayer::new(64, 32);\n        let features = vec![1.0f32; 64];\n        let zero_condition = vec![0.0f32; 32];\n        let output = film.forward(&features, &zero_condition).unwrap();\n        // scale=1, shift=0 → identity; output ≈ input\n        for (o, f) in output.iter().zip(features.iter()) {\n            assert!((o - f).abs() < 0.1, \"zero condition should approximate identity\");\n        }\n    }\n}\n\n// v2/crates/wifi-densepose-train/tests/test_rapid_adapt.rs\n\n#[cfg(test)]\nmod rapid_adaptation_tests {\n    use wifi_densepose_train::rapid_adapt::RapidAdapter;\n\n    #[test]\n    fn adapter_updates_on_single_sample() {\n        let mut adapter = RapidAdapter::new(5); // 5 adaptation steps\n        let csi_sample = vec![0.1f32; 56 * 3];\n        let pose_label = vec![0.5f32; 17 * 2]; // 17 keypoints × (x, y)\n        let result = adapter.adapt_step(&csi_sample, &pose_label);\n        assert!(result.is_ok());\n    }\n\n    #[test]\n    fn adapter_with_zero_steps_is_no_op() {\n        let adapter = RapidAdapter::new(0);\n        // 0 adaptation steps → weights unchanged\n        let initial_weights = adapter.clone_weights();\n        let _ = adapter.adapt_step(&vec![0.1f32; 168], &vec![0.5f32; 34]);\n        assert_eq!(adapter.clone_weights(), initial_weights);\n    }\n}"
      },
      {
        "language": "rust",
        "code": "// v2/crates/wifi-densepose-sensing-server/tests/auth_tests.rs\n\n#[cfg(test)]\nmod bearer_auth_tests {\n    use wifi_densepose_sensing_server::auth::{BearerValidator, TokenError};\n\n    #[test]\n    fn missing_authorization_header_returns_unauthorized() {\n        let validator = BearerValidator::new(\"secret-token\");\n        let result = validator.validate(None);\n        assert!(matches!(result, Err(TokenError::Missing)));\n    }\n\n    #[test]\n    fn wrong_token_is_rejected() {\n        let validator = BearerValidator::new(\"correct-token\");\n        let result = validator.validate(Some(\"Bearer wrong-token\"));\n        assert!(matches!(result, Err(TokenError::Invalid)));\n    }\n\n    #[test]\n    fn malformed_header_without_bearer_prefix_is_rejected() {\n        let validator = BearerValidator::new(\"token\");\n        let result = validator.validate(Some(\"token\")); // missing \"Bearer \" prefix\n        assert!(matches!(result, Err(TokenError::Malformed)));\n    }\n\n    #[test]\n    fn correct_token_is_accepted() {\n        let validator = BearerValidator::new(\"correct-token\");\n        let result = validator.validate(Some(\"Bearer correct-token\"));\n        assert!(result.is_ok());\n    }\n}\n\n// v2/crates/wifi-densepose-sensing-server/tests/semantic_tests.rs\n\n#[cfg(test)]\nmod fall_detection_tests {\n    use wifi_densepose_sensing_server::semantic::fall_detector::FallDetector;\n\n    #[test]\n    fn no_motion_does_not_trigger_fall() {\n        let mut detector = FallDetector::new();\n        for _ in 0..30 { // 30 frames of stillness\n            detector.update_pose(stationary_pose());\n        }\n        assert!(!detector.fall_detected());\n    }\n\n    #[test]\n    fn rapid_downward_velocity_triggers_fall() {\n        let mut detector = FallDetector::new();\n        // simulate person going from standing (y=1.7m) to prone (y=0.3m) in 3 frames\n        for (frame, y) in [(0, 1.7f32), (1, 1.0), (2, 0.3)] {\n            detector.update_pose(pose_at_height(y));\n        }\n        assert!(detector.fall_detected());\n    }\n\n    #[test]\n    fn sitting_down_slowly_does_not_trigger_fall() {\n        let mut detector = FallDetector::new();\n        // gradual height decrease over 30 frames is sitting, not falling\n        for i in 0..30 {\n            let y = 1.7f32 - (i as f32 * 0.04); // ~1.2m drop over 30 frames\n            detector.update_pose(pose_at_height(y));\n        }\n        assert!(!detector.fall_detected());\n    }\n}"
      }
    ]
  },
  "rawOutputPreview": "The exploration is complete. Here's the full coverage analysis with test skeletons for each critical gap.\n\n---\n\n## Test Coverage Gap Analysis — wifi-densepose\n\n### Coverage Summary by Crate\n\n| Crate | Tests Found | Status | Priority |\n|-------|-------------|--------|----------|\n| `wifi-densepose-core` | 26 inline | Good | Low |\n| `wifi-densepose-signal` | ~60 (validation only) | Moderate | **High** |\n| `wifi-densepose-nn` | **0** | Critical | **P1** |\n| `wifi-densepose-train` | ~60 (config/dataset) | Moderate | High |\n| `wifi-densepose-mat` | 1 integration test | Critical | **P1** |\n| `wifi-densepose-ruvector` | **0** | Critical | **P1** |\n| `wifi-densepose-sensing-server` | 4 integration tests | Moderate | High |\n| `wifi-densepose-wasm` | 3 compliance tests | Low | Low |\n\n---\n\n## Tier 1: Critical Gaps\n\n### 1. `wifi-densepose-nn` — Zero test coverage\n\nEvery public API is untested. Place these at `v2/crates/wifi-densepose-nn/tests/inference_tests.rs`:\n\n```rust\n// v2/crates/wifi-densepose-nn/tests/inference_tests.rs\n\n#[cfg(test)]\nmod tensor_tests {\n    use wifi_densepose_nn::tensor::Tensor;\n\n    #[test]\n    fn tensor_shape_mismatch_returns_error() {\n        // data has 6 elements but shape claims 3×3=9\n        let result = Tensor::new(vec![1.0f32; 6], &[3, 3]);\n        assert!(result.is_err(), \"shape mismatch must be rejected\");\n    }\n\n    #[test]\n    fn tensor_empty_data_returns_error() {\n        let result = Tensor::new(vec![], &[0]);\n        assert!(result.is_err());\n    }\n\n    #[test]\n    fn tensor_nan_values_are_detected() {\n        let t = Tensor::new(vec![f32::NAN, 1.0, 2.0], &[3]).unwrap();\n        assert!(t.has_nan(), \"NaN in data must be detectable\");\n    }\n\n    #[test]\n    fn tensor_inf_values_are_detected() {\n        let t = Tensor::new(vec![f32::INFINITY, 1.0], &[2]).unwrap();\n        assert!(t.has_inf());\n    }\n}\n\n#[cfg(test)]\nmod modality_translator_tests {\n    use wifi_densepose_nn::translator::ModalityTranslator;\n\n    #[test]\n    fn translator_rejects",
  "rawOutputLength": 18269
}