Skip to content

Commit 9805a6a

Browse files
Merge pull request #55 from kirill-markin/codex/chat-panel-composer-refactor
Refactor chat panel composer ownership
2 parents 4410fbf + 6c23fc4 commit 9805a6a

11 files changed

Lines changed: 1295 additions & 860 deletions

apps/web/src/chat/ChatPanel.new-chat.test.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const {
3232
setLocalePreference,
3333
unmountChatPanel,
3434
clickNewConversation,
35-
clickAddAttachment,
3635
sendMessage,
3736
} = setupChatPanelTest();
3837

@@ -108,14 +107,12 @@ describe("ChatPanel new chat", () => {
108107
expect(textarea).not.toBeNull();
109108

110109
await setTextareaValue(textarea as HTMLTextAreaElement, "pending draft");
111-
await clickAddAttachment();
112110
await flushAsync();
113111

114112
const draftsBeforeNew = loadChatDraftWorkspaceState("workspace-1");
115113
const draftSessionIdsBeforeNew = Object.keys(draftsBeforeNew);
116114
expect(draftSessionIdsBeforeNew).toHaveLength(0);
117115
expect(textarea?.value).toBe("pending draft");
118-
expect(getContainer().textContent).toContain("attached.txt");
119116

120117
await clickNewConversation();
121118
await flushAsync();
@@ -126,7 +123,6 @@ describe("ChatPanel new chat", () => {
126123
expect(Object.keys(draftsAfterNew)).toHaveLength(0);
127124
expect(createNewChatSessionMock.mock.calls[1]?.[0]).toMatch(UUID_PATTERN);
128125
expect(textarea?.value).toBe("");
129-
expect(getContainer().textContent).not.toContain("attached.txt");
130126
});
131127

132128
it("clears a stale pending post-run sync flag when starting a new conversation", async () => {
@@ -397,6 +393,7 @@ describe("ChatPanel new chat", () => {
397393

398394
expect(createNewChatSessionMock).toHaveBeenCalledWith(
399395
expect.any(String),
396+
"workspace-1",
400397
"es-MX",
401398
);
402399
});
@@ -432,7 +429,7 @@ describe("ChatPanel new chat", () => {
432429
messages: [],
433430
},
434431
}));
435-
createNewChatSessionMock.mockImplementation((sessionId: string, uiLocale: string) => {
432+
createNewChatSessionMock.mockImplementation((sessionId: string, _workspaceId: string, uiLocale: string) => {
436433
if (uiLocale === "en") {
437434
return Promise.resolve({
438435
ok: true,
@@ -461,7 +458,7 @@ describe("ChatPanel new chat", () => {
461458

462459
expect(createNewChatSessionMock).toHaveBeenCalledTimes(2);
463460
expect(createNewChatSessionMock.mock.calls[0]?.[0]).toBe(createNewChatSessionMock.mock.calls[1]?.[0]);
464-
expect(createNewChatSessionMock.mock.calls[1]?.[1]).toBe("es-MX");
461+
expect(createNewChatSessionMock.mock.calls[1]?.[2]).toBe("es-MX");
465462
expect(getContainer().textContent).not.toContain("Study with spaced repetition");
466463
expect(secondRequestResolved).toBe(false);
467464

@@ -496,7 +493,7 @@ describe("ChatPanel new chat", () => {
496493
messages: [],
497494
},
498495
}));
499-
createNewChatSessionMock.mockImplementation((sessionId: string, uiLocale: string) => {
496+
createNewChatSessionMock.mockImplementation((sessionId: string, _workspaceId: string, uiLocale: string) => {
500497
if (uiLocale === "en") {
501498
return Promise.resolve({
502499
ok: true,
@@ -551,7 +548,7 @@ describe("ChatPanel new chat", () => {
551548
chatConfig: ReturnType<typeof createChatSnapshot>["chatConfig"];
552549
}) => void) | null = null;
553550

554-
createNewChatSessionMock.mockImplementation((sessionId: string, uiLocale: string) => {
551+
createNewChatSessionMock.mockImplementation((sessionId: string, _workspaceId: string, uiLocale: string) => {
555552
if (uiLocale === "en") {
556553
if (createNewChatSessionMock.mock.calls.length === 1) {
557554
return Promise.resolve({
@@ -586,7 +583,7 @@ describe("ChatPanel new chat", () => {
586583
expect(createNewChatSessionMock).toHaveBeenCalledTimes(3);
587584
expect(createNewChatSessionMock.mock.calls[1]?.[0]).toBe(freshSessionId);
588585
expect(createNewChatSessionMock.mock.calls[2]?.[0]).toBe(freshSessionId);
589-
expect(createNewChatSessionMock.mock.calls[2]?.[1]).toBe("es-MX");
586+
expect(createNewChatSessionMock.mock.calls[2]?.[2]).toBe("es-MX");
590587

591588
resolveSpanishRequest?.({
592589
ok: true,

apps/web/src/chat/ChatPanel.post-run-sync.test.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ describe("ChatPanel post-run sync", () => {
239239
runSync: runSyncMock,
240240
setErrorMessage: vi.fn(),
241241
}));
242-
consumeChatLiveStreamMock.mockImplementation(async ({ onEvent }) => {
242+
consumeChatLiveStreamMock.mockImplementation(async ({ onEvent, runId, sessionId }) => {
243243
onEvent({
244244
type: "assistant_tool_call",
245-
sessionId: "session-1",
246-
conversationScopeId: "session-1",
247-
runId: "run-1",
245+
sessionId,
246+
conversationScopeId: sessionId,
247+
runId,
248248
sequenceNumber: 1,
249249
streamEpoch: "epoch-1",
250250
cursor: "cursor-1",
@@ -259,9 +259,9 @@ describe("ChatPanel post-run sync", () => {
259259
});
260260
onEvent({
261261
type: "run_terminal",
262-
sessionId: "session-1",
263-
conversationScopeId: "session-1",
264-
runId: "run-1",
262+
sessionId,
263+
conversationScopeId: sessionId,
264+
runId,
265265
sequenceNumber: 2,
266266
streamEpoch: "epoch-1",
267267
cursor: null,
@@ -288,12 +288,12 @@ describe("ChatPanel post-run sync", () => {
288288
runSync: runSyncMock,
289289
setErrorMessage: vi.fn(),
290290
}));
291-
consumeChatLiveStreamMock.mockImplementation(async ({ onEvent }) => {
291+
consumeChatLiveStreamMock.mockImplementation(async ({ onEvent, runId, sessionId }) => {
292292
onEvent({
293293
type: "assistant_tool_call",
294-
sessionId: "session-1",
295-
conversationScopeId: "session-1",
296-
runId: "run-1",
294+
sessionId,
295+
conversationScopeId: sessionId,
296+
runId,
297297
sequenceNumber: 1,
298298
streamEpoch: "epoch-1",
299299
cursor: "cursor-1",
@@ -308,9 +308,9 @@ describe("ChatPanel post-run sync", () => {
308308
});
309309
onEvent({
310310
type: "assistant_message_done",
311-
sessionId: "session-1",
312-
conversationScopeId: "session-1",
313-
runId: "run-1",
311+
sessionId,
312+
conversationScopeId: sessionId,
313+
runId,
314314
sequenceNumber: 2,
315315
streamEpoch: "epoch-1",
316316
cursor: "cursor-2",
@@ -324,9 +324,9 @@ describe("ChatPanel post-run sync", () => {
324324
});
325325
onEvent({
326326
type: "run_terminal",
327-
sessionId: "session-1",
328-
conversationScopeId: "session-1",
329-
runId: "run-1",
327+
sessionId,
328+
conversationScopeId: sessionId,
329+
runId,
330330
sequenceNumber: 3,
331331
streamEpoch: "epoch-1",
332332
cursor: "cursor-3",

apps/web/src/chat/ChatPanel.send-lifecycle.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
transcribeChatAudioMock,
2121
useAppDataMock,
2222
} from "./ChatPanelTestSupport";
23-
import { getChatComposerCapabilities } from "./ChatPanel";
23+
import { getChatComposerCapabilities } from "./chatComposerState";
2424
import {
2525
createUnverifiedWorkspaceAppDataMock,
2626
createVerifiedWorkspaceAppDataMock,
@@ -160,7 +160,7 @@ describe("ChatPanel send lifecycle", () => {
160160
await renderChatPanel();
161161
await flushAsync();
162162

163-
expect(getChatSnapshotMock).toHaveBeenCalledWith("session-local-fresh");
163+
expect(getChatSnapshotMock).toHaveBeenCalledWith("session-local-fresh", "workspace-1");
164164
});
165165

166166
it("opens a stale warm-start session as a fresh local chat without loading the stale session", async () => {
@@ -238,7 +238,7 @@ describe("ChatPanel send lifecycle", () => {
238238
await renderChatPanel();
239239
await flushAsync();
240240

241-
expect(getChatSnapshotMock).toHaveBeenCalledWith("session-assistant-only");
241+
expect(getChatSnapshotMock).toHaveBeenCalledWith("session-assistant-only", "workspace-1");
242242
expect(createNewChatSessionMock).not.toHaveBeenCalled();
243243
});
244244

0 commit comments

Comments
 (0)