豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 3225eee

Browse files
committed
Dead-code cleanup + tests for fusion/depth/OSM/training/fingerprinting
Reviewer point #11 (PR #405): remove the `#![allow(dead_code)]` silencing added in 8eb808d and fix the underlying issues. - Delete csi.rs: duplicate of csi_pipeline.rs with incompatible wire format (JSON vs ADR-018 binary). csi_pipeline is the real path. - Delete serial_csi.rs: never referenced by any module. - Drop Frame.timestamp_ms (unread), AppState.csi_pipeline (unread), brain_bridge::brain_available (caller-less), fusion::fetch_wifi_occupancy (caller-less) — these had no runtime users. - Drop crate-level #![allow(dead_code)] from camera.rs, depth.rs, fusion.rs, pointcloud.rs. Tests (target: 8-12, actual: 15 unit + 9 geo unit + 8 geo integration = 32 total, all pass): - parser.rs: 5 tests (v1/v6 magic roundtrip, wrong magic, truncated header, truncated payload). - fusion.rs: 2 tests (non-overlapping merge, voxel dedup). - depth.rs: 2 tests (2x2 backproject → 4 points at z=1, NaN rejected). - training.rs: 4 tests (rejects `..`, accepts relative child, refuses TrainingSession::new("../etc/passwd"), accepts a clean tmpdir). - csi_pipeline.rs: 2 tests (set_light_level toggles is_dark, record_fingerprint stores and self-identifies). - osm.rs: 3 tests (parse_overpass_json minimal fixture, rejects malformed payload, fetch_buildings rejects > MAX_RADIUS_M). Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent d2b2cbf commit 3225eee

File tree

8 files changed

+158
-394
lines changed

8 files changed

+158
-394
lines changed

rust-port/wifi-densepose-rs/crates/wifi-densepose-geo/src/osm.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,51 @@ fn parse_roads(data: &serde_json::Value) -> Result<Vec<OsmFeature>> {
166166

167167
Ok(roads)
168168
}
169+
170+
#[cfg(test)]
171+
mod tests {
172+
use super::*;
173+
174+
#[test]
175+
fn parse_overpass_json_accepts_minimal_fixture() {
176+
// Minimal fixture: three nodes forming a triangular building.
177+
let j = serde_json::json!({
178+
"elements": [
179+
{ "type": "node", "id": 1, "lat": 43.0, "lon": -79.0 },
180+
{ "type": "node", "id": 2, "lat": 43.0001, "lon": -79.0 },
181+
{ "type": "node", "id": 3, "lat": 43.0, "lon": -79.0001 },
182+
{
183+
"type": "way", "id": 100,
184+
"nodes": [1, 2, 3, 1],
185+
"tags": { "building": "yes", "name": "Test Hall" }
186+
}
187+
]
188+
});
189+
let features = parse_overpass_json(&j).expect("minimal payload should parse");
190+
assert_eq!(features.len(), 1);
191+
match &features[0] {
192+
OsmFeature::Building { outline, name, .. } => {
193+
assert_eq!(outline.len(), 4);
194+
assert_eq!(name.as_deref(), Some("Test Hall"));
195+
}
196+
_ => panic!("expected a Building"),
197+
}
198+
}
199+
200+
#[test]
201+
fn parse_overpass_json_rejects_malformed() {
202+
// Missing the `elements` array entirely.
203+
let j = serde_json::json!({ "version": 0.6 });
204+
assert!(parse_overpass_json(&j).is_err());
205+
// Not even an object.
206+
let arr = serde_json::json!([1, 2, 3]);
207+
assert!(parse_overpass_json(&arr).is_err());
208+
}
209+
210+
#[tokio::test]
211+
async fn fetch_buildings_rejects_oversized_radius() {
212+
let center = GeoPoint { lat: 43.0, lon: -79.0, alt: 0.0 };
213+
let err = fetch_buildings(&center, MAX_RADIUS_M + 1.0).await.err();
214+
assert!(err.is_some(), "should reject radius > MAX_RADIUS_M");
215+
}
216+
}

rust-port/wifi-densepose-rs/crates/wifi-densepose-pointcloud/src/brain_bridge.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,3 @@ pub async fn sync_to_brain(pipeline: &PipelineOutput, camera_frames: u64) {
9090
}
9191
}
9292

