Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

test(agy): isolate rollback tests from concurrently swapped test homes

Jasonec663402baa5
diff --git a/src-tauri/src/services/agy_account/tests.rs b/src-tauri/src/services/agy_account/tests.rs
index 9787e601b..32dc407f8 100644
--- a/src-tauri/src/services/agy_account/tests.rs
+++ b/src-tauri/src/services/agy_account/tests.rs
@@ -95,6 +95,8 @@ mod switching {
use crate::provider::{AuthBinding, AuthBindingSource, Provider, ProviderMeta};
use crate::services::provider::agy_direct::save_from_editor;
use crate::store::AppState;
+ use crate::test_support::TestHome;
+ use serial_test::serial;
fn official_card(account: &str) -> Provider {
let mut provider =
@@ -139,7 +141,12 @@ mod switching {
}
#[test]
+ #[serial]
fn a_missing_bound_account_leaves_the_login_and_provider_unchanged() {
+ // A failed save rolls the row back only when no agy operation is pending in the
+ // device store, which lives under the process-wide test home. Serial tests swap
+ // that home and may hold a pending agy operation, so use a home of our own.
+ let _home = TestHome::new();
let (_dir, login, manager) = manager();
let state = AppState::new(Arc::new(Database::memory().unwrap()));
set_live(&login, &credential("alice", "a1"));
@@ -188,9 +195,13 @@ mod switching {
}
#[test]
+ #[serial]
fn cloud_snapshot_waits_for_a_failed_binding_save_to_roll_back() {
use crate::services::sync_protocol::sync_mutex;
+ // Own test home, as in the test above.
+ let _home = TestHome::new();
+
struct CancelUnlock;
impl AgyLoginStore for CancelUnlock {
@@ -217,13 +228,25 @@ mod switching {
.db
.save_provider(&AppType::Agy, &official_card("alice"))
.unwrap();
- let before = state.db.export_sql_string_for_sync().unwrap();
+ // The dump header carries a per-second timestamp; drop it so two snapshots
+ // taken across a second boundary still compare equal.
+ let snapshot = || {
+ state
+ .db
+ .export_sql_string_for_sync()
+ .unwrap()
+ .lines()
+ .filter(|line| !line.starts_with("-- 生成时间:"))
+ .collect::<Vec<_>>()
+ .join("\n")
+ };
+ let before = snapshot();
let error = save_from_editor(&state, &manager, official_card("bob")).unwrap_err();
assert_eq!(error.to_string(), "keychain unlock cancelled");
let _sync_guard = sync_mutex().blocking_lock();
- assert_eq!(state.db.export_sql_string_for_sync().unwrap(), before);
+ assert_eq!(snapshot(), before);
}
#[tokio::test]