Files
Netcatty/components/terminal/terminalContinuousRendering.test.ts
T
陈大猫 f6bac5fcf0 fix(terminal): batch hidden log output (#2399)
* fix(terminal): batch hidden log output

* fix(terminal): preserve ordered hidden output

* fix(terminal): bound hidden output overhead

* fix(terminal): respect custom tab stops in timestamps

* fix(terminal): preserve terminal parser state

* fix(terminal): preserve hidden output boundaries

* fix(terminal): retain batching with prompt formatting

* fix(terminal): preserve prompt boundaries through transforms

* fix(terminal): handle unbatched prompt output

* fix(terminal): preserve batched prompt and time boundaries

* fix(terminal): retain background timestamp boundaries

* fix(terminal): preserve visible timestamp boundaries

* fix(terminal): separate shell output from tui frames

* fix(terminal): separate output after tui exit

* fix(terminal): preserve prompts across output slices

* fix(terminal): flush output before context reads

* fix(terminal): time-slice timestamp marker cleanup

* fix(terminal): preserve prompt columns after bare LF

* fix(terminal): preserve background write yielding

* fix(terminal): retain yields across timestamp boundaries

* perf(terminal): scan output boundaries once

* fix(terminal): track prompt cursor movement

* fix(terminal): resume prompt scan after resets

* fix(terminal): preserve stateful prompt ordering

* fix(terminal): drain close output before capture

* fix(terminal): measure control-only prompt prefixes

* fix(terminal): preserve prompt control boundaries

* fix(terminal): preserve prompt mode toggles

* fix(terminal): bound hidden batches and unfocus policy

Always drain write-coalescer size caps even when scheduled frames are gated,
keep unfocused-but-visible panes on throttled batching instead of per-chunk
force flush, compute prompt starts on post-transform display data, and model
full-width wrap so prompt-on-newline does not insert a blank line.

* perf(terminal): skip off-path timestamps and share alt-screen probes

When host line timestamps are disabled, write plain bytes without the
segmenter/marker hot path. Reuse one alt-screen CSI probe per coalesced
chunk for frame split and schedule mode, and reuse a single full-batch
visual-row measure on the single-segment batched timestamp path.

* fix(terminal): read line-timestamp enable from live hostRef

Session data handlers close over boot-time ctx.host, so toolbar/vault
toggles of showLineTimestamps were ignored. Prefer hostRef.current for
the marker hot-path gate and keep hostRef synced on every Terminal render.

* perf(terminal): per-second timestamp ledger while gutter is off

When line timestamps are hidden, keep a lightweight one-stamp-per-second
ledger without xterm markers. Opening the gutter materializes recent
ledger entries into markers for paint; while visible, keep per-line
markers for accuracy.

* perf(terminal): separate timestamp record from gutter paint

Always record a one-stamp-per-second ledger on the write path with no
xterm markers. Gutter rendering maps the ledger to visible rows, so open
and closed modes share the same cheap record path.

* fix(terminal): fill gutter gaps with previous second stamp

When painting line timestamps from the per-second ledger, blank rows
between stamps inherit the preceding stamp's label so multi-line output
in the same second is fully labeled.

* fix(terminal): stop empty gutter paint and false scrollback rebase

Only rebase ledger anchors when the buffer is actually full and baseY
grows from top trim — not when baseY rises while the buffer is still
growing (which deleted MOTD/login stamps on scroll). Cap gutter paint at
the last content line so empty viewport rows past the cursor stay blank.

* fix(terminal): soft-wrap stamp placement and sparse reflow anchors

Estimate ledger lines with visual-row measurement so narrow terminals
do not pin the next second on a wrap continuation. After each write,
attach at most one xterm marker per stamped second so reflow and
scrollback trim keep anchors honest without per-line marker storms.

* fix(terminal): ignore alt-screen rows when placing timestamp anchors

Stamp line estimates froze incorrectly through vim/less alt-screen
output, so sparse reflow markers landed far below the restored normal
buffer. Skip visual-row advancement while DEC alt-screen is active,
key one-stamp-per-second from the batch arrival date, and only attach
anchors still present in the ledger after capacity trim.

* fix(terminal): seed stamp lines from normal buffer when already on alt

When a write begins on the alternate screen, active cursor is the TUI
row — freezing that through 1049 leave mis-pinned sparse anchors and
dropped them past normal bufferLength. Seed and restore stamp estimates
from buffer.normal, and cover multi-write already-on-alt leave+prompt.

* fix(terminal): keep same-chunk pre-enter line on alt leave

Leave CSI must not always re-read pre-write buffer.normal: when enter
happened in the same walk, the frozen estimate already includes normal
advances before the TUI. Only restore buffer.normal when the write
started already on the alternate screen.

* fix(terminal): pure alt stamp transitions that never rewind lines

Stamp estimates stay in normal-buffer coordinates: seed once (active or
buffer.normal when already on alt), freeze while alt is active, and on
leave only clear altActive — never re-read the live term mid-walk.
Export applyAltScreenAction with a table-driven unit test covering
spurious leave, plus write-path cases for already-on-alt, same-chunk
pre-enter advance, and leave-without-enter.
2026-07-23 22:18:31 +08:00

78 lines
3.6 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const terminalSource = readFileSync(new URL("../Terminal.tsx", import.meta.url), "utf8");
const effectsSource = readFileSync(new URL("./useTerminalEffects.ts", import.meta.url), "utf8");
const supportSource = readFileSync(new URL("../terminalLayer/TerminalLayerSupport.tsx", import.meta.url), "utf8");
const viewSource = readFileSync(new URL("../terminalLayer/TerminalLayerView.tsx", import.meta.url), "utf8");
const tabBridgeSource = readFileSync(new URL("../terminalLayer/TerminalLayerTabBridge.tsx", import.meta.url), "utf8");
const workspaceLayoutSource = readFileSync(new URL("../terminalLayer/useTerminalWorkspaceLayout.ts", import.meta.url), "utf8");
const layerEffectsSource = readFileSync(new URL("../terminalLayer/useTerminalLayerEffects.ts", import.meta.url), "utf8");
test("renderer activity follows the hibernate setting instead of active-tab visibility", () => {
assert.match(
terminalSource,
/const isRendererActive = isVisible \|\| !hibernateEnabled/,
);
assert.match(terminalSource, /isPaneVisibleRef: isVisibleRef/);
assert.match(terminalSource, /isVisibleRef: isRendererActiveRef/);
assert.match(terminalSource, /if \(!isRendererActiveRef\.current && !options\?\.allowHidden\)/);
assert.match(
effectsSource,
/const isRendererActive = isVisible \|\| !hibernateHiddenTabs;[\s\S]*const isRendererActiveRef = useRef\(isRendererActive\)/,
);
});
test("inactive terminal surfaces remain painted and non-interactive without hibernate", () => {
assert.match(supportSource, /resolveTerminalHibernateEnabledForProtocol\(terminalSettings, host\.protocol\)/);
assert.match(supportSource, /inert=\{isVisible \? undefined : true\}/);
assert.match(viewSource, /ctx\.hibernateHiddenTabs/);
assert.match(viewSource, /inert=\{ctx\.isTerminalLayerVisible \? undefined : true\}/);
});
test("background split workspaces keep their live geometry without hibernate", () => {
assert.match(
tabBridgeSource,
/shouldKeepHiddenWorkspaceLaidOut/,
);
assert.match(
workspaceLayoutSource,
/if \(shouldKeepHiddenWorkspaceLaidOut\(workspace\)\) \{[\s\S]*cachedSizeIsUsable[\s\S]*computeWorkspaceRects\(layoutWorkspace, layoutSize\)/,
);
assert.match(
supportSource,
/const layoutWorkspaceId = activeWorkspaceId \?\? \(!hibernateHiddenTabs \? session\.workspaceId : undefined\)/,
);
assert.match(supportSource, /inWorkspace=\{keepsWorkspacePresentation\}/);
assert.match(
supportSource,
/isWorkspaceComposeBarOpen=\{inActiveWorkspace \? isComposeBarOpen : undefined\}/,
);
assert.match(
supportSource,
/shouldUseTerminalPaneSplitLayout\(\{[\s\S]*workspace: layoutWorkspace,[\s\S]*sessionId: session\.id,[\s\S]*isVisible,[\s\S]*hibernateHiddenTabs/,
);
assert.match(
supportSource,
/const initializeHiddenFullSize = !hibernateHiddenTabs[\s\S]*&& !rect[\s\S]*&& !lastVisiblePaneSizeRef\.current;[\s\S]*bumpHiddenPaneSizeVersion/,
);
assert.match(
supportSource,
/if \(isVisible\) \{[\s\S]*const observer = new ResizeObserver\(\(\) => \{[\s\S]*capturePaneSize\(\)/,
);
assert.match(
layerEffectsSource,
/if \(!shouldMeasureTerminalLayerLayout\) return;[\s\S]*?remeasureWorkspaceArea\(\)/,
);
assert.match(
tabBridgeSource,
/const keepHiddenLayoutActive = !hibernateHiddenTabs \|\| localWorkspaceIds\.size > 0/,
);
assert.match(
tabBridgeSource,
/shouldMeasureTerminalLayerLayout: shouldMeasureTerminalLayerLayout\(\{[\s\S]*keepHiddenLayoutActive,[\s\S]*workspaceArea/,
);
assert.doesNotMatch(tabBridgeSource, /isTerminalLayerRendererActive/);
});