93-
/// Check if brain is reachable.
94-
pub async fn brain_available() -> bool {
95-
// Must .await directly — calling `Handle::current().block_on(...)` from
96-
// inside an async fn panics with "Cannot start a runtime from within a
97-
// runtime" because a worker thread is already driving a runtime.
98-
let Ok(client) = reqwest::Client::builder()
99-
.timeout(std::time::Duration::from_secs(2))
100-
.build()
101-
else {
102-
return false;
103-
};
104-
client
105-
.get(format!("{}/health", brain_url()))
106-
.send()
107-
.await
108-
.is_ok()
109-
}

rust-port/wifi-densepose-rs/crates/wifi-densepose-pointcloud/src/camera.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Camera capture — cross-platform frame grabber.
2-
#![allow(dead_code)]
32
//!
43
//! macOS: uses `screencapture` or `ffmpeg -f avfoundation` for camera frames
54
//! Linux: uses `v4l2-ctl` or `ffmpeg -f v4l2` for camera frames
@@ -14,7 +13,6 @@ pub struct Frame {
1413
pub width: u32,
1514
pub height: u32,
1615
pub rgb: Vec<u8>, // row-major [height * width * 3]
17-
pub timestamp_ms: i64,
1816
}
1917

2018
/// Camera source configuration.
@@ -96,7 +94,6 @@ fn capture_ffmpeg(config: &CameraConfig, tmp: &PathBuf) -> Result<Frame> {
9694
width: config.width,
9795
height: config.height,
9896
rgb: rgb[..expected].to_vec(),
99-
timestamp_ms: chrono::Utc::now().timestamp_millis(),
10097
})
10198
}
10299

@@ -170,7 +167,6 @@ fn decode_jpeg_to_rgb(path: &PathBuf, _width: u32, _height: u32) -> Result<Frame
170167
width: _width,
171168
height: _height,
172169
rgb: data,
173-
timestamp_ms: chrono::Utc::now().timestamp_millis(),
174170
})
175171
}
176172

rust-port/wifi-densepose-rs/crates/wifi-densepose-pointcloud/src/csi.rs

Lines changed: 0 additions & 189 deletions
This file was deleted.

rust-port/wifi-densepose-rs/crates/wifi-densepose-pointcloud/src/depth.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,46 @@ pub fn demo_depth_cloud() -> PointCloud {
210210
backproject_depth(&depth, &scaled_intrinsics, None, 1)
211211
}
212212

213+
#[cfg(test)]
214+
mod tests {
215+
use super::*;
216+
217+
#[test]
218+
fn backproject_2x2_depth_yields_four_points() {
219+
// 2x2 image, depth=1m everywhere; trivial intrinsics.
220+
let intr = CameraIntrinsics {
221+
fx: 1.0, fy: 1.0, cx: 0.5, cy: 0.5,
222+
width: 2, height: 2,
223+
};
224+
let depth = vec![1.0f32; 4];
225+
let cloud = backproject_depth(&depth, &intr, None, 1);
226+
assert_eq!(cloud.points.len(), 4, "2x2 depth → 4 backprojected points");
227+
// Every point should be at z=1.0.
228+
for p in &cloud.points {
229+
assert!((p.z - 1.0).abs() < 1e-6, "z should be 1.0, got {}", p.z);
230+
}
231+
// With cx=0.5, cy=0.5 the four pixel centers backproject symmetrically
232+
// about the optical axis: x in {-0.5, 0.5}, y in {-0.5, 0.5}.
233+
let mut xs: Vec<f32> = cloud.points.iter().map(|p| p.x).collect();
234+
xs.sort_by(|a, b| a.partial_cmp(b).unwrap());
235+
assert!((xs[0] + 0.5).abs() < 1e-6);
236+
assert!((xs.last().unwrap() - 0.5).abs() < 1e-6);
237+
}
238+
239+
#[test]
240+
fn backproject_rejects_invalid_depth() {
241+
let intr = CameraIntrinsics {
242+
fx: 1.0, fy: 1.0, cx: 0.5, cy: 0.5,
243+
width: 2, height: 2,
244+
};
245+
// All pixels NaN → no points.
246+
let depth = vec![f32::NAN; 4];
247+
let cloud = backproject_depth(&depth, &intr, None, 1);
248+
assert_eq!(cloud.points.len(), 0);
249+
}
250+
}
251+
252+
#[allow(dead_code)]
213253
fn find_midas_model() -> Result<String> {
214254
let paths = [
215255
dirs::home_dir().unwrap_or_default().join(".local/share/ruview/midas_v21_small_256.onnx"),

0 commit comments

Comments
 (0)