Skip to content

Commit e1dcd27

Browse files
committed
fix(tui): force render final early returns
1 parent 8ee767b commit e1dcd27

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/tui/tui-event-handlers.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
469469
});
470470

471471
it("keeps a local BTW result visible when its empty final chat event arrives", () => {
472-
const { state, btw, loadHistory, noteLocalBtwRunId, handleBtwEvent, handleChatEvent } =
472+
const { state, btw, loadHistory, noteLocalBtwRunId, tui, handleBtwEvent, handleChatEvent } =
473473
createHandlersHarness({
474474
state: { activeChatRunId: null },
475475
});
@@ -482,6 +482,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
482482
question: "what changed?",
483483
text: "nothing important",
484484
} satisfies BtwEvent);
485+
tui.requestRender.mockClear();
485486

486487
handleChatEvent({
487488
runId: "run-btw",
@@ -495,6 +496,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
495496
text: "nothing important",
496497
isError: undefined,
497498
});
499+
expect(tui.requestRender).toHaveBeenCalledWith(true);
498500
});
499501

500502
it("clears stale streaming for a local BTW empty final without hiding the result", () => {
@@ -701,6 +703,25 @@ describe("tui-event-handlers: handleAgentEvent", () => {
701703
expect(loadHistory).toHaveBeenCalledTimes(1);
702704
});
703705

706+
it("forces render when a command final only adds system text", () => {
707+
const { state, chatLog, tui, handleChatEvent } = createHandlersHarness({
708+
state: { activeChatRunId: "run-command" },
709+
});
710+
711+
handleChatEvent({
712+
runId: "run-command",
713+
sessionKey: state.currentSessionKey,
714+
state: "final",
715+
message: {
716+
command: true,
717+
content: [{ type: "text", text: "/status done" }],
718+
},
719+
});
720+
721+
expect(chatLog.addSystem).toHaveBeenCalledWith("/status done");
722+
expect(tui.requestRender).toHaveBeenCalledWith(true);
723+
});
724+
704725
it("binds optimistic pending messages to the first gateway run id and skips history reload", () => {
705726
const { state, loadHistory, isLocalRunId, handleChatEvent } = createHandlersHarness({
706727
state: { activeChatRunId: null, pendingOptimisticUserMessage: true },
@@ -1127,7 +1148,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
11271148
});
11281149

11291150
it("reloads history when a local run ends without a displayable final message", () => {
1130-
const { state, loadHistory, noteLocalRunId, handleChatEvent } = createHandlersHarness({
1151+
const { state, loadHistory, noteLocalRunId, tui, handleChatEvent } = createHandlersHarness({
11311152
state: { activeChatRunId: "run-local-silent" },
11321153
});
11331154

@@ -1140,6 +1161,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
11401161
});
11411162

11421163
expect(loadHistory).toHaveBeenCalledTimes(1);
1164+
expect(tui.requestRender).toHaveBeenCalledWith(true);
11431165
});
11441166

11451167
it("does not reload history for local run with empty final when another run is active (#53115)", () => {

src/tui/tui-event-handlers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type EventHandlerChatLog = {
2222
};
2323

2424
type EventHandlerTui = {
25-
requestRender: () => void;
25+
requestRender: (force?: boolean) => void;
2626
};
2727

2828
type EventHandlerBtwPresenter = {
@@ -489,7 +489,7 @@ export function createEventHandlers(context: EventHandlerContext) {
489489
forgetLocalBtwRunId?.(evt.runId);
490490
noteFinalizedRun(evt.runId);
491491
clearStaleStreamingIfNoTrackedRunRemains();
492-
tui.requestRender();
492+
tui.requestRender(true);
493493
return;
494494
}
495495
if (!evt.message) {
@@ -498,7 +498,7 @@ export function createEventHandlers(context: EventHandlerContext) {
498498
});
499499
chatLog.dropAssistant(evt.runId);
500500
finalizeRun({ runId: evt.runId, wasActiveRun, status: "idle" });
501-
tui.requestRender();
501+
tui.requestRender(true);
502502
return;
503503
}
504504
if (isCommandMessage(evt.message)) {
@@ -508,7 +508,7 @@ export function createEventHandlers(context: EventHandlerContext) {
508508
chatLog.addSystem(text);
509509
}
510510
finalizeRun({ runId: evt.runId, wasActiveRun, status: "idle", displayedFinal: true });
511-
tui.requestRender();
511+
tui.requestRender(true);
512512
return;
513513
}
514514
maybeRefreshHistoryForRun(evt.runId);

0 commit comments

Comments
 (0)