From 98ed022428c7d9a7231b71bb6dec36ea9b39dabb Mon Sep 17 00:00:00 2001 From: rcourtman <8825017+rcourtman@users.noreply.github.com> Date: Mon, 5 Oct 2026 17:25:50 +0100 Subject: [PATCH] Give Patrol autopilot tests their own session store TestPatrolAutopilotStoreUnavailableDoesNotChangeModeOrFabricateEvidence built its request through patrolAutopilotSessionRequest, which writes a session into the process-global store, but never initialized one. Run alone it panicked in GetSessionStore; in the package run it passed only because an earlier test left a store behind. The rest of the file got its store from newPatrolAutopilotTestHandler, which called InitSessionStore on a t.TempDir() and never cleared it, so these tests were also the ones leaving a store pointed at a deleted directory for whatever ran next. Both now go through initPatrolAutopilotSessionStore, which follows the package's existing resetSessionStoreForTests/t.Cleanup pattern: start from no store, initialize one on a temp dir, and clear it when the test ends. Every test in the file passes when run alone. --- internal/api/patrol_autopilot_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/api/patrol_autopilot_test.go b/internal/api/patrol_autopilot_test.go index 27c720c088..8d91973ece 100644 --- a/internal/api/patrol_autopilot_test.go +++ b/internal/api/patrol_autopilot_test.go @@ -54,10 +54,17 @@ func TestPatrolRunAPIRejectsClientAuthoredContext(t *testing.T) { } } +func initPatrolAutopilotSessionStore(t *testing.T, dataPath string) { + t.Helper() + resetSessionStoreForTests() + t.Cleanup(resetSessionStoreForTests) + InitSessionStore(dataPath) +} + func newPatrolAutopilotTestHandler(t *testing.T, orgID string, now *time.Time) (*AISettingsHandler, *config.ConfigPersistence) { t.Helper() dir := t.TempDir() - InitSessionStore(dir) + initPatrolAutopilotSessionStore(t, dir) persistence := config.NewConfigPersistence(dir) cfg := config.NewDefaultAIConfig() cfg.PatrolAutonomyLevel = config.PatrolAutonomyApproval @@ -429,6 +436,7 @@ func TestPatrolAutopilotVersionRotationAndRevocationRaceFailClosed(t *testing.T) func TestPatrolAutopilotStoreUnavailableDoesNotChangeModeOrFabricateEvidence(t *testing.T) { now := time.Date(2026, 7, 11, 20, 0, 0, 0, time.UTC) + initPatrolAutopilotSessionStore(t, t.TempDir()) handler := newTestAISettingsHandler(&config.Config{}, nil, nil) handler.SetPatrolAutopilotServerPolicyProvider(func() unifiedresources.PatrolAutopilotServerPolicy { return unifiedresources.CurrentPatrolAutopilotServerPolicy(now)