Skip to content

Commit dbc4ebd

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(desktop): key desktop windows by an opaque WindowId
## What Changed Main mints a random `WindowId` (UUID v4, `node:crypto`) per desktop window and passes it to the renderer as the `--t3code-window-id` preload argument. The registry, preview ownership, Hyprland claims, the snapshot sender check and the update-restore manifest key by it. Project identity stays as data on the window record. - `WindowRegistry.fork.ts` (new): registry keyed by `WindowId`; identity lookup is a scan; a restored id is reused unless a live window holds it. - `WindowId.fork.ts` (new): brand, preload argument, validation; package-free for the sandboxed preload. - `ElectronWindow.ts`, `DesktopWindow.ts`: one-line `multi-window` hooks delegate to the registry; `getOrCreate` passes the reserved id to `create`. - `WindowPolicy*.ts`, `Manager.ts`: preview owner is `WindowId | "app"`; the bridge exposes `windowId`. - `HyprlandPlacement.ts`: claims and moves key by `WindowId`. - `DesktopWindowSession.ts`, `DesktopStartupDrain.fork.ts`, `DesktopUpdates.ts`: the manifest carries an optional `windowId`; restore reopens under the old id. A manifest from before this change still restores. ## Why A project key cannot name two windows on the same project, or a window whose project changes. An opaque id keys the window itself, so #1342 through #1345 can build on it. None of them is pre-built here. Closes #1341 ### Close conditions - [x] Registry: keyed by `WindowId` - `ElectronWindow.fork.test.ts`: "keys each window by a minted WindowId, never by what it shows", "reuses a restored WindowId unless a live window already holds it" - [x] Previews: ownership keyed by `WindowId` - `WindowPolicy.fork.test.ts`, `preview.fork.test.ts`: owner routing by `WindowId`; `preview.test.ts` asserts owner `[windowId]`, not the project identity; `DesktopWindow.test.ts` asserts `setWindow` owner `[testWindowId(1)]` - [x] Hyprland: claim keyed by `WindowId` - `DesktopWindow.test.ts`: claims and workspace moves carry `[hubId, projectWindowId]` on restore and `testWindowId(1)` on launch - Unit tests only: the live claim log is debug-level - [x] Demand, snapshot: keyed by `WindowId` - Snapshot: `snapShotSender.fork.ts` resolves the sender through `windowIdFor`; `snapShot.fork.test.ts` covers a registered project window and an unregistered one - Demand: published per window on its own `webContents`; no project key exists on that path - [x] Reload: id survives a renderer reload - Live (host, `.dump/evidence/1364-live/`): menu Reload (`22-ctrl-r.txt`), `forcefullyCrashRenderer` (`23-crash.txt`) and update restore (`40-*`, `41-renderer-ids.txt`) all keep the id - Unit: `DesktopWindow.fork.test.ts` pins the id across `render-process-gone` recovery; `WindowPolicy.fork.test.ts` reads the id from argv and leaves it unset when absent ### Swap proof (each reverted with `git checkout -- <file>`) ```diff - registry keys by identity key → ElectronWindow.fork.test 2 failed - id dropped from preload arguments → DesktopWindow.test 3 failed - drain ignores entry.windowId → DesktopWindow.test 1 failed - manifest read drops windowId → DesktopWindowSession.test 2 failed - Hyprland claim keyed by identity → DesktopWindow.test 1 failed - id dropped (crash recovery test) → DesktopWindow.fork.test 1 failed - preview owner keyed by identity → DesktopWindow.test 1 failed ``` ### Checks ``` vp test run <targeted desktop dirs> → exit 0 (64 files, 700 tests) vp run fork:ci → exit 0 (scripts 59 files, 648 tests) vpr typecheck → exit 0 vp run knip:check → exit 0 ``` ### Note The crash-recovery case lives in `DesktopWindow.fork.test.ts`: the fork:ci upstream-test rule refuses a new case in `DesktopWindow.test.ts`. `registerMain` now reuses a registered window's id and never mints one the preload cannot see. ## UI Changes None. Main-process window keying only. ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [x] I included before/after screenshots for any UI changes (n/a: no UI change) - [x] I included a video for animation/interaction changes (n/a: no motion) Model and harness: Claude Opus 5.5, Claude Code in T3 Code. ## Fork trailers Squashes: - ef5a421 feat(desktop): key desktop windows by an opaque WindowId (#1576) (#1588) (#1590) - ee337a4 fixup! feat(desktop): key desktop windows by an opaque WindowId - 3ccc7bc fixup! feat(desktop): key desktop windows by an opaque WindowId - 69a9cc5 fixup! feat(desktop): key desktop windows by an opaque WindowId - cd0487c feat(desktop): key desktop windows by an opaque WindowId (#1576) (#1588) (#1590) - faa53bd refactor(multi-window): createWindow seams become marked insertions (#1811) (#1811) Fork-Domain: multi-window Fork-Tier: core Fork-Upstreamable: no
1 parent 958560c commit dbc4ebd

