-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlayout-shell.test.tsx
More file actions
796 lines (711 loc) · 21.1 KB
/
Copy pathlayout-shell.test.tsx
File metadata and controls
796 lines (711 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
import { Suspense, act } from "react";
import { cleanup, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, test, vi } from "vitest";
import { LixProvider } from "@/lib/lix-react";
import { KeyValueProvider } from "@/hooks/key-value/use-key-value";
import { KEY_VALUE_DEFINITIONS } from "@/hooks/key-value/schema";
import { openLix } from "@/test-utils/node-lix-sdk";
import { qb } from "@/lib/lix-kysely";
import {
FILE_EXTENSION_KIND,
FILES_EXTENSION_KIND,
fileExtensionInstanceForKind,
} from "@/extension-runtime/extension-instance-helpers";
import { resolveLixFileForOpen, V2LayoutShell } from "./layout-shell";
import type { FlashtypeUiState } from "./ui-state";
import type { Lix } from "@/lib/lix-types";
type DesktopMock = {
readonly emitNewFile: () => Promise<void>;
readonly onNewFile: ReturnType<typeof vi.fn>;
};
type AgentHooksDesktopMock = {
readonly emitTurnEvent: (event: AgentHookTurnEventInput) => Promise<unknown>;
readonly onTurnEvent: ReturnType<typeof vi.fn>;
readonly setActiveFilePath: ReturnType<typeof vi.fn>;
};
type AgentHookTurnEventInput = {
readonly id: string;
readonly instanceId?: string;
readonly agent: "claude" | "codex";
readonly phase: "turn-start" | "turn-stop";
readonly sessionId?: string;
readonly turnId?: string;
readonly cwd?: string;
readonly createdAt: number;
};
const originalDesktop = window.flashtypeDesktop;
function queryFileTreeHosts(container: HTMLElement): NodeListOf<HTMLElement> {
return container.querySelectorAll<HTMLElement>("file-tree-container");
}
function queryFilesViewRenameInputs(
container: HTMLElement,
): HTMLInputElement[] {
const inputs: HTMLInputElement[] = [];
for (const host of queryFileTreeHosts(container)) {
const input = host.shadowRoot?.querySelector("[data-item-rename-input]");
if (input instanceof HTMLInputElement) inputs.push(input);
}
return inputs;
}
function queryFilesViewRenameInput(
container: HTMLElement,
): HTMLInputElement | null {
return queryFilesViewRenameInputs(container)[0] ?? null;
}
function queryFilesViewTreeItemByPath(
container: HTMLElement,
path: string,
): HTMLElement | null {
for (const host of queryFileTreeHosts(container)) {
const item = host.shadowRoot?.querySelector(
`[data-type='item'][data-item-path='${CSS.escape(path)}']`,
);
if (item instanceof HTMLElement) return item;
}
return null;
}
async function findFilesViewRenameInput(
container: HTMLElement,
): Promise<HTMLInputElement> {
return waitFor(() => {
const input = queryFilesViewRenameInput(container);
if (!input) {
throw new Error("file tree rename input not found");
}
return input;
});
}
function getFileTreeHostForShadowElement(
container: HTMLElement,
element: Element,
): HTMLElement {
for (const host of queryFileTreeHosts(container)) {
if (host.shadowRoot?.contains(element)) return host;
}
throw new Error("file tree host for shadow element not found");
}
afterEach(() => {
cleanup();
window.flashtypeDesktop = originalDesktop;
});
describe("resolveLixFileForOpen", () => {
test("uses the existing Lix row for normalized file paths", async () => {
const lix = await openLix();
const importFilesystemPaths = vi.spyOn(lix, "importFilesystemPaths");
await qb(lix)
.insertInto("lix_file")
.values({
id: "real_file",
path: "/docs/readme.md",
data: new TextEncoder().encode("Lix content"),
})
.execute();
const resolved = await resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "docs/./readme.md",
});
expect(resolved).toEqual({ id: "real_file", path: "/docs/readme.md" });
expect(importFilesystemPaths).not.toHaveBeenCalled();
await lix.close();
});
test("preserves backslashes as filename characters in Lix paths", async () => {
const lix = await openLix();
const importFilesystemPaths = vi.spyOn(lix, "importFilesystemPaths");
await qb(lix)
.insertInto("lix_file")
.values({
id: "backslash_file",
path: "/erjtyjtyr\\treytj.md",
data: new TextEncoder().encode("Lix content"),
})
.execute();
const resolved = await resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "/erjtyjtyr\\treytj.md",
});
expect(resolved).toEqual({
id: "backslash_file",
path: "/erjtyjtyr\\treytj.md",
});
expect(importFilesystemPaths).not.toHaveBeenCalled();
await lix.close();
});
test("preserves surrounding whitespace in Lix path segments", async () => {
const lix = await openLix();
const importFilesystemPaths = vi.spyOn(lix, "importFilesystemPaths");
await qb(lix)
.insertInto("lix_file")
.values({
id: "spaced_file",
path: "/ notes.md ",
data: new TextEncoder().encode("Lix content"),
})
.execute();
const resolved = await resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "/ notes.md ",
});
expect(resolved).toEqual({
id: "spaced_file",
path: "/ notes.md ",
});
expect(importFilesystemPaths).not.toHaveBeenCalled();
await lix.close();
});
test("imports an ephemeral disk file and returns the inserted Lix id", async () => {
const lix = await openLix();
const importFilesystemPaths = vi
.spyOn(lix, "importFilesystemPaths")
.mockImplementation(async ([path]) => {
await qb(lix)
.insertInto("lix_file")
.values({
path,
data: new TextEncoder().encode("# Imported"),
})
.execute();
});
const resolved = await resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "/notes.md",
});
expect(importFilesystemPaths).toHaveBeenCalledWith(["/notes.md"]);
expect(resolved?.path).toBe("/notes.md");
expect(resolved?.id).toBeTruthy();
const row = await qb(lix)
.selectFrom("lix_file")
.select(["id", "path", "data"])
.where("path", "=", "/notes.md")
.executeTakeFirstOrThrow();
expect(row.id).toBe(resolved?.id);
expect(new TextDecoder().decode(row.data as Uint8Array)).toBe("# Imported");
await lix.close();
});
test("does not overwrite a Lix row created while importing", async () => {
const lix = await openLix();
vi.spyOn(lix, "importFilesystemPaths").mockImplementation(async () => {
await qb(lix)
.insertInto("lix_file")
.values({
id: "raced_file",
path: "/race.md",
data: new TextEncoder().encode("Existing Lix data"),
})
.execute();
});
const resolved = await resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "/race.md",
});
expect(resolved).toEqual({ id: "raced_file", path: "/race.md" });
const row = await qb(lix)
.selectFrom("lix_file")
.select(["data"])
.where("path", "=", "/race.md")
.executeTakeFirstOrThrow();
expect(new TextDecoder().decode(row.data as Uint8Array)).toBe(
"Existing Lix data",
);
await lix.close();
});
test("refuses files that cannot be found or imported", async () => {
const lix = await openLix();
const importFilesystemPaths = vi
.spyOn(lix, "importFilesystemPaths")
.mockResolvedValue();
await expect(
resolveLixFileForOpen({
lix,
workspace: {
ephemeral: false,
path: "/workspace/.lix",
name: "workspace",
},
filePath: "/missing.md",
}),
).resolves.toBeNull();
expect(importFilesystemPaths).not.toHaveBeenCalled();
await expect(
resolveLixFileForOpen({
lix,
workspace: ephemeralWorkspace(),
filePath: "/missing.md",
}),
).resolves.toBeNull();
expect(importFilesystemPaths).toHaveBeenCalledWith(["/missing.md"]);
await lix.close();
});
});
describe("V2LayoutShell native New File", () => {
test("routes to the active FilesView draft before creating directly", async () => {
const desktop = installDesktopMock();
const lix = await openLix();
const utils = await renderShell(lix);
await screen.findByRole("button", { name: "New file" });
await waitFor(() => expect(desktop.onNewFile).toHaveBeenCalled());
await act(async () => {
await desktop.emitNewFile();
});
const input = await findFilesViewRenameInput(utils.container);
const inputHost = getFileTreeHostForShadowElement(utils.container, input);
await waitFor(() =>
expect(inputHost.shadowRoot?.activeElement).toBe(input),
);
expect(input.value).toBe("new-file");
await expect(findFilePath(lix, "/new-file.md")).resolves.toBeUndefined();
utils.unmount();
await lix.close();
});
test("prefers the focused panel when more than one FilesView is active", async () => {
const desktop = installDesktopMock();
const lix = await openLix({
keyValues: [uiStateKeyValue(twoFilesViewsState())],
});
const utils = await renderShell(lix);
await waitFor(() => {
expect(screen.getAllByRole("button", { name: "New file" })).toHaveLength(
2,
);
});
await waitFor(() => expect(desktop.onNewFile).toHaveBeenCalled());
await act(async () => {
await desktop.emitNewFile();
});
const input = await findFilesViewRenameInput(utils.container);
const inputHost = getFileTreeHostForShadowElement(utils.container, input);
const remainingButton = screen.getByRole("button", { name: "New file" });
expect(
remainingButton.compareDocumentPosition(inputHost) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
expect(queryFilesViewRenameInputs(utils.container)).toHaveLength(1);
utils.unmount();
await lix.close();
});
test("falls back to direct file creation when no FilesView is active", async () => {
const desktop = installDesktopMock();
const lix = await openLix({
keyValues: [uiStateKeyValue(noFilesViewState())],
});
const utils = await renderShell(lix);
await screen.findByTestId("central-panel-empty-state");
await waitFor(() => expect(desktop.onNewFile).toHaveBeenCalled());
await act(async () => {
await desktop.emitNewFile();
});
await expectNewFileCreatedAndOpened(lix);
expect(queryFilesViewRenameInput(utils.container)).toBeNull();
utils.unmount();
await lix.close();
});
test("falls back to direct file creation when the active FilesView is collapsed", async () => {
const desktop = installDesktopMock();
const lix = await openLix({
keyValues: [uiStateKeyValue(collapsedFilesViewState())],
});
const utils = await renderShell(lix);
await screen.findByRole("button", { name: "New file" });
await waitFor(() => expect(desktop.onNewFile).toHaveBeenCalled());
await act(async () => {
await desktop.emitNewFile();
});
await expectNewFileCreatedAndOpened(lix);
expect(queryFilesViewRenameInput(utils.container)).toBeNull();
utils.unmount();
await lix.close();
});
});
describe("V2LayoutShell active file sidebar highlight", () => {
test("highlights the active central file in the Files view", async () => {
const lix = await openLix({
keyValues: [
uiStateKeyValue(
filesViewWithOpenFileState("file_active", "/docs/readme.md"),
),
],
});
await qb(lix)
.insertInto("lix_directory")
.values({ path: "/docs/" } as any)
.execute();
await writeReviewFile(lix, "file_active", "/docs/readme.md", "# Readme");
const utils = await renderShell(lix);
await waitFor(() => {
expect(
queryFilesViewTreeItemByPath(utils.container, "docs/readme.md"),
).toHaveAttribute("data-item-selected", "true");
});
await unmountShell(utils);
await lix.close();
});
});
describe("V2LayoutShell agent review auto-open", () => {
test("returns current active file context from turn-start hooks", async () => {
const desktop = installAgentHooksDesktopMock();
const lix = await openLix({
keyValues: [
uiStateKeyValue(openFileState("file_current", "/current.md")),
],
});
vi.spyOn(lix, "syncDiskToLix").mockResolvedValue();
await writeReviewFile(lix, "file_current", "/current.md", "# Current");
const utils = await renderShell(lix);
await waitFor(() => expect(desktop.onTurnEvent).toHaveBeenCalled());
let result: unknown;
await act(async () => {
result = await desktop.emitTurnEvent(agentTurnEvent("turn-start"));
});
expect(result).toEqual({
additionalContext: "The current document is: ./current.md",
});
await unmountShell(utils);
await lix.close();
});
test("leaves the current file open when it already has a pending review", async () => {
const desktop = installAgentHooksDesktopMock();
const lix = await openLix({
keyValues: [
uiStateKeyValue(openFileState("file_current", "/current.md")),
],
});
vi.spyOn(lix, "syncDiskToLix").mockResolvedValue();
await writeReviewFile(lix, "file_a", "/a.md", "# A before");
await writeReviewFile(
lix,
"file_current",
"/current.md",
"# Current before",
);
const utils = await renderShell(lix);
await waitFor(() => expect(desktop.onTurnEvent).toHaveBeenCalled());
await waitFor(() =>
expect(desktop.setActiveFilePath).toHaveBeenCalledWith({
filePath: "/current.md",
}),
);
await act(async () => {
await desktop.emitTurnEvent(agentTurnEvent("turn-start"));
await writeReviewFile(lix, "file_a", "/a.md", "# A after");
await writeReviewFile(
lix,
"file_current",
"/current.md",
"# Current after",
);
await desktop.emitTurnEvent(agentTurnEvent("turn-stop"));
});
expect(
await screen.findByRole("button", { name: /keep/i }),
).toHaveAttribute("data-attr", "diff-accept");
expect(desktop.setActiveFilePath).not.toHaveBeenCalledWith({
filePath: "/a.md",
});
await unmountShell(utils);
await lix.close();
});
test("opens the first edited review file when the current file has no pending review", async () => {
const desktop = installAgentHooksDesktopMock();
const lix = await openLix({
keyValues: [
uiStateKeyValue(openFileState("file_current", "/current.md")),
],
});
vi.spyOn(lix, "syncDiskToLix").mockResolvedValue();
await writeReviewFile(lix, "file_current", "/current.md", "# Current");
await writeReviewFile(lix, "file_b", "/b.md", "# B before");
await writeReviewFile(lix, "file_a", "/a.md", "# A before");
const utils = await renderShell(lix);
await waitFor(() => expect(desktop.onTurnEvent).toHaveBeenCalled());
await waitFor(() =>
expect(desktop.setActiveFilePath).toHaveBeenCalledWith({
filePath: "/current.md",
}),
);
await act(async () => {
await desktop.emitTurnEvent(agentTurnEvent("turn-start"));
await writeReviewFile(lix, "file_b", "/b.md", "# B after");
await writeReviewFile(lix, "file_a", "/a.md", "# A after");
await desktop.emitTurnEvent(agentTurnEvent("turn-stop"));
});
await waitFor(() =>
expect(desktop.setActiveFilePath).toHaveBeenCalledWith({
filePath: "/a.md",
}),
);
expect(
await screen.findByRole("button", { name: /keep/i }),
).toHaveAttribute("data-attr", "diff-accept");
await waitForPersistedActiveState(lix, "file_a", "/a.md");
await unmountShell(utils);
await lix.close();
});
});
async function renderShell(lix: Lix) {
let result: ReturnType<typeof render> | undefined;
await act(async () => {
result = render(
<LixProvider lix={lix}>
<KeyValueProvider defs={KEY_VALUE_DEFINITIONS}>
<Suspense fallback={<div data-testid="loading" />}>
<V2LayoutShell workspaceName="Workspace" />
</Suspense>
</KeyValueProvider>
</LixProvider>,
);
});
return result!;
}
async function expectNewFileCreatedAndOpened(lix: Lix) {
await waitFor(async () => {
expect(await findFilePath(lix, "/new-file.md")).toBeDefined();
});
await screen.findByTestId("tiptap-editor");
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
}
async function unmountShell(utils: ReturnType<typeof render>): Promise<void> {
await act(async () => {
utils.unmount();
await new Promise((resolve) => setTimeout(resolve, 0));
});
}
function installDesktopMock(): DesktopMock {
let listener: (() => void | Promise<void>) | null = null;
const onNewFile = vi.fn((nextListener: () => void | Promise<void>) => {
listener = nextListener;
return () => {
if (listener === nextListener) {
listener = null;
}
};
});
window.flashtypeDesktop = {
workspace: {
onNewFile,
setActiveFilePath: vi.fn(),
setOpenFilePaths: vi.fn(),
},
} as unknown as Window["flashtypeDesktop"];
return {
emitNewFile: async () => {
if (!listener) {
throw new Error("native New File listener was not registered");
}
await listener();
},
onNewFile,
};
}
function installAgentHooksDesktopMock(): AgentHooksDesktopMock {
let listener: ((event: unknown) => unknown | Promise<unknown>) | null = null;
const onTurnEvent = vi.fn(
(nextListener: (event: unknown) => unknown | Promise<unknown>) => {
listener = nextListener;
return () => {
if (listener === nextListener) {
listener = null;
}
};
},
);
const setActiveFilePath = vi.fn();
window.flashtypeDesktop = {
workspace: {
setActiveFilePath,
setOpenFilePaths: vi.fn(),
},
agentHooks: {
onTurnEvent,
},
} as unknown as Window["flashtypeDesktop"];
return {
emitTurnEvent: async (event) => {
if (!listener) {
throw new Error("agent hook listener was not registered");
}
return await listener(event);
},
onTurnEvent,
setActiveFilePath,
};
}
function agentTurnEvent(
phase: AgentHookTurnEventInput["phase"],
): AgentHookTurnEventInput {
return {
id: `event-${phase}`,
instanceId: "test-instance",
agent: "codex",
phase,
sessionId: "test-session",
turnId: "test-turn",
createdAt: phase === "turn-start" ? 1 : 2,
};
}
function uiStateKeyValue(value: FlashtypeUiState) {
return {
key: "flashtype_ui_state",
value,
lixcol_branch_id: "global",
lixcol_global: true,
lixcol_untracked: true,
};
}
function noFilesViewState(): FlashtypeUiState {
return {
focusedPanel: "central",
panels: {
left: { views: [], activeInstance: null },
central: { views: [], activeInstance: null },
right: { views: [], activeInstance: null },
},
layout: { sizes: { left: 20, central: 50, right: 30 } },
};
}
function twoFilesViewsState(): FlashtypeUiState {
return {
focusedPanel: "right",
panels: {
left: {
views: [{ instance: "files-left", kind: FILES_EXTENSION_KIND }],
activeInstance: "files-left",
},
central: { views: [], activeInstance: null },
right: {
views: [{ instance: "files-right", kind: FILES_EXTENSION_KIND }],
activeInstance: "files-right",
},
},
layout: { sizes: { left: 20, central: 50, right: 30 } },
};
}
function collapsedFilesViewState(): FlashtypeUiState {
return {
focusedPanel: "left",
panels: {
left: {
views: [{ instance: "files-left", kind: FILES_EXTENSION_KIND }],
activeInstance: "files-left",
},
central: { views: [], activeInstance: null },
right: { views: [], activeInstance: null },
},
layout: { sizes: { left: 0, central: 70, right: 30 } },
};
}
function filesViewWithOpenFileState(
fileId: string,
filePath: string,
): FlashtypeUiState {
const state = openFileState(fileId, filePath);
return {
...state,
panels: {
...state.panels,
left: {
views: [{ instance: "files-left", kind: FILES_EXTENSION_KIND }],
activeInstance: "files-left",
},
},
};
}
function openFileState(fileId: string, filePath: string): FlashtypeUiState {
const instance = fileExtensionInstanceForKind(FILE_EXTENSION_KIND, fileId);
return {
focusedPanel: "central",
panels: {
left: { views: [], activeInstance: null },
central: {
views: [
{
instance,
kind: FILE_EXTENSION_KIND,
state: {
fileId,
filePath,
flashtype: {
label: filePath.split("/").filter(Boolean).pop() ?? filePath,
},
},
},
],
activeInstance: instance,
},
right: { views: [], activeInstance: null },
},
layout: { sizes: { left: 20, central: 50, right: 30 } },
};
}
async function findFilePath(
lix: Lix,
path: string,
): Promise<string | undefined> {
return (
await qb(lix)
.selectFrom("lix_file")
.select("path")
.where("path", "=", path)
.executeTakeFirst()
)?.path;
}
async function writeReviewFile(
lix: Lix,
id: string,
path: string,
text: string,
): Promise<void> {
await qb(lix)
.insertInto("lix_file")
.values({ id, path, data: new TextEncoder().encode(text) })
.onConflict((oc) =>
oc.column("id").doUpdateSet({
path,
data: new TextEncoder().encode(text),
}),
)
.execute();
}
async function waitForPersistedActiveState(
lix: Lix,
fileId: string,
filePath: string,
): Promise<void> {
await waitFor(async () => {
const activeFileRow = await qb(lix)
.selectFrom("lix_key_value_by_branch")
.select("value")
.where("key", "=", "flashtype_active_file_id")
.where("lixcol_branch_id", "=", "global")
.executeTakeFirst();
expect(activeFileRow?.value).toBe(fileId);
const uiStateRow = await qb(lix)
.selectFrom("lix_key_value_by_branch")
.select("value")
.where("key", "=", "flashtype_ui_state")
.where("lixcol_branch_id", "=", "global")
.executeTakeFirst();
const uiState = uiStateRow?.value as FlashtypeUiState | undefined;
const activeInstance = uiState?.panels.central.activeInstance;
const activeEntry = uiState?.panels.central.views.find(
(entry) => entry.instance === activeInstance,
);
expect(activeEntry?.state?.filePath).toBe(filePath);
});
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
}
function ephemeralWorkspace() {
return {
ephemeral: true,
path: "/workspace",
name: "workspace",
openFilePaths: [],
} as const;
}