From 80926a20e4ddbbef3dc61b9b57972aed46db8dff Mon Sep 17 00:00:00 2001 From: AlexJoaquimPereira Date: Mon, 16 Nov 2026 23:45:25 +0530 Subject: [PATCH] Keep a pin size estimate in its own project's dialog (R2.10) A pin estimate that finished after the person cancelled or opened another project's dialog wrote its size into the open draft; an estimate error could also fall through to a toast. The estimate result and every project_pin_create error now name the project (estimate errors also say estimate), and the dialog fills only when the Pin dialog is open for the same normalized project. Estimate errors the open dialog rejects are swallowed; a failed pin creation still tells the person. Regressions: a late estimate and a late estimate error for another project, an estimate after the dialog closed, and a failed creation that still toasts. Engine tests check the estimate result and both error details, including an open-project failure. --- crates/engine/src/tools/pin_tools.rs | 35 +++++++++-- crates/ui-egui/src/pins.rs | 92 +++++++++++++++++++++++++++- docs/ROADMAP.md | 8 ++- docs/STATUS.md | 1 + 4 files changed, 126 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/tools/pin_tools.rs b/crates/engine/src/tools/pin_tools.rs index 3523ca9e5..a45b9f393 100644 --- a/crates/engine/src/tools/pin_tools.rs +++ b/crates/engine/src/tools/pin_tools.rs @@ -223,11 +223,11 @@ fn start_program(ctx: &mut Ctx<'_>, app: &Path, log: &Path, another: bool, label fn project_pin_create(ctx: &mut Ctx<'_>, params: Value) -> Result { let p: CreateParams = parse_params(params)?; - let ws = open_project(&p.project)?; + let ws = open_project(&p.project).map_err(|e| e.with_details(json!({"project": &p.project, "estimate": p.estimate})))?; let godot = godot(ctx); if p.estimate { - let size = pins::estimate(&ws, godot.as_deref())?; - return Ok(ToolOutput::Value(json!({"estimate": size}))); + let size = pins::estimate(&ws, godot.as_deref()).map_err(|e| e.with_details(json!({"project": &ws.root, "estimate": true})))?; + return Ok(ToolOutput::Value(json!({"project": &ws.root, "estimate": size}))); } let cancel = ctx.cancel.clone(); let mut last = std::time::Instant::now(); @@ -239,7 +239,7 @@ fn project_pin_create(ctx: &mut Ctx<'_>, params: Value) -> Result 0); assert!(pins::list(&ws).is_empty(), "an estimate pins nothing"); let made = call("project_pin_create", json!({"project": ws.root})).unwrap(); @@ -435,4 +436,30 @@ mod tests { assert_eq!(list["copied_bytes"], light["pin"]["bytes"]); assert_eq!(call("project_pin_open", json!({"project": ws.root, "pin": 1})).unwrap_err().code, ErrorCode::NotFound); } + + #[test] + fn an_estimate_error_names_the_project_it_was_for() { + let d = tempfile::tempdir().unwrap(); + let ws = Workspace::create(d.path(), "Empty", "nothing built", TargetRef::None).unwrap(); + let e = Engine::new(crate::testing::session()); + let err = e + .call("project_pin_create", json!({"project": &ws.root, "estimate": true}), CallOptions::new(Caller::Cli).with_consent(Consent::Granted)) + .unwrap_err(); + let details = err.details.as_ref().expect("an estimate error names its project"); + assert_eq!(details["project"].as_str(), ws.root.to_str()); + assert_eq!(details["estimate"].as_bool(), Some(true)); + } + + #[test] + fn an_open_project_error_on_an_estimate_names_the_project() { + let d = tempfile::tempdir().unwrap(); + let root = d.path().join("missing"); + let e = Engine::new(crate::testing::session()); + let err = e + .call("project_pin_create", json!({"project": &root, "estimate": true}), CallOptions::new(Caller::Cli).with_consent(Consent::Granted)) + .unwrap_err(); + let details = err.details.as_ref().expect("an estimate open error names its project"); + assert_eq!(details["project"].as_str(), root.to_str()); + assert_eq!(details["estimate"].as_bool(), Some(true)); + } } diff --git a/crates/ui-egui/src/pins.rs b/crates/ui-egui/src/pins.rs index cd6fa3dcc..7cc238634 100644 --- a/crates/ui-egui/src/pins.rs +++ b/crates/ui-egui/src/pins.rs @@ -19,6 +19,26 @@ const POLL: Duration = Duration::from_secs(3); /// Above this, the pin dialog points out that a frozen copy is big. const BIG_COPY: u64 = 1_000_000_000; +/// Whether two project paths name the same folder after resolving `.` and `..`. +fn same_project(named: &str, project: &Path) -> bool { + craft_anything_engine::workspace::normalized(Path::new(named)) == craft_anything_engine::workspace::normalized(project) +} + +/// Whether an estimate result names the project whose dialog is open. A missing name is another +/// project's (an older engine's estimate) and must not fill this dialog. +fn estimate_for(value: &Value, project: &Path) -> bool { + value.get("project").and_then(Value::as_str).is_some_and(|named| same_project(named, project)) +} + +/// Whether a pin create error names the project whose dialog is open. Errors that carry no project +/// (a malformed request, a lock) keep the existing modal guard. +fn error_for_project(error: &ToolError, project: &Path) -> bool { + match error.details.as_ref().and_then(|d| d.get("project")).and_then(Value::as_str) { + Some(named) => same_project(named, project), + None => true, + } +} + /// One pin as the sidebar shows it. #[derive(Debug, Clone, PartialEq)] pub struct PinRow { @@ -92,12 +112,19 @@ impl CraftApp { } ("project_pins_list", Err(e)) => log::warn!("pinned builds couldn't be read: {}", e.message), ("project_pin_create", Ok(v)) if v.get("estimate").is_some() => { - let bytes = |k: &str| v["estimate"][k].as_u64().unwrap_or(0); - self.state.pin_draft.size = Some(Ok((bytes("bytes"), bytes("light_bytes")))); + if self.state.modal == Some(Modal::Pin) && estimate_for(&v, &self.state.pin_draft.project) { + let bytes = |k: &str| v["estimate"][k].as_u64().unwrap_or(0); + self.state.pin_draft.size = Some(Ok((bytes("bytes"), bytes("light_bytes")))); + } } - ("project_pin_create", Err(e)) if self.state.modal == Some(Modal::Pin) && self.state.pin_draft.size.is_none() => { + ("project_pin_create", Err(e)) + if self.state.modal == Some(Modal::Pin) && self.state.pin_draft.size.is_none() && error_for_project(&e, &self.state.pin_draft.project) => + { self.state.pin_draft.size = Some(Err(e.for_people())); } + // An estimate error the open dialog rejected: it is not this dialog's to show, and it + // is not a failed pin creation either, so it must not become a toast. + ("project_pin_create", Err(e)) if e.details.as_ref().and_then(|d| d.get("estimate")).and_then(Value::as_bool) == Some(true) => {} ("project_pin_create", Ok(v)) => { let name = v["pin"]["name"].as_str().unwrap_or_default(); self.toast(trf("Pinned: {name}. Open it from the sidebar any time.", &[("name", name)]), false); @@ -371,3 +398,62 @@ pub fn delete_modal(app: &mut CraftApp, ui: &mut Ui, project: &Path, id: u32, cl } }); } + +#[cfg(test)] +mod tests { + use super::*; + use std::path::PathBuf; + + fn draft(project: &str) -> PinDraft { + PinDraft { project: PathBuf::from(project), ..Default::default() } + } + + fn app() -> CraftApp { + crate::demo::app(crate::demo::engine(craft_anything_engine::Mode::Beginner, true)) + } + + #[test] + fn a_late_estimate_for_another_project_is_ignored() { + let mut app = app(); + app.state.modal = Some(Modal::Pin); + app.state.pin_draft = draft("/projects/b"); + app.pin_done("project_pin_create", Ok(json!({"project": "/projects/a", "estimate": {"bytes": 10, "light_bytes": 5}}))); + assert!(app.state.pin_draft.size.is_none(), "another project's estimate must not land in this dialog"); + app.pin_done("project_pin_create", Ok(json!({"project": "/projects/b", "estimate": {"bytes": 10, "light_bytes": 5}}))); + assert_eq!(app.state.pin_draft.size, Some(Ok((10, 5)))); + } + + #[test] + fn a_late_estimate_error_for_another_project_is_ignored() { + let mut app = app(); + app.state.modal = Some(Modal::Pin); + app.state.pin_draft = draft("/projects/b"); + let error = ToolError::invalid("nothing to pin").with_details(json!({"project": "/projects/a", "estimate": true})); + app.pin_done("project_pin_create", Err(error)); + assert!(app.state.pin_draft.size.is_none(), "another project's error must not land in this dialog"); + assert!(app.state.toasts.is_empty(), "an ignored estimate error must not become a toast: {:?}", app.state.toasts); + let error = ToolError::invalid("nothing to pin").with_details(json!({"project": "/projects/b", "estimate": true})); + app.pin_done("project_pin_create", Err(error)); + assert!(matches!(app.state.pin_draft.size, Some(Err(_)))); + } + + #[test] + fn a_failed_pin_creation_still_tells_the_person() { + let mut app = app(); + app.state.modal = Some(Modal::Pin); + app.state.pin_draft = draft("/projects/b"); + let error = ToolError::invalid("copy failed").with_details(json!({"project": "/projects/a"})); + app.pin_done("project_pin_create", Err(error)); + assert!(app.state.pin_draft.size.is_none(), "another project's creation error isn't this dialog's"); + assert!(app.state.toasts.iter().any(|(text, error)| *error && text.contains("copy failed")), "{:?}", app.state.toasts); + } + + #[test] + fn an_estimate_does_not_land_after_the_dialog_closed() { + let mut app = app(); + app.state.modal = None; + app.state.pin_draft = draft("/projects/b"); + app.pin_done("project_pin_create", Ok(json!({"project": "/projects/b", "estimate": {"bytes": 10, "light_bytes": 5}}))); + assert!(app.state.pin_draft.size.is_none()); + } +} diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 15d84545f..ee4df20cd 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -1907,9 +1907,11 @@ to the project next. loaded machine could grow the file past the bound with nothing wrong. The stand-in now reads its own log and stops once it has seen a cut and written past it — claimed: muraa-p, branch test/r2.10-log-cap-waits-for-cut -- [ ] A slow pin size estimate that finishes after the person cancels or opens another project's - dialog is applied to the open dialog: the estimate and its errors should name their project, - and the dialog should ignore a result for another project or a closed dialog +- [x] A slow pin size estimate that finished after the person cancelled or opened another + project's dialog was applied to the open dialog: the estimate and its errors now name their + project, and the dialog ignores a result for another project or a closed dialog. The result + and error detail carry the project; UI regressions cover a late estimate, a late error and a + closed dialog — claimed: AlexJoaquimPereira, branch bugfix/r2.10-pin-estimate-project - [ ] Opening a pin that's already running brings its window to the front, instead of a message - [x] How much space pins take in Settings diff --git a/docs/STATUS.md b/docs/STATUS.md index a50af2c91..8c4dace21 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -68,6 +68,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie | New-project toolchains | New Python, Go, .NET, Maven, Gradle and Make projects use the same build catalogue as existing projects (`engine/src/toolchains.toml`). A Python project without a root entrypoint can start its one installed `[project.scripts]` console wrapper from its virtual environment. Shared launch recipes let screenshots, self-tests and Play start Python `main.py`, `app.py` or `__main__.py`, a single Python package with a `/__main__.py` as `python3 -m ` in a project with a Python marker, Go with a root `main.go` or a single `cmd//main.go`, one root `.csproj`, and the single runnable jar (its manifest names a `Main-Class`) a Maven (`target/*.jar`) or Gradle (`build/libs/*.jar`) build left, with `java -jar`. Maven builds with `package -DskipTests`, so that jar is this build's. Python uses a project-local virtual environment when present, resolves its executable to an absolute path even for relative project folders, and forces fresh syntax compilation; .NET passes app options after `--`. Manifest markers take priority over standalone Python files. Runtime window-capture requests normalize relative project and runner paths to absolute paths. Godot and Electron receive an absolute project path when launched from a relative workspace. Existing packaged programs, Rust, Electron and Godot keep launch priority. Multiple `.csproj`, package or runnable-jar matches or a capped scan do not choose a project. Other layouts still need a packaged program or another launch recipe | Catalogue and launch regressions cover argv boundaries, ambiguous entrypoints, scan limits and Windows/local interpreter selection, including relative project folders and unchanged argument boundaries. Capture-request tests cover relative placements and PATH results, local interpreters and optional UI-tree output without opening a window. An owned interpreter stand-in runs the full new-project build/screenshot path, rejects failed builds, and verifies a failed screenshot cannot reuse an old PNG. An opt-in real Python 3.15.2 fixture on macOS passes build/screenshot checks, ignores invalid virtualenv code, and rejects a syntax error even when its mtime matches the cached version. Without `compileall -f` that same syntax-error probe incorrectly exits zero. Real Go/.NET/Maven/Gradle runs, Windows and GUI apps have not been verified for this change; `java -jar` on a real jar has not been run | | Relative project folders | Engine build arguments, option runs (`--screenshot`, `--self-test`), console run checks, Play and pins resolve their program, working directory and option/output paths to absolute paths before starting a child in `app/`. | Engine and AI regressions cover a relative workspace with a built program: Play and a pinned copy start and exit, an option run saves its file, a console run check compares its output, and Unity build arguments stay absolute; existing absolute-path controls remain. | | Cargo target directories | A Rust build's program is looked for under `CARGO_TARGET_DIR`, then the closest `config`/`config.toml` `build.target-dir` (project or ancestor), then the default `target/`. A shared or ancestor target outside the app supplies only a program the manifests name, and only one whose Cargo record (`.d` beside it) lists the app's sources, so another project's program of the same name in a shared `CARGO_TARGET_DIR` isn't taken; of the programs that count, the newest is started. Without a name, only target directories inside the app are searched. A pin made before programs were recorded starts only what is inside its own copy. A pin copies a program built outside the app into its own `pin-program/` folder and records the copy. Play, screenshot and self-test checks use it. | An AI regression with `.cargo/config.toml` `target-dir = "out"` fails before the fix; engine tests cover the environment (relative and absolute), a shared directory's unrelated executable, a named program from a shared directory, a project and ancestor setting, a relative app below a config, the legacy `config` preference and no fallthrough, the pin copy, a same-named program in a shared directory with no record or another project's record (and the newer of two of the project's own builds), and an older pin beside a newer build in a Cargo setting above it. Not handled: `build.dep-info-basedir` makes Cargo's record list relative paths, so a program built outside the app with that setting isn't found; a program of the same name from a project that depends on the app by path counts as the app's. No live build with a custom target dir was run. | +| Pin estimate dialog | A pin size estimate that finishes after the dialog closed or another project's dialog opened is ignored; the estimate result and its errors name the project they were for, and the matching project still fills the dialog. | UI regressions: a late estimate or error for another project, and an estimate after the dialog closed, leave the open draft unchanged; the matching project fills it. Engine regression: an estimate result and an estimate error name their project. | | Keep non-UTF-8 Godot paths from opening a different project | Decline a Godot launch when its project path cannot be represented as UTF-8 instead of silently replacing bytes in the selected path. | Regression fixtures cover two distinct Unix project directories whose paths collapse under lossy conversion, plus the valid Unicode project. | | Cargo paths in Rust binaries | A versioned directory contributes dependency evidence only for a valid crate name and complete semantic version. Prerelease and build identifiers remain available. | Mixed registry-style path evidence with invalid names, invalid versions and a versioned dependency. | | Mac call observation | `apple_calls_observe` launches an executable under LLDB, records named function hits and reports a debugger refusal as an error with remediation. | Opt-in engine regression on arm64 macOS 27.0.1 with Apple LLDB 2100.0.16.4 recorded `alpha` and `beta` in order and returned `ProgramFailed` for a non-executable input (#1844). |