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, 06:00 UTC
fix(web): preserve newer project action drafts when imports fail (#39312)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 21:19 UTC
916fcdc364859f6cc0eddd00995aa092c7b55687
13 files changed
+198
-7
apps/web/src/components/ProjectScriptsControl.browser.test.tsx
new
+72
@@ -0,0 +1,72 @@
1
+import { EnvironmentId } from "@t3tools/contracts";
2
+import * as Cause from "effect/Cause";
3
+import { AsyncResult } from "effect/reactivity";
4
+import { expect, it } from "vite-plus/test";
5
+import { page, userEvent } from "vite-plus/test/browser";
6
+
7
+import { act, render } from "../../test/render";
8
+import ProjectScriptsControl, { type ProjectScriptActionResult } from "./ProjectScriptsControl";
9
+
10
+it.each(["edit", "dismiss", "newer import fails first"] as const)(
11
+ "keeps a failed import from replacing a newer action after %s",
12
+ async (nextAction) => {
13
+ const older = Promise.withResolvers<ProjectScriptActionResult>();
14
+ const newer = Promise.withResolvers<ProjectScriptActionResult>();
15
+ await using screen = await render(
16
+ <ProjectScriptsControl
17
+ environmentId={EnvironmentId.make("test")}
18
+ displayMode="panel"
19
+ scripts={[
20
+ {
21
+ id: "local-check",
22
+ name: "Local check",
23
+ command: "echo local",
24
+ icon: "play",
25
+ runOnWorktreeCreate: false,
26
+ },
27
+ ]}
28
+ fileScripts={[
29
+ { name: "Shared build", command: "echo build" },
30
+ { name: "Shared lint", command: "echo lint" },
31
+ ]}
32
+ onRunScript={() => {}}
33
+ onAddScript={({ name }) => (name === "Shared build" ? older.promise : newer.promise)}
34
+ onUpdateScript={async () => AsyncResult.success(undefined)}
35
+ onDeleteScript={async () => AsyncResult.success(undefined)}
36
+ />,
37
+ );
38
+
39
+ const actions = screen.getByRole("button", { name: "Script actions" });
40
+ const dialog = page.getByRole("dialog");
41
+ const name = dialog.getByRole("textbox", { name: "Name" });
42
+ const failure = AsyncResult.failure<void, unknown>(
43
+ Cause.fail(new Error("Settings write failed")),
44
+ );
45
+
46
+ await actions.click();
47
+ await page.getByRole("menuitem", { name: /Shared build/ }).click();
48
+ await actions.click();
49
+
50
+ switch (nextAction) {
51
+ case "edit":
52
+ await page.getByRole("button", { name: "Edit Local check" }).click();
53
+ await act(async () => older.resolve(failure));
54
+ expect(name.query()).toHaveProperty("value", "Local check");
55
+ break;
56
+ case "dismiss":
57
+ await page.getByRole("menuitem", { name: "Add project script" }).click();
58
+ await expect.element(dialog).toBeVisible();
59
+ await userEvent.keyboard("{Escape}");
60
+ await expect.element(dialog).not.toBeInTheDocument();
61
+ await act(async () => older.resolve(failure));
62
+ expect(dialog.query() === null).toBe(true);
63
+ break;
64
+ case "newer import fails first":
65
+ await page.getByRole("menuitem", { name: /Shared lint/ }).click();
66
+ await act(async () => newer.resolve(failure));
67
+ await act(async () => older.resolve(failure));
68
+ expect(name.query()).toHaveProperty("value", "Shared lint");
69
+ break;
70
+ }
71
+ },
72
+);
apps/web/src/components/ProjectScriptsControl.tsx
+22
-7
@@ -47,6 +47,7 @@ import {
47
MenuSubTrigger,
48
MenuSubPopup,
49
} from "./ui/menu";
50
+import { stackedThreadToast, toastManager } from "./ui/toast";
51
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
52
import { cn } from "~/lib/utils";
53
import {
@@ -108,6 +109,7 @@ export default function ProjectScriptsControl({
109
setActionsMenuOpen({ presentation, scripts: false, imports: false });
110
}
111
const [editorRequest, setEditorRequest] = useState<ProjectScriptEditorRequest | null>(null);
112
+ const editorRequestIdRef = React.useRef(0);
113
114
const primaryScript =
115
(preferredScriptId ? scripts.find((script) => script.id === preferredScriptId) : undefined) ??
@@ -122,10 +124,12 @@ export default function ProjectScriptsControl({
124
);
125
126
const openAddDialog = () => {
127
+ editorRequestIdRef.current += 1;
128
setEditorRequest({ scriptId: null, initial: EMPTY_PROJECT_SCRIPT_INPUT });
129
};
130
131
const openEditDialog = (script: ProjectScript) => {
132
+ editorRequestIdRef.current += 1;
133
onRequestMenuClose?.();
134
setActionsMenuOpen({ presentation, scripts: false, imports: false });
135
setEditorRequest(editorRequestForScript(script, keybindings));
@@ -135,6 +139,7 @@ export default function ProjectScriptsControl({
139
scriptId === null ? onAddScript(input) : onUpdateScript(scriptId, input);
140
141
const importFileScript = async (fileScript: T3ProjectFileScript) => {
142
+ const requestId = ++editorRequestIdRef.current;
143
const payload: NewProjectScriptInput = {
144
name: fileScript.name,
145
command: fileScript.command,
@@ -148,14 +153,24 @@ export default function ProjectScriptsControl({
153
autoOpenPreview: fileScript.previewUrl ? (fileScript.autoOpenPreview ?? false) : false,
154
};
155
const result = await onAddScript(payload);
151
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
152
- const error = squashAtomCommandFailure(result);
153
- setEditorRequest({
154
- scriptId: null,
155
- initial: payload,
156
- error: thrownErrorMessage(error, m) ?? gt("Failed to import action."),
157
- });
156
+ if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
157
+
158
+ const message = thrownErrorMessage(squashAtomCommandFailure(result), m);
159
+ if (requestId !== editorRequestIdRef.current) {
160
+ toastManager.add(
161
+ stackedThreadToast({
162
+ type: "error",
163
+ title: gt("Failed to import {name}.", { name: fileScript.name }),
164
+ ...(message ? { description: message } : {}),
165
+ }),
166
+ );
167
+ return;
168
}
169
+ setEditorRequest({
170
+ scriptId: null,
171
+ initial: payload,
172
+ error: message ?? gt("Failed to import action."),
173
+ });
174
};
175
176
const importMenuItems = importableScripts.length > 0 && (
apps/web/src/i18n/translations/de.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "{name} loslösen",
2195
"c4c2d240ffe55dec": "{name} anheften",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "{name} konnte nicht importiert werden.",
2198
"924d4b8e011c9127": "Aktion konnte nicht importiert werden.",
2199
"0421f870f82997bc": "Importieren",
2200
"06690d4ce0d19c30": "{name} bearbeiten",
apps/web/src/i18n/translations/en.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Unpin {name}",
2195
"c4c2d240ffe55dec": "Pin {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "Failed to import {name}.",
2198
"924d4b8e011c9127": "Failed to import action.",
2199
"0421f870f82997bc": "Import",
2200
"06690d4ce0d19c30": "Edit {name}",
apps/web/src/i18n/translations/es.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Desfijar {name}",
2195
"c4c2d240ffe55dec": "Fijar {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "No se pudo importar {name}.",
2198
"924d4b8e011c9127": "No se pudo importar la acción.",
2199
"0421f870f82997bc": "Importar",
2200
"06690d4ce0d19c30": "Editar {name}",
apps/web/src/i18n/translations/fr.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Désépingler {name}",
2195
"c4c2d240ffe55dec": "Épingler {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "Échec de l’import de « {name} ».",
2198
"924d4b8e011c9127": "Échec de l’import de l’action.",
2199
"0421f870f82997bc": "Importer",
2200
"06690d4ce0d19c30": "Modifier {name}",
apps/web/src/i18n/translations/ja.json
+1
@@ -2192,6 +2192,7 @@
2192
"63977cd5e4535393": "{name} のピン留めを解除",
2193
"c4c2d240ffe55dec": "{name} をピン留め",
2194
"a1190e56375f2032": "{action} ({shortcut})",
2195
+ "f16b6d8ef68bab61": "「{name}」をインポートできませんでした。",
2196
"924d4b8e011c9127": "アクションをインポートできませんでした。",
2197
"0421f870f82997bc": "インポート",
2198
"06690d4ce0d19c30": "{name} を編集",
apps/web/src/i18n/translations/ko.json
+1
@@ -2193,6 +2193,7 @@
2193
"63977cd5e4535393": "{name} 고정 해제",
2194
"c4c2d240ffe55dec": "{name} 고정",
2195
"a1190e56375f2032": "{action}({shortcut})",
2196
+ "f16b6d8ef68bab61": "‘{name}’을(를) 가져오지 못했습니다.",
2197
"924d4b8e011c9127": "작업을 가져오지 못했습니다.",
2198
"0421f870f82997bc": "가져오기",
2199
"06690d4ce0d19c30": "{name} 편집",
apps/web/src/i18n/translations/pt-BR.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Desafixar {name}",
2195
"c4c2d240ffe55dec": "Fixar {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "Não foi possível importar {name}.",
2198
"924d4b8e011c9127": "Falha ao importar a ação.",
2199
"0421f870f82997bc": "Importar",
2200
"06690d4ce0d19c30": "Editar {name}",
apps/web/src/i18n/translations/ru.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Открепить {name}",
2195
"c4c2d240ffe55dec": "Закрепить {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "Не удалось импортировать «{name}».",
2198
"924d4b8e011c9127": "Не удалось импортировать действие.",
2199
"0421f870f82997bc": "Импортировать",
2200
"06690d4ce0d19c30": "Изменить {name}",
apps/web/src/i18n/translations/sv.json
+1
@@ -2194,6 +2194,7 @@
2194
"63977cd5e4535393": "Lossa {name}",
2195
"c4c2d240ffe55dec": "Fäst {name}",
2196
"a1190e56375f2032": "{action} ({shortcut})",
2197
+ "f16b6d8ef68bab61": "Det gick inte att importera {name}.",
2198
"924d4b8e011c9127": "Det gick inte att importera åtgärden.",
2199
"0421f870f82997bc": "Importera",
2200
"06690d4ce0d19c30": "Redigera {name}",
apps/web/src/i18n/translations/zh.json
+1
@@ -2198,6 +2198,7 @@
2198
"63977cd5e4535393": "取消置顶 {name}",
2199
"c4c2d240ffe55dec": "置顶 {name}",
2200
"a1190e56375f2032": "{action} ({shortcut})",
2201
+ "f16b6d8ef68bab61": "无法导入“{name}”。",
2202
"924d4b8e011c9127": "无法导入操作。",
2203
"0421f870f82997bc": "导入",
2204
"06690d4ce0d19c30": "编辑 {name}",
scripts/scenarios/project-action-draft-survives-failed-import.e2e.ts
new
+94
@@ -0,0 +1,94 @@
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
+);