Wave 39/45: diagnostics.kernel takes a typed contract, as main's other diagnostics commands do

1 commits, squashed; the originals stay reachable from branch jyviko/merge-main-develop-solidcore (#11360).

- 7ad1d3e12 jyviko: diagnostics.kernel takes a typed contract, as main's other diagnostics commands do

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-11-02 16:58:17 -05:00
parent f582b1f39e
commit 28e983e191
115 changed files with 18703 additions and 600 deletions
+41 -1
View File
@@ -55,11 +55,22 @@ pub static COMMANDS: &[CommandSpec] = &[
trace?: path (write the recorded spans as a Chrome trace-event file, for chrome://tracing or Perfetto). Returns what \
was recorded before enabled and reset apply: {compiled, enabled, wall_ms, spans, dropped, by_category: [{category, \
self_ms, share}], rows: [{category, name, count, total_ms, self_ms, max_ms}], rows_total, trace?}, the rows the most \
self time first. Categories: smlib (SMLib's C API calls, timed by the C API), kernel, feature (one per feature \
self time first. Categories: solidcore (the kernel's calls), smlib (SMLib's C API calls, timed by the C API, when it is asked for), kernel, feature (one per feature \
computed, by its type), doc, command, import (STEP/IGES stages), io. Self time is a span's time less the spans \
inside it; total counts its outermost run only. Recording also starts with SOLIDCRAFT_PROFILE=1, the CLI's \
--profile and the app's preference; off, it costs nothing measurable. Read-only",
),
CommandSpec::new("diagnostics.kernel", "Geometry Kernel", crate::checked!("diagnostics.kernel", kernel))
.icon("bug_report")
.noundo()
.contract(&KERNEL_CONTRACT)
.output(output_schema_for::<crate::schema::diagnostics::KernelReply>)
.params(
"choice?: solidcore | smlib (sets which kernel answers every operation: solidcore, the default = the Rust port; \
smlib = the C++ SMLib kernel, refused as not available on a build without it, such as the web app; bodies already \
computed keep their results). SOLIDCRAFT_KERNEL, when set, wins over it. Returns {choice, environment}: choice is \
the kernel in force, environment whether SOLIDCRAFT_KERNEL chose it",
),
CommandSpec::new("diagnostics.validation", "Validation", crate::checked!("diagnostics.validation", validation))
.icon("bug_report")
.noundo()
@@ -85,6 +96,34 @@ pub static COMMANDS: &[CommandSpec] = &[
),
];
fn kernel(_: &mut Session, p: &Value) -> Result<Value> {
use solidcraft_kernel::kernel_route as route;
if let Some(v) = p.get("choice").filter(|v| !v.is_null()) {
route::set_choice(kernel_asked(v, solidcraft_kernel::smlib_built())?);
}
use crate::schema::diagnostics::{KernelChoice, KernelReply};
let choice = match route::choice() {
route::Backend::Solidcore => KernelChoice::Solidcore,
route::Backend::Smlib => KernelChoice::Smlib,
};
serde_json::to_value(KernelReply { choice, environment: route::overridden() }).map_err(|e| bad("diagnostics.kernel", e.to_string()))
}
/// The kernel `choice` asks for, on a build that has (`built`) the C++ kernel or doesn't. A choice of
/// the wrong type is refused like an unknown one, not read as no choice; `smlib` on a build without
/// it is refused too, never answered by the other kernel.
pub(crate) fn kernel_asked(choice: &Value, built: bool) -> Result<solidcraft_kernel::kernel_route::Backend> {
use solidcraft_kernel::kernel_route::Backend;
let asked = choice.as_str().and_then(Backend::from_id).ok_or_else(|| bad("diagnostics.kernel", "`choice` is solidcore or smlib"))?;
if asked == Backend::Smlib && !built {
return Err(EngineError::Disabled(
"diagnostics.kernel".into(),
"this build doesn't include the C++ SMLib kernel; build with --features smlib".into(),
));
}
Ok(asked)
}
fn dir(cmd: &str) -> Result<std::path::PathBuf> {
crash::default_dir().ok_or_else(|| bad(cmd, "no crash folder on this system"))
}
@@ -143,6 +182,7 @@ fn crash_test(_: &mut Session, p: &Value) -> Result<Value> {
const PROFILE_CONTRACT: crate::schema::TypedContract<crate::schema::diagnostics::ProfileParams> = crate::schema::TypedContract::new();
const KERNEL_CONTRACT: crate::schema::TypedContract<crate::schema::diagnostics::KernelParams> = crate::schema::TypedContract::new();
const VALIDATION_CONTRACT: crate::schema::TypedContract<crate::schema::diagnostics::ValidationParams> = crate::schema::TypedContract::new();
fn validation(s: &mut Session, p: &Value) -> Result<Value> {
+2 -3
View File
@@ -1124,8 +1124,7 @@ mod tests {
use super::*;
/// While the profiler records, a STEP import's reply carries its own profile: the import's
/// stages and SMLib's calls, as diagnostics.profile reports them.
#[cfg(feature = "smlib")]
/// stages and the kernel's calls, as diagnostics.profile reports them.
#[test]
fn a_step_import_reports_its_profile_while_the_profiler_records() {
let _serial = crate::schema::diagnostics::PROFILE_TESTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
@@ -1144,7 +1143,7 @@ mod tests {
let p = &out["profile"];
let rows = p["rows"].as_array().unwrap();
let has = |cat: &str| rows.iter().any(|r| r["category"] == cat);
assert!(has("import") && has("smlib"), "{p}");
assert!(has("import") && (has("solidcore") || has("smlib")), "{p}");
assert!(p["by_category"].as_array().is_some_and(|c| !c.is_empty()) && p["wall_ms"].as_f64().is_some_and(|w| w > 0.0), "{p}");
}
+1 -1
View File
@@ -34,7 +34,7 @@ mod component_clone;
mod component_clone_assembly;
mod construct;
mod delete;
mod diagnostics;
pub(crate) mod diagnostics;
mod edit;
mod face;
mod features;