Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
79 lines
3.7 KiB
TypeScript
79 lines
3.7 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
const assertRecoverTerminalOnAppResumeOrder = (source: string): void => {
|
|
const handlerIndex = source.indexOf("const recoverTerminalOnAppResume = () => {");
|
|
assert.notEqual(handlerIndex, -1, "recoverTerminalOnAppResume must exist");
|
|
|
|
const bodyStart = source.indexOf("{", handlerIndex);
|
|
assert.notEqual(bodyStart, -1, "recoverTerminalOnAppResume must have a body");
|
|
|
|
let depth = 0;
|
|
let bodyEnd = -1;
|
|
for (let index = bodyStart; index < source.length; index += 1) {
|
|
const char = source[index];
|
|
if (char === "{") depth += 1;
|
|
if (char === "}") {
|
|
depth -= 1;
|
|
if (depth === 0) {
|
|
bodyEnd = index + 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
assert.notEqual(bodyEnd, -1, "recoverTerminalOnAppResume body must close");
|
|
|
|
const handlerSource = source.slice(handlerIndex, bodyEnd);
|
|
const flushIndex = handlerSource.indexOf("flushPendingTerminalWritesOnResume(term)");
|
|
const scrollIndex = handlerSource.indexOf("flushPendingOutputScroll()");
|
|
const recoveryIndex = handlerSource.indexOf("recoverWebglRendererOnAppResume()");
|
|
const refitIndex = handlerSource.indexOf("scheduleLayoutRecoveryRefit([0, 100, 300])");
|
|
|
|
assert.notEqual(flushIndex, -1, "recoverTerminalOnAppResume must flush pending writes");
|
|
assert.notEqual(scrollIndex, -1, "recoverTerminalOnAppResume must flush pending scroll");
|
|
assert.notEqual(recoveryIndex, -1, "recoverTerminalOnAppResume must recover WebGL");
|
|
assert.notEqual(refitIndex, -1, "recoverTerminalOnAppResume must schedule layout recovery");
|
|
assert.ok(flushIndex < scrollIndex, "flush pending writes before pending scroll");
|
|
assert.ok(scrollIndex < recoveryIndex, "flush pending scroll before WebGL recovery");
|
|
assert.ok(recoveryIndex < refitIndex, "recover WebGL before layout recovery");
|
|
};
|
|
|
|
test("app resume handlers flush backlog and recover the terminal renderer before refit", () => {
|
|
const source = readFileSync(new URL("./useTerminalEffects.ts", import.meta.url), "utf8");
|
|
const resumeEffectIndex = source.indexOf("const recoverWebglRendererOnAppResume = () => {");
|
|
const resumeEffectEnd = source.indexOf("// Only register the snippet executor", resumeEffectIndex);
|
|
const resumeEffectSource = source.slice(resumeEffectIndex, resumeEffectEnd);
|
|
|
|
assert.ok(resumeEffectIndex >= 0);
|
|
assert.ok(resumeEffectEnd > resumeEffectIndex);
|
|
assertRecoverTerminalOnAppResumeOrder(source);
|
|
assert.match(
|
|
resumeEffectSource,
|
|
/const handleVisibilityChange = \(\) => \{\s*if \(document\.visibilityState !== 'visible'\) \{\s*syncOutputPressureVisibility\(\);\s*return;\s*\}\s*recoverTerminalOnAppResume\(\);\s*\};/,
|
|
);
|
|
assert.match(
|
|
resumeEffectSource,
|
|
/const handleWindowFocus = \(\) => \{\s*recoverTerminalOnAppResume\(\);\s*\};/,
|
|
);
|
|
assert.match(
|
|
resumeEffectSource,
|
|
/const unsubscribeWindowShown = terminalBackend\.onWindowShown\?\.\(\(\) => \{\s*recoverTerminalOnAppResume\(\);\s*\}\);/,
|
|
);
|
|
assert.doesNotMatch(resumeEffectSource, /\binWorkspace\b/);
|
|
assert.doesNotMatch(resumeEffectSource, /\bisFocusMode\b/);
|
|
assert.doesNotMatch(resumeEffectSource, /\bisFocused\b/);
|
|
assert.doesNotMatch(source, /shouldRecoverOnAppResume/);
|
|
});
|
|
|
|
test("useTerminalBackend exposes onWindowShown so the resume hook actually fires", () => {
|
|
const source = readFileSync(
|
|
new URL("../../application/state/useTerminalBackend.ts", import.meta.url),
|
|
"utf8",
|
|
);
|
|
assert.match(source, /const onWindowShown = useCallback\(\(cb: \(\) => void\) => \{\s*const bridge = netcattyBridge\.get\(\);\s*return bridge\?\.onWindowShown\?\.\(cb\);/);
|
|
const returnIndex = source.indexOf("useMemo(");
|
|
assert.notEqual(returnIndex, -1);
|
|
assert.match(source.slice(returnIndex), /onWindowShown,/);
|
|
});
|