返回 DeepSeek-Reasonix
legacy_empty_session_cleanup_owners_test.go
根目录 / desktop / legacy_empty_session_cleanup_owners_test.go
1 package main
2
3 import (
4 "testing"
5
6 "reasonix/desktop/internal/workspacestate"
7 "reasonix/internal/session"
8 )
9
10 func TestLegacyCleanupProtectsRegistryRecoveryOwners(t *testing.T) {
11 for _, fixture := range []struct {
12 name string
13 reason string
14 own func(*testing.T, *App, session.SessionRef, string, string)
15 }{
16 {
17 name: "recovery entry", reason: "recovery_owner",
18 own: func(t *testing.T, app *App, ref session.SessionRef, workspaceID, workspaceRoot string) {
19 t.Helper()
20 if err := app.workspaceRegistry().RecordRecovery(t.Context(), workspacestate.RecoveryEntry{
21 ID: "cleanup-recovery", SourceKey: "cleanup-source", SessionID: ref.SessionID, WorkspaceID: workspaceID,
22 Scope: "project", WorkspaceRoot: workspaceRoot, Format: "canonical", Reason: "interrupted", Status: "pending",
23 }); err != nil {
24 t.Fatal(err)
25 }
26 },
27 },
28 {
29 name: "pending operation", reason: "pending_operation",
30 own: func(t *testing.T, app *App, ref session.SessionRef, workspaceID, _ string) {
31 t.Helper()
32 if err := app.workspaceRegistry().BeginOperation(t.Context(), workspacestate.Operation{
33 ID: "cleanup-operation", Kind: "command", Lifecycle: workspacestate.Active,
34 SessionIDs: []string{ref.SessionID}, WorkspaceID: workspaceID,
35 }); err != nil {
36 t.Fatal(err)
37 }
38 },
39 },
40 } {
41 t.Run(fixture.name, func(t *testing.T) {
42 app, workspaceRoot := newLegacyCleanupTestApp(t)
43 ref, workspaceID := createLegacyCleanupSession(t, app, workspaceRoot, "legacy-registry-owner", false)
44 fixture.own(t, app, ref, workspaceID, workspaceRoot)
45 if err := app.initializeLegacyEmptySessionCleanupBatch(); err != nil {
46 t.Fatal(err)
47 }
48 app.processLegacyCleanupSession(cleanupCandidate(t, app, "session:"+ref.SessionID))
49 if got := cleanupCandidate(t, app, "session:"+ref.SessionID); got.Phase != "protected" || got.Reason != fixture.reason {
50 t.Fatalf("registry-owned candidate = %+v", got)
51 }
52 })
53 }
54 }
55
55 lines GO