From faffa666483aa5170a77636acc4dc825c40b6be3 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Tue, 27 Oct 2026 10:08:18 -0400 Subject: [PATCH] Profiler: the diagnostics.profile test holds while other tests record The profiler is process-wide, so the engine's other tests (the schema check's failing diagnostics.profile calls among them) record into it while this test does. It now shows the reset by the wall time starting again, and checks only rows that are certain to be there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LUXeKMoxpM7Vuv8Rb6E3K2 --- crates/engine/src/schema/diagnostics_tests.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/schema/diagnostics_tests.rs b/crates/engine/src/schema/diagnostics_tests.rs index df0f343bc..23cbef048 100644 --- a/crates/engine/src/schema/diagnostics_tests.rs +++ b/crates/engine/src/schema/diagnostics_tests.rs @@ -45,13 +45,18 @@ fn diagnostics_profile_reports_commands_features_and_the_kernel() { let dir = std::env::temp_dir().join(format!("solidcraft-profile-trace-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); let path = dir.join("trace.json").to_string_lossy().to_string(); + let since_trace = std::time::Instant::now(); let t = s.execute("diagnostics.profile", &json!({"trace": path, "enabled": false, "reset": true})).unwrap(); assert_eq!((t["trace"].as_str(), t["enabled"].as_bool()), (Some(path.as_str()), Some(false))); let trace: serde_json::Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap(); assert!(trace["traceEvents"].as_array().unwrap().iter().any(|e| e["ph"] == "X" && e["name"] == "solid.box"), "{trace}"); - // Only the call that reset it (its own span ends after the reset). + // Other tests run commands (this one among them) while it records, so the rows after the + // reset can hold theirs too. The wall time shows the reset: it starts again at the call that + // reset it, whose own span ends after the reset and is the one row certain to be there. let after = s.execute("diagnostics.profile", &json!({})).unwrap(); - let names: Vec<&str> = after["rows"].as_array().unwrap().iter().filter_map(|r| r["name"].as_str()).collect(); - assert_eq!(names, ["diagnostics.profile"], "{after}"); + assert!(after["wall_ms"].as_f64().unwrap() <= since_trace.elapsed().as_secs_f64() * 1000.0 + 0.001, "{after}"); + let rows = after["rows"].as_array().unwrap(); + assert!(rows.iter().any(|x| x["category"] == "command" && x["name"] == "diagnostics.profile"), "{after}"); + assert_eq!(after["enabled"], json!(false), "{after}"); let _ = std::fs::remove_dir_all(&dir); }