mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-17 16:09:36 +00:00
The perf suite had no terminal scenario, so nothing guarded the terminal row cache (#2239) against regressions. The new terminalTui scenario streams a full-screen TUI into the terminal at 10 fps (every row rewritten, only the spinner row changed, the title updated, as agent CLIs do) while typing in an editor, through a hidden action registered only in dev and perf builds. rowsRebuiltPerTuiFrame counts row elements rebuilt per frame independently of MutationObserver batching and fails when no terminal output arrives; budget 3 (about 1.4 with the cache, the screen height without it). Co-authored-by: brunobelloni <14021404+brunobelloni@users.noreply.github.com>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { startTuiRowObserver, stopTuiRowObserver } from "./tuiRows.ts";
|
|
|
|
afterEach(() => {
|
|
try {
|
|
stopTuiRowObserver();
|
|
} catch {
|
|
// A test may already have stopped it, or deliberately rendered no rows.
|
|
}
|
|
document.body.replaceChildren();
|
|
});
|
|
|
|
function terminalRow() {
|
|
document.body.innerHTML = '<div class="xterm"><div class="xterm-rows"><div><span>ready</span></div></div></div>';
|
|
return document.querySelector(".xterm-rows > div")!;
|
|
}
|
|
|
|
describe("TUI row measurement", () => {
|
|
it.each([false, true])("counts each rebuild with separate deliveries: %s", async (separate) => {
|
|
const row = terminalRow();
|
|
startTuiRowObserver();
|
|
for (let n = 0; n < 3; n++) {
|
|
row.replaceChildren(document.createElement("span"));
|
|
if (separate) await Promise.resolve();
|
|
}
|
|
expect(stopTuiRowObserver()).toBe(3);
|
|
row.replaceChildren();
|
|
expect(() => stopTuiRowObserver()).toThrow("did not start");
|
|
});
|
|
|
|
it("ignores nested span changes and changes outside the terminal rows", () => {
|
|
const row = terminalRow();
|
|
startTuiRowObserver();
|
|
row.firstChild!.textContent = "changed";
|
|
document.body.append(document.createElement("div"));
|
|
row.replaceChildren();
|
|
expect(stopTuiRowObserver()).toBe(1);
|
|
});
|
|
|
|
it.each(["", '<div class="xterm"><div class="xterm-rows"></div></div>'])(
|
|
"rejects a missing or empty row renderer: %s",
|
|
(html) => {
|
|
document.body.innerHTML = html;
|
|
expect(() => startTuiRowObserver()).toThrow("row renderer did not open");
|
|
},
|
|
);
|
|
|
|
it("rejects a stream that never renders", () => {
|
|
terminalRow();
|
|
startTuiRowObserver();
|
|
expect(() => stopTuiRowObserver()).toThrow("did not render any rows");
|
|
});
|
|
});
|