From 53ef5bb7c22f157f5dca3f368198bce2b5410652 Mon Sep 17 00:00:00 2001 From: selune <35337584+0xlillith@users.noreply.github.com> Date: Sat, 31 Oct 2026 05:38:12 +0100 Subject: [PATCH] docs(render): preserve exact C24 quality-test macro recovery WIP --- proposals/render/2026-10-30/README.md | 4 + .../2026-10-31/c24-two-parentheses/README.md | 11 + .../src/render_workspace_inspector_tests.rs | 2803 +++++++++++++++++ .../c24-two-parentheses/delta.patch | 11 + .../c24-two-parentheses/source-bindings.json | 33 + 5 files changed, 2862 insertions(+) create mode 100644 proposals/render/2026-10-31/c24-two-parentheses/README.md create mode 100644 proposals/render/2026-10-31/c24-two-parentheses/candidate/crates/ui-egui/src/render_workspace_inspector_tests.rs create mode 100644 proposals/render/2026-10-31/c24-two-parentheses/delta.patch create mode 100644 proposals/render/2026-10-31/c24-two-parentheses/source-bindings.json diff --git a/proposals/render/2026-10-30/README.md b/proposals/render/2026-10-30/README.md index 280f4b07f..f1e54ab32 100644 --- a/proposals/render/2026-10-30/README.md +++ b/proposals/render/2026-10-30/README.md @@ -203,3 +203,7 @@ The complete API consumer connects captured direct visibility and RGB shading to [Four-path source and request-boundary documentation](../2026-10-31/cpu-directional-shadow-ui/README.md). UniformON/OFF reaches the existing producer; mixed assignments refuse explicitly. Original277cases retained, one old unsupported-feature frontier deliberately updated,7newcasesUNRUN. Included in C23source only, not native/image/GPU/full-CI qualification. - [U04 original GPU owner patches: proposed source integration](../2026-10-31/u04-owner-integrated-source/README.md) — Twelve literal hunks from plexi32's #6813 and #6850, original tests and RAW bindings. Not adopted; Rust/Naga/GPU/native UNRUN. + +## C24 existing quality-test macro expression (2026-10-31) + +[One-file checkpoint, exact two-parentheses delta and source bindings](../2026-10-31/c24-two-parentheses/README.md). Immediate base is C23 post-format source, not the earlier unformatted public candidate. No production change or new tests; C24 resource admission stopped before combined Cargo, with 953 cases and 60 required marker contracts UNRUN. No gate/readiness PASS inferred. diff --git a/proposals/render/2026-10-31/c24-two-parentheses/README.md b/proposals/render/2026-10-31/c24-two-parentheses/README.md new file mode 100644 index 000000000..a0b9c6b89 --- /dev/null +++ b/proposals/render/2026-10-31/c24-two-parentheses/README.md @@ -0,0 +1,11 @@ +# C24: two parentheses in an existing quality test + +This source checkpoint contains one adopted test-file change following the [C23 quality proposal](../c23-three-path-source/README.md). It adds only `(` and `)` around `["Q-001","Q-002","Q-003"][index]` inside the existing `json!` call in `quality_highlight_derives_every_projected_field_and_returns_to_custom`. C23's actual compiler reported `no rules expected [` at this expression; the parentheses group the indexed expression for the macro. No renderer production code changes. + +All fixture IDs, the index, variant, omission acknowledgement, assertions, tolerances and oracles remain byte-identical outside these two inserted characters. The file retains the same 81 test declarations, with zero new declarations. Existing source, authorship and notices are preserved verbatim. + +The patch's immediate before file is the actual C23 post-format source, SHA256 `87c0acbdfd3e45128e3ced3819fa5b9740d8940eec2ce5402aa567b3435b53b9`. The earlier public C23 candidate has SHA256 `867fbaa191e057b56dcc09b0d61e624edab130e53dab0ea3882e98ee850a2da6`; it precedes that formatting and is not this patch's literal receiver. This archive supplies no cumulative patch from the older public file. Reconcile that receiver explicitly before applying the two-character delta; do not apply earlier quality deltas again to a file that already contains them. + +`candidate/` is the exact adopted C24 test file, SHA256 `5dfa8eb8be2da3ae24895ed098ebe62029a4de69f508ab7e26cabdba54ad5292`. `delta.patch` is the 597-byte single-hunk alternative from the exact before source. Forward and inverse byte replay match. Use the candidate OR apply the patch once to its exact receiver; these are alternatives. Other integrated workspace prerequisites are not bundled, so this is not a standalone buildable branch. `source-bindings.json` separates Git commits from source/artifact SHA256 pins. + +C24 stopped at resource admission before the combined Cargo build. This is a resource stop, not a test or product failure. The changed C24 source has no combined-build or test qualification: all 953 selected cases and 60 required CPU-supported marker contracts remain UNRUN. No normal development gate, full CI, native desktop/GPU acceptance or readiness PASS is claimed, and prior partial results do not transfer. A later exact-source attempt requires its own authorized execution and admission; this archive creates neither. diff --git a/proposals/render/2026-10-31/c24-two-parentheses/candidate/crates/ui-egui/src/render_workspace_inspector_tests.rs b/proposals/render/2026-10-31/c24-two-parentheses/candidate/crates/ui-egui/src/render_workspace_inspector_tests.rs new file mode 100644 index 000000000..387edb659 --- /dev/null +++ b/proposals/render/2026-10-31/c24-two-parentheses/candidate/crates/ui-egui/src/render_workspace_inspector_tests.rs @@ -0,0 +1,2803 @@ +use super::*; +use crate::{scenario::Harness, theme::Tokens}; +fn fixture() -> Harness { + let mut h = Harness::new(); + h.call("ui.resize", json!({"width":1440,"height":1000})); + h.app.run("solid.box", json!({"length":20,"width":15,"height":10,"body_name":"Subject"})).unwrap(); + super::super::enter(&mut h.app, true).unwrap(); + h.app.run("view.render_stage", json!({"stage":"output"})).unwrap(); + h.frames(3); + h +} + +fn reveal_inspector_target(h: &mut Harness, target: &str) -> egui::Rect { + for _ in 0..8 { + let rect = crate::scenario::rect_of(target).unwrap(); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let top = crate::scenario::rect_of("render:inspector:header").unwrap().bottom() + Tokens::get().space_8; + let bottom = inspector.bottom() - Tokens::get().space_8; + if rect.top() >= top && rect.bottom() <= bottom { + return rect; + } + let at = rect.center(); + let delta = at.y.clamp(top + rect.height() / 2.0, bottom - rect.height() / 2.0) - at.y; + h.call("ui.scroll", json!({"x":inspector.center().x,"y":(top+bottom)/2.0,"delta":delta})); + h.frames(20); + } + panic!("inspector target {target} is still clipped"); +} + +fn ordered_sections(keys: &[&str], app: &SolveApp) { + let mut bottom = f32::NEG_INFINITY; + for key in keys { + let rect = crate::scenario::rect_of(&format!("dialog:section:{}", app.tr(key))).unwrap(); + assert!(rect.top() >= bottom, "{key} must follow the previous section"); + bottom = rect.bottom(); + } +} + +#[test] +fn render_workspace_shot_and_scene_widgets_fit_inspector_content_width() { + let mut h = fixture(); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + super::super::shot::choose_aspect(&mut h.app, &name, 0).unwrap(); + h.app.cam.target = solidcraft_engine::geom::Vec3::new(-18.0, 125.5, -18.0); + let ctx = crate::fonts::test_context(); + let mut textures = std::collections::HashMap::new(); + for width in [350.0, 320.0] { + for editor in ["scene", "raster", "cpu_raytrace", "gpu_path", "orthographic"] { + if editor != "scene" { + h.app.cam.fov = if editor == "orthographic" { 0.0 } else { 0.6 }; + let job = if editor == "orthographic" { "raster" } else { editor }; + let mut job = json!({"method":job}); + if editor == "gpu_path" { + job["options"] = json!({"lens":h.app.render_workspace.view.studio.lens}); + } + let patch = json!({"job":job,"camera":h.app.cam}); + super::super::shot::edit_settings(&mut h.app, &name, patch).unwrap(); + h.app.cam.yaw += 0.1; // Include the changed-camera banner and enabled Update/Revert. + } + let before = h.app.session.doc.to_json(); + let content = egui::Rect::from_min_size(egui::pos2(8.0, 8.0), egui::vec2(width, 1600.0)); + let mut widgets = Vec::new(); + for frame in 0..3 { + crate::scenario::clear_handles(); + let mut output = ctx.run_ui(egui::RawInput { screen_rect: Some(content.expand(8.0)), ..Default::default() }, |ui| { + ui.scope_builder(egui::UiBuilder::new().max_rect(content), |ui| { + ui.painter().rect_filled(content, 0.0, crate::theme::Tokens::get().dialog_body); + ui_kit::scope(ui, |ui| { + let preceding: std::collections::HashSet<_> = ctx.viewport(|vp| { + vp.this_pass.widgets.layers().flat_map(|(_, widgets)| widgets.iter().map(|widget| widget.id)).collect() + }); + if editor == "scene" { + scene_controls(&mut h.app, ui); + } else { + super::super::shot::editor(&mut h.app, ui, &name); + } + widgets = ctx.viewport(|vp| { + vp.this_pass + .widgets + .layers() + .flat_map(|(_, widgets)| widgets.iter().filter(|widget| !preceding.contains(&widget.id)).copied()) + .collect() + }); + }); + }); + }); + ui_kit::test_textures_update(&mut textures, &output.textures_delta); + output.textures_delta.clear(); + for shape in &output.shapes { + if let egui::Shape::Text(text) = &shape.shape + && [h.app.tr("render.perspective"), h.app.tr("render.stage_orthographic"), h.app.tr("render.shot_distance")] + .contains(&text.galley.text()) + { + assert!(!text.galley.elided, "{editor} at {width} pt: {} is truncated", text.galley.text()); + let rect = egui::Rect::from_min_size(text.pos, text.galley.size()); + assert!(shape.clip_rect.expand(1.0).contains_rect(rect), "{} is clipped: {rect:?}", text.galley.text()); + } + } + if frame == 2 + && width == 350.0 + && let Some(dir) = std::env::var_os("SOLIDCRAFT_SHOT_LAYOUT_EVIDENCE") + { + std::fs::create_dir_all(&dir).unwrap(); + ui_kit::test_raster(&ctx, output.shapes, output.pixels_per_point, content, &textures) + .save(std::path::Path::new(&dir).join(format!("{editor}.png"))) + .unwrap(); + } + } + assert!(widgets.len() > 10, "must inspect actual editor widgets"); + for widget in widgets { + assert!( + widget.rect.left() >= content.left() - 0.5 && widget.rect.right() <= content.right() + 0.5, + "{editor} at {width} pt: widget {:?} extends outside {content:?}: {:?}", + widget.id, + widget.rect + ); + } + if editor != "scene" { + let cells = crate::scenario::rects(&format!("dialog:widget:{}", h.app.tr("render.shot_target"))); + assert_eq!(cells.len(), 3); + assert!(cells.windows(2).all(|pair| (pair[0].1.width() - pair[1].1.width()).abs() < 0.5)); + } + assert_eq!(h.app.session.doc.to_json(), before, "layout must not edit saved intent"); + } + } +} + +#[test] +fn render_workspace_scene_overview_selection_order_links_and_readiness_are_read_only() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":1600})); + setups::save(&mut h.app).unwrap(); + h.app.run("view.render_select", json!({"kind":"nothing"})).unwrap(); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Scene); + ordered_sections(&["render.scene_stages", "render.scene_ready", "render.scene_reminders"], &h.app); + let mut bottom = f32::NEG_INFINITY; + for id in ["look", "light", "frame", "output"] { + let rect = crate::scenario::rect_of(&format!("render:scene:{id}")).unwrap(); + assert!(rect.top() >= bottom); + bottom = rect.bottom(); + } + for id in ["open-check", "check", "render", "all-shots"] { + assert!(crate::scenario::rect_of(&format!("render:scene:{id}")).is_some()); + } + assert!(crate::scenario::rect_of("dialog:note:render.scene_batch_reason").is_some()); + h.step(&json!({"click":{"handle":"render:scene:frame"}})).unwrap(); + assert!(matches!(h.app.render_workspace.view.selection, super::super::RenderSelection::Shot(_))); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Camera); + h.app.run("view.render_select", json!({"kind":"nothing"})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":"render:scene:output"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, super::super::RenderSelection::Output); + h.app.run("view.render_select", json!({"kind":"nothing"})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":"render:scene:open-check"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Diagnostics); + assert_eq!(h.app.render_workspace.view.selection, super::super::RenderSelection::Check); + assert!(crate::scenario::rect_of("render:check").is_some()); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.session.undo.len(), undo); + assert!(h.app.render_workspace.view.job.is_none()); +} + +#[test] +fn render_workspace_shot_e7_order_disabled_reasons_output_link_and_confirm_remove() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1600,"height":1800})); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + h.app.run("view.render_select", json!({"kind":"shot","id":name})).unwrap(); + let before = h.app.session.doc.to_json(); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Camera); + assert!(crate::scenario::rect_of("render:job-footer").is_none(), "Shot owns its actions"); + assert!(crate::scenario::rect_of("dialog:editor_footer").is_none(), "Appearance footer stays in Appearance"); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let header = crate::scenario::rect_of("render:inspector:header").unwrap(); + assert!(inspector.contains_rect(header)); + assert!(h.widget(&name).is_some(), "selected Shot names the inspector"); + ordered_sections(&["render.page_camera", "render.shot_lens", "render.shot_exposure_section", "render.stage_frame"], &h.app); + for key in ["render.shot_lens_gpu_reason", "render.shot_exposure_reason", "render.shot_selection_reason"] { + assert!(crate::scenario::rect_of(&format!("dialog:note:{key}")).is_some(), "{key}"); + } + for id in ["name", "update", "revert", "duplicate", "remove", "output", "distance", "look-selection"] { + assert!(crate::scenario::rect_of(&format!("render:shot:{id}")).is_some(), "{id}"); + } + assert!(crate::scenario::rect_of("render:shot:width").is_none(), "size belongs in Output"); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"render:shot:remove"}})).unwrap(); + assert!(confirmation_open(&h.app)); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"dialog:cancel"}})).unwrap(); + assert!(!confirmation_open(&h.app)); + assert_eq!(h.app.session.doc.to_json(), before, "cancelling removal keeps the Shot"); + h.step(&json!({"click":{"handle":"render:shot:output"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, super::super::RenderSelection::Output); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Output); +} + +#[test] +fn render_workspace_shot_camera_controls_save_undo_and_refuse_hostile_values() { + let mut h = fixture(); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + let before = h.app.session.doc.to_json(); + let camera = solidcraft_engine::render::Camera { yaw: 0.7, roll: 0.2, distance: 123.0, ..h.app.cam }; + super::super::shot::set_camera(&mut h.app, &name, camera).unwrap(); + assert_eq!(h.app.cam, camera); + assert_eq!(h.app.session.doc.render.setups[&name].camera, camera); + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + for value in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1.0, 0.0, f64::MAX] { + let camera = solidcraft_engine::render::Camera { distance: value, ..camera }; + assert!(super::super::shot::set_camera(&mut h.app, &name, camera).is_err()); + assert_eq!(h.app.session.doc.to_json(), before); + } +} + +#[test] +fn render_workspace_shot_lens_saves_only_lens_and_orthographic_keeps_faded_controls() { + use solidcraft_engine::doc::render_settings::RenderJob; + let mut h = fixture(); + h.call("ui.resize", json!({"width":1600,"height":1800})); + let name = "Lens shot"; + let camera = solidcraft_engine::render::Camera { fov: 0.6, ..h.app.cam }; + h.app + .run("render.settings.set", json!({"name":name,"set":{"camera":camera,"job":{"method":"gpu_path","options":{"samples":128,"seed":42}}}})) + .unwrap(); + h.app.run("render.camera.set", json!({"camera":camera})).unwrap(); + h.app.follow_view_request(false); + h.app.run("view.render_select", json!({"kind":"shot","id":name})).unwrap(); + let before = h.app.session.doc.render.setups[name].clone(); + let undo = h.app.session.undo.len(); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.shot_dof")})).unwrap(); + let mut expected = before.clone(); + if let Some(RenderJob::GpuPath { options, .. }) = &mut expected.job { + options.lens = Some(h.app.render_workspace.view.studio.lens); + } + assert_eq!(h.app.session.doc.render.setups[name], expected); + assert_eq!(h.app.session.undo.len(), undo + 1); + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(h.app.session.doc.render.setups[name], before); + h.app.cam.fov = 0.0; + h.frames(3); + for key in ["render.shot_fov_reason", "render.shot_lens_perspective_reason"] { + assert!(crate::scenario::rect_of(&format!("dialog:note:{key}")).is_some(), "{key}"); + } + assert_eq!(h.app.session.doc.render.setups[name], before, "opening must not change saved intent or method"); +} +#[test] +fn native_inspector_keeps_stage_actions_on_screen_and_output_has_no_pinned_footer() { + for dark in [false, true] { + for layout in [crate::shell::LayoutMode::Docked, crate::shell::LayoutMode::Floating] { + let mut h = fixture(); + h.app.preferences.theme = if dark { "dark" } else { "light" }.into(); + h.app.ui.layout = layout; + h.call("ui.resize", json!({"width":1280,"height":900})); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Output); + let before = h.app.session.doc.to_json(); + let revision = h.app.session.revision; + let history = (h.app.session.undo.len(), h.app.session.redo.len()); + for page in Page::ALL { + h.app.render_workspace.view.inspector.page = page; + h.frames(3); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.session.revision, revision); + assert_eq!((h.app.session.undo.len(), h.app.session.redo.len()), history); + assert!(h.app.render_workspace.view.job.is_none()); + assert!(h.app.render_workspace.view.completed.is_none()); + if page == Page::Appearance { + let footer = crate::scenario::rect_of("dialog:editor_footer").unwrap(); + assert!(inspector.contains_rect(footer), "Appearance footer outside inspector: {inspector:?} {footer:?}"); + assert!(crate::scenario::rect_of("render:job-footer").is_none()); + continue; + } + if matches!(page, Page::Output | Page::Effects | Page::Diagnostics | Page::Sampling) { + assert!(crate::scenario::rect_of("render:job-footer").is_none()); + let bar = crate::scenario::rect_of("render:stage_bar").unwrap(); + for name in ["render:stage:render.start", "render:stage:render.cancel"] { + let action = crate::scenario::rect_of(name).unwrap(); + assert!(bar.contains_rect(action), "{name} outside stage bar: {bar:?} {action:?}"); + } + } else if page == Page::Scene { + let stages = crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr("render.scene_stages"))).unwrap(); + assert!(inspector.contains_rect(stages), "Scene stages outside inspector: {inspector:?} {stages:?}"); + assert!(crate::scenario::rect_of("render:job-footer").is_none()); + } else { + let footer = crate::scenario::rect_of("render:job-footer").unwrap(); + assert!(inspector.contains_rect(footer), "footer outside inspector at {page:?}: {inspector:?} {footer:?}"); + for name in ["render:check", "render:start", "render:cancel", "render:export"] { + let target = crate::scenario::rect_of(name).unwrap(); + assert!(footer.contains_rect(target), "{name} clipped at {page:?}"); + } + } + } + } + } +} +#[test] +fn stage_navigation_is_local_and_never_switches_executor_or_overwrites_drafts() { + let mut h = fixture(); + let before = h.app.session.doc.to_json(); + h.app.render_workspace.view.samples = 37; + h.app.render_workspace.view.draft.width = 777; + for stage in super::super::Stage::ALL { + h.step(&json!({"click":{"handle":format!("render:stage:{}",stage.key())}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, stage.page()); + assert_eq!(h.app.render_workspace.view.method, ImageMethod::Raster); + assert_eq!(h.app.render_workspace.view.samples, 37); + assert_eq!(h.app.render_workspace.view.draft.width, 777); + assert_eq!(h.app.session.doc.to_json(), before); + } +} + +#[test] +fn dirty_shot_switch_keep_discard_and_save_are_explicit_and_lossless() { + let mut h = fixture(); + h.app.render_workspace.view.name = "A".into(); + setups::save(&mut h.app).unwrap(); + h.app.run("render.settings.set", json!({"name":"B","set":{"width":321,"job":{"method":"raster"}}})).unwrap(); + h.app.render_workspace.view.draft.width = 123; + setups::refresh_dirty(&mut h.app); + request_action(&mut h.app, PendingAction::Switch("B".into())); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.keep_editing")})).unwrap(); + assert_eq!(h.app.render_workspace.view.name, "A"); + assert_eq!(h.app.render_workspace.view.draft.width, 123); + request_action(&mut h.app, PendingAction::Switch("B".into())); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.discard_continue")})).unwrap(); + assert_eq!(h.app.render_workspace.view.name, "B"); + assert_eq!(h.app.render_workspace.view.draft.width, 321); + assert_ne!(h.app.session.doc.render.setups["A"].width, 123); + h.app.render_workspace.view.draft.width = 456; + setups::refresh_dirty(&mut h.app); + request_action(&mut h.app, PendingAction::Switch("A".into())); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.save_continue")})).unwrap(); + assert_eq!(h.app.session.doc.render.setups["B"].width, 456); + assert_eq!(h.app.render_workspace.view.name, "A"); +} +#[test] +fn expired_confirmation_cannot_remove_a_changed_shot() { + let mut h = fixture(); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + request_action(&mut h.app, PendingAction::Remove(name.clone())); + h.app.run("solid.box", json!({"length":1,"width":1,"height":1,"body_name":"Later"})).unwrap(); + h.frames(3); + assert!(h.app.render_workspace.view.inspector.pending.is_none()); + assert!(h.app.session.doc.render.setups.contains_key(&name)); +} +#[test] +fn projected_quality_changes_only_requested_budget_fields_and_has_no_runtime_claim() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.cam.fov = 0.6; + h.app.render_workspace.view.studio.intensity = 0.42; + h.app.render_workspace.view.draft.exposure_ev = 1.23; + h.app.render_workspace.view.studio.ambient = [0.11, 0.22, 0.33]; + let before = h.app.session.doc.to_json(); + let camera = h.app.cam; + let plan = h.app.run("render.quality.prepare", json!({"id":"Q-002","variant":"fixed_samples_png","acknowledge_omissions":true})).unwrap(); + apply_quality(&mut h.app, &plan).unwrap(); + assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (1600, 900)); + assert_eq!(h.app.render_workspace.view.samples, 512); + assert_eq!(h.app.cam, camera); + assert_eq!(h.app.render_workspace.view.studio.intensity, 0.42); + assert_eq!(h.app.render_workspace.view.studio.ambient, [0.11, 0.22, 0.33]); + assert_eq!(h.app.render_workspace.view.draft.exposure_ev, 1.23); + assert_eq!(h.app.session.doc.to_json(), before); + super::super::select_image_method(&mut h.app, ImageMethod::CpuRaytrace); + assert!(apply_quality(&mut h.app, &plan).is_err()); +} +#[test] +fn complete_native_studio_can_be_reviewed_and_applied_from_real_ui_controls() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + setups::save(&mut h.app).unwrap(); + library::open_category(&mut h.app, "native_scenes"); + h.frames(4); + h.step(&json!({"click":{"handle":"render:light:NATIVE-STUDIO-002"}})).unwrap(); + let before = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:light:review"}})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + assert!(h.app.render_workspace.view.library.review.is_some()); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!(!h.app.render_workspace.view.draft.stage.is_empty()); + assert!(h.app.render_workspace.view.library.review.is_none()); + assert!(!h.app.render_workspace.view.dirty); +} + +#[test] +fn surface_stage_contains_preview_target_plane_repeat_and_method_reason_in_order() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1600,"height":1800})); + h.app.run("select.set", json!({"items":[solidcraft_engine::Sel::Body { name:"Subject".into() }]})).unwrap(); + library::open_category(&mut h.app, "surfaces"); + h.frames(3); + let before = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:library:SURF-001"}})).unwrap(); + h.frames(3); + let note = crate::scenario::rect_of("dialog:note:surface:note").unwrap(); + let target = crate::scenario::rect_of("render:surface:target").unwrap(); + let plane = crate::scenario::rect_of("render:surface:xy").unwrap(); + let repeat = crate::scenario::rect_of("render:surface:repeat").unwrap(); + let reason = crate::scenario::rect_of("dialog:note:surface:gpu:reason").unwrap(); + assert!(note.bottom() < target.top()); + assert!(target.bottom() <= plane.top()); + assert!(plane.bottom() <= repeat.top()); + assert!(repeat.bottom() < reason.top()); + assert_eq!(h.app.render_workspace.view.method, ImageMethod::Raster); + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn stage_catalogs_fill_a_290_by_530_panel_and_keep_two_line_labels_inside_tiles() { + use crate::{scenario, ui_kit}; + use egui::{Pos2, RawInput, Rect, vec2}; + let previous_theme = crate::theme::is_dark(); + for dark in [false, true] { + for (kind, selected, method, key) in [ + ("appearances", None, ImageMethod::Raster, "render:library:catalog"), + ("surfaces", None, ImageMethod::Raster, "render:surface:catalog"), + ("surfaces", Some("SURF-001"), ImageMethod::Raster, "render:surface:catalog"), + ("physical_profiles", Some("steel-304-plate"), ImageMethod::Raster, "render:surface:catalog"), + ("native_scenes", None, ImageMethod::Raster, "render:light:catalog"), + ("native_scenes", Some("NATIVE-STUDIO-002"), ImageMethod::GpuRaytrace, "render:light:catalog"), + ] { + let mut h = fixture(); + // Capture the font atlas from its first upload along with panel textures. + h.ctx = crate::fonts::test_context(); + crate::theme::set_dark(dark); + h.ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() }); + // A resizable 290 pt card needs the floating, wide-screen policy. + h.app.ui.layout = crate::shell::LayoutMode::Floating; + h.app.preferences.render_browser_width = 290.0; + h.app.preferences.render_browser_side = "left".into(); + super::super::select_image_method(&mut h.app, method); + library::open_category(&mut h.app, kind); + crate::theme::TabAccent::publish(&h.app, &h.ctx); + let document = h.app.session.doc.to_json(); + let history = (h.app.session.undo.len(), h.app.session.redo.len()); + // Panel::workspace reserves an 8 pt bottom gap in these bounds. + let bounds = Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 538.0)); + let mut textures = std::collections::HashMap::new(); + let mut output = None; + let mut unselected_height = 0.0; + for pass in 0..8 { + if pass == 4 { + unselected_height = scenario::rect_of(&format!("{key}:body")).unwrap().height(); + if let Some(id) = selected { + let mut view = std::mem::take(&mut h.app.render_workspace.view.library); + library::choose(&mut h.app, &mut view, kind, id).unwrap(); + h.app.render_workspace.view.library = view; + } + } + let mut frame = h.ctx.run_ui(RawInput { screen_rect: Some(bounds), ..Default::default() }, |ui| { + scenario::clear_handles(); + library::card(&mut h.app, ui, bounds); + }); + ui_kit::test_textures_update(&mut textures, &frame.textures_delta); + frame.textures_delta.clear(); + output = Some(frame); + } + let panel = h.app.shell.workspace_panels.get("render:appearances").unwrap().0; + assert!((panel.width() - 290.0).abs() < 2.0 && (panel.height() - 530.0).abs() < 2.0, "{panel:?}"); + let content = scenario::rect_of(&format!("{key}:content")).unwrap(); + let body = scenario::rect_of(&format!("{key}:body")).unwrap(); + let footer = scenario::rect_of(&format!("{key}:footer")).unwrap(); + assert!(body.height() >= 0.7 * (content.height() - footer.height()), "{kind} {selected:?}: {content:?} {body:?} {footer:?}"); + assert!(panel.contains_rect(body) && panel.contains_rect(footer), "{kind}: {panel:?} {body:?} {footer:?}"); + assert!(body.bottom() <= footer.top() + 0.1, "{kind}: overlapping body and footer"); + assert!((content.bottom() - footer.bottom()).abs() <= 1.0, "{kind}: footer is not at the bottom"); + if key == "render:surface:catalog" { + let row = scenario::rect_of("render:library:SURF-001").or_else(|| scenario::rect_of("render:library:steel-304-plate")).unwrap(); + assert!(body.height() >= row.height() * 3.0, "three complete list rows must remain visible"); + if selected.is_some() { + assert!(body.height() < unselected_height, "selecting a resource must make room for its detail card"); + } + } else { + let labels: Vec<_> = scenario::rects("render:").into_iter().filter(|(name, _)| name.ends_with(":galley")).collect(); + assert!(labels.len() >= 3, "{kind}: missing tile captions"); + for (name, galley) in labels { + let id = name.strip_suffix(":galley").unwrap(); + let tile = scenario::rect_of(id).unwrap(); + let label = scenario::rect_of(&format!("{id}:label")).unwrap(); + assert!(tile.contains_rect(label) && label.expand(0.1).contains_rect(galley), "{name}: {tile:?} {label:?} {galley:?}"); + } + let frame = output.as_ref().unwrap(); + let captions: Vec<_> = crate::test_support::text_shapes(frame).filter(|text| text.galley.job.wrap.max_rows == 2).collect(); + assert!(captions.iter().any(|text| text.galley.rows.len() == 2), "{kind}: exercise a two-line caption"); + assert!(captions.iter().all(|text| text.galley.rows.len() <= 2 && !text.galley.job.wrap.break_anywhere)); + let note = h.app.tr(if kind == "appearances" { "render.stage_layout.appearance_note" } else { "render.stage_layout.studio_note" }); + let note = crate::test_support::text_shapes(frame).find(|text| text.galley.job.text == note).unwrap(); + assert_eq!(note.galley.rows.len(), 1, "catalog notes must stay on one line"); + } + assert_eq!(h.app.session.doc.to_json(), document); + assert_eq!((h.app.session.undo.len(), h.app.session.redo.len()), history); + if let Some(dir) = std::env::var_os("SOLIDCRAFT_STAGE_LAYOUT_EVIDENCE") { + std::fs::create_dir_all(&dir).unwrap(); + let frame = output.unwrap(); + let image = ui_kit::test_raster(&h.ctx, frame.shapes, frame.pixels_per_point, panel, &textures); + image + .save(std::path::Path::new(&dir).join(format!( + "{kind}-{}-{}-{}.png", + selected.unwrap_or("none"), + method.label(), + if dark { "dark" } else { "light" } + ))) + .unwrap(); + } + } + } + crate::theme::set_dark(previous_theme); +} + +#[test] +fn review_expires_when_the_reviewed_settings_or_document_change() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + library::review::quality(&mut h.app, "Q-002").unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.app.render_workspace.view.draft.width = 333; + h.frames(3); + assert!(crate::scenario::rect_of("dialog:report:review:stale").is_some()); + let before = h.app.session.doc.to_json(); + let ok = crate::scenario::rect_of("dialog:ok").unwrap().center(); + h.step(&json!({"click":[ok.x,ok.y]})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.render_workspace.view.draft.width, 333); + assert!(h.app.render_workspace.view.library.review.is_some()); +} + +#[test] +fn quality_review_is_callable_by_command_and_saves_only_after_acknowledgement() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let mut view = library::View::default(); + library::choose(&mut h.app, &mut view, "quality", "Q-002").unwrap(); + h.app.render_workspace.view.library = view; + let before = h.app.session.doc.to_json(); + h.app.start("render.quality.prepare"); + h.frames(3); + assert!(h.app.render_workspace.view.library.review.is_some()); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + let saved = &h.app.session.doc.render.setups[&h.app.render_workspace.view.name]; + assert_eq!((saved.width, saved.height), (1600, 900)); + assert_eq!(h.app.render_workspace.view.samples, 512); + assert!(h.app.render_workspace.view.library.review.is_none()); +} + +#[test] +fn physical_review_is_read_only_and_can_be_closed_after_acknowledgement() { + let mut h = fixture(); + let before = h.app.session.doc.to_json(); + let plan = h.app.run("render.library.physical.prepare", json!({"id":"steel-304-plate","name":"Reference","acknowledge_reference":true})).unwrap(); + library::review::open(&mut h.app, "physical", "304 steel".into(), plan.clone(), library::review::Apply::Physical(plan)).unwrap(); + h.frames(3); + assert!(crate::scenario::rect_of("dialog:note:review:physical").is_some()); + assert!(crate::scenario::rect_of("dialog:apply").is_some()); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + assert!(h.app.session.doc.user_materials.is_empty()); +} + +#[test] +fn quality_review_rejects_hostile_ids_and_preserves_the_design() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let before = h.app.session.doc.to_json(); + for id in ["", "../Q-002", "\0", "Q-999999999999999999999999999"] { + assert!(library::review::quality(&mut h.app, id).is_err()); + } + assert_eq!(h.app.session.doc.to_json(), before); + assert!(h.app.render_workspace.view.library.review.is_none()); +} + +#[test] +fn saved_optics_removal_requires_confirmation_and_keeps_geometry() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + h.app + .run( + "render.optics.bind", + json!({"name":name,"body_index":0,"body_name":"Subject", "expected_revision":h.app.session.revision,"optics":{"ior":1.4}}), + ) + .unwrap(); + setups::load(&mut h.app); + let target = h.app.render_workspace.view.draft.optics.iter().next().unwrap().target.clone(); + let before = h.app.session.doc.to_json(); + let geometry = h.app.session.doc.features.clone(); + let revision = h.app.session.revision; + library::review::remove(&mut h.app, "render.optics.unbind", json!({"name":name,"target":target,"expected_revision":revision})); + h.frames(3); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"dialog:cancel"}})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + library::review::remove(&mut h.app, "render.optics.unbind", json!({"name":name,"target":target,"expected_revision":revision})); + h.frames(3); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!(h.app.session.doc.render.setups[&name].optics.is_empty()); + assert_eq!(h.app.session.doc.features, geometry); +} + +#[test] +fn temporary_maps_review_keeps_plane_scale_and_requires_acknowledgement() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let target: materials::Target = serde_json::from_value(h.app.run("render.scene", json!({})).unwrap()["bodies"][0].clone()).unwrap(); + let plan = h + .app + .run("render.library.surface.prepare", json!({"id":"SURF-001","body_index":target.ordinal,"body_name":target.name,"plane":"yz","scale":2.5})) + .unwrap(); + let before = h.app.session.doc.to_json(); + library::review::open( + &mut h.app, + "maps", + "Brushed stainless".into(), + plan, + library::review::Apply::Maps { id: "SURF-001".into(), target, plane: "yz".into(), scale: 2.5 }, + ) + .unwrap(); + h.frames(3); + assert!(h.app.render_workspace.view.materials.bindings.is_empty()); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + let binding = &h.app.render_workspace.view.materials.bindings[0]; + assert_eq!(binding.maps.frame.u, [0.0, 250.0, 0.0]); + assert_eq!(binding.maps.frame.v, [0.0, 0.0, 250.0]); + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn rig_review_contains_fit_and_consent_controls_in_design_order_without_applying() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let mut view = library::View::default(); + library::choose(&mut h.app, &mut view, "rigs", "RIG-002").unwrap(); + let before = h.app.session.doc.to_json(); + library::review::light(&mut h.app, &view, "RIG-002").unwrap(); + h.frames(3); + let mut previous = crate::scenario::rect_of("review:sphere").unwrap().bottom(); + for key in ["render:review:center:0", "render:review:extent", "render:review:bounds", "render:review:emitters-only", "render:review:acknowledge"] + { + let rect = crate::scenario::rect_of(key).unwrap(); + assert!(rect.top() >= previous, "{key} is out of design order"); + previous = rect.bottom(); + } + assert_eq!(h.app.session.doc.to_json(), before); + assert!(!h.app.render_workspace.view.library.review.as_ref().unwrap().acknowledged); +} + +#[test] +fn returning_between_look_and_light_restores_catalogs_for_the_selected_scope() { + let mut h = fixture(); + let catalog = h.app.run("appearance.library", json!({})).unwrap(); + let id = catalog["appearances"].as_array().unwrap().iter().find_map(|entry| entry["id"].as_str()).unwrap().to_string(); + let before = h.app.session.doc.to_json(); + library::open_category(&mut h.app, "native_scenes"); + h.frames(3); + assert!(crate::scenario::rect_of("render:light:NATIVE-STUDIO-001").is_some()); + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + assert!(crate::scenario::rect_of(&format!("render:library:{id}")).is_some()); + library::open_category(&mut h.app, "scenes"); + h.frames(3); + assert!(crate::scenario::rect_of("render:light:SCENE-001").is_some()); + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + h.app.run("view.render_stage", json!({"stage":"light"})).unwrap(); + h.frames(3); + assert!(crate::scenario::rect_of("render:light:SCENE-001").is_some()); + assert!(crate::scenario::rect_of("dialog:note:render:light:reason").is_some()); + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn surface_target_dropdown_keeps_the_chosen_body_through_review() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1600,"height":1800})); + h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"body_name":"Other"})).unwrap(); + h.app.run("select.set", json!({"items":[solidcraft_engine::Sel::Body { name:"Subject".into() }]})).unwrap(); + library::open_category(&mut h.app, "surfaces"); + h.frames(3); + h.step(&json!({"click":{"handle":"render:library:SURF-001"}})).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":"render:surface:target"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:list:Other"}})).unwrap(); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.stage_panels.use_uniform")})).unwrap(); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!(h.app.session.doc.appearances.bodies.contains_key("Other")); + assert!(!h.app.session.doc.appearances.bodies.contains_key("Subject")); +} +#[test] +fn unsupported_output_is_visible_and_never_fakes_export_or_clamps_intent() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.inspector.page = Page::Output; + h.app.render_workspace.view.draft.width = 7000; + h.app.render_workspace.view.draft.height = 6000; + h.app.render_workspace.view.samples = 37; + h.frames(4); + assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (7000, 6000)); + assert_eq!(h.app.render_workspace.view.samples, 37); + assert!(super::super::image_request(&h.app).is_err()); + assert!(h.app.render_workspace.view.completed.is_none()); + assert!(h.app.tr("render.output_format_status").contains("EXR")); +} + +#[test] +fn rational_resolution_lock_preserves_anchor_rounding_and_rejects_without_partial_changes() { + let mut edit = Resolution { locked: true, ..Default::default() }; + let mut size = [3840, 2160]; + size = edit.edit(size, 0, 1920, 8192).unwrap(); + assert_eq!(size, [1920, 1080]); + size = edit.edit(size, 1, 720, 8192).unwrap(); + assert_eq!(size, [1280, 720]); + let anchor = edit.anchor; + for _ in 0..100 { + size = edit.edit(size, 0, 1001, 8192).unwrap(); + assert_eq!(size, [1001, 563]); + size = edit.edit(size, 0, 1920, 8192).unwrap(); + assert_eq!(size, [1920, 1080]); + } + assert_eq!(edit.anchor, anchor, "rounded edits must not drift the anchor"); + assert!(edit.edit(size, 1, 8192, 8192).is_none()); + assert_eq!(edit.observed, Some(size), "a refused linked dimension must not partly change size"); + assert!(edit.rejected); + assert!(edit.edit(size, 0, 0, 8192).is_none()); + assert!(edit.edit(size, 2, 100, 8192).is_none()); + let mut extreme = Resolution { locked: true, ..Default::default() }; + assert!(extreme.edit([1, u32::MAX], 0, u32::MAX, u32::MAX).is_none()); + assert!(Resolution { locked: true, ..Default::default() }.edit([0, 1], 0, 1, 8192).is_none()); +} + +#[test] +fn resolution_lock_reanchors_for_explicit_presets_and_does_not_affect_other_intent() { + let mut edit = Resolution { locked: true, ..Default::default() }; + assert_eq!(edit.edit([3840, 2160], 0, 1920, 8192), Some([1920, 1080])); + edit.observe([1080, 1920]); + assert_eq!(edit.edit([1080, 1920], 1, 960, 8192), Some([540, 960])); + edit.observe([1000, 1000]); + assert_eq!(edit.edit([1000, 1000], 0, 777, 8192), Some([777, 777])); + edit.locked = false; + assert_eq!(edit.edit([777, 777], 0, 555, 8192), Some([555, 777])); + edit.locked = true; + assert_eq!(edit.edit([555, 777], 0, 1110, 8192), Some([1110, 1554])); +} + +#[test] +fn actual_output_ratio_is_local_and_orientation_saves_once_preserving_other_capture_fields() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.draft.width = 1920; + h.app.render_workspace.view.draft.height = 1080; + h.app.render_workspace.view.samples = 37; + h.app.render_workspace.view.inspector.page = Page::Output; + setups::save(&mut h.app).unwrap(); + let saved = h.app.session.doc.clone(); + let undo = h.app.session.undo.len(); + let camera = h.app.cam; + reveal(&mut h.app, "render_output_advanced"); + h.frames(24); + h.step(&json!({"click":{"handle":"render:aspect-lock"}})).unwrap(); + assert!(h.app.render_workspace.view.inspector.resolution.locked); + assert!(!h.app.render_workspace.view.dirty, "coupling editor coordinates is not a saved numerical edit"); + assert!(Arc::ptr_eq(&saved, &h.app.session.doc)); + assert_eq!(undo, h.app.session.undo.len()); + h.step(&json!({"click":{"handle":"render:swap-size"}})).unwrap(); + assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (1080, 1920)); + assert_eq!(h.app.render_workspace.view.samples, 37); + assert_eq!(h.app.cam, camera); + let mut expected = saved.render.setups[&h.app.render_workspace.view.name].clone(); + expected.width = 1080; + expected.height = 1920; + assert_eq!(h.app.session.doc.render.setups[&h.app.render_workspace.view.name], expected); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert!(h.app.render_workspace.view.dirty); + setups::load(&mut h.app); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.resolution.anchor, Some([1080, 1920])); +} + +#[test] +fn contextual_scope_notes_wrap_with_native_tokens_instead_of_clipping() { + let mut h = fixture(); + h.app.render_workspace.view.inspector.page = Page::Scene; + h.frames(3); + let rect = crate::scenario::rect_of("dialog:note:render.scene_preserves_design").unwrap(); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + assert!(rect.height() > Tokens::get().font_small + Tokens::get().space_8, "long scope notice must have more than one line"); + assert!(inspector.contains_rect(rect)); + assert!(rect.bottom() < inspector.bottom()); + assert!(crate::scenario::rect_of("render:job-footer").is_none()); +} + +#[test] +fn temporary_library_maps_preserve_the_reviewed_plane_scale_and_optical_exclusivity() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let targets = h.app.run("render.scene", json!({})).unwrap(); + let target: materials::Target = serde_json::from_value(targets["bodies"][0].clone()).unwrap(); + let before = h.app.session.doc.to_json(); + materials::install_library_surface(&mut h.app, "SURF-001", target.clone(), "yz", 2.5).unwrap(); + let binding = &h.app.render_workspace.view.materials.bindings[0]; + assert_eq!(binding.maps.frame.u, [0.0, 250.0, 0.0]); + assert_eq!(binding.maps.frame.v, [0.0, 0.0, 250.0]); + assert_eq!(h.app.session.doc.to_json(), before, "temporary maps must not change the native model"); + let original = binding.maps.frame; + assert!(materials::install_library_surface(&mut h.app, "SURF-001", target.clone(), "unknown", 1.0).is_err()); + assert!(materials::install_library_surface(&mut h.app, "SURF-001", target.clone(), "xy", 0.0).is_err()); + for scale in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1.0, f64::MAX] { + assert!(materials::install_library_surface(&mut h.app, "SURF-001", target.clone(), "xy", scale).is_err()); + assert_eq!(h.app.render_workspace.view.materials.bindings[0].maps.frame, original); + } + assert_eq!(h.app.render_workspace.view.materials.bindings[0].maps.frame, original); + h.app.render_workspace.view.materials.bindings[0].glass_enabled = true; + assert!(materials::install_library_surface(&mut h.app, "SURF-001", target, "xy", 1.0).is_err()); + assert!(h.app.render_workspace.view.materials.bindings[0].glass_enabled); + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn native_composition_review_actions_are_visible_in_shared_dialog() { + for dark in [false, true] { + let mut h = fixture(); + h.call("ui.set", json!({"dark":dark})); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + setups::save(&mut h.app).unwrap(); + library::open_category(&mut h.app, "native_scenes"); + h.frames(3); + h.step(&json!({"click":{"handle":"render:light:NATIVE-STUDIO-002"}})).unwrap(); + h.step(&json!({"click":{"handle":"render:light:review"}})).unwrap(); + h.frames(3); + let card = crate::scenario::rect_of("review:sphere").unwrap(); + let replaces = crate::scenario::rect_of("dialog:note:review:replaces").unwrap(); + let kept = crate::scenario::rect_of("dialog:note:review:kept").unwrap(); + let ack = crate::scenario::rect_of("render:review:acknowledge").unwrap(); + assert!(card.bottom() <= replaces.top()); + assert!(replaces.bottom() <= kept.top()); + assert!(kept.bottom() <= ack.top()); + assert!(crate::scenario::rect_of("dialog:ok").is_some()); + assert!(!h.app.render_workspace.view.library.review.as_ref().unwrap().acknowledged); + } +} + +#[test] +fn native_composition_review_actions_are_visible_before_auxiliary_resource_details() { + for dark in [false, true] { + let mut h = fixture(); + h.call("ui.set", json!({"dark":dark})); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + setups::save(&mut h.app).unwrap(); + library::open_category(&mut h.app, "native_scenes"); + h.frames(3); + let before = h.app.session.doc.to_json(); + let history = (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()); + h.step(&json!({"click":{"handle":"render:light:NATIVE-STUDIO-002"}})).unwrap(); + let library = h.app.shell.workspace_panels.get("render:appearances").unwrap().0; + let review = crate::scenario::rect_of("render:light:review").unwrap(); + let note = crate::scenario::rect_of("catalog:footer").unwrap(); + assert!(library.contains_rect(review), "the review action must remain inside the library card: {library:?} {review:?}"); + assert!(review.bottom() <= note.top(), "the review action must precede supplementary prose"); + h.step(&json!({"click":{"handle":"render:light:review"}})).unwrap(); + h.frames(3); + let card = crate::scenario::rect_of("review:sphere").unwrap(); + let replaces = crate::scenario::rect_of("dialog:note:review:replaces").unwrap(); + let kept = crate::scenario::rect_of("dialog:note:review:kept").unwrap(); + let ack = crate::scenario::rect_of("render:review:acknowledge").unwrap(); + assert!(card.bottom() <= replaces.top()); + assert!(replaces.bottom() <= kept.top()); + assert!(kept.bottom() <= ack.top()); + let apply = crate::scenario::rect_of("dialog:ok").unwrap(); + assert!(ack.bottom() <= apply.top()); + let dialog = crate::scenario::rect_of("dialog:window").unwrap(); + for (name, rect) in [("acknowledge", ack), ("apply", apply)] { + assert!(dialog.contains_rect(rect), "{name} must remain inside the review dialog: {dialog:?} {rect:?}"); + assert!(h.ctx.content_rect().contains_rect(rect), "{name} must remain on screen: rect={rect:?}, dark={dark}"); + } + assert!(!h.app.render_workspace.view.library.review.as_ref().unwrap().acknowledged); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), history); + assert!(h.app.render_workspace.view.job.is_none()); + assert!(h.app.render_workspace.view.completed.is_none()); + } +} + +#[test] +fn ribbon_navigation_reuses_inspector_and_preserves_exact_unsaved_intent() { + let mut h = fixture(); + h.app.render_workspace.view.samples = 37; + h.app.render_workspace.view.draft.width = 777; + let doc = h.app.session.doc.to_json(); + let history = (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()); + for (id, page) in [ + ("render.preset.resolve", Page::Scene), + ("render.settings.get", Page::Scene), + ("render.library.appearance.apply", Page::Appearance), + ("render.library.surface.bind", Page::Appearance), + ("render.library.studio.prepare", Page::Lighting), + ("render.library.studio.apply", Page::Lighting), + ("render.library.environment.apply", Page::Environment), + ("render.stage.backdrop", Page::Background), + ("render.quality.prepare", Page::Output), + ("render.status", Page::Diagnostics), + ("render.camera.get", Page::Camera), + ("render.camera.set", Page::Camera), + ("render.preset.apply", Page::Scene), + ("render.shot.duplicate", Page::Scene), + ("render.shot.rename", Page::Scene), + ("render.shot.remove", Page::Scene), + ("render.optics.bind", Page::Appearance), + ("render.optics.unbind", Page::Appearance), + ("render.library.surface.prepare", Page::Appearance), + ("render.library.surface.unbind", Page::Appearance), + ("render.library.physical.prepare", Page::Appearance), + ("render.stage.ground", Page::Background), + ("render.stage.clear", Page::Background), + ("render.hdr.inspect", Page::Environment), + ("render.environment.set", Page::Environment), + ("render.settings.capture_hdr", Page::Environment), + ("render.aging.describe", Page::Appearance), + ("render.effects.describe", Page::Effects), + ("render.backends", Page::Diagnostics), + ] { + h.app.start(id); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.page, page, "{id}"); + assert_eq!(h.app.render_workspace.view.samples, 37); + assert_eq!(h.app.render_workspace.view.draft.width, 777); + assert_eq!(h.app.session.doc.to_json(), doc, "navigation may not execute a parameterless apply"); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), history); + assert!(h.app.render_workspace.view.job.is_none()); + assert!(h.app.render_workspace.view.completed.is_none()); + assert!(!crate::icon_svg::resolve(solidcraft_engine::find_command(id).unwrap().icon).placeholder); + } +} + +#[test] +fn render_stage_bar_keeps_actions_and_personal_preferences_in_both_layouts() { + assert!(crate::workspace::panels("RENDER").is_empty()); + for layout in [crate::shell::LayoutMode::Docked, crate::shell::LayoutMode::Floating] { + let mut h = fixture(); + h.app.ui.layout = layout; + h.app.toolbar_custom.panels.insert("DESIGN/RENDER/RESULT".into(), vec!["render.export".into()]); + let preferences = h.app.toolbar_custom.prefs(); + for width in [800, 1024, 1440, 2000] { + h.call("ui.resize", json!({"width":width,"height":900})); + h.frames(3); + let bar = crate::scenario::rect_of("render:stage_bar").unwrap(); + let workspace = crate::scenario::rect_of("ribbon:workspace").unwrap(); + assert_eq!(bar.height(), workspace.height()); + assert_eq!(bar.top(), workspace.top()); + for id in ["render:stage:render.start", "render:stage:render.cancel"] { + if let Some(action) = crate::scenario::rect_of(id) { + assert!(bar.contains_rect(action)); + } + } + assert!(crate::scenario::rect_of("ribbon:card").is_none()); + assert!(super::super::job_ready(&h.app, "render.cancel").is_err()); + assert!(h.app.render_workspace.view.job.is_none()); + assert_eq!(h.app.toolbar_custom.prefs(), preferences); + } + } +} + +#[test] +fn ribbon_and_sticky_footer_submit_the_current_draft_not_defaults_or_saved_shot() { + let mut h = fixture(); + h.app.render_workspace.view.draft.width = 32; + h.app.render_workspace.view.draft.height = 24; + h.app.render_workspace.view.draft.background = [24, 63, 107]; + let before = h.app.session.doc.to_json(); + let export = solidcraft_engine::find_command("render.export").unwrap(); + assert!(!super::super::interactive_command_info(&h.app, export).enabled); + assert!(export.info(&h.app.session).enabled, "UI state must not alter direct engine API semantics"); + h.app.start("render.preflight"); + let request = super::super::image_request(&h.app).unwrap(); + h.step(&json!({"click":{"handle":"render:stage:render.start"}})).unwrap(); + let job = h.app.render_workspace.view.job.expect("ribbon submitted an actual job"); + let handle = h.app.session.render_job_handle(job).unwrap(); + assert_eq!((handle.status().unwrap().request.width, handle.status().unwrap().request.height), (32, 24)); + assert_eq!(handle.status().unwrap().request.background, [24, 63, 107]); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10); + while h.app.render_workspace.view.completed != Some(job) { + assert!(std::time::Instant::now() < deadline, "CPU fixture did not complete"); + h.frames(1); + std::thread::sleep(std::time::Duration::from_millis(1)); + } + assert_eq!(super::super::image_request(&h.app).unwrap(), request); + assert_eq!(h.app.session.doc.to_json(), before); + assert!(super::super::interactive_command_info(&h.app, export).enabled); + h.app.render_workspace.view.studio.export_exr = true; + assert!(!super::super::interactive_command_info(&h.app, export).enabled, "a PNG-only result never pretends to have EXR"); +} + +#[test] +fn saved_bloom_intent_roundtrips_and_rejects_unsupported_transparent_output() { + use solidcraft_engine::render::job::bloom::Bloom; + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.studio.finishing.bloom = Some(Bloom { strength: 0.25, threshold: 2.5, radius: 12 }); + let expected = setups::snapshot(&h.app).unwrap(); + setups::save(&mut h.app).unwrap(); + h.app.render_workspace.view.studio.finishing.bloom = None; + setups::load(&mut h.app); + assert_eq!(setups::snapshot(&h.app).unwrap(), expected); + let reopened = solidcraft_engine::doc::Document::from_json(&h.app.session.doc.to_json()).unwrap(); + assert_eq!(reopened.render.setups[&h.app.render_workspace.view.name], expected); + h.app.render_workspace.view.transparent = true; + assert!(setups::snapshot(&h.app).is_err()); + h.app.render_workspace.view.transparent = false; + super::super::select_image_method(&mut h.app, ImageMethod::CpuRaytrace); + assert!(super::super::image_request(&h.app).is_ok(), "inactive GPU settings remain portable but are not sent to CPU"); +} + +#[test] +fn ribbon_frame_preserves_explicit_roll_world_up_and_saved_view_authority() { + let mut h = fixture(); + h.app.cam.roll = 0.37; + h.app.cam.yaw = 0.21; + h.app.cam.pitch = 0.43; + h.app.cam.up = solidcraft_engine::render::UpAxis::Y; + let orientation = (h.app.cam.roll, h.app.cam.yaw, h.app.cam.pitch, h.app.cam.up); + let document = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + h.app.start("render.camera.fit"); + assert_eq!((h.app.cam.roll, h.app.cam.yaw, h.app.cam.pitch, h.app.cam.up), orientation); + assert_eq!(h.app.session.doc.to_json(), document); + assert_eq!(h.app.session.undo.len(), undo); + assert!(h.app.session.camera.is_none(), "the explicit view request was consumed by the viewport"); + assert_eq!(h.app.ui.up_axis, h.app.cam.up); +} + +#[test] +fn independent_sampling_and_volume_intent_roundtrip_offline_without_silent_conflict_repairs() { + use solidcraft_engine::render::job::{adaptive::AdaptiveSampling, volume::HomogeneousVolume}; + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.samples = 64; + h.app.render_workspace.view.studio.adaptive = + Some(AdaptiveSampling { pilot_samples: 16, min_samples: 32, relative_error: 0.03, absolute_error: 0.004, coverage_error: 0.02 }); + h.app.render_workspace.view.studio.volume = Some(HomogeneousVolume { + min_mm: [-30.0, -20.0, -1.0], + max_mm: [30.0, 20.0, 40.0], + extinction_per_mm: 0.002, + scattering_albedo: [0.7, 0.8, 0.9], + anisotropy: 0.35, + }); + h.app.render_workspace.view.studio.linear_exr = true; + let expected = setups::snapshot(&h.app).unwrap(); + setups::save(&mut h.app).unwrap(); + h.app.render_workspace.view.studio.adaptive = None; + h.app.render_workspace.view.studio.volume = None; + setups::load(&mut h.app); + assert_eq!(setups::snapshot(&h.app).unwrap(), expected); + let reopened = solidcraft_engine::doc::Document::from_json(&h.app.session.doc.to_json()).unwrap(); + assert_eq!(reopened.render.setups[&h.app.render_workspace.view.name], expected); + let original = h.app.session.doc.to_json(); + h.app.render_workspace.view.studio.denoise = true; + assert!(setups::snapshot(&h.app).is_err()); + assert_eq!(h.app.session.doc.to_json(), original); + h.app.render_workspace.view.studio.denoise = false; + h.app.render_workspace.view.studio.transmission_samples = 4; + assert!(setups::snapshot(&h.app).is_err(), "active volume does not silently replace transmission strata"); + h.app.render_workspace.view.studio.volume = None; + assert!(setups::snapshot(&h.app).is_ok()); + h.app.render_workspace.view.samples = 16; + assert!(setups::snapshot(&h.app).is_err(), "minimum production count may not be silently clamped to the ceiling"); + h.app.render_workspace.view.samples = 64; + setups::save(&mut h.app).unwrap(); + let stored = setups::snapshot(&h.app).unwrap(); + h.app.render_workspace.view.studio.transmission_samples = 1; + setups::load(&mut h.app); + assert_eq!(setups::snapshot(&h.app).unwrap(), stored); +} + +#[test] +fn master_regrade_requires_a_retained_master_instead_of_reconstructing_a_png() { + let mut h = fixture(); + let spec = solidcraft_engine::find_command("render.result.regrade").unwrap(); + assert!(spec.info(&h.app.session).enabled, "direct API is validated by exact explicit source identity"); + assert!(!super::super::interactive_command_info(&h.app, spec).enabled); + let document = h.app.session.doc.to_json(); + h.app.start("render.result.regrade"); + assert!(h.app.render_workspace.view.job.is_none()); + assert_eq!(h.app.session.doc.to_json(), document); + assert!(!crate::icon_svg::resolve(spec.icon).placeholder); + h.app.render_workspace.view.draft.width = 8; + h.app.render_workspace.view.draft.height = 8; + h.app.start("render.start"); + let job = h.app.render_workspace.view.job.unwrap(); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10); + while h.app.render_workspace.view.completed != Some(job) { + assert!(std::time::Instant::now() < deadline); + h.frames(1); + std::thread::sleep(std::time::Duration::from_millis(1)); + } + assert!(!super::super::interactive_command_info(&h.app, spec).enabled); + assert_eq!(h.app.session.doc.to_json(), document); +} + +#[test] +fn public_render_inspection_exposes_exact_identities_without_execution_or_document_mutation() { + let mut h = fixture(); + let doc = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + let camera = h.app.cam; + let inspected = h.call("ui.inspect", json!({})); + assert_eq!(inspected["result"]["render"]["active"], true); + assert_eq!(inspected["result"]["render"]["method"], "raster"); + assert!(inspected["result"]["render"]["job"].is_null()); + h.app.render_workspace.view.draft.width = 8; + h.app.render_workspace.view.draft.height = 8; + h.app.start("render.start"); + let identity = h.app.render_workspace.view.job.unwrap(); + let inspected = h.call("ui.inspect", json!({})); + assert_eq!(inspected["result"]["render"]["job"], json!(identity)); + assert_eq!(h.app.session.doc.to_json(), doc); + assert_eq!(h.app.session.undo.len(), undo); + assert_eq!(h.app.cam, camera); + h.app.session.execute("render.cancel", &json!({"job":identity})).unwrap(); +} + +#[test] +fn aging_tab_adds_reorders_disables_and_persists_layers_without_engineering_edits() { + use solidcraft_engine::render::job::aging::AgingKind; + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let before = h.app.session.doc.to_json(); + h.app.start("render.aging.describe"); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + assert!(!crate::icon_svg::resolve(solidcraft_engine::find_command("render.aging.describe").unwrap().icon).placeholder); + for code in [1, 3] { + h.step(&json!({"click":{"handle":"render:aging-add"}})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":format!("dialog:list:aging-add-{code}")}})).unwrap(); + h.frames(2); + } + assert_eq!(h.app.render_workspace.view.studio.aging.len(), 2); + assert_eq!(h.app.render_workspace.view.studio.aging.get(1).unwrap().kind, AgingKind::Dust); + h.step(&json!({"click":{"handle":"render:aging-up"}})).unwrap(); + h.frames(2); + assert_eq!(h.app.render_workspace.view.studio.aging.get(0).unwrap().kind, AgingKind::Dust); + h.step(&json!({"click":{"handle":"render:aging-enabled"}})).unwrap(); + h.frames(2); + assert!(!h.app.render_workspace.view.studio.aging.get(0).unwrap().enabled); + assert_eq!(h.app.session.doc.to_json(), before, "editing layers only edits the render draft"); + let targets = super::super::materials::read_targets(&mut h.app).unwrap(); + let identity = targets.iter().find(|target| target.name == "Subject").unwrap().stable_target.clone().unwrap(); + h.app.render_workspace.view.studio.aging.get_mut(0).unwrap().target = Some(identity.clone()); + let expected = setups::snapshot(&h.app).unwrap(); + let wire = serde_json::to_value(&expected).unwrap(); + assert_eq!(wire["job"]["options"]["aging"][0]["target"]["definition"], "Subject"); + assert!(wire["job"]["options"]["aging"][0]["target"].get("body_index").is_none()); + setups::save(&mut h.app).unwrap(); + h.app.render_workspace.view.studio.aging = Default::default(); + setups::load(&mut h.app); + assert_eq!(setups::snapshot(&h.app).unwrap(), expected); + let reopened = solidcraft_engine::doc::Document::from_json(&h.app.session.doc.to_json()).unwrap(); + assert_eq!(reopened.render.setups[&h.app.render_workspace.view.name], expected); + assert_eq!(h.app.render_workspace.view.studio.aging.get(0).unwrap().target.as_ref(), Some(&identity)); + h.step(&json!({"click":{"handle":"render:aging-remove"}})).unwrap(); + h.frames(2); + assert_eq!(h.app.render_workspace.view.studio.aging.len(), 1); +} + +#[test] +fn wear_selection_precedes_output_page_and_appearance_selection_chrome() { + fn assert_header(h: &Harness, title: &str) { + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let header = crate::scenario::rect_of("render:inspector:header").unwrap(); + assert!(inspector.contains_rect(header)); + let tree = h.output.accesskit_update.as_ref().unwrap(); + let context = format!( + "layout={:?}, page={:?}, title={title:?}, header={header:?}, pixels_per_point={}", + h.app.ui.layout, + h.app.render_workspace.view.inspector.page, + h.ctx.pixels_per_point(), + ); + // egui stores Role::Label text in value(), not label(). Each pass supplies the + // title node; its bounds are UI points (the root carries the pixel-scale transform). + let titles: Vec<_> = + tree.nodes.iter().filter(|(_, node)| node.role() == egui::accesskit::Role::Label && node.value() == Some(title)).collect(); + assert!(!titles.is_empty(), "missing inspector title: {context}"); + let bounds: Vec<_> = titles.iter().map(|(id, node)| (id, node.bounds())).collect(); + eprintln!( + "header diagnostic: {context}, bounds={bounds:?}, label_matches={}", + tree.nodes.iter().filter(|(_, node)| node.label() == Some(title)).count() + ); + assert!( + titles.iter().any(|(_, node)| { + node.bounds().is_some_and(|bounds| { + bounds.x1 > bounds.x0 + && bounds.y1 > bounds.y0 + && header.contains_rect(egui::Rect::from_min_max( + egui::pos2(bounds.x0 as f32, bounds.y0 as f32), + egui::pos2(bounds.x1 as f32, bounds.y1 as f32), + )) + }) + }), + "inspector title has missing, empty or out-of-header bounds: {context}, bounds={bounds:?}" + ); + } + for layout in [crate::shell::LayoutMode::Docked, crate::shell::LayoutMode::Floating] { + let mut h = fixture(); + h.app.ui.layout = layout; + h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Subject".into() }]; + let before = h.app.session.doc.to_json(); + let history = (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()); + h.app.run("view.render_select", json!({"kind":"wear"})).unwrap(); + assert!(h.app.session.selection.is_empty(), "Render focus clears object picks"); + let wear_history = (history.0 + 1, history.1, history.2); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), wear_history); + // Exercise stale object picks alongside Wear; normal focus commands clear them. + h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Subject".into() }]; + for page in [Page::Output, Page::Appearance] { + h.app.render_workspace.view.inspector.page = page; + h.frames(3); + assert_header(&h, h.app.tr("render.wear_title")); + assert!(crate::scenario::rect_of("render:wear:controls").is_some()); + assert!(crate::scenario::rect_of("render:appearance:close").is_none()); + assert!(crate::scenario::rect_of("dialog:editor_footer").is_none()); + assert!(crate::scenario::rect_of("render:page:aging").is_none()); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let footer = crate::scenario::rect_of("render:job-footer").unwrap(); + assert!(inspector.contains_rect(footer)); + for name in ["render:check", "render:start", "render:cancel", "render:export"] { + assert!(footer.contains_rect(crate::scenario::rect_of(name).unwrap()), "{name} outside Wear footer"); + } + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), wear_history); + } + h.app.run("view.render_select", json!({"kind":"output"})).unwrap(); + assert!(h.app.session.selection.is_empty()); + let output_history = (history.0 + 2, history.1, history.2); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), output_history); + h.app.render_workspace.view.inspector.page = Page::Appearance; + h.frames(3); + assert_header(&h, h.app.tr("render.page_output")); + assert!(crate::scenario::rect_of("render:wear:controls").is_none()); + assert!(crate::scenario::rect_of("render:job-footer").is_none()); + assert!(crate::scenario::rect_of("render:appearance:close").is_none()); + h.app.run("view.render_select", json!({"kind":"nothing"})).unwrap(); + // Clearing semantic focus opens Scene; choose Appearance to test its header recovery. + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Scene); + h.app.render_workspace.view.inspector.page = Page::Appearance; + h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Subject".into() }]; + h.frames(3); + assert_header(&h, "Subject"); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let header = crate::scenario::rect_of("render:inspector:header").unwrap(); + assert!(header.contains_rect(crate::scenario::rect_of("render:appearance:close").unwrap())); + assert!(inspector.contains_rect(crate::scenario::rect_of("dialog:editor_footer").unwrap())); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), output_history); + } +} + +#[test] +fn wear_selection_shows_disabled_controls_with_reason_and_never_changes_method() { + use solidcraft_engine::render::job::aging::{AgingKind, AgingLayer}; + fn text_color(shape: &egui::Shape, label: &str) -> Option { + match shape { + egui::Shape::Text(text) if text.galley.text().to_lowercase().contains(&label.to_lowercase()) => Some(text.fallback_color), + egui::Shape::Vec(shapes) => shapes.iter().find_map(|shape| text_color(shape, label)), + _ => None, + } + } + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":1800})); + h.app.render_workspace.view.studio.aging.push(AgingLayer::preset(AgingKind::Rust)).unwrap(); + h.app.render_workspace.view.dirty = true; + let document = h.app.session.doc.to_json(); + let stack = h.app.render_workspace.view.studio.aging.clone(); + h.app.run("view.render_select", json!({"kind":"wear"})).unwrap(); + let mut colours = Vec::new(); + for method in [ImageMethod::Raster, ImageMethod::CpuRaytrace, ImageMethod::GpuRaytrace] { + h.app.render_workspace.view.method = method; + h.frames(3); + assert_eq!(h.app.render_workspace.view.method, method); + assert!(crate::scenario::rect_of("render:wear:controls").is_some()); + assert!(crate::scenario::rect_of("render:aging-enabled").is_some()); + assert!(crate::scenario::rect_of("render:aging-target").is_some()); + assert!(crate::scenario::rect_of("render:page:aging").is_none(), "Wear has no master page switcher"); + assert!(h.shapes.iter().any(|s| text_color(&s.shape, h.app.tr("render.effects_gpu_only")).is_some())); + colours.push(h.shapes.iter().find_map(|s| text_color(&s.shape, h.app.tr("render.wear_layers"))).unwrap()); + if method != ImageMethod::GpuRaytrace { + for handle in ["render:aging-add", "render:aging-enabled", "render:aging-layer:0:enabled", "render:aging-remove"] { + h.step(&json!({"click":{"handle":handle}})).unwrap(); + assert_eq!(h.app.render_workspace.view.studio.aging, stack); + } + } + assert_eq!(h.app.session.doc.to_json(), document); + } + for colour in &colours[..2] { + assert!(colour.a() < colours[2].a(), "unsupported methods fade the editor"); + } + h.step(&json!({"click":{"handle":"render:aging-layer:0:enabled"}})).unwrap(); + assert!(!h.app.render_workspace.view.studio.aging.get(0).unwrap().enabled); + h.app.start("render.aging.describe"); + h.frames(3); + assert_eq!(h.app.render_workspace.view.selection, super::super::RenderSelection::Nothing); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + assert!(crate::scenario::rect_of("render:wear:controls").is_some(), "Appearance Advanced mounts the same editor"); + assert!(h.shapes.iter().any(|s| text_color(&s.shape, h.app.tr("render.aging_airborne")).is_some())); +} + +#[test] +fn wear_editor_bounds_stale_selection_and_hostile_layer_values_never_panic() { + use solidcraft_engine::render::job::aging::{AgingKind, AgingLayer}; + let mut h = fixture(); + h.app.render_workspace.view.method = ImageMethod::GpuRaytrace; + h.app.run("view.render_select", json!({"kind":"wear"})).unwrap(); + h.app.render_workspace.view.inspector.effects.selected_aging = usize::MAX; + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.effects.selected_aging, 0); + h.app.render_workspace.view.studio.aging.push(AgingLayer::preset(AgingKind::Dust)).unwrap(); + h.app.render_workspace.view.dirty = true; + for value in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1e300, 1e300] { + let layer = h.app.render_workspace.view.studio.aging.get_mut(0).unwrap(); + layer.strength = value; + layer.coverage = value; + layer.scale_mm = value; + layer.roughness = value; + layer.metallic = value; + layer.upward_bias = value; + layer.origin_mm = [value; 3]; + layer.seed = u32::MAX; + h.app.render_workspace.view.inspector.effects.selected_aging = usize::MAX; + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.effects.selected_aging, 0); + } + h.step(&json!({"click":{"handle":"render:aging-remove"}})).unwrap(); + assert!(h.app.render_workspace.view.studio.aging.is_empty()); + h.frames(3); + assert!(crate::scenario::rect_of("render:aging-enabled").is_none()); +} + +#[test] +fn output_effects_retains_ordered_looks_and_photographic_intent_across_save_and_reload() { + use solidcraft_engine::render::job::looks::LookKind; + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let before = h.app.session.doc.to_json(); + h.app.start("render.effects.describe"); + h.frames(24); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Effects); + assert_eq!(h.app.session.doc.to_json(), before, "opening Effects is read-only"); + let undo = h.app.session.undo.len(); + + for code in [3, 6] { + h.step(&json!({"click":{"handle":"render:look-add"}})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":format!("dialog:list:look-add-{code}")}})).unwrap(); + h.frames(2); + } + assert_eq!(h.app.render_workspace.view.studio.finishing.looks.len(), 2); + assert_eq!(h.app.render_workspace.view.studio.finishing.looks.get(0).unwrap().kind, LookKind::Warm); + h.step(&json!({"click":{"handle":"render:look-up"}})).unwrap(); + h.frames(2); + assert_eq!(h.app.render_workspace.view.studio.finishing.looks.get(0).unwrap().kind, LookKind::Faded); + assert_eq!(h.app.session.undo.len(), undo + 3); + assert_eq!(setups::snapshot(&h.app).unwrap().job, h.app.session.doc.render.setups[&h.app.render_workspace.view.name].job); + h.app.render_workspace.view.studio.finishing.photographic.chromatic_pixels = 1.5; + h.app.render_workspace.view.studio.finishing.photographic.flare.strength = 0.4; + let expected = setups::snapshot(&h.app).unwrap(); + setups::save(&mut h.app).unwrap(); + h.app.render_workspace.view.studio.finishing = Default::default(); + setups::load(&mut h.app); + assert_eq!(setups::snapshot(&h.app).unwrap(), expected); + let doc = h.app.session.doc.to_json(); + h.app.render_workspace.view.transparent = true; + assert!(super::super::ribbon::presentation(&h.app).validate().is_err(), "spatial lens effects cannot silently flatten alpha"); + assert_eq!(h.app.session.doc.to_json(), doc); +} + +#[test] +fn backgrounds_ribbon_exposes_camera_and_physical_options_without_mutating_draft_or_switching_renderer() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.studio.backdrop_enabled = true; + h.app.render_workspace.view.studio.backdrop.first_srgb = [30, 60, 90]; + h.app.render_workspace.view.dirty = true; + let draft = setups::snapshot(&h.app).unwrap(); + let doc = h.app.session.doc.to_json(); + let revision = h.app.session.revision; + h.app.start("render.stage.backdrop"); + h.frames(3); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Background); + assert_eq!(setups::snapshot(&h.app).unwrap(), draft); + assert_eq!(h.app.session.doc.to_json(), doc); + assert_eq!(h.app.session.revision, revision); + assert!(crate::scenario::rect_of("dialog:section:Backdrop").is_some()); + assert!(crate::scenario::rect_of("dialog:section:Ground and stage").is_some()); + assert!(crate::scenario::rect_of("dialog:section:Atmosphere").is_some()); + assert!(h.app.render_workspace.view.job.is_none()); + assert!( + super::super::ribbon::action_ready(&h.app, "render.result.regrade").is_err(), + "no raw master cannot be silently reconstructed from the viewport" + ); +} + +#[test] +fn clearing_physical_stage_preserves_unsaved_camera_background_and_output_intent() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1600,"height":2600})); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + setups::save(&mut h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + h.app.run("render.stage.ground", json!({"name":name})).unwrap(); + setups::load(&mut h.app); + assert_eq!(h.app.render_workspace.view.draft.stage.len(), 1); + h.app.render_workspace.view.draft.background = [17, 53, 89]; + h.app.render_workspace.view.draft.width = 421; + h.app.render_workspace.view.draft.height = 239; + h.app.render_workspace.view.draft.exposure_ev = 1.25; + h.app.render_workspace.view.studio.backdrop_enabled = true; + h.app.render_workspace.view.studio.backdrop.mode = solidcraft_engine::render::job::finishing::BackdropMode::Radial; + h.app.render_workspace.view.studio.backdrop.center = [0.3, 0.6]; + h.app.render_workspace.view.dirty = true; + let mut expected = setups::snapshot(&h.app).unwrap(); + expected.stage = Default::default(); + let geometry = h.app.session.doc.features.clone(); + let materials = h.app.session.doc.materials.clone(); + h.app.start("render.stage.clear"); + h.frames(4); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Background); + h.step(&json!({"click":{"handle":"render:stage-clear"}})).unwrap(); + h.frames(3); + assert_eq!(h.app.render_workspace.view.draft.stage.len(), 1, "removal needs consent"); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + h.frames(3); + assert_eq!(setups::snapshot(&h.app).unwrap(), expected, "clearing stage must keep the unsaved numerical draft, not reload an older one"); + assert_eq!(h.app.session.doc.render.setups[&name], expected); + assert_eq!(h.app.session.doc.features, geometry); + assert_eq!(h.app.session.doc.materials, materials); + let reopened = solidcraft_engine::doc::Document::from_json(&h.app.session.doc.to_json()).unwrap(); + assert_eq!(reopened.render.setups[&name], expected); +} + +#[test] +fn render_camera_labels_do_not_shadow_mechanical_pitch_and_axes_remain_explicit() { + let en = crate::i18n::Locale::for_language("en"); + let de = crate::i18n::Locale::for_language("de"); + assert_eq!(de.label("Pitch"), "Steigung"); + assert_eq!(de.text("coupling.pitch"), "Steigung"); + assert_eq!(en.text("render.camera_pitch"), "Camera pitch"); + assert_ne!(en.text("render.camera_pitch"), en.text("coupling.pitch")); + assert_eq!(de.text("render.camera_pitch"), "Kameraneigung"); + for locale in ["en", "de", "es", "ja", "zh"] { + let locale = crate::i18n::Locale::for_language(locale); + assert_eq!(locale.text("material.editor.axes_numeric"), "1 / 2 / 3"); + assert_eq!(locale.text("material.editor.axes_wood"), "L / R / T"); + } +} + +#[test] +fn camera_draft_uses_render_command_and_keeps_saved_design_unchanged() { + let mut h = fixture(); + let document = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + for up in [solidcraft_engine::render::UpAxis::Z, solidcraft_engine::render::UpAxis::Y] { + let mut camera = h.app.cam; + camera.up = up; + camera.roll = 0.41; + camera.pitch = 0.27; + apply_camera_draft(&mut h.app, camera).unwrap(); + assert_eq!(h.app.cam, camera); + assert!(h.app.render_workspace.view.dirty); + let mut invalid = camera; + invalid.distance = 0.0; + assert!(apply_camera_draft(&mut h.app, invalid).is_err()); + assert_eq!(h.app.cam, camera); + fit_subject(&mut h.app).unwrap(); + assert_eq!((h.app.cam.up, h.app.cam.roll, h.app.cam.pitch), (up, camera.roll, camera.pitch)); + assert_eq!(h.app.session.doc.to_json(), document); + assert_eq!(h.app.session.undo.len(), undo); + } +} + +#[test] +fn shots_strip_uses_the_existing_dirty_shot_confirmation() { + let mut h = fixture(); + h.app.render_workspace.view.name = "A".into(); + setups::save(&mut h.app).unwrap(); + h.app.run("render.settings.set", json!({"name":"B","set":{"width":321,"job":{"method":"raster"}}})).unwrap(); + h.app.render_workspace.view.draft.width = 123; + h.frames(3); + h.step(&json!({"click":{"handle":"render:shots:setup:B"}})).unwrap(); + assert!(confirmation_open(&h.app)); + assert_eq!(h.app.render_workspace.view.name, "A"); + h.step(&json!({"widget":h.app.tr("render.keep_editing")})).unwrap(); + assert_eq!(h.app.render_workspace.view.draft.width, 123); + h.step(&json!({"click":{"handle":"render:shots:setup:B"}})).unwrap(); + h.step(&json!({"widget":h.app.tr("render.discard_continue")})).unwrap(); + assert_eq!(h.app.render_workspace.view.name, "B"); + assert_eq!(h.app.render_workspace.view.draft.width, 321); +} + +#[test] +fn output_sections_bloom_tone_and_grading_save_one_command_per_edit_without_starting() { + use solidcraft_engine::render::job::ToneMap; + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":3000})); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + let document = h.app.session.doc.clone(); + let undo = h.app.session.undo.len(); + h.app.start("render.effects.describe"); + h.frames(24); + assert!(Arc::ptr_eq(&document, &h.app.session.doc)); + assert_eq!(undo, h.app.session.undo.len()); + let tone = crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr("render.children.tone"))).unwrap(); + let grading = crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr("render.children.finishing"))).unwrap(); + let bloom = crate::scenario::rect_of("render:bloom-enable").unwrap(); + let reset = crate::scenario::rect_of("render:post-reset").unwrap(); + assert!(tone.bottom() <= grading.top()); + assert!(grading.bottom() <= bloom.top() && bloom.bottom() <= reset.top(), "Bloom belongs to the Finishing section"); + reveal_inspector_target(&mut h, "render:bloom-enable"); + h.step(&json!({"click":{"handle":"render:bloom-enable"}})).unwrap(); + assert_eq!(undo + 1, h.app.session.undo.len()); + assert!(h.app.render_workspace.view.studio.finishing.bloom.is_some()); + let (next, expected) = if h.app.render_workspace.view.studio.tone_map == ToneMap::Reinhard { + ("render:tone:aces", ToneMap::AcesFitted) + } else { + ("render:tone:reinhard", ToneMap::Reinhard) + }; + reveal_inspector_target(&mut h, next); + h.step(&json!({"click":{"handle":next}})).unwrap(); + assert_eq!(h.app.render_workspace.view.studio.tone_map, expected); + assert_eq!(undo + 2, h.app.session.undo.len()); + let contrast = reveal_inspector_target(&mut h, "render.post_contrast"); + h.step(&json!({"click":[contrast.right()-10.0,contrast.center().y],"double":true})).unwrap(); + h.step(&json!({"key":"A","cmd":true})).unwrap(); + h.step(&json!({"text":"1.4"})).unwrap(); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.render_workspace.view.studio.finishing.contrast, 1.4); + assert_eq!(undo + 3, h.app.session.undo.len()); + assert_eq!(setups::snapshot(&h.app).unwrap().job, h.app.session.doc.render.setups[&h.app.render_workspace.view.name].job); + assert!(h.app.render_workspace.view.job.is_none()); + assert_eq!(h.app.session.doc.features, document.features); +} + +#[test] +fn output_sections_check_report_copies_success_staleness_and_errors_through_platform_queue() { + let mut h = fixture(); + h.app.session.set_render_job_host(Some(solidcraft_engine::render::job::CpuHost::cooperative())).unwrap(); + let doc = h.app.session.doc.clone(); + let state = (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len(), h.app.session.is_dirty()); + super::super::ribbon::perform_job(&mut h.app, "render.preflight").unwrap(); + let report = check_report(&h.app).unwrap(); + assert!(report.contains(h.app.tr("render.output_ready"))); + assert!(report.contains("cpu-raster")); + h.app.run("render.preflight.copy", json!({"text":report})).unwrap(); + assert_eq!(h.app.render_workspace.clipboard_text.as_deref(), Some(report.as_str())); + h.frames(1); + assert!(h.output.commands.iter().any(|command| matches!(command, egui::OutputCommand::CopyText(text) if text == &report))); + assert!(h.app.render_workspace.clipboard_text.is_none()); + assert!(h.app.render_workspace.view.job.is_none()); + assert_eq!(h.app.session.render_job_host().unwrap().admitted_bytes(), 0); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(state, (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len(), h.app.session.is_dirty())); + h.app.render_workspace.view.draft.width = 32; + let lines = check_lines(&h.app); + assert_eq!(lines[0].key, "stale"); + assert_eq!(lines[0].status, ui_kit::CheckStatus::Warning); + assert!(check_report(&h.app).unwrap().contains(h.app.tr("render.review_stale"))); + let request = super::super::image_params(&h.app).unwrap(); + record_check(&mut h.app, &request, &json!({"error":"host refused the request"})); + let lines = check_lines(&h.app); + assert_eq!(lines[0].status, ui_kit::CheckStatus::Error); + assert_eq!(lines[0].label, "host refused the request"); + assert!(check_report(&h.app).unwrap().contains("host refused the request")); + + let quality = json!({"name":"Quality report regression", "gpu_options":{"samples":128}}); + library::review::open(&mut h.app, "quality", "Quality".into(), quality.clone(), library::review::Apply::Quality(quality.clone())).unwrap(); + let report = check_report(&h.app).unwrap(); + assert!(report.contains(h.app.tr("render.quality_review"))); + assert!(report.contains(&quality.to_string())); + h.app.run("render.preflight.copy", json!({"text":report})).unwrap(); + assert_eq!(h.app.render_workspace.clipboard_text.as_deref(), Some(report.as_str())); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(state, (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len(), h.app.session.is_dirty())); +} + +#[test] +fn output_sections_sizes_refuse_hostile_input_and_4k_follows_the_selected_budget() { + let mut h = fixture(); + let before = h.app.render_workspace.view.draft.clone(); + let doc = h.app.session.doc.clone(); + let undo = h.app.session.undo.len(); + for (width, height) in [(0, 1), (1, 0), (u32::MAX, 1), (4096, 4096), (3840, 2160)] { + assert!(apply_size(&mut h.app, width, height, false).is_err()); + assert_eq!(h.app.render_workspace.view.draft, before); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(h.app.session.undo.len(), undo); + } + let reason = size_limit_reason(&h.app, 3840, 2160); + assert!(reason.contains("4194304")); + assert!(reason.contains("2730 × 1536")); + super::super::select_image_method(&mut h.app, ImageMethod::CpuRaytrace); + h.app.render_workspace.view.raytrace.budget = solidcraft_engine::render::job::CpuBudget::Studio; + h.frames(3); + h.step(&json!({"click":{"handle":"render:preset:4k"}})).unwrap(); + assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (3840, 2160)); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert!(h.app.render_workspace.view.job.is_none()); +} + +#[test] +fn shots_strip_render_submits_the_current_job_request() { + let mut h = fixture(); + h.app.render_workspace.view.draft.width = 24; + h.app.render_workspace.view.draft.height = 16; + h.app.render_workspace.view.draft.background = [31, 57, 83]; + let document = h.app.session.doc.clone(); + h.frames(3); + h.step(&json!({"click":{"handle":"render:shots:render"}})).unwrap(); + let job = h.app.render_workspace.view.job.unwrap(); + let status = h.app.session.render_job_handle(job).unwrap().status().unwrap(); + assert_eq!((status.request.width, status.request.height), (24, 16)); + assert_eq!(status.request.background, [31, 57, 83]); + assert_eq!(h.app.session.doc, document); +} + +#[test] +fn browser_shot_menus_keep_target_and_draft_through_confirmation() { + let mut h = fixture(); + h.app.render_workspace.view.name = "A".into(); + setups::save(&mut h.app).unwrap(); + h.app.run("render.settings.set", json!({"name":"B","set":{"width":321,"job":{"method":"raster"}}})).unwrap(); + h.app.render_workspace.view.draft.width = 123; + h.frames(3); + h.step(&json!({"click":{"handle":"render:tree:shot:B"},"button":"right"})).unwrap(); + h.step(&json!({"widget":h.app.tr("render.shot_rename")})).unwrap(); + assert!(confirmation_open(&h.app)); + assert_eq!(h.app.render_workspace.view.name, "A"); + h.step(&json!({"widget":h.app.tr("render.keep_editing")})).unwrap(); + assert_eq!(h.app.render_workspace.view.draft.width, 123); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Output); + shot_row_action(&mut h.app, "B".into(), "render.shot.rename"); + h.frames(3); + h.step(&json!({"widget":h.app.tr("render.discard_continue")})).unwrap(); + assert_eq!(h.app.render_workspace.view.name, "B"); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Scene); + assert_eq!(h.app.render_workspace.view.draft.width, 321); + h.app.render_workspace.view.draft.width = 456; + shot_row_action(&mut h.app, "A".into(), "render.shot.remove"); + h.frames(3); + assert!(confirmation_open(&h.app)); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!( + !h.app.session.doc.render.setups.contains_key("A"), + "pending={:?}, status={:?}", + h.app.render_workspace.view.inspector.pending, + h.app.status + ); + assert_eq!(h.app.render_workspace.view.name, "B"); + assert_eq!(h.app.render_workspace.view.draft.width, 456, "removing another shot preserves this draft"); +} + +#[test] +fn appearance_inspector_targets_and_chain_follow_body_face_and_component() { + use super::selection_appearance::{chains, inspected_look, targets}; + use solidcraft_engine::{Sel, geom::Vec3}; + let mut h = Harness::new(); + h.app.run("component.create", json!({"name":"Part"})).unwrap(); + h.app.run("solid.box", json!({"body_name":"Subject","length":20,"width":15,"height":10})).unwrap(); + h.app.run("material.assign", json!({"bodies":["Subject"],"material":"Steel"})).unwrap(); + h.app.run("appearance.assign", json!({"components":["Part"],"appearance":"ABS - Blue"})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.app.run("appearance.assign", json!({"body":"Subject","faces":[[10,7,10]],"appearance":"Copper"})).unwrap(); + let face = h.app.run("model.faces", json!({"body":"Subject"})).unwrap()["faces"] + .as_array() + .unwrap() + .iter() + .find(|f| f["point"][2] == 10.0) + .unwrap()["index"] + .as_u64() + .unwrap() as usize; + h.app.session.selection = vec![Sel::Face { body: "Subject".into(), index: face, point: Vec3::new(10.0, 7.0, 10.0) }]; + let before = h.app.session.doc.to_json(); + for (step, present) in [ + (ui_kit::LookStep::Face, [true, true, true, true]), + (ui_kit::LookStep::Body, [false, true, true, true]), + (ui_kit::LookStep::Component, [false, false, true, true]), + ] { + let target = targets(&h.app, step); + let chain = chains(&mut h.app, &target).unwrap(); + assert_eq!(chain[0].each_ref().map(Option::is_some), present); + assert_eq!(inspected_look(&chain[0], Some(ui_kit::LookStep::Component)).unwrap().name, "ABS - Blue"); + assert_eq!(inspected_look(&chain[0], Some(ui_kit::LookStep::Material)).unwrap().name, "Steel"); + let mut inherited = chain[0].clone(); + inherited[1] = None; + inherited[2] = None; + assert_eq!(inspected_look(&inherited, Some(ui_kit::LookStep::Body)).unwrap().name, "Steel"); + } + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn appearance_inspector_all_users_replaces_exact_look_once_without_changing_mass() { + use super::selection_appearance::{assign, chains, targets, users}; + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + h.app.run("material.assign", json!({"bodies":["Subject","Other"],"material":"Steel"})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Subject","Other"],"appearance":"ABS - Red"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + let target = targets(&h.app, ui_kit::LookStep::Body); + let from = chains(&mut h.app, &target).unwrap()[0][1].clone().unwrap(); + assert_eq!(users(&h.app, &from), 2); + let mut to = from.clone(); + to.color = [12, 34, 56]; + let mass = h.app.run("component.properties", json!({})).unwrap(); + let undo = h.app.session.undo.len(); + assign(&mut h.app, &target, &from, &to, true).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + for name in ["Subject", "Other"] { + assert_eq!(h.app.session.doc.appearances.bodies.get(name), Some(&to)); + } + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(users(&h.app, &from), 2); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog:{}:{}", h.app.tr("render.inspector_applies_to"), crate::i18n::format("render.inspector_all_users", &[("count", "2")]))}})) + .unwrap(); + h.step(&json!({"click":{"handle":"render:appearance:preview:replace"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog: search"}})).unwrap(); + h.step(&json!({"text":"ABS - Blue"})).unwrap(); + let blue = crate::dialogs_appearance::replacement_library(&mut h.app).iter().position(|look| look.name == "ABS - Blue").unwrap(); + h.step(&json!({"click":{"handle":format!("render:appearance:replace:{blue}")}})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + for name in ["Subject", "Other"] { + assert_eq!(h.app.session.doc.appearances.bodies[name].name, "ABS - Blue"); + } + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog:{}:{}",h.app.tr("render.inspector_finish"),h.app.tr("render.inspector_matte"))}})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1, "an all-users field edit is one replacement command"); + for name in ["Subject", "Other"] { + assert_eq!(h.app.session.doc.appearances.bodies[name].pbr.unwrap().roughness(), 0.85); + } + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); +} + +#[test] +fn appearance_inspector_finish_presets_mixed_set_all_and_clear_use_existing_assignments() { + use super::selection_appearance::{assign, chains, clear, finish, mixed, targets}; + use solidcraft_engine::{Sel, doc::appearance::Look}; + let mut h = fixture(); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + h.app.run("material.assign", json!({"bodies":["Subject","Other"],"material":"Steel"})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Other"],"appearance":"ABS - Blue"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }, Sel::Body { name: "Other".into() }]; + let target = targets(&h.app, ui_kit::LookStep::Body); + let looks: Vec<_> = chains(&mut h.app, &target).unwrap().into_iter().map(|c| c[1].clone().unwrap()).collect(); + assert!(mixed(&looks, |l| l.color)); + assert!(!mixed(&looks, |l| l.opacity)); + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + assert!(h.widget(h.app.tr("render.tree_mixed")).is_some()); + appearance_inspector_capture(&mut h, "mixed"); + let mass = h.app.run("component.properties", json!({})).unwrap(); + let mut to = Look::custom([40, 50, 60], 0.5); + for (index, metallic, roughness) in [(0, 0.0, 0.85), (1, 0.0, 0.5), (2, 0.0, 0.12), (3, 1.0, 0.32)] { + finish(&mut to, index).unwrap(); + let pbr = to.pbr.unwrap(); + assert_eq!((pbr.metallic(), pbr.roughness(), to.opacity), (metallic, roughness, 1.0)); + } + let undo = h.app.session.undo.len(); + assign(&mut h.app, &target, &looks[0], &to, false).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert_eq!(h.app.session.doc.appearances.bodies.get("Subject"), h.app.session.doc.appearances.bodies.get("Other")); + clear(&mut h.app, &target, &to).unwrap(); + assert!(h.app.session.doc.appearances.bodies.is_empty()); + assert!(chains(&mut h.app, &target).unwrap().iter().all(|c| c[3].as_ref().is_some_and(|l| l.name == "Steel"))); + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); +} + +#[test] +fn appearance_inspector_real_controls_switch_targets_inspect_chain_and_edit_finish() { + use solidcraft_engine::{Sel, geom::Vec3}; + let mut h = fixture(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + let face = h.app.run("model.faces", json!({"body":"Subject"})).unwrap()["faces"] + .as_array() + .unwrap() + .iter() + .find(|f| f["point"][2] == 10.0) + .unwrap()["index"] + .as_u64() + .unwrap() as usize; + h.app.session.selection = vec![Sel::Face { body: "Subject".into(), index: face, point: Vec3::new(10.0, 7.0, 10.0) }]; + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + let before = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:appearance:chain-menu"}})).unwrap(); + h.step(&json!({"click":{"handle":"render:appearance:chain:body"}})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + appearance_inspector_capture(&mut h, "face"); + h.frames(3); + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog:{}:{}",h.app.tr("render.inspector_finish"),h.app.tr("render.inspector_metal"))}})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert_eq!(h.app.session.doc.appearances.bodies["Subject"].pbr.unwrap().metallic(), 1.0); + let roughness = crate::scenario::rect_of(&format!("dialog:scalar:{}", h.app.tr("appearance.roughness"))).unwrap().center(); + let drag_undo = h.app.session.undo.len(); + h.step(&json!({"drag":[[roughness.x,roughness.y],[roughness.x+20.0,roughness.y]],"steps":12})).unwrap(); + assert_eq!(h.app.session.undo.len(), drag_undo + 1, "a multi-frame field edit is one undo step"); + assert_ne!(h.app.session.doc.appearances.bodies["Subject"].pbr.unwrap().roughness(), 0.32); + let edited_undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr("render.pick_body"))}})).unwrap(); + assert!(h.app.ui.pick_bodies); + assert_eq!(h.app.session.undo.len(), edited_undo); + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr("render.pick_component"))}})).unwrap(); + assert!(h.app.ui.pick_components); + assert!(h.widget(h.app.tr("render.inspector_pick_target")).is_some(), "root bodies have no component override target"); + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr("render.pick_face"))}})).unwrap(); + assert!(!h.app.ui.pick_components && !h.app.ui.pick_bodies); + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr("render.pick_body"))}})).unwrap(); + assert_eq!(h.app.session.undo.len(), edited_undo); + appearance_inspector_capture(&mut h, "body"); + h.app.session.selection.clear(); + h.frames(3); + assert!(h.widget(h.app.tr("render.base_appearance")).is_some()); + appearance_inspector_capture(&mut h, "explicit-target"); +} + +#[test] +fn appearance_inspector_mixed_fields_are_inert_until_edited_and_accept_the_first_value() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + for (name, opacity) in [("Subject", 0.25), ("Other", 0.75)] { + h.app.run("appearance.assign", json!({"bodies":[name],"color":"#123456","opacity":opacity})).unwrap(); + } + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }, Sel::Body { name: "Other".into() }]; + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + let field = format!("dialog:scalar:{}", h.app.tr("render.inspector_opacity")); + h.step(&json!({"click":{"handle":field}})).unwrap(); + h.step(&json!({"key":"Tab"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before, "leaving Mixed without editing must be inert"); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"click":{"handle":field}})).unwrap(); + h.step(&json!({"text":"NaN"})).unwrap(); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before, "invalid input must not set mixed targets"); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"click":{"handle":field}})).unwrap(); + h.step(&json!({"text":"0.25"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo, "typing keeps a local draft until commit"); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + for name in ["Subject", "Other"] { + assert_eq!(h.app.session.doc.appearances.bodies[name].opacity, 0.25); + } + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); +} + +#[test] +fn appearance_inspector_optical_colour_and_opacity_edits_commit_once_with_shared_bounds() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app + .run( + "appearance.assign", + json!({"bodies":["Subject"],"color":"#123456", + "pbr":{"metallic":0.2,"roughness":0.4,"dielectric_ior":1.5}}), + ) + .unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + let mass = h.app.run("component.properties", json!({})).unwrap(); + for (key, text) in [("appearance.metallic", "2"), ("appearance.roughness", "0"), ("render.inspector_opacity", "0.25")] { + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog:scalar:{}",h.app.tr(key))}})).unwrap(); + h.step(&json!({"text":text})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1, "{key}"); + let look = &h.app.session.doc.appearances.bodies["Subject"]; + match key { + "appearance.metallic" => assert_eq!(look.pbr.unwrap().metallic(), 1.0), + "appearance.roughness" => assert_eq!(look.pbr.unwrap().roughness(), 0.045), + _ => assert_eq!((look.opacity, look.pbr), (0.25, None)), + } + } + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":format!("dialog:scalar:{}",h.app.tr("render.appearance_editor.ior"))}})).unwrap(); + h.step(&json!({"text":"3.5"})).unwrap(); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + let look = &h.app.session.doc.appearances.bodies["Subject"]; + assert_eq!((look.pbr.unwrap().dielectric_ior(), look.opacity), (3.0, 1.0)); + h.step(&json!({"click":{"handle":format!("dialog:color:{}",h.app.tr("render.inspector_colour"))}})).unwrap(); + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":"color:channel:R"}})).unwrap(); + h.step(&json!({"text":"200"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert_eq!(h.app.session.doc.appearances.bodies["Subject"].color[0], 200); + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); +} + +#[test] +fn appearance_inspector_hex_edits_validate_and_commit_once() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + appearance_picker_open(&mut h); + let hex = "color:hex"; + h.step(&json!({"click":{"handle":hex}})).unwrap(); + h.step(&json!({"key":"A","cmd":true,"ctrl":true})).unwrap(); + h.step(&json!({"text":"#GG0000"})).unwrap(); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":hex}})).unwrap(); + h.step(&json!({"key":"A","cmd":true,"ctrl":true})).unwrap(); + h.step(&json!({"text":"#123456"})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.doc.appearances.bodies["Subject"].color, [0x12, 0x34, 0x56]); + assert_eq!(h.app.session.undo.len(), undo + 1); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Other"],"color":"#ABCDEF"})).unwrap(); + h.app.session.selection.push(Sel::Body { name: "Other".into() }); + h.frames(3); + let mixed_before = h.app.session.doc.to_json(); + if crate::scenario::handle_at(hex).is_none() { + appearance_picker_open(&mut h); + } + h.step(&json!({"click":{"handle":hex}})).unwrap(); + h.step(&json!({"key":"Tab"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), mixed_before); + h.step(&json!({"click":{"handle":hex}})).unwrap(); + h.step(&json!({"key":"A","cmd":true,"ctrl":true})).unwrap(); + h.step(&json!({"text":"#123456"})).unwrap(); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.doc.appearances.bodies["Other"].color, [0x12, 0x34, 0x56]); +} + +fn appearance_picker_open(h: &mut Harness) { + h.step(&json!({"click":{"handle":format!("dialog:color:{}", h.app.tr("render.inspector_colour"))}})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":"color:format:Hex"}})).unwrap(); +} + +fn appearance_picker_paste(h: &mut Harness, text: &str) { + h.step(&json!({"click":{"handle":"color:hex"}})).unwrap(); + h.step(&json!({"key":"A","cmd":true,"ctrl":true})).unwrap(); + h.frame_with(vec![egui::Event::Paste(text.into())]); +} + +#[test] +fn appearance_inspector_shared_picker_preserves_exact_opacity_and_commits_alpha() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"color":"#abcdef","opacity":0.123456,"appearance":"Tint"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let mass = h.app.run("component.properties", json!({})).unwrap(); + appearance_picker_open(&mut h); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + for mode in ["F", "U8", "Hex"] { + h.step(&json!({"click":{"handle":format!("color:format:{mode}")}})).unwrap(); + let draft = h.app.render_workspace.view.inspector.selection_appearance.draft().unwrap(); + assert_eq!((draft.color, draft.opacity, draft.pbr), ([171, 205, 239], 0.123456, None)); + } + for text in ["#abc", "#abcdefz0"] { + appearance_picker_paste(&mut h, text); + h.frames(2); + let draft = h.app.render_workspace.view.inspector.selection_appearance.draft().unwrap(); + assert_eq!((draft.color, draft.opacity), ([171, 205, 239], 0.123456)); + assert!(h.widget(text).is_some(), "invalid text remains editable inside the picker"); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.session.undo.len(), undo); + } + for (text, color, opacity) in [ + ("#0102fe", [1, 2, 254], 0.123456), + ("#0102fe80", [1, 2, 254], 128.0 / 255.0), + ("#fE8001", [254, 128, 1], 128.0 / 255.0), + ("#22334400", [34, 51, 68], 0.0), + ] { + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + appearance_picker_paste(&mut h, text); + let draft = h.app.render_workspace.view.inspector.selection_appearance.draft().unwrap(); + assert_eq!((draft.color, draft.opacity, draft.pbr), (color, opacity, None), "{text} updates the exact draft immediately"); + assert_eq!(h.app.session.doc.to_json(), before, "typing does not commit the model"); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"key":"Enter"})).unwrap(); + h.frames(2); + let look = &h.app.session.doc.appearances.bodies["Subject"]; + assert_eq!((look.color, look.opacity, look.pbr), (color, opacity, None)); + assert_eq!(h.app.session.undo.len(), undo + 1, "one committed edit for {text}"); + } + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); +} + +#[test] +fn appearance_inspector_shared_picker_pbr_rejects_nonopaque_alpha() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app + .run("appearance.assign", json!({"bodies":["Subject"],"color":"#123456", "pbr":{"metallic":0.2,"roughness":0.4,"dielectric_ior":1.6}})) + .unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + let pbr = h.app.session.doc.appearances.bodies["Subject"].pbr; + appearance_picker_open(&mut h); + for text in ["#abcdef80", "#abcdef00"] { + appearance_picker_paste(&mut h, text); + let draft = h.app.render_workspace.view.inspector.selection_appearance.draft().unwrap(); + assert_eq!((draft.color, draft.opacity, draft.pbr), ([18, 52, 86], 1.0, pbr)); + assert!(h.widget(text).is_some()); + h.step(&json!({"key":"Enter"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.session.undo.len(), undo); + } + appearance_picker_paste(&mut h, "#abcdefFF"); + h.step(&json!({"key":"Enter"})).unwrap(); + let look = &h.app.session.doc.appearances.bodies["Subject"]; + assert_eq!((look.color, look.opacity, look.pbr), ([171, 205, 239], 1.0, pbr)); + assert_eq!(h.app.session.undo.len(), undo + 1); +} + +#[test] +fn appearance_inspector_shared_picker_has_no_outer_hex_editor_and_keeps_mixed_values_visible() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + for (body, color) in [("Subject", "#123456"), ("Other", "#abcdef")] { + h.app.run("appearance.assign", json!({"bodies":[body],"color":color,"opacity":0.123456})).unwrap(); + } + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }, Sel::Body { name: "Other".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let outer = format!("dialog:color_hex:{}", h.app.tr("render.inspector_colour")); + assert!(crate::scenario::handle_at(&outer).is_none(), "Hex editing belongs only inside the shared picker"); + assert!(crate::scenario::rect_of("dialog:note:color:mixed").is_some(), "mixed colour remains visibly labelled beside the swatch"); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + appearance_picker_open(&mut h); + assert!(crate::scenario::handle_at(&outer).is_none()); + assert!(crate::scenario::handle_at("color:hex").is_some()); + h.step(&json!({"click":{"handle":"color:hex"}})).unwrap(); + h.step(&json!({"key":"Tab"})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), before, "opening and leaving mixed input is inert"); + assert_eq!(h.app.session.undo.len(), undo); + appearance_picker_paste(&mut h, "#123456"); + h.step(&json!({"key":"Enter"})).unwrap(); + for body in ["Subject", "Other"] { + let look = &h.app.session.doc.appearances.bodies[body]; + assert_eq!((look.color, look.opacity, look.pbr), ([18, 52, 86], 0.123456, None)); + } + assert_eq!(h.app.session.undo.len(), undo + 1, "accepting the first colour still sets mixed targets once"); +} + +#[test] +fn appearance_inspector_component_and_face_overrides_remove_to_material_from_real_controls() { + use solidcraft_engine::{Sel, geom::Vec3}; + let mut h = Harness::new(); + h.call("ui.resize", json!({"width":1440,"height":1000})); + h.app.run("component.create", json!({"name":"Part"})).unwrap(); + h.app.run("solid.box", json!({"body_name":"Subject","length":20,"width":15,"height":10})).unwrap(); + h.app.run("material.assign", json!({"bodies":["Subject"],"material":"Steel"})).unwrap(); + h.app.run("appearance.assign", json!({"components":["Part"],"appearance":"ABS - Blue"})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.app.run("appearance.assign", json!({"body":"Subject","faces":[[10,7,10]],"appearance":"Copper"})).unwrap(); + let face = h.app.run("model.faces", json!({"body":"Subject"})).unwrap()["faces"] + .as_array() + .unwrap() + .iter() + .find(|f| f["point"][2] == 10.0) + .unwrap()["index"] + .as_u64() + .unwrap() as usize; + h.app.session.selection = vec![Sel::Face { body: "Subject".into(), index: face, point: Vec3::new(10.0, 7.0, 10.0) }]; + super::super::enter(&mut h.app, true).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":"render:stage:look"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.inspector.page, Page::Appearance); + let mass = h.app.run("component.properties", json!({})).unwrap(); + for (step, name) in [("face", "Copper"), ("body", "ABS - Red"), ("component", "ABS - Blue"), ("material", "Steel")] { + let before = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:appearance:chain-menu"}})).unwrap(); + h.step(&json!({"click":{"handle":format!("render:appearance:chain:{step}")}})).unwrap(); + assert!(h.widget(name).is_some(), "inspecting {step} must show {name}"); + assert_eq!(h.app.session.doc.to_json(), before); + } + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr("render.pick_component"))}})).unwrap(); + appearance_inspector_capture(&mut h, "component"); + h.frames(3); + for step in ["component", "body", "face"] { + h.step(&json!({"click":{"handle":format!("dialog::{}",h.app.tr(match step { + "component" => "render.pick_component", "body" => "render.pick_body", _ => "render.pick_face", + }))}})) + .unwrap(); + let undo = h.app.session.undo.len(); + h.step(&json!({"widget":"…"})).unwrap(); + h.step(&json!({"widget":h.app.tr("render.inspector_remove")})).unwrap(); + assert_eq!(h.app.session.undo.len(), undo + 1, "clearing {step}: {:?}", h.app.render_workspace.view.inspector.selection_appearance); + } + assert!(h.app.session.doc.appearances.is_empty()); + assert!(h.widget("Steel").is_some()); + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), mass); +} + +// Opt-in evidence from the actual application UI, without requiring a window server. +fn appearance_inspector_capture(h: &mut Harness, name: &str) { + let Some(dir) = std::env::var_os("SOLIDCRAFT_INSPECTOR_EVIDENCE") else { return }; + std::fs::create_dir_all(&dir).unwrap(); + for dark in [false, true] { + h.app.preferences.theme = if dark { "dark" } else { "light" }.into(); + h.app.ui.dark = dark; + h.app.preferences.render_inspector_width = 305.0; + let ctx = egui::Context::default(); + crate::fonts::setup_bundled_fonts(&ctx); + let mut textures = std::collections::HashMap::new(); + let mut last = None; + for frame in 0..10 { + let mut output = ctx.run_ui( + egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0))), + time: Some(frame as f64 / 10.0), + focused: true, + ..Default::default() + }, + |ui| { + h.app.logic(ui.ctx()); + h.app.ui(ui); + }, + ); + ui_kit::update_test_textures(&mut textures, &output.textures_delta); + output.textures_delta.clear(); + last = Some(output); + } + let output = last.unwrap(); + let card = crate::scenario::rect_of("render:inspector").unwrap(); + let crop = ui_kit::raster_ui(&ctx, output.shapes.clone(), output.pixels_per_point, card, &textures); + crop.save(std::path::Path::new(&dir).join(format!("{name}-{}-305.png", if dark { "dark" } else { "light" }))).unwrap(); + let image = ui_kit::raster_ui(&ctx, output.shapes, output.pixels_per_point, ctx.content_rect(), &textures); + image.save(std::path::Path::new(&dir).join(format!("{name}-{}.png", if dark { "dark" } else { "light" }))).unwrap(); + } +} + +#[test] +fn appearance_inspector_approved_layout_is_305_wide_and_preserves_stage_bounds() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("solid.box", json!({"body_name":"Boss","length":10,"width":10,"height":10,"corner":[30,0,0]})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Boss","Subject"],"appearance":"Aluminum - Anodized Blue"})).unwrap(); + h.app.run("material.assign", json!({"bodies":["Boss","Subject"],"material":"Steel"})).unwrap(); + h.app.run("select.filter", json!({"mode":"body"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Boss".into() }]; + h.app.preferences.render_inspector_width = 305.0; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let before = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + appearance_inspector_capture(&mut h, "approved"); + h.frames(3); + let inspector = crate::scenario::rect_of("render:inspector").unwrap(); + let browser = crate::scenario::rect_of("browser:card").unwrap(); + let shots = crate::scenario::rect_of("render:shots_strip").unwrap(); + assert!((inspector.width() - 305.0).abs() <= 1.0, "{inspector:?}"); + assert!((inspector.top() - browser.top()).abs() <= 1.0); + assert!(inspector.bottom() < shots.top()); + assert!(h.widget(&crate::i18n::format("render.inspector_all_users", &[("count", "2")])).is_some()); + assert!(h.widget(h.app.tr("render.inspector_save_library")).is_some()); + assert_eq!(h.app.session.doc.to_json(), before); + assert_eq!(h.app.session.undo.len(), undo); + h.step(&json!({"click":{"handle":"render:appearance:close"}})).unwrap(); + assert!(h.app.render_workspace.view.inspector.hidden); + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + assert!(!h.app.render_workspace.view.inspector.hidden); + h.step(&json!({"click":{"handle":format!("dialog:{}:{}",h.app.tr("render.inspector_finish"),h.app.tr("render.inspector_matte"))}})).unwrap(); + h.step(&json!({"click":{"handle":format!("dialog:action:{}", h.app.tr("render.inspector_reset"))}})).unwrap(); + assert_eq!(h.app.session.doc.appearances.bodies.get("Boss"), h.app.session.doc.appearances.bodies.get("Subject")); + assert!(h.app.session.doc.appearances.bodies.contains_key("Subject")); + assert_eq!(h.app.session.undo.len(), undo + 2); +} + +#[test] +fn appearance_editor_e2_sections_are_ordered_collapsed_and_expand_for_each_method() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":4000})); + h.app.preferences.render_inspector_width = 308.0; + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + let titles = [ + "render.inspector_edit", + "render.appearance_editor.glass", + "render.appearance_editor.coat", + "render.appearance_editor.maps", + "render.appearance_editor.saved", + "render.appearance_editor.reflections", + ]; + h.frames(3); + let before = h.app.session.doc.to_json(); + let mut last = 0.0; + for title in titles { + let rect = crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr(title))).unwrap(); + assert!(rect.top() > last, "{title} follows the preceding design section"); + last = rect.bottom(); + } + assert!(h.widget(h.app.tr("render.appearance_editor.glass_enable")).is_none(), "optics default to collapsed"); + assert!(h.widget(h.app.tr("render.appearance_editor.gpu_reason")).is_some()); + for title in titles.into_iter().skip(1) { + h.step(&json!({"click":{"handle":format!("dialog:section:{}",h.app.tr(title))}})).unwrap(); + } + for method in [ImageMethod::Raster, ImageMethod::GpuRaytrace, ImageMethod::CpuRaytrace] { + h.app.render_workspace.view.method = method; + h.frames(3); + for key in [ + "render.appearance_editor.glass_enable", + "render.appearance_editor.recipe", + "render.appearance_editor.boundary", + "render.appearance_editor.thickness", + "render.appearance_editor.absorption", + "render.material_shadow", + "render.subsurface_enable", + "render.material_coat_enable", + "render.appearance_editor.weight", + "render.material_maps_enable", + "render.appearance_editor.base_colour", + "render.appearance_editor.normal", + "appearance.metallic", + "appearance.roughness", + "render.appearance_editor.origin", + "render.appearance_editor.u_repeat", + "render.appearance_editor.v_repeat", + "render.appearance_editor.normal_strength", + "render.appearance_editor.v_up", + "render.material_color_replace", + "render.appearance_editor.save", + "render.appearance_editor.remove", + "render.appearance_editor.replace", + "render.appearance_editor.revalidate", + "render.cpu_reflection_off", + "render.cpu_reflection_mirror", + "render.cpu_reflection_rough", + ] { + assert!(h.widget(h.app.tr(key)).is_some(), "expanded E2 is missing {key} for {method:?}"); + } + let tree = h.output.accesskit_update.as_ref().unwrap(); + let glass = tree.nodes.iter().find(|(_, n)| n.label() == Some(h.app.tr("render.appearance_editor.glass_enable"))).unwrap(); + assert_eq!(glass.1.is_disabled(), method != ImageMethod::GpuRaytrace); + assert_eq!(h.app.session.doc.to_json(), before); + assert!(h.app.render_workspace.view.materials.bindings.is_empty(), "opening never installs temporary bindings"); + } + for selection in + [Sel::Face { body: "Subject".into(), index: 0, point: solidcraft_engine::geom::Vec3::ZERO }, Sel::Body { name: "Subject".into() }] + { + h.app.session.selection = vec![selection]; + if matches!(h.app.session.selection.first(), Some(Sel::Body { .. })) { + h.app.ui.pick_components = true; + } + h.frames(3); + assert!(h.widget(h.app.tr("render.appearance_editor.body_reason")).is_some()); + for title in titles.into_iter().skip(1) { + assert!(crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr(title))).is_some()); + } + } +} + +#[test] +fn output_children_select_their_editor_with_all_sections_in_design_order() { + use super::super::RenderSelection; + for method in [ImageMethod::Raster, ImageMethod::CpuRaytrace, ImageMethod::GpuRaytrace] { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":3000})); + super::super::select_image_method(&mut h.app, method); + let doc = h.app.session.doc.clone(); + let history = (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()); + for (kind, selection, page, sections) in [ + ( + "sampling", + RenderSelection::Sampling, + Page::Sampling, + vec!["render.output_quality", "render.children.path", "render.children.adaptive", "render.children.glass", "render.children.cpu"], + ), + ( + "effects", + RenderSelection::Effects, + Page::Effects, + vec![ + "render.children.tone", + "render.children.looks", + "render.children.lens_effects", + "render.children.finishing", + "render.children.regrade", + ], + ), + ( + "check", + RenderSelection::Check, + Page::Diagnostics, + vec!["render.children.check", "render.children.request", "render.children.renderers", "render.children.under_hood"], + ), + ( + "output", + RenderSelection::Output, + Page::Output, + vec!["render.children.renderer", "render.output_image", "render.output_destination", "render.children.render"], + ), + ] { + let handle = if kind == "output" { "render:tree:output".to_string() } else { format!("render:tree:output:{kind}") }; + // The capped Browser can publish rows below its clip after Lights adds more entries. + // Reveal the Output group before exercising each real child-row click. + h.frames(3); + let browser = crate::scenario::rect_of("browser:card").unwrap(); + let header = crate::scenario::rect_of("render:browser:header").unwrap(); + h.call("ui.scroll", json!({"x":browser.center().x,"y":(header.bottom()+browser.bottom())/2.0,"delta":-2000})); + h.frames(20); + let browser = crate::scenario::rect_of("browser:card").unwrap(); + let header = crate::scenario::rect_of("render:browser:header").unwrap(); + let target = crate::scenario::handle_at(&handle).unwrap(); + assert!(browser.shrink(Tokens::get().space_8).contains(target) && target.y > header.bottom(), "{handle} is outside the visible Browser"); + h.step(&json!({"click":{"handle":handle}})).unwrap(); + h.frames(3); + assert_eq!(h.app.render_workspace.view.selection, selection); + assert_eq!(selected_page(&h.app), page); + let mut bottom = 0.0; + for key in sections { + let rect = crate::scenario::rect_of(&format!("dialog:section:{}", h.app.tr(key))) + .unwrap_or_else(|| panic!("missing {key} for {method:?}/{kind}")); + assert!(rect.top() >= bottom, "section order for {method:?}/{kind}/{key}"); + bottom = rect.bottom(); + } + assert!(crate::scenario::rect_of("render:job-footer").is_none()); + assert!(crate::scenario::rect_of("render:page:output").is_none()); + assert_eq!(h.app.render_workspace.view.method, method); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(history, (h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len())); + } + h.step(&json!({"click":{"handle":"render:output:check"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, RenderSelection::Check); + h.app.run("view.render_select", json!({"kind":"output"})).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":"render:stage:check"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, RenderSelection::Check); + assert!(h.app.render_workspace.view.inspector.checked.is_none(), "opening Check never runs preflight"); + h.frames(3); + h.step(&json!({"click":{"handle":"render:quality:custom"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, RenderSelection::Sampling); + } +} + +#[test] +fn appearance_editor_reset_restores_each_picked_saved_look() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + let saved = h.app.session.doc.appearances.bodies["Subject"].clone(); + let target = selection_appearance::targets(&h.app, ui_kit::LookStep::Body); + let changed = solidcraft_engine::doc::appearance::Look::custom([10, 20, 30], 0.3); + selection_appearance::assign(&mut h.app, &target, &saved, &changed, false).unwrap(); + h.frames(3); + selection_appearance::reset(&mut h.app); + assert_eq!(h.app.session.doc.appearances.bodies["Subject"], saved); +} + +#[test] +fn appearance_editor_saved_optics_removal_confirms_and_preserves_other_drafts() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":2200})); + h.app.render_workspace.view.method = ImageMethod::GpuRaytrace; + let set = setups::snapshot(&h.app).unwrap(); + let name = h.app.render_workspace.view.name.clone(); + h.app + .run( + "render.optics.bind", + json!({"name":name,"set":set,"body_index":0,"body_name":"Subject", + "optics":{"ior":1.5,"absorption_per_mm":[0.0,0.0,0.0],"boundary":"closed_mesh","thickness_mm":0.0,"shadow_transmission":false}, + "expected_revision":h.app.session.revision}), + ) + .unwrap(); + setups::load(&mut h.app); + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":format!("dialog:section:{}",h.app.tr("render.appearance_editor.saved"))}})).unwrap(); + let before = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:optics-remove"}})).unwrap(); + assert!(materials::confirmation_open(&h.app)); + assert!(h.widget(h.app.tr("render.appearance_editor.remove_title")).is_some()); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"dialog:cancel"}})).unwrap(); + assert!(!materials::confirmation_open(&h.app)); + assert_eq!(h.app.session.doc.to_json(), before); + h.step(&json!({"click":{"handle":"render:optics-remove"}})).unwrap(); + h.app.run("appearance.assign", json!({"bodies":["Subject"],"appearance":"ABS - Red"})).unwrap(); + h.frames(3); + assert!(!materials::confirmation_open(&h.app), "a changed document expires the pending confirmation"); + assert_eq!(h.app.session.doc.render.setups[&name].optics.len(), 1); + h.app.render_workspace.view.draft.width = 777; + h.frames(3); + h.step(&json!({"click":{"handle":"render:optics-remove"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!(h.app.session.doc.render.setups[&name].optics.is_empty()); + assert!(h.app.render_workspace.view.draft.optics.is_empty()); + assert_eq!(h.app.render_workspace.view.draft.width, 777); + assert_eq!(h.app.session.doc.appearances.bodies["Subject"].name, "ABS - Red"); +} + +#[test] +fn appearance_editor_save_optics_keeps_other_temporary_bindings() { + use solidcraft_engine::Sel; + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":2600})); + h.app.run("solid.box", json!({"body_name":"Other","length":5,"width":5,"height":5,"corner":[30,0,0]})).unwrap(); + h.app.render_workspace.view.method = ImageMethod::GpuRaytrace; + let other = materials::read_targets(&mut h.app).unwrap().into_iter().find(|t| t.name == "Other").unwrap(); + let mut binding = materials::Binding::new(other, &h.app); + binding.coat_enabled = true; + h.app.render_workspace.view.materials.bindings.push(binding); + h.app.render_workspace.view.materials.enabled = true; + h.app.session.selection = vec![Sel::Body { name: "Subject".into() }]; + h.app.run("view.render_stage", json!({"stage":"look"})).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":format!("dialog:section:{}",h.app.tr("render.appearance_editor.glass"))}})).unwrap(); + h.step(&json!({"widget":h.app.tr("render.material_custom")})).unwrap(); + h.step(&json!({"click":{"handle":"render:glass:starter.glass.amber-tint"}})).unwrap(); + h.step(&json!({"click":{"handle":format!("dialog:section:{}",h.app.tr("render.appearance_editor.saved"))}})).unwrap(); + let geometry = h.app.run("component.properties", json!({})).unwrap(); + let undo = h.app.session.undo.len(); + h.step(&json!({"click":{"handle":"render:optics-save"}})).unwrap(); + let view = &h.app.render_workspace.view; + assert_eq!(h.app.session.doc.render.setups[&view.name].optics.len(), 1); + assert_eq!(view.materials.bindings.len(), 1); + assert_eq!(view.materials.bindings[0].target.name, "Other"); + assert!(view.materials.bindings[0].coat_enabled); + assert_eq!(h.app.session.undo.len(), undo + 1); + assert_eq!(h.app.run("component.properties", json!({})).unwrap(), geometry); +} + +#[test] +fn output_children_unsupported_controls_stay_visible_with_reason_and_cannot_edit() { + fn has_text(shape: &egui::Shape, text: &str) -> bool { + match shape { + egui::Shape::Text(s) => s.galley.text().contains(text), + egui::Shape::Vec(s) => s.iter().any(|s| has_text(s, text)), + _ => false, + } + } + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":3000})); + let doc = h.app.session.doc.clone(); + h.app.run("view.render_select", json!({"kind":"sampling"})).unwrap(); + h.frames(3); + assert!(h.shapes.iter().any(|s| has_text(&s.shape, h.app.tr("render.effects_gpu_only")))); + assert!(h.shapes.iter().any(|s| has_text(&s.shape, h.app.tr("render.children.needs_cpu")))); + h.step(&json!({"click":{"handle":format!("dialog:section:{}", h.app.tr("render.children.adaptive"))}})).unwrap(); + h.frames(3); + let before = h.app.render_workspace.view.studio.clone(); + let point = reveal_inspector_target(&mut h, "render:adaptive-enable").center(); + h.step(&json!({"click":[point.x,point.y]})).unwrap(); + assert_eq!(h.app.render_workspace.view.studio.adaptive, before.adaptive); + h.app.run("view.render_select", json!({"kind":"effects"})).unwrap(); + h.frames(3); + assert!(h.shapes.iter().any(|s| has_text(&s.shape, h.app.tr("render.children.effects_banner")))); + let point = reveal_inspector_target(&mut h, "render:bloom-enable").center(); + h.step(&json!({"click":[point.x,point.y]})).unwrap(); + assert_eq!(h.app.render_workspace.view.studio.finishing, before.finishing); + assert_eq!(h.app.render_workspace.view.method, ImageMethod::Raster); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); +} + +#[test] +fn output_children_hostile_drafts_are_readable_without_normalizing_or_saving() { + let mut h = fixture(); + super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.render_workspace.view.samples = u32::MAX; + h.app.render_workspace.view.max_depth = u32::MAX; + h.app.render_workspace.view.studio.finishing.contrast = f64::NAN; + h.app.render_workspace.view.dirty = true; + let doc = h.app.session.doc.clone(); + for kind in ["sampling", "effects", "check", "output"] { + h.app.run("view.render_select", json!({"kind":kind})).unwrap(); + h.frames(3); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(h.app.render_workspace.view.samples, u32::MAX); + assert_eq!(h.app.render_workspace.view.max_depth, u32::MAX); + assert!(h.app.render_workspace.view.studio.finishing.contrast.is_nan()); + assert!(h.app.render_workspace.view.job.is_none()); + } +} + +#[test] +fn output_children_check_diagnostics_are_collapsed_and_copy_the_current_request() { + let mut h = fixture(); + h.call("ui.resize", json!({"width":1440,"height":3000})); + h.app.session.set_render_job_host(Some(solidcraft_engine::render::job::CpuHost::cooperative())).unwrap(); + h.app.pending_fit = None; + h.app.cancel_view_animation(); + h.app.run("view.render_select", json!({"kind":"check"})).unwrap(); + h.frames(3); + assert!(h.widget(h.app.tr("render.children.copy_request")).is_none()); + h.step(&json!({"click":{"handle":"render:check"}})).unwrap(); + assert!(h.app.render_workspace.view.inspector.checked.is_some()); + assert!(h.app.render_workspace.view.job.is_none()); + let request = super::super::image_request(&h.app).unwrap(); + let expected = serde_json::to_string_pretty(&request).unwrap(); + h.step(&json!({"click":{"handle":format!("dialog:section:{}",h.app.tr("render.children.under_hood"))}})).unwrap(); + h.frames(3); + let button = crate::scenario::rect_of("render:check:copy-request").unwrap(); + assert!(crate::scenario::rect_of("render:inspector").unwrap().contains_rect(button)); + // The control-channel click helper settles four extra frames, which discards + // one-frame platform events. Drive the native button and observe every frame. + let at = button.center(); + h.frame_with(vec![egui::Event::PointerMoved(at)]); + for pressed in [true, false] { + h.frame_with(vec![egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }]); + } + let copied = |h: &Harness| { + h.output.commands.iter().find_map(|c| match c { + egui::OutputCommand::CopyText(text) => Some(text.clone()), + _ => None, + }) + }; + let mut text = copied(&h); + if text.is_none() { + assert_eq!(h.app.render_workspace.clipboard_text.as_deref(), Some(expected.as_str())); + h.frame(); + text = copied(&h); + } + assert_eq!(text.as_deref(), Some(expected.as_str())); + let request = super::super::image_params(&h.app).unwrap(); + record_check(&mut h.app, &request, &json!({"warnings":["Sampling budget needs review"]})); + h.frames(3); + assert!(crate::scenario::rect_of("render:check:go-to:1").is_some()); + h.step(&json!({"click":{"handle":"render:check:go-to:1"}})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, super::super::RenderSelection::Sampling); + h.app.run("view.render_select", json!({"kind":"check"})).unwrap(); + record_check(&mut h.app, &request, &json!({"error":"Exposure exceeds the CPU limit"})); + h.frames(3); + h.step(&json!({"click":{"handle":"render:check:go-to:0"}})).unwrap(); + assert_eq!(selected_page(&h.app), Page::Camera); +} + +#[test] +fn output_children_focus_survives_clearing_an_object_pick() { + let mut h = fixture(); + let document = h.app.session.doc.clone(); + for (kind, selection) in [ + ("sampling", super::super::RenderSelection::Sampling), + ("effects", super::super::RenderSelection::Effects), + ("check", super::super::RenderSelection::Check), + ] { + h.app.run("select.set", json!({"bodies":["Subject"]})).unwrap(); + h.app.run("view.render_select", json!({"kind":kind})).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, selection); + assert!(h.app.session.selection.is_empty()); + assert!(Arc::ptr_eq(&document, &h.app.session.doc)); + } +} + +// U10: existing fixed-budget review, never admission or full-quality certification. +mod quality_button_contract { + use super::*; + + fn gpu_fixture() -> Harness { + let mut h = fixture(); + super::super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace); + h.app.cam.fov = 0.6; + h.app.run("view.render_select", json!({"kind":"output"})).unwrap(); + h.frames(3); + h + } + + #[test] + fn quality_buttons_review_all_three_actual_catalog_budgets_before_any_edit() { + for (index, id, width, height, samples, depth, denoise) in + [(0, "Q-001", 960, 540, 64, 4, false), (1, "Q-002", 1600, 900, 512, 8, true), (2, "Q-003", 2560, 1440, 2048, 12, true)] + { + let mut h = gpu_fixture(); + let before = setups::snapshot(&h.app).unwrap(); + let doc = h.app.session.doc.clone(); + let history = (h.app.session.revision, h.app.session.undo.len()); + choose_quality(&mut h.app, index).unwrap(); + let review = h.app.render_workspace.view.library.review.as_ref().unwrap(); + assert!(!review.acknowledged); + assert_eq!(review.plan["id"], id); + assert_eq!(review.plan["status"], "fixed_budget_projection_not_full_quality_profile"); + assert_eq!(review.plan["settings"], json!({"width":width,"height":height})); + assert_eq!(review.plan["gpu_options"], json!({"samples":samples,"max_depth":depth,"seed":21026,"denoise":denoise})); + assert!(review.plan["omitted"].as_array().unwrap().iter().any(|v| v == "convergence_certification")); + assert_eq!(serde_json::to_value(setups::snapshot(&h.app).unwrap()).unwrap(), serde_json::to_value(before).unwrap()); + assert!(Arc::ptr_eq(&doc, &h.app.session.doc)); + assert_eq!(history, (h.app.session.revision, h.app.session.undo.len())); + } + } + + #[test] + fn quality_button_click_and_acknowledgement_save_one_current_shot_action() { + let mut h = gpu_fixture(); + h.app.render_workspace.view.studio.intensity = 0.42; + h.app.render_workspace.view.draft.exposure_ev = 1.23; + h.app.render_workspace.view.studio.ambient = [0.11, 0.22, 0.33]; + let camera = h.app.cam; + let shot = h.app.render_workspace.view.name.clone(); + let stage = h.app.render_workspace.view.stage; + let history = (h.app.session.revision, h.app.session.undo.len()); + let doc = h.app.session.doc.to_json(); + h.step(&json!({"click":{"handle":"render:quality:balanced"}})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), doc); + assert_eq!(history, (h.app.session.revision, h.app.session.undo.len())); + assert!(!h.app.render_workspace.view.library.review.as_ref().unwrap().acknowledged); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + assert!(h.app.render_workspace.view.library.review.is_none()); + assert_eq!(h.app.session.revision, history.0 + 1); + assert_eq!(h.app.session.undo.len(), history.1 + 1); + assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (1600, 900)); + assert_eq!((h.app.render_workspace.view.samples, h.app.render_workspace.view.max_depth, h.app.render_workspace.view.seed), (512, 8, 21026)); + assert!(h.app.render_workspace.view.studio.denoise); + assert_eq!(h.app.render_workspace.view.name, shot); + assert_eq!(h.app.render_workspace.view.stage, stage); + assert_eq!(h.app.render_workspace.view.method, ImageMethod::GpuRaytrace); + assert_eq!(h.app.cam, camera); + assert_eq!(h.app.render_workspace.view.studio.intensity, 0.42); + assert_eq!(h.app.render_workspace.view.studio.ambient, [0.11, 0.22, 0.33]); + assert_eq!(h.app.render_workspace.view.draft.exposure_ev, 1.23); + assert_eq!(h.app.session.doc.render.setups[&shot].width, 1600); + assert_eq!(quality_selection(&h.app), 1); + assert!(h.app.render_workspace.view.job.is_none(), "choosing quality never starts a renderer"); + } + + #[test] + fn quality_highlight_derives_every_projected_field_and_returns_to_custom() { + let mut h = gpu_fixture(); + for index in 0..3 { + let plan = h + .app + .run( + "render.quality.prepare", + json!({"id":(["Q-001","Q-002","Q-003"][index]),"variant":"fixed_samples_png","acknowledge_omissions":true}), + ) + .unwrap(); + apply_quality(&mut h.app, &plan).unwrap(); + assert_eq!(quality_selection(&h.app), index); + for field in 0..6 { + let original = ( + h.app.render_workspace.view.draft.width, + h.app.render_workspace.view.draft.height, + h.app.render_workspace.view.samples, + h.app.render_workspace.view.max_depth, + h.app.render_workspace.view.seed, + h.app.render_workspace.view.studio.denoise, + ); + match field { + 0 => h.app.render_workspace.view.draft.width += 1, + 1 => h.app.render_workspace.view.draft.height += 1, + 2 => h.app.render_workspace.view.samples += 1, + 3 => h.app.render_workspace.view.max_depth += 1, + 4 => h.app.render_workspace.view.seed += 1, + _ => h.app.render_workspace.view.studio.denoise = !original.5, + } + assert_eq!(quality_selection(&h.app), 3, "changed projected field {field}"); + ( + h.app.render_workspace.view.draft.width, + h.app.render_workspace.view.draft.height, + h.app.render_workspace.view.samples, + h.app.render_workspace.view.max_depth, + h.app.render_workspace.view.seed, + h.app.render_workspace.view.studio.denoise, + ) = original; + } + h.app.render_workspace.view.draft.exposure_ev = 0.37; + assert_eq!(quality_selection(&h.app), index, "highlight describes the budget, not a complete scene-quality tier"); + } + } + + #[test] + fn quality_buttons_refuse_other_methods_and_invalid_choices_without_mutation() { + let mut h = gpu_fixture(); + for method in [ImageMethod::CpuRaytrace, ImageMethod::Raster] { + h.app.render_workspace.view.method = method; + let before = format!("{:?}", h.app.render_workspace.view.draft); + let doc = h.app.session.doc.to_json(); + for index in 0..3 { + assert!(choose_quality(&mut h.app, index).is_err()); + assert!(quality_reason(&h.app, index).is_some()); + } + assert_eq!(quality_selection(&h.app), 3); + assert_eq!(h.app.render_workspace.view.method, method); + assert_eq!(format!("{:?}", h.app.render_workspace.view.draft), before); + assert_eq!(h.app.session.doc.to_json(), doc); + assert!(h.app.render_workspace.view.library.review.is_none()); + } + h.app.render_workspace.view.method = ImageMethod::GpuRaytrace; + assert!(choose_quality(&mut h.app, usize::MAX).is_err()); + assert!(h.app.render_workspace.view.library.review.is_none()); + } + + #[test] + fn quality_review_stays_bound_to_captured_draft_shot_method_and_document() { + for change in 0..4 { + let mut h = gpu_fixture(); + choose_quality(&mut h.app, 0).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":"render:review:acknowledge"}})).unwrap(); + match change { + 0 => h.app.render_workspace.view.draft.width = 333, + 1 => h.app.render_workspace.view.name = "Different shot".into(), + 2 => h.app.render_workspace.view.method = ImageMethod::CpuRaytrace, + _ => h.app.session.doc = Arc::new((*h.app.session.doc).clone()), + } + let doc = h.app.session.doc.to_json(); + let width = h.app.render_workspace.view.draft.width; + let history = (h.app.session.revision, h.app.session.undo.len()); + h.frames(3); + assert!(crate::scenario::rect_of("dialog:report:review:stale").is_some()); + let ok = crate::scenario::rect_of("dialog:ok").unwrap().center(); + h.step(&json!({"click":[ok.x,ok.y]})).unwrap(); + assert_eq!(h.app.session.doc.to_json(), doc); + assert_eq!(h.app.render_workspace.view.draft.width, width); + assert_eq!(history, (h.app.session.revision, h.app.session.undo.len())); + assert!(h.app.render_workspace.view.library.review.is_some()); + } + } + + #[test] + fn quality_custom_keeps_existing_sampling_navigation_on_all_methods() { + let mut h = gpu_fixture(); + for method in [ImageMethod::GpuRaytrace, ImageMethod::CpuRaytrace, ImageMethod::Raster] { + h.app.render_workspace.view.method = method; + let doc = h.app.session.doc.to_json(); + choose_quality(&mut h.app, 3).unwrap(); + assert_eq!(h.app.render_workspace.view.selection, super::super::super::RenderSelection::Sampling); + assert_eq!(h.app.render_workspace.view.method, method); + assert_eq!(h.app.session.doc.to_json(), doc); + } + } + + #[test] + fn quality_button_repaint_and_cancel_preserve_unsaved_draft_and_design() { + let mut h = gpu_fixture(); + h.app.render_workspace.view.draft.width = 777; + h.app.render_workspace.view.samples = 99; + let draft = serde_json::to_value(setups::snapshot(&h.app).unwrap()).unwrap(); + let doc = h.app.session.doc.to_json(); + let history = (h.app.session.revision, h.app.session.undo.len()); + h.frames(3); + assert_eq!(quality_selection(&h.app), 3); + choose_quality(&mut h.app, 2).unwrap(); + h.frames(3); + h.step(&json!({"click":{"handle":"dialog:cancel"}})).unwrap(); + assert!(h.app.render_workspace.view.library.review.is_none()); + assert_eq!(serde_json::to_value(setups::snapshot(&h.app).unwrap()).unwrap(), draft); + assert_eq!(h.app.session.doc.to_json(), doc); + assert_eq!(history, (h.app.session.revision, h.app.session.undo.len())); + } +} diff --git a/proposals/render/2026-10-31/c24-two-parentheses/delta.patch b/proposals/render/2026-10-31/c24-two-parentheses/delta.patch new file mode 100644 index 000000000..6e06e2682 --- /dev/null +++ b/proposals/render/2026-10-31/c24-two-parentheses/delta.patch @@ -0,0 +1,11 @@ +--- a/crates/ui-egui/src/render_workspace_inspector_tests.rs ++++ b/crates/ui-egui/src/render_workspace_inspector_tests.rs +@@ -2683,7 +2683,7 @@ + .app + .run( + "render.quality.prepare", +- json!({"id":["Q-001","Q-002","Q-003"][index],"variant":"fixed_samples_png","acknowledge_omissions":true}), ++ json!({"id":(["Q-001","Q-002","Q-003"][index]),"variant":"fixed_samples_png","acknowledge_omissions":true}), + ) + .unwrap(); + apply_quality(&mut h.app, &plan).unwrap(); diff --git a/proposals/render/2026-10-31/c24-two-parentheses/source-bindings.json b/proposals/render/2026-10-31/c24-two-parentheses/source-bindings.json new file mode 100644 index 000000000..4304f9f7b --- /dev/null +++ b/proposals/render/2026-10-31/c24-two-parentheses/source-bindings.json @@ -0,0 +1,33 @@ +{ + "schema": "portable-source-bindings-v1", + "scope": "One existing test expression, two inserted parentheses, no production change", + "path": "crates/ui-egui/src/render_workspace_inspector_tests.rs", + "before_sha256": "87c0acbdfd3e45128e3ced3819fa5b9740d8940eec2ce5402aa567b3435b53b9", + "before_bytes": 153358, + "candidate": "candidate/crates/ui-egui/src/render_workspace_inspector_tests.rs", + "candidate_sha256": "5dfa8eb8be2da3ae24895ed098ebe62029a4de69f508ab7e26cabdba54ad5292", + "candidate_bytes": 153360, + "delta": "delta.patch", + "delta_sha256": "a8b1b1134222c6579228d02dc0d8850828938fec824c468306325c23f6283850", + "delta_bytes": 597, + "immediate_receiver": "Actual C23 post-format test source; not the earlier public unformatted candidate", + "lineage": { + "prior_public_unit": "proposals/render/2026-10-31/c23-three-path-source/", + "prior_public_candidate_sha256": "867fbaa191e057b56dcc09b0d61e624edab130e53dab0ea3882e98ee850a2da6", + "actual_C23_post_format_source_manifest_sha256": "7cc6a040e808f5dd973310dd095f5a457ae482ab5a240309602c4f97d231b99e", + "C24_adopted_source_manifest_sha256": "2f39172dd42414588fb0c88cb23d30c2d5f626592ab3d4632b032701e85edbf1", + "C24_independent_expression_source_review_sha256": "ab7fd9e787e4cceb881047377d9efc640c53cf09166943ee412fe2c70dafa7b6", + "production_checkout_HEAD_at_source_adoption": "a077906234972dbbf11e80c54893f85ece97c8b7", + "archive_parent_commit_supplied_for_publication": "53a60b772d5c31a10bc86195814c86704d66c43f" + }, + "test_contract": { + "existing_case": "quality_highlight_derives_every_projected_field_and_returns_to_custom", + "test_declarations_before_and_after": 81, + "new_declarations": 0, + "other_fixture_ID_index_variant_acknowledgement_assertion_oracle_bytes_unchanged": true, + "selected_cases_UNRUN_on_C24_source": 953, + "required_TRUE_marker_contracts_UNRUN": 60 + }, + "C24_execution_status_at_curation": "Resource admission stop before combined Cargo build, as reported by Engineer; no passing normal gate, test run or readiness inferred", + "combined_build_or_test_qualification": false +}