fix(desktop): serialize generation-sensitive epoch tests with SCOPE_GENERATION_TEST_LOCK

test_full_tail_stop_spawn_receipt_register_save and
test_relay_mesh_preflight_precedes_stop both capture the scope generation via
current_scope_generation() and call into restart_under_captured_epoch_for or
restart_local_agent_on_config_change_for, which validate the generation under
a lock. Without SCOPE_GENERATION_TEST_LOCK, a concurrent test calling
next_scope_generation() can advance the counter between capture and validation,
causing the epoch to return Skipped instead of the expected outcome.

Both tests now hold SCOPE_GENERATION_TEST_LOCK for the duration of their
execution, matching the serialization pattern used by the workspace-transition
tests.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-08-05 01:59:07 -04:00
co-authored by Will Pfleger
parent 45f199ba5d
commit 7c455d9759
@@ -24,6 +24,7 @@ use super::*;
/// the captured definitions_dir so the spawn_fn can assert they arrive.
#[tokio::test]
async fn test_full_tail_stop_spawn_receipt_register_save() {
use crate::managed_agents::scope::SCOPE_GENERATION_TEST_LOCK;
use crate::managed_agents::{
storage::save_managed_agents_at, BackendKind, ManagedAgentPairRuntime, ManagedAgentRecord,
ManagedAgentRuntimeKey,
@@ -31,6 +32,11 @@ async fn test_full_tail_stop_spawn_receipt_register_save() {
use std::sync::{Arc, Mutex};
use tauri::Manager;
// Serialize generation-sensitive work across parallel tests.
let _gen_guard = SCOPE_GENERATION_TEST_LOCK
.lock()
.unwrap_or_else(|e| e.into_inner());
let tmp = tempfile::tempdir().unwrap();
let pubkey = "bb".repeat(32);
let relay_url = "wss://test.relay";
@@ -431,12 +437,18 @@ async fn test_full_tail_stop_spawn_receipt_register_save() {
async fn test_relay_mesh_preflight_precedes_stop() {
use super::super::restart_local_agent_on_config_change_for;
use crate::commands::global_agent_config::RestartOutcome;
use crate::managed_agents::scope::SCOPE_GENERATION_TEST_LOCK;
use crate::managed_agents::storage::save_managed_agents_at;
use crate::managed_agents::{
BackendKind, ManagedAgentPairRuntime, ManagedAgentRecord, ManagedAgentRuntimeKey,
};
use tauri::Manager;
// Serialize generation-sensitive work across parallel tests.
let _gen_guard = SCOPE_GENERATION_TEST_LOCK
.lock()
.unwrap_or_else(|e| e.into_inner());
let tmp = tempfile::tempdir().unwrap();
let app = make_mock_app();