From bf5efadbf13d7c5c3598841dd86f2c7c5eee4941 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Sat, 5 Dec 2026 20:18:57 +0800 Subject: [PATCH] fix(xiaoyi): clear saved_revision on loaded_draft template outputs and update cross-output test --- .../crates/ui-egui/src/jiansun.rs | 3 +- .../ui-egui/src/jiansun/client_update.rs | 35 +++++++++++++++++++ .../src/jiansun/product_production/tests.rs | 3 +- .../ui-egui/src/jiansun/project_file.rs | 30 ++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs index 510a267d..381348fd 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs @@ -4945,7 +4945,8 @@ impl Workspace { && let Some(state) = app.session.active_mut().filter(|state| { state.doc.id.0 == id && state.revision == rev - && (state.path.is_none() + && (self.loaded_draft == Some(id) + || state.path.is_none() || meta["savedPath"].as_str().is_some_and(|path| { state.path.as_deref().is_some_and(|source| std::path::Path::new(source) == std::path::Path::new(path)) })) diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs index 78de1f1d..a6f2bbd2 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs @@ -405,6 +405,41 @@ mod tests { assert!(w.client_update.restart_requested); } + #[test] + fn client_update_apply_clears_dirty_when_template_output_path_differs_from_saved_path() { + let (tx, requests) = mpsc::channel(); + let (_, rx) = mpsc::channel(); + let mut w = Workspace::new(tx, rx); + while requests.try_recv().is_ok() {} + w.busy = None; + w.account = json!({"id":"qa"}); + let mut session = photocraft_engine::Session::new(); + session.execute("file.new", json!({"width":40,"height":50})).unwrap(); + let mut app = PhotocraftApp::new(session, crate::Services::default()); + let doc = app.session.active().unwrap().doc.id.0; + w.loaded_draft = Some(doc); + w.configure_client_update(json!({"version":"1.0.0"}), true, |_| Ok(())); + w.client_update.sync_scope(&w.account, &w.origin); + w.client_update.state = json!({"status":"ready","latest":{"version":"1.1.0"}}); + app.session.active_mut().unwrap().path = Some("C:/Users/demo/projects/p1/template-outputs/detail.pcraft".into()); + app.session.edit("修改模板画布", |document, _| { document.name = "详情页".into(); Ok(()) }).unwrap(); + let rev = app.session.active().unwrap().revision; + assert!(app.has_unsaved_work()); + + let result = w.client_update_action(&app, &json!({"op":"apply"})).unwrap(); + assert_eq!(result["saving"], true); + assert!(w.client_update.pending_apply); + let Request::Save(_, saved_rev, _) = requests.try_recv().unwrap() else { panic!("expected Request::Save") }; + assert_eq!(saved_rev, rev); + + w.receive_event(&mut app, &egui::Context::default(), Event::Saved(doc, rev, json!({ + "savedPath": "C:/Users/demo/projects/p1/canvas.pcraft", + }))); + assert!(!app.has_unsaved_work()); + assert!(!w.client_update.pending_apply); + assert!(w.client_update.restart_requested); + } + #[test] fn settings_open_triggers_check_only_after_cooldown_and_not_when_ready_or_busy() { let base = Instant::now(); diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/product_production/tests.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/product_production/tests.rs index 5b3a00ad..6212a44d 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/product_production/tests.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/product_production/tests.rs @@ -2422,7 +2422,8 @@ fn reading_another_product_output_keeps_the_agent_lease_and_saves_user_edits_to_ assert_eq!(w.product_view_state()["working"]["variantId"], "wood"); assert_eq!(w.pi_run.as_deref(), Some("original-run")); let read = json!({"run":"original-run","documentId":doc,"page":0}); - assert!(super::super::pi_bridge::private_action_in_ui(&mut w, &mut app, &ctx, "pi-product-screen", &read).is_err()); + assert!(w.product_view_detached()); + assert!(super::super::pi_bridge::private_action_in_ui(&mut w, &mut app, &ctx, "pi-product-screen", &read).is_ok()); let (reply, receipt) = mpsc::channel(); w.with_product_target(&mut app, |w, app| { w.receive_event(app, &ctx, super::super::Event::PiAction("pi-product-screen".into(), read, reply)); diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_file.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_file.rs index 0068a1da..0ebd1192 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_file.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_file.rs @@ -576,6 +576,36 @@ mod tests { assert_eq!(app.ui.status, "已保存"); } + #[test] + fn file_save_clears_dirty_when_template_output_path_differs_from_saved_path() { + let (mut w, mut app, requests, _, _) = native_fixture(); + let ctx = egui::Context::default(); + let doc = app.session.active().unwrap().doc.id.0; + w.loaded_draft = Some(doc); + w.draft_flush = Some(std::sync::Arc::new(|_, _, _, _, _| Ok(()))); + app.session.active_mut().unwrap().path = Some("C:/Users/demo/projects/p1/template-outputs/detail.pcraft".into()); + app.session.edit("修改模板画布", |document, _| { + document.name = "详情页".into(); + Ok(()) + }).unwrap(); + let rev = app.session.active().unwrap().revision; + assert!(app.has_unsaved_work()); + + app.jiansun = Some(w); + let result = app.save_xiaoyi_project(&ctx, false).unwrap().unwrap(); + assert_eq!(result["savingProject"], true); + let Request::Save(_, saved_rev, meta) = requests.try_recv().unwrap() else { panic!("expected in-place Request::Save") }; + assert_eq!(saved_rev, rev); + assert!(meta["deliverProject"].is_null()); + + let mut w = app.jiansun.take().unwrap(); + w.receive_event(&mut app, &ctx, Event::Saved(doc, rev, json!({ + "savedPath": "C:/Users/demo/projects/p1/canvas.pcraft", + }))); + assert!(!app.has_unsaved_work()); + assert_eq!(app.ui.status, "已保存"); + } + #[test] fn file_save_as_uses_delivery_dir_directly_without_folder_picker() { let (mut w, mut app, requests, _, _) = native_fixture();