26 files changed

Lines changed: 704 additions & 248 deletions

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ function layerElectronWindow(destroyAll: Effect.Effect<void> = Effect.void) {
6868
create: () => Effect.die("unexpected window creation"),
6969
main: Effect.die("unexpected main window read"),
7070
get: () => Effect.die("unexpected identity window read"),
71+
getById: () => Effect.die("unexpected window id read"), // fork-hook: multi-window/window-id-get-by-id
7172
getOrCreate: () => Effect.die("unexpected identity window creation"),
7273
close: () => Effect.void,
73-
identityFor: () => Effect.succeed(Option.none()),
74-
listIdentities: Effect.succeed([]),
74+
windowIdFor: () => Effect.succeed(Option.none()), // fork-hook: multi-window/window-id-for
75+
listWindows: Effect.succeed([]), // fork-hook: multi-window/window-id-list
7576
currentMainOrFirst: Effect.die("unexpected current window read"),
7677
focusedMainOrFirst: Effect.die("unexpected focused window read"),
7778
setMain: () => Effect.void,

‎apps/desktop/src/app/DesktopSecondInstanceBuffer.fork.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("DesktopSecondInstanceBuffer", () => {
6464
identity.kind === "hub" ? "hub" : identity.ref.projectId,
6565
]).pipe(Effect.as(fakeWindow));
6666
const openers: WindowOpeners = {
67-
ensureIdentity: () => record,
67+
ensureIdentity: () => () => Effect.die("no restore is staged"),
6868
revealOrCreateIdentity: () => record,
6969
createMainIfBackendReady: () => Effect.void,
7070
};

‎apps/desktop/src/electron/ElectronWindow.fork.test.ts‎

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
projectWindowPreloadArgument,
3232
readProjectWindowPreloadRef,
3333
} from "../window/WindowIdentity.ts";
34+
import { isWindowId, type WindowId } from "../window/WindowId.fork.ts";
3435
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
3536
const TestLayer = ElectronWindow.layer.pipe(
3637
Layer.provide(Layer.succeed(HostProcessPlatform, "linux")),
@@ -78,24 +79,77 @@ describe("ElectronWindow", () => {
7879
const projectWindow = makeBrowserWindow({ id: 10, destroyed: false });
7980
const duplicateWindow = makeBrowserWindow({ id: 11, destroyed: false });
8081
const electronWindow = yield* ElectronWindow.ElectronWindow;
81-
const created = yield* electronWindow.getOrCreate(
82-
projectIdentity,
82+
const created = yield* electronWindow.getOrCreate(projectIdentity, () =>
8383
Effect.succeed(projectWindow),
8484
);
85-
const reused = yield* electronWindow.getOrCreate(
86-
projectIdentity,
85+
const reused = yield* electronWindow.getOrCreate(projectIdentity, () =>
8786
Effect.succeed(duplicateWindow),
8887
);
8988
assert.isTrue(created.created);
9089
assert.isFalse(reused.created);
9190
assert.strictEqual(reused.window, projectWindow);
9291
assert.deepEqual(yield* electronWindow.get(projectIdentity), Option.some(projectWindow));
9392
assert.deepEqual(
94-
yield* electronWindow.identityFor(projectWindow),
95-
Option.some(projectIdentity),
93+
yield* electronWindow.windowIdFor(projectWindow),
94+
Option.some(created.windowId),
9695
);
9796
}).pipe(Effect.provide(TestLayer)),
9897
);
98+
it.effect("keys each window by a minted WindowId, never by what it shows", () =>
99+
Effect.gen(function* () {
100+
const projectIdentity = projectWindowIdentity(
101+
EnvironmentId.make("environment-1"),
102+
ProjectId.make("project-1"),
103+
);
104+
const projectWindow = makeBrowserWindow({ id: 20, destroyed: false });
105+
const hubWindow = makeBrowserWindow({ id: 21, destroyed: false });
106+
const electronWindow = yield* ElectronWindow.ElectronWindow;
107+
let handedId: WindowId | undefined;
108+
const project = yield* electronWindow.getOrCreate(projectIdentity, (windowId) => {
109+
handedId = windowId;
110+
return Effect.succeed(projectWindow);
111+
});
112+
const hub = yield* electronWindow.getOrCreate(HUB_WINDOW_IDENTITY, () =>
113+
Effect.succeed(hubWindow),
114+
);
115+
// The creator sees the id before the window exists, so it can hand it to
116+
// the preload; the registry then files the window under that same id.
117+
assert.strictEqual(handedId, project.windowId);
118+
assert.isTrue(isWindowId(project.windowId));
119+
assert.isTrue(isWindowId(hub.windowId));
120+
assert.notStrictEqual(project.windowId, hub.windowId);
121+
assert.notStrictEqual(project.windowId, String(projectWindow.id));
122+
assert.deepEqual(yield* electronWindow.getById(project.windowId), Option.some(projectWindow));
123+
assert.deepEqual(yield* electronWindow.listWindows, [
124+
{ windowId: project.windowId, identity: projectIdentity },
125+
{ windowId: hub.windowId, identity: HUB_WINDOW_IDENTITY },
126+
]);
127+
projectWindow.__emit("closed");
128+
assert.isTrue(Option.isNone(yield* electronWindow.getById(project.windowId)));
129+
assert.isTrue(Option.isNone(yield* electronWindow.windowIdFor(projectWindow)));
130+
}).pipe(Effect.provide(TestLayer)),
131+
);
132+
it.effect("reuses a restored WindowId unless a live window already holds it", () =>
133+
Effect.gen(function* () {
134+
const restoredId = "00000000-0000-4000-8000-00000000000a" as WindowId;
135+
const first = makeBrowserWindow({ id: 30, destroyed: false });
136+
const second = makeBrowserWindow({ id: 31, destroyed: false });
137+
const electronWindow = yield* ElectronWindow.ElectronWindow;
138+
const restored = yield* electronWindow.getOrCreate(
139+
projectWindowIdentity(EnvironmentId.make("environment-1"), ProjectId.make("project-1")),
140+
() => Effect.succeed(first),
141+
restoredId,
142+
);
143+
const collided = yield* electronWindow.getOrCreate(
144+
projectWindowIdentity(EnvironmentId.make("environment-1"), ProjectId.make("project-2")),
145+
() => Effect.succeed(second),
146+
restoredId,
147+
);
148+
assert.strictEqual(restored.windowId, restoredId);
149+
assert.notStrictEqual(collided.windowId, restoredId);
150+
assert.deepEqual(yield* electronWindow.getById(restoredId), Option.some(first));
151+
}).pipe(Effect.provide(TestLayer)),
152+
);
99153
it.effect("closes identities and removes windows destroyed externally", () =>
100154
Effect.gen(function* () {
101155
const projectIdentity = projectWindowIdentity(
@@ -105,8 +159,8 @@ describe("ElectronWindow", () => {
105159
const projectWindow = makeBrowserWindow({ id: 12, destroyed: false });
106160
const hubWindow = makeBrowserWindow({ id: 13, destroyed: false });
107161
const electronWindow = yield* ElectronWindow.ElectronWindow;
108-
yield* electronWindow.getOrCreate(projectIdentity, Effect.succeed(projectWindow));
109-
yield* electronWindow.getOrCreate(HUB_WINDOW_IDENTITY, Effect.succeed(hubWindow));
162+
yield* electronWindow.getOrCreate(projectIdentity, () => Effect.succeed(projectWindow));
163+
yield* electronWindow.getOrCreate(HUB_WINDOW_IDENTITY, () => Effect.succeed(hubWindow));
110164
projectWindow.__emit("closed");
111165
assert.isTrue(Option.isNone(yield* electronWindow.get(projectIdentity)));
112166
assert.isTrue(Option.isSome(yield* electronWindow.get(HUB_WINDOW_IDENTITY)));

‎apps/desktop/src/electron/ElectronWindow.ts‎

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ import * as Semaphore from "effect/Semaphore"; // fork-hook: multi-window/regist
1515

1616
import * as Electron from "electron";
1717

18-
import {
19-
HUB_WINDOW_IDENTITY,
20-
type WindowIdentity,
21-
windowIdentityKey,
22-
} from "../window/WindowIdentity.ts";
18+
import { HUB_WINDOW_IDENTITY, type WindowIdentity } from "../window/WindowIdentity.ts"; // fork-hook: multi-window/window-identity-import
19+
import * as WindowRegistry from "./WindowRegistry.fork.ts"; // fork-hook: multi-window/window-registry-import
2320
import {
2421
activateWindowsForeground,
2522
isWindowsShellHostedForeground,
@@ -124,16 +121,12 @@ export class ElectronWindow extends Context.Service<
124121
readonly get: (
125122
identity: WindowIdentity,
126123
) => Effect.Effect<Option.Option<Electron.BrowserWindow>>;
127-
readonly getOrCreate: <E>(
128-
identity: WindowIdentity,
129-
create: Effect.Effect<Electron.BrowserWindow, E>,
130-
) => Effect.Effect<{ readonly window: Electron.BrowserWindow; readonly created: boolean }, E>;
124+
readonly getById: WindowRegistry.WindowRegistryService["getById"]; // fork-hook: multi-window/window-id-get-by-id
125+
readonly getOrCreate: WindowRegistry.WindowRegistryService["getOrCreate"]; // fork-hook: multi-window/window-id-get-or-create
131126
readonly close: (identity: WindowIdentity) => Effect.Effect<void>;
132-
readonly identityFor: (
133-
window: Electron.BrowserWindow,
134-
) => Effect.Effect<Option.Option<WindowIdentity>>;
127+
readonly windowIdFor: WindowRegistry.WindowRegistryService["windowIdFor"]; // fork-hook: multi-window/window-id-for
135128
/** Every live registered window, in registration order. */
136-
readonly listIdentities: Effect.Effect<readonly WindowIdentity[]>;
129+
readonly listWindows: WindowRegistry.WindowRegistryService["listWindows"]; // fork-hook: multi-window/window-id-list
137130
readonly currentMainOrFirst: Effect.Effect<Option.Option<Electron.BrowserWindow>>;
138131
readonly focusedMainOrFirst: Effect.Effect<Option.Option<Electron.BrowserWindow>>;
139132
readonly setMain: (window: Electron.BrowserWindow) => Effect.Effect<void>;
@@ -163,10 +156,7 @@ export const make = Effect.gen(function* () {
163156
yield* Effect.addFinalizer(() => Effect.sync(() => windowsForegroundFocus?.close()));
164157
const mainWindowRef = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
165158
const auxiliaryWindows = new WeakSet<Electron.BrowserWindow>();
166-
const windowsByIdentity = new Map<
167-
string,
168-
{ readonly identity: WindowIdentity; readonly window: Electron.BrowserWindow }
169-
>();
159+
const registry = WindowRegistry.makeWindowRegistry(); // fork-hook: multi-window/window-registry
170160
const registrySemaphore = yield* Semaphore.make(1);
171161

172162
const listWindows = Effect.try({
@@ -194,30 +184,7 @@ export const make = Effect.gen(function* () {
194184
}),
195185
}).pipe(Effect.orDie);
196186

197-
const getLiveWindow = Effect.fn("desktop.electron.window.get")(function* (
198-
identity: WindowIdentity,
199-
) {
200-
const key = windowIdentityKey(identity);
201-
const entry = windowsByIdentity.get(key);
202-
if (entry === undefined) {
203-
return Option.none<Electron.BrowserWindow>();
204-
}
205-
if (yield* isWindowDestroyed(entry.window)) {
206-
windowsByIdentity.delete(key);
207-
return Option.none<Electron.BrowserWindow>();
208-
}
209-
return Option.some(entry.window);
210-
});
211-
212-
const registerWindow = (identity: WindowIdentity, window: Electron.BrowserWindow) => {
213-
const key = windowIdentityKey(identity);
214-
windowsByIdentity.set(key, { identity, window });
215-
window.once("closed", () => {
216-
if (windowsByIdentity.get(key)?.window === window) {
217-
windowsByIdentity.delete(key);
218-
}
219-
});
220-
};
187+
const getLiveWindow = (identity: WindowIdentity) => Effect.sync(() => registry.get(identity)); // fork-hook: multi-window/window-registry-get
221188

222189
const liveMain = Effect.gen(function* () {
223190
}
@@ -297,42 +264,7 @@ export const make = Effect.gen(function* () {
297264
}),
298265
main: liveMain,
299266
get: getLiveWindow,
300-
getOrCreate: (identity, create) =>
301-
registrySemaphore.withPermits(1)(
302-
Effect.gen(function* () {
303-
const existing = yield* getLiveWindow(identity);
304-
if (Option.isSome(existing)) {
305-
return { window: existing.value, created: false } as const;
306-
}
307-
const window = yield* create;
308-
registerWindow(identity, window);
309-
if (identity.kind === "hub") {
310-
yield* Ref.set(mainWindowRef, Option.some(window));
311-
}
312-
return { window, created: true } as const;
313-
}),
314-
),
315-
close: (identity) =>
316-
registrySemaphore.withPermits(1)(
317-
Effect.gen(function* () {
318-
const existing = yield* getLiveWindow(identity);
319-
if (Option.isNone(existing)) return;
320-
windowsByIdentity.delete(windowIdentityKey(identity));
321-
existing.value.close();
322-
}),
323-
),
324-
listIdentities: Effect.sync(() =>
325-
Array.from(windowsByIdentity.values())
326-
.filter((entry) => !entry.window.isDestroyed())
327-
.map((entry) => entry.identity),
328-
),
329-
identityFor: (window) =>
330-
Effect.sync(() => {
331-
for (const entry of windowsByIdentity.values()) {
332-
if (entry.window === window) return Option.some(entry.identity);
333-
}
334-
return Option.none<WindowIdentity>();
335-
}),
267+
...WindowRegistry.makeWindowRegistryService(registry, registrySemaphore, mainWindowRef), // fork-hook: multi-window/window-registry-service
336268
currentMainOrFirst,
337269
focusedMainOrFirst,
338270
setMain: Effect.fn("ElectronWindow.setMain")(function (window) {

‎apps/desktop/src/ipc/methods/preview.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import { it as effectIt } from "@effect/vitest";
22
import {
33
DEFAULT_BROWSER_PROFILE_ID,
4-
EnvironmentId,
54
INCOGNITO_BROWSER_PROFILE_ID,
65
PreviewCaptureFailure,
7-
ProjectId,
86
} from "@t3tools/contracts";
97
import * as Cause from "effect/Cause";
108
import * as Effect from "effect/Effect";
119
import * as Schema from "effect/Schema";
1210
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1311

14-
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
1512
import * as PreviewManager from "../../preview/Manager.ts";
16-
import { projectWindowIdentity } from "../../window/WindowIdentity.ts";
1713
import * as PreviewIpc from "./preview.ts";
1814
import * as DesktopIpc from "../DesktopIpc.ts";
1915
import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";

‎apps/desktop/src/ipc/methods/snapShot.fork.test.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { assert, describe, it } from "@effect/vitest";
2-
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
32
import * as Cause from "effect/Cause";
43
import * as Effect from "effect/Effect";
54
import * as Exit from "effect/Exit";
@@ -10,7 +9,7 @@ import { vi } from "vite-plus/test";
109

1110
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
1211
import * as DesktopSnapShot from "../../snapShot/DesktopSnapShot.ts";
13-
import { projectWindowIdentity } from "../../window/WindowIdentity.ts";
12+
import type { WindowId } from "../../window/WindowId.fork.ts";
1413
import { listPendingSnapShots } from "./snapShot.ts";
1514

1615
const { fromWebContents, fromId } = vi.hoisted(() => ({
@@ -29,19 +28,16 @@ const PROJECT_WEB_CONTENTS_ID = 11;
2928
const hubWindow = { webContents: { id: HUB_WEB_CONTENTS_ID } } as Electron.BrowserWindow;
3029
const projectWindow = { webContents: { id: PROJECT_WEB_CONTENTS_ID } } as Electron.BrowserWindow;
3130

32-
const projectIdentity = projectWindowIdentity(
33-
EnvironmentId.make("env-1"),
34-
ProjectId.make("project-1"),
35-
);
31+
const projectWindowId = "00000000-0000-4000-8000-000000000002" as WindowId;
3632

3733
/** Registers `projectWindow` only, so an unregistered sender resolves to None. */
3834
const windowLayer = (registered: Electron.BrowserWindow | null) =>
3935
Layer.succeed(
4036
ElectronWindow.ElectronWindow,
4137
ElectronWindow.ElectronWindow.of({
42-
main: Effect.succeed(Option.some(hubWindow)),
43-
identityFor: (window: Electron.BrowserWindow) =>
44-
Effect.succeed(window === registered ? Option.some(projectIdentity) : Option.none()),
38+
main: Effect.succeedSome(hubWindow),
39+
windowIdFor: (window: Electron.BrowserWindow) =>
40+
Effect.succeed(window === registered ? Option.some(projectWindowId) : Option.none()),
4541
} as ElectronWindow.ElectronWindow["Service"]),
4642
);
4743

‎apps/desktop/src/ipc/methods/snapShotSender.fork.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const resolveRegisteredSenderWindow = Effect.fn(
2727
const senderWindow = runtime.BrowserWindow?.fromWebContents(senderWebContents) ?? null;
2828
if (senderWindow === null) return Option.none<Electron.BrowserWindow>();
2929

30-
const identity = yield* electronWindow.identityFor(senderWindow);
31-
return Option.isNone(identity)
30+
const windowId = yield* electronWindow.windowIdFor(senderWindow);
31+
return Option.isNone(windowId)
3232
? Option.none<Electron.BrowserWindow>()
3333
: Option.some(senderWindow);
3434
});

‎apps/desktop/src/preview/Manager.fork.test.ts‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { it as effectIt } from "@effect/vitest";
2-
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
32
import * as Cause from "effect/Cause";
43
import * as Effect from "effect/Effect";
54
import * as Exit from "effect/Exit";
65
import * as Fiber from "effect/Fiber";
76
import * as Option from "effect/Option";
87
import type * as Scope from "effect/Scope";
98
import { describe, expect, vi } from "vite-plus/test";
10-
import { projectWindowIdentity, windowIdentityKey } from "../window/WindowIdentity.ts";
9+
import type { WindowId } from "../window/WindowId.fork.ts";
1110
import { previewManagerFixtureLayer } from "./Manager.fork-test-harness.ts";
1211
import * as PreviewManager from "./Manager.ts";
1312

@@ -36,20 +35,14 @@ describe("fork preview manager ownership", () => {
3635
effectIt.effect("namespaces equal tab ids by owning window and routes events to that owner", () =>
3736
withManager((manager) =>
3837
Effect.gen(function* () {
39-
const firstIdentity = projectWindowIdentity(
40-
EnvironmentId.make("environment-1"),
41-
ProjectId.make("project-1"),
42-
);
43-
const secondIdentity = projectWindowIdentity(
44-
EnvironmentId.make("environment-1"),
45-
ProjectId.make("project-2"),
46-
);
47-
const first = yield* manager.forWindow(firstIdentity);
48-
const second = yield* manager.forWindow(secondIdentity);
38+
const firstWindowId = "00000000-0000-4000-8000-000000000001" as WindowId;
39+
const secondWindowId = "00000000-0000-4000-8000-000000000002" as WindowId;
40+
const first = yield* manager.forWindow(firstWindowId);
41+
const second = yield* manager.forWindow(secondWindowId);
4942
const deliveries: string[] = [];
50-
yield* manager.subscribeOwnedStateChanges((identity, tabId) =>
43+
yield* manager.subscribeOwnedStateChanges((owner, tabId) =>
5144
Effect.sync(() => {
52-
deliveries.push(`${windowIdentityKey(identity)}:${tabId}`);
45+
deliveries.push(`${owner}:${tabId}`);
5346
}),
5447
);
5548

@@ -58,29 +51,16 @@ describe("fork preview manager ownership", () => {
5851

5952
expect(firstState.zoomFactor).toBe(1.25);
6053
expect(secondState.zoomFactor).toBe(0.8);
61-
expect(deliveries).toEqual([
62-
`${windowIdentityKey(firstIdentity)}:shared-tab`,
63-
`${windowIdentityKey(secondIdentity)}:shared-tab`,
64-
]);
54+
expect(deliveries).toEqual([`${firstWindowId}:shared-tab`, `${secondWindowId}:shared-tab`]);
6555
}),
6656
),
6757
);
6858

6959
effectIt.effect("explicitly rejects a tab owned only by another window", () =>
7060
withManager((manager) =>
7161
Effect.gen(function* () {
72-
const owner = yield* manager.forWindow(
73-
projectWindowIdentity(
74-
EnvironmentId.make("environment-1"),
75-
ProjectId.make("project-owner"),
76-
),
77-
);
78-
const other = yield* manager.forWindow(
79-
projectWindowIdentity(
80-
EnvironmentId.make("environment-1"),
81-
ProjectId.make("project-other"),
82-
),
83-
);
62+
const owner = yield* manager.forWindow("00000000-0000-4000-8000-00000000000a" as WindowId);
63+
const other = yield* manager.forWindow("00000000-0000-4000-8000-00000000000b" as WindowId);
8464
yield* owner.createTab("owned-tab");
8565

8666
const exit = yield* Effect.exit(other.closeTab("owned-tab"));

0 commit comments

Comments
 (0)