mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-24 04:33:17 +00:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user