a95be2860f
Addresses Copilot + Codex review on #2521: - computeEditorMaxHeight returned 1 on terminals too small to host both the editor and the chrome reserve, but the bordered editor never renders fewer than 3 rows (2 border + 1 content). The cap now floors at that real minimum (EDITOR_MIN_RENDERED_ROWS) so it no longer misreports the rows the editor occupies; rendering is unchanged, and the contract is documented honestly (reserve holds once terminalRows >= 7). - #resolveOverlayLayout now always resolves maxHeight (?? availHeight), so the maxHeight !== undefined branch in effectiveHeight, the composite slice guard, and the number | undefined return type were dead. Tightened all three. - Mirrored the maxHeight-default contract in the render stress oracle (resolveExpectedOverlayLayout + compositeExpectedOverlays) so the randomized sweep validates the real clipped geometry instead of the obsolete unclipped one; updated the oracle helper test expectation accordingly. Editor-height tests rewritten to assert the real contract (reserve when the terminal can host both; pinned to the bordered minimum below that).
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { computeEditorMaxHeight } from "@oh-my-pi/pi-coding-agent/modes/interactive-mode";
|
|
|
|
describe("computeEditorMaxHeight", () => {
|
|
it("caps the editor within the comfortable band on roomy terminals", () => {
|
|
expect(computeEditorMaxHeight(30)).toBe(18);
|
|
expect(computeEditorMaxHeight(18)).toBe(6);
|
|
expect(computeEditorMaxHeight(8)).toBe(4);
|
|
expect(computeEditorMaxHeight(Number.NaN)).toBe(12);
|
|
expect(computeEditorMaxHeight(0)).toBe(12);
|
|
});
|
|
|
|
it("reserves at least four chrome rows once the terminal can host both", () => {
|
|
// Editor floor (3 rendered rows, bordered) + chrome reserve (4) = 7 rows.
|
|
for (let rows = 7; rows <= 18; rows += 1) {
|
|
expect(rows - computeEditorMaxHeight(rows)).toBeGreaterThanOrEqual(4);
|
|
}
|
|
});
|
|
|
|
it("pins the cap to the bordered editor's real minimum on tinier terminals", () => {
|
|
// Below 7 rows there is no room for both; the cap collapses to the editor's
|
|
// real rendered floor (2 border + 1 content) rather than a fictitious value
|
|
// the editor would silently overshoot.
|
|
expect(computeEditorMaxHeight(6)).toBe(3);
|
|
expect(computeEditorMaxHeight(5)).toBe(3);
|
|
expect(computeEditorMaxHeight(4)).toBe(3);
|
|
expect(computeEditorMaxHeight(1)).toBe(3);
|
|
});
|
|
});
|