| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/desktop/internal/workspacestate" |
| 7 | ) |
| 8 | |
| 9 | // Exercise the reported ordering on disposable state, including a retired |
| 10 | // draft database that must not participate in either creation or reopening. |
| 11 | func TestManualCreationAfterArchive(t *testing.T) { |
| 12 | for _, scope := range []string{"global", "project"} { |
| 13 | t.Run(scope, func(t *testing.T) { |
| 14 | a := newManualSessionTestApp(t) |
| 15 | corruptRetiredDraftDatabase(t) |
| 16 | root := "" |
| 17 | if scope == "project" { |
| 18 | root = t.TempDir() |
| 19 | } |
| 20 | create := func(id string) ManualSessionCreationView { |
| 21 | t.Helper() |
| 22 | if _, err := a.BeginManualSessionCreation(ManualSessionCreationRequest{OperationID: id, Scope: scope, WorkspaceRoot: root}); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | a.manualCreationTasks.Wait() |
| 26 | view, err := a.GetManualSessionCreation(id) |
| 27 | if err != nil || view.Phase != "ready" { |
| 28 | t.Fatalf("creation: %+v %v", view, err) |
| 29 | } |
| 30 | if _, err := a.OpenSession(view.Ref); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | return view |
| 34 | } |
| 35 | first := create("manual-before-archive") |
| 36 | receipt, err := a.ArchiveSessionTarget(SessionSelector{Ref: &first.Ref}) |
| 37 | if err != nil || !receipt.Committed { |
| 38 | t.Fatalf("archive: %+v %v", receipt, err) |
| 39 | } |
| 40 | assertNoVisibleRuntime(t, a) |
| 41 | second := create("manual-after-archive") |
| 42 | if second.Ref == first.Ref { |
| 43 | t.Fatal("new creation reused the archived identity") |
| 44 | } |
| 45 | state, err := a.workspaceRegistry().Load(t.Context()) |
| 46 | if err != nil { |
| 47 | t.Fatal(err) |
| 48 | } |
| 49 | if state.SessionStates[first.Ref.SessionID].Lifecycle != workspacestate.Archived || state.SessionStates[second.Ref.SessionID].Lifecycle != workspacestate.Active { |
| 50 | t.Fatal("archive/new lifecycle did not remain independent") |
| 51 | } |
| 52 | pending, err := a.ListManualSessionCreations() |
| 53 | if err != nil || len(pending) != 0 { |
| 54 | t.Fatalf("creation recovery remained: %+v %v", pending, err) |
| 55 | } |
| 56 | }) |
| 57 | } |
| 58 | } |
| 59 |