@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 94 lines 3.17 KB
Raw
1 /// <reference lib="dom" />
2 import { expect } from "e2e";
3
4 import { test, WEB } from "./t3.ts";
5
6 declare global {
7 interface Window {
8 projectActionImportFailure?: Promise<() => void>;
9 }
10 }
11
12 test(
13 "A failed project action import preserves a manual action draft",
14 WEB,
15 async ({ t3, app, browser, screen }) => {
16 const project = await t3.project("demo", {
17 "t3.json": JSON.stringify({
18 scripts: [{ name: "Shared build", command: "echo build" }],
19 }),
20 });
21 const thread = await t3.thread({ project, title: "Action import", messages: ["Start"] });
22 await browser.setViewport({ width: 1920, height: 1000 });
23
24 await browser.addInitScript(() => {
25 const pending = Promise.withResolvers<() => void>();
26 window.projectActionImportFailure = pending.promise;
27 const send = WebSocket.prototype.send;
28 WebSocket.prototype.send = function (data) {
29 const request: { _tag: string; id: string; tag: string } | null =
30 typeof data === "string" ? JSON.parse(data) : null;
31 if (
32 typeof data !== "string" ||
33 request?._tag !== "Request" ||
34 request.tag !== "server.updateSettings" ||
35 !data.includes("Shared build")
36 ) {
37 return send.call(this, data);
38 }
39 // Delay a settings write failure until the user has started a different action.
40 WebSocket.prototype.send = send;
41 pending.resolve(() => {
42 this.dispatchEvent(
43 new MessageEvent("message", {
44 data: JSON.stringify({
45 _tag: "Exit",
46 requestId: request.id,
47 exit: {
48 _tag: "Failure",
49 cause: [
50 {
51 _tag: "Fail",
52 error: {
53 _tag: "ServerSettingsError",
54 operation: "write-file",
55 settingsPath: "settings.json",
56 },
57 },
58 ],
59 },
60 }),
61 }),
62 );
63 });
64 };
65 });
66
67 await t3.open(thread);
68 const actions = screen.getByRole("button", "Choose project action", { exact: true });
69 await actions.tap();
70 await screen.getByRole("menuitem", /Shared build/).tap();
71 await browser.evaluate(async () => {
72 await window.projectActionImportFailure;
73 return null;
74 });
75
76 await actions.tap();
77 await screen.getByRole("menuitem", "Add project script", { exact: true }).tap();
78 const draftName = "My local check";
79 await browser.locator("#script-name").fill(draftName);
80 await browser.locator("#script-command").fill("echo local");
81 await browser.evaluate(async () => {
82 const release = await window.projectActionImportFailure!;
83 release();
84 return null;
85 });
86
87 await screen.getByText("Server settings write-file failed at settings.json.").waitFor();
88 await app.screenshot("action-draft-after-import-fails");
89 const name = await browser.evaluate(
90 () => document.querySelector<HTMLInputElement>("#script-name")?.value ?? null,
91 );
92 expect(name, "The failed import preserves the manual action name").toBe(draftName);
93 },
94 );