fix(web): keep Reload history off while the incoming tab loads (#814)

- _historyReloadActionEligible() also requires no terminal load state:
  selectSession sets it before switching activeSessionId, so the sync
  right after the switch no longer offers Reload for the loading tab.
- _clearTerminalLoadState() re-syncs the action, so a marked tab offers
  Reload once its load ends.
- Changeset: note the reading-position fix for live flushes at the
  scrollback cap.
This commit is contained in:
Hadrien Kerlero committed 2026-11-22 02:44:23 +01:00
1 parent b4d729a054
commit 5f0366c060
5 files changed
+101 -1

No files matched your search

+81
View File
@@ -13,6 +13,7 @@ type HistoryApp = {
sessions: Map<string, object>;
activeSessionId: string;
hideWelcome(): void;
selectSession(sessionId: string): Promise<void>;
_onSessionTerminal(event: { id: string; data: string }): void;
_liveOutputSinceFullPull: Set<string>;
_fullHistoryRepullInFlight: boolean;
@@ -39,6 +40,7 @@ type RepairWindow = Window & {
app: HistoryApp;
repairTest: { pulls: number; anchor: Anchor | null; inject: boolean };
repairReadiness?: { cols: number; rows: number; frames: number };
tabLoadTest?: { requested: boolean; release(): void; selection: Promise<void> };
};
const SESSION = 'history-repair-browser';
@@ -467,6 +469,85 @@ describe.each([true, false])('manual history gap repair (touch: %s)', (touch) =>
}, 60_000);
});
it('hides Reload history while a marked incoming tab capture is pending', async () => {
const { context, page } = await openTerminal(false);
const incoming = `${SESSION}-incoming`;
try {
await page.evaluate((session) => {
const w = window as RepairWindow;
const app = w.app;
app.terminal.scrollToLine(10);
app.sessions.set(session, { id: session, mode: 'omp', status: 'idle', name: 'Incoming history' });
app._liveOutputSinceFullPull.add(session);
const response = Promise.withResolvers<Response>();
const realFetch = window.fetch.bind(window);
const terminalBuffer = 'INCOMING-HISTORY\r\n';
w.tabLoadTest = {
requested: false,
release: () =>
response.resolve(
new Response(
JSON.stringify({
success: true,
data: { terminalBuffer, source: 'mux-full-history', paneHistoryLines: 1, truncated: false },
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
),
selection: Promise.resolve(),
};
window.fetch = ((input: RequestInfo | URL, init?: RequestInit) => {
const url = String(typeof input === 'string' ? input : ((input as Request).url ?? input));
if (!url.includes(`/api/sessions/${session}/terminal`)) return realFetch(input, init);
w.tabLoadTest!.requested = true;
return response.promise;
}) as typeof window.fetch;
}, incoming);
expect((await bufferState(page)).baseY - (await bufferState(page)).viewportY).toBeGreaterThan(5);
await page.evaluate((session) => {
const w = window as RepairWindow;
w.tabLoadTest!.selection = w.app.selectSession(session);
}, incoming);
await page.waitForFunction((session) => {
const w = window as RepairWindow;
return (
w.tabLoadTest?.requested &&
w.app.activeSessionId === session &&
w.app.terminalLoadStates.has(session) &&
w.app._isLoadingBuffer
);
}, incoming);
const bar = page.locator('#historyTruncationBar');
expect(await bar.getByRole('button', { name: 'Reload history' }).count()).toBe(0);
expect(await bar.isHidden()).toBe(true);
await page.evaluate(async () => {
const test = (window as RepairWindow).tabLoadTest!;
test.release();
await test.selection;
});
await page.waitForFunction((session) => {
const app = (window as RepairWindow).app;
return (
app.activeSessionId === session &&
!app.terminalLoadStates.has(session) &&
!app._isLoadingBuffer &&
!app.pendingWrites.length &&
!app._terminalWriteInFlight
);
}, incoming);
expect(
await page.evaluate(() => {
const buffer = (window as RepairWindow).app.terminal.buffer.active;
return buffer.getLine(0)?.translateToString(true);
})
).toBe('INCOMING-HISTORY');
} catch (error) {
throw await failureDetails(page, error);
} finally {
await context.close();
}
}, 60_000);
it('holds an OMP reading row through repeated repaint history and capped live flushes', async () => {
const { context, page } = await openTerminal(true);
const readingRow = 'Reading tool result: src/engine.ts — preserve this row';
+15
View File
@@ -987,6 +987,7 @@ describe('manual history banner action', () => {
detached: false,
enabled: true,
loadingBuffer: false,
loadState: false,
paneHistoryLines: undefined as number | undefined,
...options,
};
@@ -1026,6 +1027,7 @@ describe('manual history banner action', () => {
_historyNoticeRevealedFor: null as string | null,
_fullHistoryRepullInFlight: Boolean(state.inFlight),
_isLoadingBuffer: Boolean(state.loadingBuffer),
terminalLoadStates: new Map(state.loadState ? [['s1', { generation: 1, phase: 'resizing' }]] : []),
_paneHistoryLines: new Map<string, number>(
state.paneHistoryLines === undefined ? [] : [['s1', Number(state.paneHistoryLines)]]
),
@@ -1058,6 +1060,7 @@ describe('manual history banner action', () => {
{ opts: { paneHistoryLines: 0 }, visible: true },
{ opts: { paneHistoryLines: 5 }, visible: true },
{ opts: { loadingBuffer: true }, visible: false },
{ opts: { loadState: true }, visible: false },
{ opts: { tiles: true }, visible: false },
{ opts: { active: false }, visible: false },
{ opts: { detached: true }, visible: false },
@@ -1102,6 +1105,18 @@ describe('manual history banner action', () => {
expect(bar.hidden).toBe(true);
});
it('shows the action when the matching terminal load state clears', () => {
const { app, bar, button } = fixture({ loadState: true });
Object.assign(app, { _updateTerminalLoadTab: vi.fn() });
app._syncHistoryReloadAction();
expect(bar.hidden).toBe(true);
expect(button()).toBeUndefined();
loadAppMethod('_clearTerminalLoadState').call(app, 's1', 1);
expect(app.terminalLoadStates.has('s1')).toBe(false);
expect(bar.hidden).toBe(false);
expect(button()!.textContent).toBe('Reload history');
});
it('syncs the action after a marked session finishes loading', () => {
const { app, bar, button } = fixture({ marked: false });
const owner = (mixin._beginBufferLoad as Function).call(app);