mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(web): make the early history repair a manual Reload history action (#814)
- Scrolling pulls tmux history only at the top of the buffer again (#205); the automatic pull on any upward scroll is removed. - Reload history lives in the existing #historyTruncationBar on desktop and touch, shown for a marked non-shell session scrolled away from live output. It never duplicates Load full history; one × dismisses what the bar carried. - New per-device setting historyReloadAction (Terminal & Input > Scrolling & rendering), default on, kept out of SettingsUpdateSchema. - Eligibility sync is transition-only and onScroll is coalesced per frame. - Remove the floating #historyReloadBtn and its z-index 20 layer. - Deferred dropped-output recovery resumes at its saved attempt. - zh-CN entries for the new strings; docs and changeset updated.
This commit is contained in:
1 parent
b890ef3302
commit
fd6b392b4d
13 files changed
+517
-271
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/** Real xterm + trusted phone gestures recover tmux repaint gaps while reading (#814). */
|
||||
/** Real xterm + manual banner actions recover tmux repaint gaps while reading (#814). */
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { chromium, type Browser, type BrowserContext, type Page } from 'playwright';
|
||||
import type { Terminal } from '@xterm/xterm';
|
||||
@@ -29,7 +29,11 @@ type HistoryApp = {
|
||||
_lastResizeDims: { cols: number; rows: number } | null;
|
||||
_syncStickyScrollBaseline(): void;
|
||||
_captureViewportAnchor(): Anchor;
|
||||
_syncHistoryReloadButton(): void;
|
||||
_syncHistoryReloadAction(): void;
|
||||
loadAppSettingsFromStorage(): Record<string, unknown>;
|
||||
saveAppSettingsToStorage(settings: Record<string, unknown>): void;
|
||||
_setHistoryTruncation(sessionId: string, payload: Record<string, unknown>): void;
|
||||
_setHistoryNoticeRevealed(sessionId: string): void;
|
||||
};
|
||||
type RepairWindow = Window & {
|
||||
app: HistoryApp;
|
||||
@@ -331,20 +335,29 @@ async function waitForRepair(page: Page): Promise<void> {
|
||||
|
||||
const allNumbers = Array.from({ length: 144 }, (_, i) => `NUMBER-${String(i).padStart(3, '0')}`);
|
||||
|
||||
describe('history gap repair on phones', () => {
|
||||
it('repairs from mid-history after a real upward scroll and holds the content anchor', async () => {
|
||||
const { context, page } = await openTerminal(true);
|
||||
describe.each([true, false])('manual history gap repair (touch: %s)', (touch) => {
|
||||
async function readHistory(page: Page) {
|
||||
if (touch) await scrollHistoryByTouch(page, 100);
|
||||
else await page.evaluate(() => (window as RepairWindow).app.terminal.scrollToLine(10));
|
||||
const position = await page.evaluate(() => {
|
||||
const b = (window as RepairWindow).app.terminal.buffer.active;
|
||||
return { viewportY: b.viewportY, baseY: b.baseY };
|
||||
});
|
||||
expect(position.viewportY).toBeGreaterThan(0);
|
||||
expect(position.baseY - position.viewportY).toBeGreaterThan(5);
|
||||
}
|
||||
|
||||
it('repairs mid-history only on a banner tap/click and holds the reading line offset', async () => {
|
||||
const { context, page } = await openTerminal(touch);
|
||||
try {
|
||||
await scrollHistoryByTouch(page, 100);
|
||||
const position = await page.evaluate(() => {
|
||||
const b = (window as RepairWindow).app.terminal.buffer.active;
|
||||
return { viewportY: b.viewportY, baseY: b.baseY };
|
||||
});
|
||||
expect(position.viewportY).toBeGreaterThan(0);
|
||||
expect(position.baseY - position.viewportY).toBeGreaterThan(5);
|
||||
await readHistory(page);
|
||||
await burst(page);
|
||||
expect((await bufferState(page)).numbers).not.toContain('NUMBER-090');
|
||||
await scrollHistoryByTouch(page, 40);
|
||||
expect((await bufferState(page)).pulls).toBe(0);
|
||||
const button = page.locator('#historyTruncationBar').getByRole('button', { name: 'Reload history' });
|
||||
await button.waitFor({ state: 'visible' });
|
||||
if (touch) await button.tap();
|
||||
else await button.click();
|
||||
await waitForRepair(page);
|
||||
const state = await bufferState(page);
|
||||
expect(state.numbers).toEqual(allNumbers);
|
||||
@@ -358,14 +371,16 @@ describe('history gap repair on phones', () => {
|
||||
}, 60_000);
|
||||
|
||||
it('keeps output arriving during the capture download exactly once', async () => {
|
||||
const { context, page } = await openTerminal(true);
|
||||
const { context, page } = await openTerminal(touch);
|
||||
try {
|
||||
await scrollHistoryByTouch(page, 100);
|
||||
await readHistory(page);
|
||||
await burst(page);
|
||||
await page.evaluate(() => {
|
||||
(window as RepairWindow).repairTest.inject = true;
|
||||
});
|
||||
await scrollHistoryByTouch(page, 40);
|
||||
const button = page.locator('#historyTruncationBar').getByRole('button', { name: 'Reload history' });
|
||||
if (touch) await button.tap();
|
||||
else await button.click();
|
||||
await waitForRepair(page);
|
||||
const state = await bufferState(page);
|
||||
const detail = JSON.stringify({ state, events: pageEvents.get(page) });
|
||||
@@ -378,69 +393,71 @@ describe('history gap repair on phones', () => {
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it('offers a touch reload while reading and tapping it recovers the missing rows', async () => {
|
||||
const { context, page } = await openTerminal(true);
|
||||
try {
|
||||
await scrollHistoryByTouch(page, 100);
|
||||
await burst(page);
|
||||
const button = page.getByRole('button', { name: 'Reload history' });
|
||||
await button.waitFor({ state: 'visible' });
|
||||
const box = await button.boundingBox();
|
||||
expect(box!.height).toBeGreaterThanOrEqual(44);
|
||||
expect(box!.width).toBeGreaterThanOrEqual(44);
|
||||
await button.tap();
|
||||
await waitForRepair(page);
|
||||
const state = await bufferState(page);
|
||||
expect(state.numbers).toEqual(allNumbers);
|
||||
expect(state.anchorOffset).toBe(state.expectedOffset);
|
||||
expect(await button.isVisible()).toBe(false);
|
||||
} catch (error) {
|
||||
throw await failureDetails(page, error);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
}, 60_000);
|
||||
it.each([false, true])(
|
||||
'keeps the revealed notice and one unobstructed load control (exhausted: %s)',
|
||||
async (exhausted) => {
|
||||
const { context, page } = await openTerminal(touch);
|
||||
try {
|
||||
await readHistory(page);
|
||||
await burst(page);
|
||||
await page.evaluate(
|
||||
({ session, exhausted }) => {
|
||||
const app = (window as RepairWindow).app;
|
||||
app._setHistoryTruncation(session, {
|
||||
truncated: true,
|
||||
truncationReason: 'tail',
|
||||
source: 'mux-full-history',
|
||||
fullSize: 2 * 1024 * 1024,
|
||||
retainedBytes: 1024 * 1024,
|
||||
paneHistoryLines: 121,
|
||||
exhausted,
|
||||
});
|
||||
app._setHistoryNoticeRevealed(session);
|
||||
},
|
||||
{ session: SESSION, exhausted }
|
||||
);
|
||||
const bar = page.locator('#historyTruncationBar');
|
||||
await bar.waitFor({ state: 'visible' });
|
||||
expect(await bar.locator('.history-trunc-text').textContent()).not.toBe(
|
||||
'Recent output may be missing from this view.'
|
||||
);
|
||||
const button = bar.locator('.history-trunc-load');
|
||||
expect(await button.count()).toBe(1);
|
||||
expect(await button.textContent()).toBe(exhausted ? 'Reload history' : 'Load full history');
|
||||
for (const control of await bar.getByRole('button').all()) {
|
||||
expect(
|
||||
await control.evaluate((element) => {
|
||||
const box = element.getBoundingClientRect();
|
||||
return document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2) === element;
|
||||
})
|
||||
).toBe(true);
|
||||
}
|
||||
} catch (error) {
|
||||
throw await failureDetails(page, error);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
},
|
||||
60_000
|
||||
);
|
||||
|
||||
it('floats a 44px reload control on wide touch viewports without resizing the terminal', async () => {
|
||||
const { context, page } = await openTerminal(true, { width: 1280, height: 800 });
|
||||
it('does not offer a reload action when disabled on this device', async () => {
|
||||
const { context, page } = await openTerminal(touch);
|
||||
try {
|
||||
await page.evaluate(() => {
|
||||
(window as RepairWindow).app.terminal.scrollToLine(10);
|
||||
const app = (window as RepairWindow).app;
|
||||
app.saveAppSettingsToStorage({ ...app.loadAppSettingsFromStorage(), historyReloadAction: false });
|
||||
app._syncHistoryReloadAction();
|
||||
});
|
||||
const dimensions = () =>
|
||||
page.evaluate(() => {
|
||||
const terminal = (window as RepairWindow).app.terminal;
|
||||
const box = document.getElementById('terminalContainer')!.getBoundingClientRect();
|
||||
return { width: box.width, height: box.height, cols: terminal.cols, rows: terminal.rows };
|
||||
});
|
||||
const before = await dimensions();
|
||||
expect(await page.locator('#historyReloadBtn').isVisible()).toBe(false);
|
||||
await readHistory(page);
|
||||
await burst(page);
|
||||
const button = page.getByRole('button', { name: 'Reload history' });
|
||||
await button.waitFor({ state: 'visible' });
|
||||
expect(await button.evaluate((element) => getComputedStyle(element).position)).toBe('absolute');
|
||||
const box = await button.boundingBox();
|
||||
expect(box!.height).toBeGreaterThanOrEqual(44);
|
||||
expect(box!.width).toBeGreaterThanOrEqual(44);
|
||||
expect(await dimensions()).toEqual(before);
|
||||
} catch (error) {
|
||||
throw await failureDetails(page, error);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it('never shows the reload control in a non-touch context', async () => {
|
||||
const { context, page } = await openTerminal(false);
|
||||
try {
|
||||
// Wait for the same coalesced scroll synchronization used in production.
|
||||
await page.evaluate(() => {
|
||||
(window as RepairWindow).app.terminal.scrollToLine(10);
|
||||
const { promise, resolve } = Promise.withResolvers<void>();
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
|
||||
return promise;
|
||||
});
|
||||
await burst(page);
|
||||
await page.evaluate(() => {
|
||||
(window as RepairWindow).app._syncHistoryReloadButton();
|
||||
});
|
||||
expect(await page.locator('#historyReloadBtn').isVisible()).toBe(false);
|
||||
expect(await page.getByRole('button', { name: 'Reload history' }).isVisible()).toBe(false);
|
||||
expect((await bufferState(page)).pulls).toBe(0);
|
||||
} catch (error) {
|
||||
throw await failureDetails(page, error);
|
||||
|
||||
@@ -186,28 +186,33 @@ describe('partial-history notice: lazy reveal', () => {
|
||||
expect(loadButton(bar)?.textContent).toBe('Load full history');
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ viewportY: 0, revealed: true },
|
||||
{ viewportY: 200, revealed: false },
|
||||
])(
|
||||
'retains the initiating top state through a marked repair from row $viewportY',
|
||||
async ({ viewportY, revealed }) => {
|
||||
const { app, bar, buffer } = makeApp();
|
||||
app._setHistoryTruncation('s1', TAIL);
|
||||
app._liveOutputSinceFullPull.add('s1');
|
||||
app._maybeRefetchFullHistory.mockImplementation(async () => {
|
||||
app._setHistoryTruncation('s1', { ...TAIL, source: 'mux-full-history' });
|
||||
buffer.viewportY = 100; // The content anchor restored the old top below recovered rows.
|
||||
});
|
||||
buffer.viewportY = viewportY;
|
||||
app._maybeLoadMoreHistoryOnScroll(-5);
|
||||
for (let i = 0; i < 5; i++) await Promise.resolve();
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledOnce();
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledWith({ anchor: 'content' });
|
||||
expect(bar.hidden).toBe(!revealed);
|
||||
if (revealed) expect(loadButton(bar)?.textContent).toBe('Load full history');
|
||||
}
|
||||
);
|
||||
it.each([0, 200])('marked scrolling from row %s remains top-only', async (viewportY) => {
|
||||
const { app, bar, buffer, settle } = makeApp();
|
||||
app._setHistoryTruncation('s1', TAIL);
|
||||
app._liveOutputSinceFullPull.add('s1');
|
||||
buffer.viewportY = viewportY;
|
||||
app._maybeLoadMoreHistoryOnScroll(-5);
|
||||
await settle();
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledTimes(viewportY === 0 ? 1 : 0);
|
||||
if (viewportY === 0) expect(app._maybeRefetchFullHistory).toHaveBeenCalledWith();
|
||||
expect(bar.hidden).toBe(viewportY !== 0);
|
||||
});
|
||||
|
||||
it('reveals the resulting notice when a top pull grows the buffer and restores below row zero', async () => {
|
||||
const { app, bar, buffer } = makeApp();
|
||||
app._setHistoryTruncation('s1', TAIL);
|
||||
app._maybeRefetchFullHistory.mockImplementation(async () => {
|
||||
buffer.baseY += 100;
|
||||
buffer.viewportY = 100; // Recovered rows precede the old top reading position.
|
||||
});
|
||||
buffer.viewportY = 0;
|
||||
app._maybeLoadMoreHistoryOnScroll(-500);
|
||||
for (let i = 0; i < 5; i++) await Promise.resolve();
|
||||
expect(buffer.viewportY).toBe(100);
|
||||
expect(app._historyNoticeRevealedFor).toBe('s1');
|
||||
expect(bar.hidden).toBe(false);
|
||||
expect(loadButton(bar)?.textContent).toBe('Load full history');
|
||||
});
|
||||
|
||||
it('a later frame of the same gesture does not flash the pre-pull state while the pull runs', async () => {
|
||||
const { app, bar, buffer } = makeApp();
|
||||
|
||||
@@ -182,6 +182,45 @@ async function boot(who: Who, stored: Settings, server: Settings | null) {
|
||||
// What the server already holds for this instance: an admin has saved App Settings before.
|
||||
const SERVER: Settings = { autoNameSessions: false, workspaceHooksEnabled: true, claudeMode: 'auto' };
|
||||
|
||||
describe('the per-device History Reload Button setting', () => {
|
||||
it.each(['non-admin', 'admin', 'single-user'] as const)(
|
||||
'%s saves locally and never sends the device key',
|
||||
async (who) => {
|
||||
const { app, target, box, storedBlob } = await boot(who, { ...SERVER }, SERVER);
|
||||
target._syncHistoryReloadAction = vi.fn();
|
||||
await open_(app);
|
||||
expect(box('appSettingsHistoryReloadAction').checked).toBe(true);
|
||||
expect(app._displaySettingKeySet().has('historyReloadAction')).toBe(true);
|
||||
box('appSettingsHistoryReloadAction').checked = false;
|
||||
await app.saveAppSettings();
|
||||
expect(storedBlob().historyReloadAction).toBe(false);
|
||||
expect(target._syncHistoryReloadAction).toHaveBeenCalledOnce();
|
||||
if (who === 'non-admin') expect(target._apiPut).not.toHaveBeenCalled();
|
||||
else {
|
||||
const [path, body] = target._apiPut.mock.calls[0] as [string, Settings];
|
||||
expect(path).toBe('/api/settings');
|
||||
expect(body).not.toHaveProperty('historyReloadAction');
|
||||
expect(SettingsUpdateSchema.safeParse(body).error?.issues ?? []).toEqual([]);
|
||||
}
|
||||
await open_(app);
|
||||
expect(box('appSettingsHistoryReloadAction').checked).toBe(false);
|
||||
}
|
||||
);
|
||||
|
||||
it('preserves the local choice when another device saved a different value', async () => {
|
||||
const { app, box, storedBlob } = await boot('admin', { historyReloadAction: false }, { historyReloadAction: true });
|
||||
await open_(app);
|
||||
expect(box('appSettingsHistoryReloadAction').checked).toBe(false);
|
||||
expect(storedBlob().historyReloadAction).toBe(false);
|
||||
});
|
||||
|
||||
it('also defaults to enabled on handheld devices', async () => {
|
||||
const { app, win } = await boot('admin', {}, {});
|
||||
win.eval('MobileDetection.isHandheldDevice = () => true;');
|
||||
expect(app.getDefaultSettings().historyReloadAction).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a non-admin in multi-user mode saving App Settings', () => {
|
||||
it('keeps the per-device keys, sends no PUT, keeps the synced key at the server value, and toasts once', async () => {
|
||||
const { app, target, box, storedBlob, toasts, puts } = await boot('non-admin', { ...SERVER }, SERVER);
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('shell scroll-up pulls a bounded window of tmux history', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('early full-history recovery above live output (#814)', () => {
|
||||
describe('manual full-history recovery while reading (#814)', () => {
|
||||
function makeScrollApp(mode = 'omp') {
|
||||
const { app: base, urls } = makeApp(mode, { bufferRows: 130, capture: lines(400) });
|
||||
const app = Object.assign(base, {
|
||||
@@ -348,29 +348,20 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
});
|
||||
return { ready, release };
|
||||
}
|
||||
return { app, active, urls, liveOutput, scroll, pauseReplay };
|
||||
const reload = () => app._maybeRefetchFullHistory({ force: true, anchor: 'content' });
|
||||
return { app, active, urls, liveOutput, scroll, reload, pauseReplay };
|
||||
}
|
||||
|
||||
it('pulls on the first upward scroll after live output and preserves distance from the new bottom', async () => {
|
||||
it('never pulls mid-history after live output, but still pulls at the top', async () => {
|
||||
const { app, active, urls, liveOutput, scroll } = makeScrollApp();
|
||||
liveOutput();
|
||||
await scroll(-5);
|
||||
expect(urls).toEqual([]);
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(true);
|
||||
await scroll(-active.viewportY);
|
||||
expect(urls).toEqual(['/api/sessions/s1/terminal?full=1']);
|
||||
expect(app.chunkedTerminalWrite).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
32 * 1024,
|
||||
expect.stringMatching(/^buffer-/),
|
||||
expect.objectContaining({ flushQueued: true })
|
||||
);
|
||||
expect(active.viewportY).toBe(365);
|
||||
expect(active.baseY - active.viewportY).toBe(5);
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledWith();
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(false);
|
||||
expect(app._syncStickyScrollBaseline).toHaveBeenCalledOnce();
|
||||
// No second early pull until another live write dirties this session.
|
||||
active.viewportY = active.baseY;
|
||||
app._fullHistoryRepullAt.clear();
|
||||
await scroll(-3);
|
||||
expect(urls).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -381,10 +372,11 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
{ moves: [20, -12], distance: 12 },
|
||||
{ moves: [-1000, 30], distance: 340 },
|
||||
])('replays travel $moves made during an unfinished replay, clamped per move', async ({ moves, distance }) => {
|
||||
const { app, active, liveOutput, scroll, pauseReplay } = makeScrollApp();
|
||||
const { app, active, liveOutput, reload, pauseReplay } = makeScrollApp();
|
||||
liveOutput();
|
||||
active.viewportY -= 5; // Read five rows above live output before the manual action.
|
||||
const paused = pauseReplay();
|
||||
const pull = scroll(-5);
|
||||
const pull = reload();
|
||||
await paused.ready;
|
||||
// The temporary reset buffer cannot scroll, but the gesture still counts.
|
||||
for (const move of moves) (mixin._maybeLoadMoreHistoryOnScroll as Function).call(app, move);
|
||||
@@ -396,7 +388,7 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
});
|
||||
|
||||
it('queues download-time output and replays it through batchTerminalWrite after the capture', async () => {
|
||||
const { app, urls, liveOutput, scroll } = makeScrollApp();
|
||||
const { app, urls, liveOutput, reload } = makeScrollApp();
|
||||
liveOutput();
|
||||
const fetchCapture = app._fetchTerminalCapture.getMockImplementation()!;
|
||||
const { promise, resolve: release } = Promise.withResolvers<void>();
|
||||
@@ -406,7 +398,7 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
await promise;
|
||||
return capture;
|
||||
});
|
||||
const pull = scroll(-5);
|
||||
const pull = reload();
|
||||
loadAppMethod('_onSessionTerminal').call(app, { id: 's1', data: 'download-time output' });
|
||||
expect(app._loadBufferQueue).toEqual([expect.objectContaining({ data: 'download-time output' })]);
|
||||
release();
|
||||
@@ -420,12 +412,12 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps live output flushed before the final restore dirty for the next early pull', async () => {
|
||||
const { app, active, urls, liveOutput, scroll, pauseReplay } = makeScrollApp();
|
||||
it('keeps live output flushed before the final restore dirty for the next manual pull', async () => {
|
||||
const { app, active, urls, liveOutput, reload, pauseReplay } = makeScrollApp();
|
||||
liveOutput();
|
||||
const generation = app._liveOutputGen.get('s1');
|
||||
const paused = pauseReplay(liveOutput);
|
||||
const pull = scroll(-5);
|
||||
const pull = reload();
|
||||
await paused.ready;
|
||||
paused.release();
|
||||
await pull;
|
||||
@@ -433,7 +425,7 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(true);
|
||||
app._fullHistoryRepullAt.clear();
|
||||
active.viewportY = active.baseY;
|
||||
await scroll(-3);
|
||||
await reload();
|
||||
expect(urls).toEqual(['/api/sessions/s1/terminal?full=1', '/api/sessions/s1/terminal?full=1']);
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(false);
|
||||
});
|
||||
@@ -464,37 +456,29 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
expect(app._liveOutputSinceFullPull.size).toBe(0);
|
||||
});
|
||||
|
||||
it('repairs while already reading mid-history, but never on downward travel', async () => {
|
||||
const { app, active, urls, liveOutput, scroll } = makeScrollApp();
|
||||
it('keeps marked mid-history travel local in either direction', async () => {
|
||||
const { active, urls, liveOutput, scroll } = makeScrollApp();
|
||||
liveOutput();
|
||||
active.viewportY = 50;
|
||||
await scroll(-5);
|
||||
expect(urls).toHaveLength(1);
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledWith({ anchor: 'content' });
|
||||
app._fullHistoryRepullAt.clear();
|
||||
liveOutput();
|
||||
await scroll(3);
|
||||
expect(urls).toHaveLength(1);
|
||||
expect(urls).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(['_isLoadingBuffer', '_fullHistoryRepullInFlight'] as const)('respects the %s guard', async (guard) => {
|
||||
const { app, urls, liveOutput, scroll } = makeScrollApp();
|
||||
const { app, urls, liveOutput, reload } = makeScrollApp();
|
||||
liveOutput();
|
||||
app[guard] = true;
|
||||
await scroll(-5);
|
||||
await reload();
|
||||
expect(urls).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps the cooldown and downgrade guard on an early pull', async () => {
|
||||
const { app, active, urls, liveOutput, scroll } = makeScrollApp();
|
||||
it('bypasses the cooldown for manual reload but keeps the downgrade guard', async () => {
|
||||
const { app, active, urls, liveOutput, reload } = makeScrollApp();
|
||||
liveOutput();
|
||||
app._fullHistoryRepullAt.set('s1', Date.now());
|
||||
await scroll(-3);
|
||||
expect(urls).toEqual([]);
|
||||
app._fullHistoryRepullAt.clear();
|
||||
active.viewportY = active.baseY;
|
||||
active.length = 1000;
|
||||
await scroll(-3);
|
||||
await reload();
|
||||
expect(urls).toHaveLength(1);
|
||||
expect(app._resetTerminalForReplay).not.toHaveBeenCalled();
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(true);
|
||||
@@ -598,17 +582,43 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
}
|
||||
);
|
||||
|
||||
it.each([false, true])('resumes a deferred recovery at its saved attempt (timer armed: %s)', async (armed) => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const { app } = makeApp('omp', { bufferRows: 30, capture: lines(400) });
|
||||
const retry = vi.fn(() => false);
|
||||
const schedule = loadAppMethod('_scheduleDroppedOutputRecovery', {
|
||||
setTimeout,
|
||||
window: { CodemanDroppedOutput: { DROP_RECOVERY_DELAY_MS: 2000, shouldRetryDroppedOutputRecovery: retry } },
|
||||
});
|
||||
Object.assign(app, {
|
||||
_scheduleDroppedOutputRecovery: (...args: unknown[]) => schedule.apply(app, args),
|
||||
_onSessionNeedsRefresh: vi.fn(async () => false),
|
||||
});
|
||||
if (armed) schedule.call(app, 's1', 3);
|
||||
const owner = (app._beginBufferLoad as Function).call(app);
|
||||
if (armed) await vi.advanceTimersByTimeAsync(2000);
|
||||
else schedule.call(app, 's1', 3);
|
||||
expect(Reflect.get(app, '_pendingDroppedOutputRecovery')).toEqual({ sessionId: 's1', attempt: 3 });
|
||||
app._finishBufferLoad(owner);
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
expect(retry).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ attempt: 3 }));
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not resume a deferred recovery for a tab that is no longer active', () => {
|
||||
const { app } = makeApp('omp', { bufferRows: 30, capture: lines(400) });
|
||||
const owner = (app._beginBufferLoad as Function).call(app);
|
||||
Object.assign(app, { _pendingDroppedOutputRecovery: 's1', activeSessionId: 's2' });
|
||||
Object.assign(app, { _pendingDroppedOutputRecovery: { sessionId: 's1', attempt: 3 }, activeSessionId: 's2' });
|
||||
app._finishBufferLoad(owner);
|
||||
expect(app._scheduleDroppedOutputRecovery).not.toHaveBeenCalled();
|
||||
expect(Reflect.get(app, '_pendingDroppedOutputRecovery')).toBeNull();
|
||||
});
|
||||
|
||||
it.each(['mux-full-history', 'history'])('clears the scroll-pull mark only for a mux capture: %s', async (source) => {
|
||||
const { app, liveOutput, scroll } = makeScrollApp();
|
||||
const { app, liveOutput, reload } = makeScrollApp();
|
||||
liveOutput();
|
||||
const fetchCapture = app._fetchTerminalCapture.getMockImplementation()!;
|
||||
app._fetchTerminalCapture.mockImplementationOnce(async (url) => {
|
||||
@@ -616,15 +626,15 @@ describe('early full-history recovery above live output (#814)', () => {
|
||||
capture.json.data.source = source;
|
||||
return capture;
|
||||
});
|
||||
await scroll(-5);
|
||||
await reload();
|
||||
expect(app._liveOutputSinceFullPull.has('s1')).toBe(source !== 'mux-full-history');
|
||||
});
|
||||
|
||||
it('does not swallow another tab’s travel or clear the old mark when replay is cancelled', async () => {
|
||||
const { app, active, liveOutput, scroll, pauseReplay } = makeScrollApp();
|
||||
const { app, active, liveOutput, reload, pauseReplay } = makeScrollApp();
|
||||
liveOutput();
|
||||
const paused = pauseReplay();
|
||||
const pull = scroll(-5);
|
||||
const pull = reload();
|
||||
await paused.ready;
|
||||
app.activeSessionId = 's2';
|
||||
app._selectGeneration++;
|
||||
@@ -906,62 +916,211 @@ describe('content anchors hold the reader through a history repair', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('touch history reload control', () => {
|
||||
function fixture({
|
||||
touch = true,
|
||||
mode = 'omp',
|
||||
bottom = false,
|
||||
marked = true,
|
||||
inFlight = false,
|
||||
tiles = false,
|
||||
active = true,
|
||||
} = {}) {
|
||||
const button = { hidden: true, disabled: false, textContent: '', onclick: null as (() => void) | null };
|
||||
const ui = loadTerminalMixin({
|
||||
MobileDetection: { isTouchDevice: () => touch },
|
||||
document: { addEventListener: vi.fn(), getElementById: () => button },
|
||||
});
|
||||
const app = {
|
||||
activeSessionId: active ? 's1' : null,
|
||||
sessions: new Map([['s1', { mode }]]),
|
||||
isTerminalAtBottom: () => bottom,
|
||||
_liveOutputSinceFullPull: new Set(marked ? ['s1'] : []),
|
||||
_fullHistoryRepullInFlight: inFlight,
|
||||
_tilesOwnTerminal: () => tiles,
|
||||
_maybeRefetchFullHistory: vi.fn(async (_opts: object) => {}),
|
||||
_syncHistoryReloadButton: () => (ui._syncHistoryReloadButton as Function).call(app),
|
||||
describe('manual history banner action', () => {
|
||||
type BannerElement = {
|
||||
hidden: boolean;
|
||||
disabled: boolean;
|
||||
textContent: string;
|
||||
className: string;
|
||||
type: string;
|
||||
children: BannerElement[];
|
||||
onclick: (() => Promise<void> | void) | null;
|
||||
appendChild(child: BannerElement): void;
|
||||
setAttribute: Function;
|
||||
};
|
||||
function fixture(options: Record<string, unknown> = {}) {
|
||||
const state = {
|
||||
touch: true,
|
||||
mode: 'omp',
|
||||
bottom: false,
|
||||
marked: true,
|
||||
inFlight: false,
|
||||
tiles: false,
|
||||
active: true,
|
||||
detached: false,
|
||||
enabled: true,
|
||||
...options,
|
||||
};
|
||||
return { app, button };
|
||||
const element = (): BannerElement => ({
|
||||
hidden: true,
|
||||
disabled: false,
|
||||
textContent: '',
|
||||
className: '',
|
||||
type: '',
|
||||
children: [],
|
||||
onclick: null,
|
||||
appendChild(child) {
|
||||
this.children.push(child);
|
||||
},
|
||||
setAttribute: vi.fn(),
|
||||
});
|
||||
const bar = element();
|
||||
const frames: FrameRequestCallback[] = [];
|
||||
const document = { addEventListener: vi.fn(), getElementById: () => bar, createElement: element };
|
||||
const ui = loadTerminalMixin({
|
||||
document,
|
||||
MobileDetection: { isTouchDevice: () => state.touch },
|
||||
requestAnimationFrame: (callback: FrameRequestCallback) => frames.push(callback),
|
||||
});
|
||||
const { app: base } = makeApp(String(state.mode), { bufferRows: 130, capture: lines(400) });
|
||||
const render = loadAppMethod('_renderHistoryTruncationBanner', {
|
||||
document,
|
||||
computeHistoryTruncationNotice: computeNotice,
|
||||
});
|
||||
const app = Object.assign(base, {
|
||||
activeSessionId: state.active ? 's1' : '',
|
||||
isTerminalAtBottom: () => state.bottom,
|
||||
loadAppSettingsFromStorage: () => ({ historyReloadAction: state.enabled }),
|
||||
_liveOutputSinceFullPull: new Set(state.marked ? ['s1'] : []),
|
||||
_historyReloadDismissed: new Set<string>(),
|
||||
_historyNoticeDismissed: new Set<string>(),
|
||||
_historyNoticeRevealedFor: null as string | null,
|
||||
_fullHistoryRepullInFlight: Boolean(state.inFlight),
|
||||
detachedSessions: new Set(state.detached ? ['s1'] : []),
|
||||
_tilesOwnTerminal: () => state.tiles,
|
||||
_maybeRefetchFullHistory: vi.fn(async (_opts: object) => {}),
|
||||
_historyReloadActionEligible: () => loadAppMethod('_historyReloadActionEligible').call(app),
|
||||
_syncHistoryReloadAction: () => loadAppMethod('_syncHistoryReloadAction').call(app),
|
||||
_scheduleHistoryReloadActionSync: () => (ui._scheduleHistoryReloadActionSync as Function).call(app),
|
||||
_renderHistoryTruncationBanner: vi.fn(() => {
|
||||
bar.children = [];
|
||||
render.call(app);
|
||||
}),
|
||||
});
|
||||
const button = () => bar.children.find((child) => child.className === 'history-trunc-load');
|
||||
const dismiss = () => bar.children.find((child) => child.className === 'history-trunc-dismiss');
|
||||
return { app, bar, button, dismiss, state, frames };
|
||||
}
|
||||
|
||||
it.each([
|
||||
{ opts: {}, visible: true },
|
||||
{ opts: { touch: false }, visible: false },
|
||||
{ opts: { touch: false }, visible: true },
|
||||
{ opts: { enabled: false }, visible: false },
|
||||
{ opts: { mode: 'shell' }, visible: false },
|
||||
{ opts: { bottom: true }, visible: false },
|
||||
{ opts: { marked: false }, visible: false },
|
||||
{ opts: { inFlight: true }, visible: false },
|
||||
{ opts: { tiles: true }, visible: false },
|
||||
{ opts: { active: false }, visible: false },
|
||||
{ opts: { detached: true }, visible: false },
|
||||
])('visibility is $visible for $opts', ({ opts, visible }) => {
|
||||
const { app, button } = fixture(opts);
|
||||
app._syncHistoryReloadButton();
|
||||
expect(button.hidden).toBe(!visible);
|
||||
const { app, bar, button } = fixture(opts);
|
||||
app._syncHistoryReloadAction();
|
||||
expect(bar.hidden).toBe(!visible);
|
||||
if (visible) expect(button()?.textContent).toBe('Reload history');
|
||||
});
|
||||
|
||||
it('forces a content-anchored pull on tap and resets the loading state on settle', async () => {
|
||||
it('forces a content-anchored pull on tap and resets loading on settle', async () => {
|
||||
const { app, button } = fixture();
|
||||
const { promise, resolve: release } = Promise.withResolvers<void>();
|
||||
app._maybeRefetchFullHistory.mockReturnValueOnce(promise);
|
||||
app._syncHistoryReloadButton();
|
||||
const tapped = button.onclick!();
|
||||
app._syncHistoryReloadAction();
|
||||
const tapped = button()!.onclick!();
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledWith({ force: true, anchor: 'content' });
|
||||
expect(button.disabled).toBe(true);
|
||||
expect(button.textContent).toBe('Loading…');
|
||||
expect(button()!.disabled).toBe(true);
|
||||
expect(button()!.textContent).toBe('Loading…');
|
||||
release();
|
||||
await tapped;
|
||||
expect(button.disabled).toBe(false);
|
||||
expect(button.textContent).toBe('↻ Reload history');
|
||||
expect(button()!.disabled).toBe(false);
|
||||
expect(button()!.textContent).toBe('Reload history');
|
||||
});
|
||||
|
||||
it.each(['recoverable', 'exhausted', 'capped'])('never duplicates the %s notice load control', (kind) => {
|
||||
const { app, bar, button } = fixture();
|
||||
app._historyNoticeRevealedFor = 's1';
|
||||
app._setHistoryTruncation('s1', {
|
||||
...TAIL_CUT,
|
||||
exhausted: kind === 'exhausted',
|
||||
truncationReason: kind === 'capped' ? 'capped' : 'tail',
|
||||
});
|
||||
expect(bar.children.filter((child) => child.className === 'history-trunc-load')).toHaveLength(1);
|
||||
expect(button()!.textContent).toBe(kind === 'recoverable' ? 'Load full history' : 'Reload history');
|
||||
});
|
||||
|
||||
it('does no DOM work without a transition and coalesces all-device onScroll calls per frame', () => {
|
||||
const { app, state, frames } = fixture({ touch: false });
|
||||
let onScroll!: () => void;
|
||||
const source = readFileSync(resolve(PUBLIC, 'terminal-ui.js'), 'utf8');
|
||||
const registration = source.match(/^ this\.terminal\.onScroll\(.*$/m)![0];
|
||||
vm.runInNewContext(`(function () { ${registration} }).call(app)`, {
|
||||
app: {
|
||||
terminal: {
|
||||
onScroll: (callback: () => void) => {
|
||||
onScroll = callback;
|
||||
},
|
||||
},
|
||||
_scheduleHistoryReloadActionSync: app._scheduleHistoryReloadActionSync,
|
||||
},
|
||||
});
|
||||
app._syncHistoryReloadAction();
|
||||
for (let i = 0; i < 100; i++) onScroll();
|
||||
expect(frames).toHaveLength(1);
|
||||
frames.shift()!(0);
|
||||
expect(app._renderHistoryTruncationBanner).toHaveBeenCalledOnce();
|
||||
state.bottom = true;
|
||||
onScroll();
|
||||
onScroll();
|
||||
expect(frames).toHaveLength(1);
|
||||
frames.shift()!(1);
|
||||
expect(app._renderHistoryTruncationBanner).toHaveBeenCalledTimes(2);
|
||||
app._syncHistoryReloadAction();
|
||||
expect(app._renderHistoryTruncationBanner).toHaveBeenCalledTimes(2);
|
||||
app.activeSessionId = 's2';
|
||||
app._syncHistoryReloadAction();
|
||||
expect(app._renderHistoryTruncationBanner).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it.each(['mux-full-history', 'history'])('dismisses reload until an actual full mux replay: %s', async (source) => {
|
||||
const { app, bar, dismiss, state } = fixture();
|
||||
app._syncHistoryReloadAction();
|
||||
dismiss()!.onclick!();
|
||||
expect(bar.hidden).toBe(true);
|
||||
expect(app._historyNoticeDismissed.size).toBe(0);
|
||||
state.bottom = true;
|
||||
app._syncHistoryReloadAction();
|
||||
state.bottom = false;
|
||||
app._syncHistoryReloadAction();
|
||||
expect(bar.hidden).toBe(true);
|
||||
const capture = app._fetchTerminalCapture.getMockImplementation()!;
|
||||
app._fetchTerminalCapture.mockImplementationOnce(async (url) => {
|
||||
const result = await capture(url);
|
||||
result.json.data.source = source;
|
||||
return result;
|
||||
});
|
||||
await refetch.call(app, { force: true });
|
||||
expect(app._historyReloadDismissed.has('s1')).toBe(source !== 'mux-full-history');
|
||||
app._liveOutputSinceFullPull.add('s1');
|
||||
app._syncHistoryReloadAction();
|
||||
expect(bar.hidden).toBe(source !== 'mux-full-history');
|
||||
});
|
||||
|
||||
it('one × on a combined notice dismisses both, and scroll frames keep the bar hidden', () => {
|
||||
const { app, bar, button, dismiss, frames } = fixture();
|
||||
app._historyNoticeRevealedFor = 's1';
|
||||
app._setHistoryTruncation('s1', { ...TAIL_CUT, exhausted: true, truncationReason: 'tail' });
|
||||
expect(button()!.textContent).toBe('Reload history');
|
||||
dismiss()!.onclick!();
|
||||
expect(bar.hidden).toBe(true);
|
||||
expect(app._historyNoticeDismissed.has('s1')).toBe(true);
|
||||
expect(app._historyReloadDismissed.has('s1')).toBe(true);
|
||||
app._scheduleHistoryReloadActionSync();
|
||||
frames.shift()!(0);
|
||||
expect(bar.hidden).toBe(true);
|
||||
});
|
||||
|
||||
it('dismissing a notice that carried no reload action lets a later eligible action show', () => {
|
||||
const { app, bar, button, dismiss, state } = fixture({ marked: false });
|
||||
app._historyNoticeRevealedFor = 's1';
|
||||
app._setHistoryTruncation('s1', { ...TAIL_CUT, exhausted: true, truncationReason: 'tail' });
|
||||
expect(button()).toBeUndefined();
|
||||
dismiss()!.onclick!();
|
||||
expect(bar.hidden).toBe(true);
|
||||
expect(app._historyReloadDismissed.has('s1')).toBe(false);
|
||||
state.marked = true;
|
||||
app._liveOutputSinceFullPull.add('s1');
|
||||
app._syncHistoryReloadAction();
|
||||
expect(bar.hidden).toBe(false);
|
||||
expect(button()!.textContent).toBe('Reload history');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user