Skip to content

Commit 869d207

Browse files
steipeteampagent
andauthored
1 parent 49d916e commit 869d207

6 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎src/tui/tui-command-handlers.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
type TuiPendingSubmit,
2525
} from "./tui-submit-state.js";
2626
import { createEditorSubmitHandler, createSubmitBurstCoalescer } from "./tui-submit.js";
27-
import type { SessionInfo } from "./tui-types.js";
27+
import type { SessionInfo, TuiOptions } from "./tui-types.js";
2828

2929
type LoadHistoryMock = ReturnType<typeof vi.fn> & (() => Promise<void>);
3030
type RunAuthFlow = NonNullable<Parameters<typeof createCommandHandlers>[0]["runAuthFlow"]>;
@@ -115,7 +115,7 @@ function createHarness(params?: {
115115
activeChatRunId?: string | null;
116116
pendingSubmit?: TuiPendingSubmit | null;
117117
activityStatus?: string;
118-
opts?: { local?: boolean };
118+
opts?: Pick<TuiOptions, "local" | "timeoutMs">;
119119
currentSessionId?: string | null;
120120
sessionGeneration?: number;
121121
currentAgentId?: string;
@@ -582,6 +582,23 @@ describe("tui command handlers", () => {
582582
expect(requestRender).toHaveBeenCalled();
583583
});
584584

585+
it("scopes an explicit timeout override to one message", async () => {
586+
const { handleCommand, sendMessage, sendChat, state } = createHarness();
587+
588+
await sendMessage("automatic hatch", 300_000);
589+
state.pendingSubmit = null;
590+
await handleCommand("later interactive turn");
591+
592+
expect(sendChat).toHaveBeenNthCalledWith(
593+
1,
594+
expect.objectContaining({ message: "automatic hatch", timeoutMs: 300_000 }),
595+
);
596+
expect(sendChat).toHaveBeenNthCalledWith(
597+
2,
598+
expect.objectContaining({ message: "later interactive turn", timeoutMs: undefined }),
599+
);
600+
});
601+
585602
it("projects the canonical pending user before chat.send is acknowledged", async () => {
586603
const deferred = createDeferred<{ runId: string }>();
587604
const sendChat = vi.fn(() => deferred.promise);

‎src/tui/tui-command-handlers.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
886886
tui.requestRender();
887887
};
888888

889-
const sendMessage = async (text: string) => {
889+
const sendMessage = async (text: string, timeoutMs = opts.timeoutMs) => {
890890
const admission = resolveMessageAdmission(text);
891891
if (admission.status === "blocked") {
892892
reportBlockedMessageSubmit(text, admission);
@@ -942,7 +942,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
942942
message: text,
943943
thinking: opts.thinking,
944944
deliver: deliverDefault,
945-
timeoutMs: opts.timeoutMs,
945+
timeoutMs,
946946
runId,
947947
});
948948
const acceptedRunId = sendResult.runId || runId;

‎src/tui/tui-types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export type TuiOptions = {
1717
timeoutMs?: number;
1818
historyLimit?: number;
1919
message?: string;
20+
/** Overrides timeoutMs only for the message sent automatically at startup. */
21+
initialMessageTimeoutMs?: number;
2022
/**
2123
* Internal CLI guard: after the standalone TUI returns, force the child
2224
* process out if imported runtime handles keep the event loop alive.

‎src/tui/tui.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ async function runTuiUnlocked(opts: RunTuiOptions): Promise<TuiResult> {
18581858
scheduleDynamicSlashCommandsRefresh();
18591859
if (!state.autoMessageSent && autoMessage) {
18601860
state.autoMessageSent = true;
1861-
await sendMessage(autoMessage);
1861+
await sendMessage(autoMessage, opts.initialMessageTimeoutMs);
18621862
if (!ownsConnection()) {
18631863
return;
18641864
}

‎src/wizard/setup.finalize.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ describe("finalizeSetupWizard", () => {
604604
local: true,
605605
deliver: false,
606606
message: undefined,
607-
timeoutMs: 300_000,
607+
initialMessageTimeoutMs: 300_000,
608608
});
609609
});
610610

@@ -669,6 +669,8 @@ describe("finalizeSetupWizard", () => {
669669
const tuiOptions = runTui.mock.calls.at(-1)?.[0] as Record<string, unknown>;
670670
expect(tuiOptions).not.toHaveProperty("url");
671671
expect(tuiOptions).not.toHaveProperty("token");
672+
expect(tuiOptions).toMatchObject({ initialMessageTimeoutMs: 300_000 });
673+
expect(tuiOptions).not.toHaveProperty("timeoutMs");
672674
});
673675

674676
it.each([
@@ -867,7 +869,7 @@ describe("finalizeSetupWizard", () => {
867869
local: true,
868870
deliver: false,
869871
message: "Wake up, my friend!",
870-
timeoutMs: 300_000,
872+
initialMessageTimeoutMs: 300_000,
871873
});
872874
});
873875

@@ -1026,7 +1028,7 @@ describe("finalizeSetupWizard", () => {
10261028
local: true,
10271029
deliver: false,
10281030
message: undefined,
1029-
timeoutMs: 300_000,
1031+
initialMessageTimeoutMs: 300_000,
10301032
});
10311033
});
10321034

@@ -1073,7 +1075,7 @@ describe("finalizeSetupWizard", () => {
10731075
local: true,
10741076
deliver: false,
10751077
message: "醒醒,我的朋友!",
1076-
timeoutMs: 300_000,
1078+
initialMessageTimeoutMs: 300_000,
10771079
});
10781080
} finally {
10791081
if (previousLocale === undefined) {
@@ -2013,9 +2015,10 @@ describe("finalizeSetupWizard", () => {
20132015
},
20142016
deliver: false,
20152017
message: undefined,
2016-
timeoutMs: 300_000,
2018+
initialMessageTimeoutMs: 300_000,
20172019
}),
20182020
);
2021+
expect(runTui.mock.calls.at(-1)?.[0]).not.toHaveProperty("timeoutMs");
20192022
expect(sessionGateway.close).toHaveBeenCalledWith({ reason: "onboarding tui exited" });
20202023
expect(cancelProcessExitAfterTuiReturn).toHaveBeenCalledWith(setupCleanupExitTimer);
20212024
expect(scheduleProcessExitAfterTuiReturn).toHaveBeenCalledTimes(2);

‎src/wizard/setup.finalize.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ export async function finalizeSetupWizard(
10381038
message: shouldSeedBootstrapHatch
10391039
? t("wizard.finalize.bootstrapHatchMessage")
10401040
: undefined,
1041-
timeoutMs: HATCH_TUI_TIMEOUT_MS,
1041+
initialMessageTimeoutMs: HATCH_TUI_TIMEOUT_MS,
10421042
});
10431043
} finally {
10441044
restoreTerminalState("post-setup tui", { resumeStdinIfPaused: false });

0 commit comments

Comments
 (0)