| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/desktop/internal/workspacestate" |
| 8 | ) |
| 9 | |
| 10 | func TestWorkspacePlaceholderRuntimeIdentity(t *testing.T) { |
| 11 | isolateDesktopUserDirs(t) |
| 12 | a := NewApp() |
| 13 | root := t.TempDir() |
| 14 | nodes := a.projectTreeRuntimeTopics([]catalogRuntimeSnapshot{{ |
| 15 | tabID: "starting", scope: "project", workspaceRoot: root, topicID: "draft", open: true, |
| 16 | }}) |
| 17 | if len(nodes) != 1 || !slices.Contains(nodes[0].Node.IdentityAliases, "topic\x00draft") { |
| 18 | t.Fatalf("startup must identify its owned placeholder: %+v", nodes) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func TestWorkspaceCanonicalPlaceholderAliasIsUnambiguous(t *testing.T) { |
| 23 | state := workspacestate.State{ |
| 24 | Workspaces: map[string]workspacestate.Workspace{"w": {ID: "w", SessionIDs: []string{"first"}}}, |
| 25 | Presentation: map[string]workspacestate.Presentation{"first": {TopicID: "draft"}, "branch": {TopicID: "draft"}}, |
| 26 | } |
| 27 | if !slices.Contains(sourceAliases(state, "w", "first"), "topic\x00draft") { |
| 28 | t.Fatal("the first durable session must retire its placeholder") |
| 29 | } |
| 30 | w := state.Workspaces["w"] |
| 31 | w.SessionIDs = append(w.SessionIDs, "branch") |
| 32 | state.Workspaces["w"] = w |
| 33 | for _, id := range w.SessionIDs { |
| 34 | if slices.Contains(sourceAliases(state, "w", id), "topic\x00draft") { |
| 35 | t.Fatal("a shared topic is not a unique session alias") |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 |