Preferences: a Geometry kernel setting, applied through diagnostics.kernel
Preferences > Design gains a Geometry kernel segmented control (Routed, SMLib, solidcore), saved with the other preferences and applied through the diagnostics.kernel command at startup and when it changes, so an agent's choice in between stands. When SOLIDCRAFT_KERNEL overrides it the control is disabled and a hint says the environment variable wins. ui.prefs refuses an unknown geometry_kernel. diagnostics.kernel now refuses a `choice` of the wrong type instead of reading it as no choice. Tests cover the routing report, setting the choice (skipped under SOLIDCRAFT_KERNEL), unknown and hostile choices, and put the choice back to routed however they end. The command's label and the new strings are in a pending locale file, complete for ar, he, ja and zh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SdcgExNEwfR9CX2RAzp2Pt
This commit is contained in:
1 parent
12ace49736
commit
22351d84cc
5 files changed
+219
-2
No files matched your search
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"en": {
|
||||
"cmd.diagnostics_kernel": "Geometry Kernel",
|
||||
"prefs.geometry_kernel": "Geometry kernel",
|
||||
"prefs.geometry_kernel_environment": "The SOLIDCRAFT_KERNEL environment variable is set; it wins over this setting.",
|
||||
"prefs.geometry_kernel_note": "Routed uses solidcore only for operations that match SMLib on the kernel test rig; a solidcore failure is reported, never retried on SMLib.",
|
||||
"prefs.geometry_kernel_routed": "Routed"
|
||||
},
|
||||
"ar": {
|
||||
"cmd.diagnostics_kernel": "نواة الهندسة",
|
||||
"prefs.geometry_kernel": "نواة الهندسة",
|
||||
"prefs.geometry_kernel_environment": "متغير البيئة SOLIDCRAFT_KERNEL مضبوط، وله الأولوية على هذا الإعداد.",
|
||||
"prefs.geometry_kernel_note": "يستخدم الوضع الموجَّه solidcore فقط للعمليات التي تطابق SMLib على منصة اختبار النواة؛ ويُبلَّغ عن إخفاق solidcore ولا تُعاد المحاولة أبدًا على SMLib.",
|
||||
"prefs.geometry_kernel_routed": "موجَّه"
|
||||
},
|
||||
"de": {
|
||||
"cmd.diagnostics_kernel": "Geometriekernel",
|
||||
"prefs.geometry_kernel": "Geometriekernel",
|
||||
"prefs.geometry_kernel_environment": "Die Umgebungsvariable SOLIDCRAFT_KERNEL ist gesetzt; sie hat Vorrang vor dieser Einstellung.",
|
||||
"prefs.geometry_kernel_note": "Geroutet nutzt solidcore nur für Vorgänge, die auf dem Kernel-Prüfstand mit SMLib übereinstimmen; ein Fehler in solidcore wird gemeldet, nie mit SMLib wiederholt.",
|
||||
"prefs.geometry_kernel_routed": "Geroutet"
|
||||
},
|
||||
"fr": {
|
||||
"cmd.diagnostics_kernel": "Noyau géométrique",
|
||||
"prefs.geometry_kernel": "Noyau géométrique",
|
||||
"prefs.geometry_kernel_environment": "La variable d’environnement SOLIDCRAFT_KERNEL est définie ; elle l’emporte sur ce réglage.",
|
||||
"prefs.geometry_kernel_note": "Routé n’utilise solidcore que pour les opérations qui concordent avec SMLib sur le banc d’essai du noyau ; un échec de solidcore est signalé, jamais réessayé avec SMLib.",
|
||||
"prefs.geometry_kernel_routed": "Routé"
|
||||
},
|
||||
"he": {
|
||||
"cmd.diagnostics_kernel": "ליבת גאומטריה",
|
||||
"prefs.geometry_kernel": "ליבת גאומטריה",
|
||||
"prefs.geometry_kernel_environment": "משתנה הסביבה SOLIDCRAFT_KERNEL מוגדר, והוא גובר על הגדרה זו.",
|
||||
"prefs.geometry_kernel_note": "מנותב משתמש ב-solidcore רק לפעולות שתואמות את SMLib במתקן הבדיקה של הליבה; כשל של solidcore מדווח, ולעולם אינו מנוסה שוב ב-SMLib.",
|
||||
"prefs.geometry_kernel_routed": "מנותב"
|
||||
},
|
||||
"ja": {
|
||||
"cmd.diagnostics_kernel": "ジオメトリ カーネル",
|
||||
"prefs.geometry_kernel": "ジオメトリ カーネル",
|
||||
"prefs.geometry_kernel_environment": "環境変数 SOLIDCRAFT_KERNEL が設定されているため、この設定より優先されます。",
|
||||
"prefs.geometry_kernel_note": "ルーティングでは、カーネルのテスト環境で SMLib と一致した処理にのみ solidcore を使います。solidcore の失敗は報告され、SMLib で再試行されることはありません。",
|
||||
"prefs.geometry_kernel_routed": "ルーティング"
|
||||
},
|
||||
"zh": {
|
||||
"cmd.diagnostics_kernel": "几何内核",
|
||||
"prefs.geometry_kernel": "几何内核",
|
||||
"prefs.geometry_kernel_environment": "已设置环境变量 SOLIDCRAFT_KERNEL,它优先于此设置。",
|
||||
"prefs.geometry_kernel_note": "路由模式仅对在内核测试台上与 SMLib 结果一致的操作使用 solidcore;solidcore 失败时会报告,绝不会改用 SMLib 重试。",
|
||||
"prefs.geometry_kernel_routed": "路由"
|
||||
}
|
||||
}
|
||||
@@ -53,8 +53,9 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
|
||||
fn kernel(_: &mut Session, p: &Value) -> Result<Value> {
|
||||
use solidcraft_kernel::kernel_route as route;
|
||||
if let Some(id) = str_(p, "choice") {
|
||||
let c = route::Choice::from_id(id).ok_or_else(|| bad("diagnostics.kernel", "`choice` is routed, smlib or solidcore"))?;
|
||||
// A choice of the wrong type is refused like an unknown one, not read as no choice.
|
||||
if let Some(v) = p.get("choice").filter(|v| !v.is_null()) {
|
||||
let c = v.as_str().and_then(route::Choice::from_id).ok_or_else(|| bad("diagnostics.kernel", "`choice` is routed, smlib or solidcore"))?;
|
||||
route::set_choice(c);
|
||||
}
|
||||
let routes: Vec<Value> = route::Op::ALL
|
||||
|
||||
@@ -60,3 +60,93 @@ fn diagnostics_profile_reports_commands_features_and_the_kernel() {
|
||||
assert_eq!(after["enabled"], json!(false), "{after}");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Tests that set the process-wide kernel choice run one at a time, and put `routed` back however
|
||||
/// they end (a failed assertion included).
|
||||
struct KernelChoice(#[allow(dead_code)] std::sync::MutexGuard<'static, ()>);
|
||||
|
||||
static KERNEL_TESTS: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
impl KernelChoice {
|
||||
fn take() -> Self {
|
||||
KernelChoice(KERNEL_TESTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for KernelChoice {
|
||||
fn drop(&mut self) {
|
||||
solidcraft_kernel::kernel_route::set_choice(solidcraft_kernel::kernel_route::Choice::Routed);
|
||||
}
|
||||
}
|
||||
|
||||
/// diagnostics.kernel lists every operation family with the table's kernel and the one it runs
|
||||
/// on now, and its `choice` moves them (unless SOLIDCRAFT_KERNEL overrides it).
|
||||
#[test]
|
||||
fn diagnostics_kernel_reports_and_sets_the_choice() {
|
||||
use solidcraft_kernel::kernel_route as route;
|
||||
let _choice = KernelChoice::take();
|
||||
let mut s = Session::default();
|
||||
let r = s.execute("diagnostics.kernel", &json!({})).unwrap();
|
||||
let routes = r["routes"].as_array().unwrap();
|
||||
assert_eq!(routes.len(), route::Op::ALL.len(), "{r}");
|
||||
for (row, op) in routes.iter().zip(route::Op::ALL) {
|
||||
assert_eq!(row["op"], json!(format!("{op:?}").to_lowercase()), "{r}");
|
||||
assert_eq!(row["route"], json!(op.route().id()), "{r}");
|
||||
assert!(matches!(row["backend"].as_str(), Some("smlib" | "solidcore")), "{r}");
|
||||
}
|
||||
let environment = route::overridden();
|
||||
assert_eq!(r["environment"], json!(environment), "{r}");
|
||||
for choice in ["solidcore", "smlib", "routed"] {
|
||||
let r = s.execute("diagnostics.kernel", &json!({ "choice": choice })).unwrap();
|
||||
// Back to the table straight away: other tests in this process build bodies meanwhile.
|
||||
if choice != "routed" {
|
||||
route::set_choice(route::Choice::Routed);
|
||||
}
|
||||
if environment {
|
||||
continue; // SOLIDCRAFT_KERNEL wins: the choice and the backends stay its own
|
||||
}
|
||||
assert_eq!(r["choice"], json!(choice), "{r}");
|
||||
for (row, op) in r["routes"].as_array().unwrap().iter().zip(route::Op::ALL) {
|
||||
// `.smb` files stay on SMLib whatever is chosen.
|
||||
let want = match choice {
|
||||
_ if op == route::Op::File => "smlib",
|
||||
"routed" => op.route().id(),
|
||||
other => other,
|
||||
};
|
||||
assert_eq!(row["backend"], json!(want), "{choice}: {r}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An unknown or mistyped choice is an error that changes nothing; no hostile value panics.
|
||||
#[test]
|
||||
fn diagnostics_kernel_refuses_unknown_choices() {
|
||||
let _choice = KernelChoice::take();
|
||||
let mut s = Session::default();
|
||||
let before = s.execute("diagnostics.kernel", &json!({})).unwrap()["choice"].clone();
|
||||
let huge = "solidcore".repeat(100_000);
|
||||
for bad in [
|
||||
json!("truck"),
|
||||
json!("SMLIB"),
|
||||
json!(""),
|
||||
json!(huge),
|
||||
json!("routed\0"),
|
||||
json!(5),
|
||||
json!(true),
|
||||
json!(["smlib"]),
|
||||
json!({"choice": "smlib"}),
|
||||
] {
|
||||
match s.execute("diagnostics.kernel", &json!({ "choice": bad })) {
|
||||
Err(crate::EngineError::Internal(..)) | Ok(_) => panic!("`{}` was not refused", bad.as_str().map_or(0, str::len)),
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
for v in crate::tests::hostile_values() {
|
||||
for p in [json!({ "choice": v.clone() }), v] {
|
||||
if let Err(crate::EngineError::Internal(_, msg)) = s.execute("diagnostics.kernel", &p) {
|
||||
panic!("diagnostics.kernel {p}: {msg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(s.execute("diagnostics.kernel", &json!({})).unwrap()["choice"], before);
|
||||
}
|
||||
@@ -33,6 +33,8 @@ use crate::ui_kit;
|
||||
use crate::viewport::NavMode;
|
||||
|
||||
pub const UNITS: [&str; 5] = ["mm", "cm", "m", "in", "ft"];
|
||||
/// The Geometry kernel preference's choices, as `diagnostics.kernel` spells them.
|
||||
pub const KERNELS: [&str; 3] = ["routed", "smlib", "solidcore"];
|
||||
pub const OPENSCAD_NAV: &str = "openscad";
|
||||
pub const TOUCHPAD_NAV: &str = "touchpad";
|
||||
/// A mouse button that can drag the camera.
|
||||
@@ -621,6 +623,10 @@ preference_settings! {
|
||||
/// the tap maker's drills; off by default: the tap maker's drill (M8: 6.8 mm). Saved designs
|
||||
/// keep the drill they stored either way.
|
||||
metric_tap_drill_major_less_pitch: bool = false, PAGE_DESIGN => check_id("prefs.metric_tap_drill_major_less_pitch");
|
||||
/// Which geometry kernel answers (one of [`KERNELS`]): `routed` (each operation on the
|
||||
/// kernel the routing table gives it), `smlib` or `solidcore` for all. Applied through
|
||||
/// `diagnostics.kernel`; `SOLIDCRAFT_KERNEL`, when set, wins.
|
||||
geometry_kernel: String = "routed".into(), PAGE_DESIGN;
|
||||
/// Reopen the saved designs that were open when the app was last closed (#5542).
|
||||
reopen_designs: bool = true, PAGE_GENERAL;
|
||||
/// Those designs' files, in tab order, as the last quit left them.
|
||||
@@ -840,6 +846,12 @@ pub struct PrefsWindow {
|
||||
/// The Profile operations preference the profiler last followed: applied when it changes,
|
||||
/// so `diagnostics.profile` (an agent) and SOLIDCRAFT_PROFILE can switch it in between.
|
||||
applied_profile: Option<bool>,
|
||||
/// The Geometry kernel preference `diagnostics.kernel` last applied: applied when it changes
|
||||
/// (and at startup), so an agent's `diagnostics.kernel` in between stands.
|
||||
applied_kernel: Option<String>,
|
||||
/// The choice `SOLIDCRAFT_KERNEL` forces when it overrides the preference (the command's
|
||||
/// `environment` and `choice`).
|
||||
pub(crate) kernel_environment: Option<String>,
|
||||
/// The search text of the interface font list.
|
||||
font_filter: String,
|
||||
/// Search text on the Plugins page.
|
||||
@@ -1117,6 +1129,19 @@ pub fn apply(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
}
|
||||
app.prefs_window.applied_profile = Some(profile);
|
||||
}
|
||||
// The geometry kernel, through its command (an unknown saved value is Routed).
|
||||
let kernel = KERNELS.iter().copied().find(|k| *k == app.preferences.geometry_kernel).unwrap_or("routed");
|
||||
if app.prefs_window.applied_kernel.as_deref() != Some(kernel) {
|
||||
match app.session.execute("diagnostics.kernel", &json!({ "choice": kernel })) {
|
||||
Ok(v) => {
|
||||
let environment = v.get("environment").and_then(serde_json::Value::as_bool).unwrap_or(false);
|
||||
app.prefs_window.kernel_environment =
|
||||
environment.then(|| v.get("choice").and_then(serde_json::Value::as_str).unwrap_or_default().to_string());
|
||||
}
|
||||
Err(e) => log::warn!("geometry kernel preference `{kernel}`: {e}"),
|
||||
}
|
||||
app.prefs_window.applied_kernel = Some(kernel.into());
|
||||
}
|
||||
// The viewport's display quality (an unknown saved value draws at Normal).
|
||||
solidcraft_engine::doc::display_quality::set_current(
|
||||
solidcraft_engine::doc::display_quality::DisplayQuality::parse(&app.preferences.display_quality).unwrap_or_default(),
|
||||
@@ -2323,6 +2348,9 @@ pub fn set(app: &mut SolveApp, p: &serde_json::Value) -> Result<serde_json::Valu
|
||||
if !UNITS.contains(&new.default_units.as_str()) {
|
||||
return Err(format!("units must be one of {}", UNITS.join(", ")));
|
||||
}
|
||||
if !KERNELS.contains(&new.geometry_kernel.as_str()) {
|
||||
return Err(format!("`geometry_kernel` must be one of {}", KERNELS.join(", ")));
|
||||
}
|
||||
if !WINDOW_SYSTEMS.contains(&new.window_system.as_str()) {
|
||||
return Err(format!("`window_system` must be one of {}", WINDOW_SYSTEMS.join(", ")));
|
||||
}
|
||||
@@ -2428,6 +2456,32 @@ mod tests {
|
||||
assert!(!solidcraft_engine::profile::enabled());
|
||||
}
|
||||
|
||||
/// The Geometry kernel preference reaches the kernel through diagnostics.kernel, at startup
|
||||
/// and when it changes, and only a choice the command knows is accepted. (The kernel choice
|
||||
/// is process-wide and other tests start harnesses meanwhile, so this reads what was applied,
|
||||
/// and only `smlib`, which runs every family where Routed does today.)
|
||||
#[test]
|
||||
fn the_geometry_kernel_preference_applies_through_its_command() {
|
||||
use serde_json::json;
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.frames(1);
|
||||
assert_eq!(h.app.prefs_window.applied_kernel.as_deref(), Some("routed"), "applied at startup");
|
||||
let r = h.app.session.execute("diagnostics.kernel", &json!({})).unwrap();
|
||||
let environment = (r["environment"] == json!(true)).then(|| r["choice"].as_str().unwrap_or_default().to_string());
|
||||
assert_eq!(h.app.prefs_window.kernel_environment, environment);
|
||||
assert!(h.call("ui.prefs", json!({"geometry_kernel": "truck"}))["error"].as_str().is_some_and(|e| e.contains("geometry_kernel")));
|
||||
assert_eq!(h.app.preferences.geometry_kernel, "routed");
|
||||
h.call("ui.prefs", json!({"geometry_kernel": "smlib"}));
|
||||
h.frames(2);
|
||||
assert_eq!(h.app.prefs_window.applied_kernel.as_deref(), Some("smlib"));
|
||||
h.call("ui.prefs", json!({"geometry_kernel": "routed"}));
|
||||
h.frames(2);
|
||||
assert_eq!(h.app.prefs_window.applied_kernel.as_deref(), Some("routed"));
|
||||
// Saved with the other preferences.
|
||||
let saved = serde_json::to_value(&h.app.preferences).unwrap();
|
||||
assert_eq!(saved["geometry_kernel"], json!("routed"));
|
||||
}
|
||||
|
||||
/// New metric tapped holes drill the tap maker's drill (M8: 6.8 mm); the preference keeps
|
||||
/// the major diameter less the pitch they took before (6.75 mm). It reaches the hole command
|
||||
/// whether set through the control channel or the Preferences page, and a hole given its
|
||||
|
||||
@@ -82,6 +82,27 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
ui_kit::settings_section(ui, "placement", app.tr("prefs.placement"), |ui| {
|
||||
setting::placement_handles(app, ui);
|
||||
});
|
||||
// Which geometry kernel answers; `prefs::apply` applies it through diagnostics.kernel.
|
||||
ui_kit::settings_section(ui, "geometry_kernel", app.tr("prefs.geometry_kernel"), |ui| {
|
||||
// Under SOLIDCRAFT_KERNEL the control shows the environment's choice, disabled.
|
||||
let environment = app.prefs_window.kernel_environment.clone();
|
||||
ui.add_enabled_ui(environment.is_none(), |ui| {
|
||||
let options = [app.tr("prefs.geometry_kernel_routed"), "SMLib", "solidcore"];
|
||||
let shown = environment.as_deref().unwrap_or(&app.preferences.geometry_kernel);
|
||||
let mut selected = KERNELS.iter().position(|k| *k == shown).unwrap_or(0);
|
||||
ui_kit::segmented(ui, &mut selected, &options, ui_kit::Segments { intrinsic: true, ..Default::default() });
|
||||
if let Some(kernel) = KERNELS.get(selected)
|
||||
&& environment.is_none()
|
||||
&& app.preferences.geometry_kernel != *kernel
|
||||
{
|
||||
app.preferences.geometry_kernel = (*kernel).into();
|
||||
}
|
||||
});
|
||||
ui_kit::text(ui, app.tr("prefs.geometry_kernel_note"), ui_kit::Text::Hint("geometry_kernel"));
|
||||
if environment.is_some() {
|
||||
ui_kit::text(ui, app.tr("prefs.geometry_kernel_environment"), ui_kit::Text::Hint("geometry_kernel_environment"));
|
||||
}
|
||||
});
|
||||
// Where the files a design names may be: never a network location the user hasn't allowed.
|
||||
ui_kit::settings_section(ui, "network_locations", app.tr("prefs.network_locations_section"), |ui| {
|
||||
setting::network_locations(app, ui);
|
||||
|
||||
Reference in new issue
Block a user