@devries-cameron20 / t3code Mirror · read-only / commits / 04f35381b6
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 22, 13:15 UTC

fix(mobile): discard unchanged queued edits after starting (#25232)

Co-authored-by: Tristan Knight <18444302+tris203@users.noreply.github.com>

maria committed Oct 29, 2026 at 17:58 UTC 04f35381b65015f5204c2ceb11a94ba931a38fea
1 file changed +78 -2
apps/mobile/src/state/queued-run-edit.test.ts
+78 -2
@@ -1,4 +1,4 @@
1 -import { describe, expect, it } from "vite-plus/test";
1 +import { describe, expect, it, vi } from "vite-plus/test";
2 import { Atom } from "effect/reactivity";
3 import {
4 ChatAttachmentId,
@@ -20,7 +20,25 @@ import {
20 type QueuedRunEdit,
21 } from "./queued-run-edit";
22 import { threadComposerErrorsAtom } from "./thread-composer-error";
23 -import { getComposerDraftSnapshot, setComposerDraftText } from "./use-composer-drafts";
23 +import {
24 + flushComposerDrafts,
25 + getComposerDraftSnapshot,
26 + setComposerDraftText,
27 + waitForComposerDraftsLoaded,
28 +} from "./use-composer-drafts";
29 +
30 +vi.mock("expo-file-system", () => ({
31 + Directory: class {
32 + create() {}
33 + },
34 + File: class {
35 + exists = false;
36 + create() {}
37 + write() {}
38 + moveSync() {}
39 + },
40 + Paths: { document: { uri: "file:///documents" } },
41 +}));
42
43 const image = (id: string): ChatAttachment => ({
44 type: "image",
@@ -94,6 +112,64 @@ describe("resolveQueuedEditPayload", () => {
112 });
113
114 describe("beginQueuedRunEdit", () => {
115 + it("silently drops an untouched edit when its run starts", () => {
116 + const threadKey = "env-exit:thread-untouched";
117 + const runId = RunId.make("run-1");
118 + const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
119 + { id: runId, status: "queued" },
120 + ]);
121 + beginQueuedRunEdit(threadKey, edit([]), runs);
122 +
123 + appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
124 +
125 + expect(getQueuedRunEdit(threadKey)).toBeNull();
126 + expect(getComposerDraftSnapshot(threadKey).text).toBe("");
127 + expect(getComposerDraftSnapshot(queuedEditDraftKey(threadKey, runId)).text).toBe("");
128 + expect(appAtomRegistry.get(threadComposerErrorsAtom)[threadKey]?.message).toBeUndefined();
129 + });
130 +
131 + it("recovers text after a server attachment was removed", async () => {
132 + await waitForComposerDraftsLoaded();
133 + const threadKey = "env-exit:thread-removed-recover";
134 + const runId = RunId.make("run-1");
135 + const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
136 + { id: runId, status: "queued" },
137 + ]);
138 + beginQueuedRunEdit(threadKey, edit([image("removed")]), runs);
139 + removeQueuedRunEditAttachment(threadKey, "removed");
140 +
141 + appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
142 + await flushComposerDrafts();
143 +
144 + expect(getQueuedRunEdit(threadKey)).toBeNull();
145 + expect(getComposerDraftSnapshot(threadKey).text).toBe("original");
146 + expect(getComposerDraftSnapshot(queuedEditDraftKey(threadKey, runId)).text).toBe("");
147 + expect(appAtomRegistry.get(threadComposerErrorsAtom)[threadKey]?.message).toBe(
148 + "That message already started. Your edit is back in the composer.",
149 + );
150 + });
151 +
152 + it("recovers changed text into an empty thread draft", async () => {
153 + await waitForComposerDraftsLoaded();
154 + const threadKey = "env-exit:thread-changed-recover";
155 + const runId = RunId.make("run-1");
156 + const runs = Atom.make<ReadonlyArray<{ readonly id: RunId; readonly status: string }> | null>([
157 + { id: runId, status: "queued" },
158 + ]);
159 + beginQueuedRunEdit(threadKey, edit([]), runs);
160 + setComposerDraftText(queuedEditDraftKey(threadKey, runId), "revised");
161 +
162 + appAtomRegistry.set(runs, [{ id: runId, status: "running" }]);
163 + await flushComposerDrafts();
164 +
165 + expect(getQueuedRunEdit(threadKey)).toBeNull();
166 + expect(getComposerDraftSnapshot(threadKey).text).toBe("revised");
167 + expect(getComposerDraftSnapshot(queuedEditDraftKey(threadKey, runId)).text).toBe("");
168 + expect(appAtomRegistry.get(threadComposerErrorsAtom)[threadKey]?.message).toBe(
169 + "That message already started. Your edit is back in the composer.",
170 + );
171 + });
172 +
173 it("ends a changed edit when its run starts, without the thread's composer mounted", () => {
174 const threadKey = "env-exit:thread-exit";
175 const runId = RunId.make("run-1");