Skip to content

Commit b0253c2

Browse files
authored
test(tui): stabilize live session proof
1 parent 42527bb commit b0253c2

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Docs: https://docs.openclaw.ai
5353
- **Control UI connection errors:** preserve structured pairing and authentication failures for pending RPC callers while keeping generic disconnect behavior unchanged. (#54758) Thanks @ruanrrn.
5454
- **iOS embedded terminal:** open the terminal-only Control surface directly while native Gateway authentication connects instead of exposing the Web UI login screen.
5555
- **TUI startup status:** show `starting up` during post-connect initialization without overwriting active-run or reconnect state. (#93999) Thanks @ml12580.
56-
- **TUI live session history:** refresh the selected transcript when another Gateway client appends a message, while preserving local runs and preventing stale history loads from repainting a newly selected session. (#96252, #38829) Thanks @harjothkhara.
5756
- **Control UI restart recovery:** recover stale bundle pages through a bounded whole-document refresh after Gateway updates or restarts. (#99111) Thanks @ZengWen-DT.
5857
- **TUI active Gateway ports:** follow the verified active local Gateway port when no explicit URL, port, or remote target is configured. (#73338, #42461) Thanks @haishmg and @vincentkoc.
5958
- **Apple chat run recovery:** restore active responses from canonical Gateway history after reconnects, foreground resumes, and event gaps, while preserving gateway user-turn identity across Codex and Copilot transcript mirrors to prevent duplicate rows. (#100277)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,19 +1084,21 @@ describe("tui-event-handlers: handleAgentEvent", () => {
10841084
});
10851085

10861086
it("coalesces overlapping session.message history reloads", async () => {
1087-
let resolveFirstHistory!: () => void;
1087+
let resolveFirstHistory!: (result: TuiHistoryLoadResult) => void;
10881088
const { state, loadHistory, handleSessionMessageEvent } = createHandlersHarness({
10891089
state: {
10901090
activeChatRunId: null,
10911091
},
10921092
});
1093-
const firstHistory = new Promise<void>((resolve) => {
1093+
const firstHistory = new Promise<TuiHistoryLoadResult>((resolve) => {
10941094
resolveFirstHistory = resolve;
10951095
});
10961096
let historyCalls = 0;
10971097
loadHistory.mockImplementation(() => {
10981098
historyCalls += 1;
1099-
return historyCalls === 1 ? firstHistory : Promise.resolve();
1099+
return historyCalls === 1
1100+
? firstHistory
1101+
: Promise.resolve({ loaded: true, inFlightRunId: null });
11001102
});
11011103

11021104
handleSessionMessageEvent({
@@ -1110,7 +1112,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
11101112

11111113
expect(loadHistory).toHaveBeenCalledTimes(1);
11121114

1113-
resolveFirstHistory();
1115+
resolveFirstHistory({ loaded: true, inFlightRunId: null });
11141116
await Promise.resolve();
11151117
await Promise.resolve();
11161118

‎src/tui/tui-pty-local.e2e.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ async function waitForOutputAfter(run: PtyRun, needle: string, offset: number) {
4040
});
4141
}
4242

43+
async function waitForGatewaySessionIdle(
44+
client: Awaited<ReturnType<typeof connectGatewayClient>>,
45+
sessionKey: string,
46+
) {
47+
const deadline = Date.now() + LOCAL_OUTPUT_TIMEOUT_MS;
48+
while (Date.now() < deadline) {
49+
const result = await client.request<{
50+
sessions: Array<{ key: string; hasActiveRun?: boolean }>;
51+
}>("sessions.list", { limit: 100 });
52+
const session = result.sessions.find((entry) => entry.key === sessionKey);
53+
if (session?.hasActiveRun === false) {
54+
return;
55+
}
56+
await sleep(50);
57+
}
58+
throw new Error(`Gateway still reports ${sessionKey} as active`);
59+
}
60+
4361
async function readRequestBody(req: IncomingMessage): Promise<string> {
4462
const chunks: Buffer[] = [];
4563
for await (const chunk of req) {
@@ -608,13 +626,20 @@ describe("TUI PTY real backends", () => {
608626
queueMode: "followup",
609627
firstResponseDelayMs: 0,
610628
});
629+
let sessionClient: Awaited<ReturnType<typeof connectGatewayClient>> | undefined;
611630
try {
612631
await fixture.run.waitForOutput("gateway connected", LOCAL_STARTUP_TIMEOUT_MS);
613632
await fixture.run.write("seed gateway session\r");
614633
await fixture.run.waitForOutput("FIRST_RUN_ACTIVE");
615634

616635
const responseOffset = fixture.run.output().lastIndexOf("FIRST_RUN_ACTIVE");
617636
await waitForOutputAfter(fixture.run, "| idle", responseOffset);
637+
sessionClient = await connectGatewayClient({
638+
url: fixture.gateway.url,
639+
token: fixture.gateway.gatewayToken,
640+
clientDisplayName: "new-session-active-run-probe",
641+
});
642+
await waitForGatewaySessionIdle(sessionClient, "agent:main:main");
618643

619644
await fixture.run.write("/new\r", { delay: false });
620645
await fixture.run.waitForOutput("new session: agent:main:tui-");
@@ -634,6 +659,7 @@ describe("TUI PTY real backends", () => {
634659
await fixture.run.write("/exit\r", { delay: false });
635660
expect((await fixture.run.waitForExit()).exitCode).toBe(0);
636661
} finally {
662+
sessionClient?.stop();
637663
await fixture.cleanup();
638664
}
639665
},

0 commit comments

Comments
 (0)