|
| 1 | +/** |
| 2 | + * QUEUED INPUT zone geometry: requested height, seating on the prompt box, |
| 3 | + * coexistence with WORKER WAITING / pending, collapse before worker_wait and |
| 4 | + * restore when room returns, and in-bounds no-overlap on a short terminal. |
| 5 | + */ |
| 6 | +import { describe, expect, test } from "bun:test"; |
| 7 | +import { defined } from "../../../testkit/defined.js"; |
| 8 | +import { |
| 9 | + COLLAPSE_ORDER, |
| 10 | + IDLE_TRANSCRIPT_FLOOR, |
| 11 | + PROMPT_BASE_ROWS, |
| 12 | + PROMPT_IDLE_ROWS, |
| 13 | + ZONE_REGISTRY, |
| 14 | + resolveGeometry, |
| 15 | + type GeometryInput, |
| 16 | +} from "./index.js"; |
| 17 | +import { PAINT_ORDER } from "./zones.js"; |
| 18 | + |
| 19 | +function idle80x24(overrides: Partial<GeometryInput> = {}) { |
| 20 | + return resolveGeometry({ |
| 21 | + terminal: { columns: 80, rows: 24 }, |
| 22 | + ...overrides, |
| 23 | + }); |
| 24 | +} |
| 25 | + |
| 26 | +describe("queued_input zone", () => { |
| 27 | + test("requested visibility seats exactly one row directly on the prompt box", () => { |
| 28 | + const baseline = idle80x24(); |
| 29 | + const layout = idle80x24({ visibility: { queuedInput: true } }); |
| 30 | + const strip = defined(layout.regions.queued_input, "queued_input"); |
| 31 | + const prompt = defined(layout.regions.prompt, "prompt"); |
| 32 | + expect(strip.height).toBe(1); |
| 33 | + expect(strip.y + strip.height).toBe(prompt.y); |
| 34 | + // The strip takes its row from the transcript, never the composer. |
| 35 | + expect(layout.heights.prompt).toBe(baseline.heights.prompt); |
| 36 | + expect(layout.transcriptHeight).toBe(baseline.transcriptHeight - 1); |
| 37 | + }); |
| 38 | + |
| 39 | + test("zero visibility costs zero chrome", () => { |
| 40 | + const layout = idle80x24(); |
| 41 | + expect(layout.heights.queued_input).toBe(0); |
| 42 | + expect(layout.regions.queued_input).toBeUndefined(); |
| 43 | + }); |
| 44 | + |
| 45 | + test("sits between worker_wait and prompt in paint order", () => { |
| 46 | + expect(PAINT_ORDER.indexOf("worker_wait")).toBeLessThan( |
| 47 | + PAINT_ORDER.indexOf("queued_input"), |
| 48 | + ); |
| 49 | + expect(PAINT_ORDER.indexOf("queued_input")).toBeLessThan( |
| 50 | + PAINT_ORDER.indexOf("prompt"), |
| 51 | + ); |
| 52 | + const layout = idle80x24({ |
| 53 | + visibility: { workerWait: true, queuedInput: true }, |
| 54 | + }); |
| 55 | + const waiting = defined(layout.regions.worker_wait, "worker_wait"); |
| 56 | + const queued = defined(layout.regions.queued_input, "queued_input"); |
| 57 | + const prompt = defined(layout.regions.prompt, "prompt"); |
| 58 | + expect(waiting.height).toBe(1); |
| 59 | + expect(queued.height).toBe(1); |
| 60 | + expect(waiting.y + waiting.height).toBe(queued.y); |
| 61 | + expect(queued.y + queued.height).toBe(prompt.y); |
| 62 | + expect(layout.heights.prompt).toBe(PROMPT_IDLE_ROWS); |
| 63 | + }); |
| 64 | + |
| 65 | + test("coexists with pending items above worker_wait", () => { |
| 66 | + const layout = idle80x24({ |
| 67 | + visibility: { pending: 2, workerWait: true, queuedInput: true }, |
| 68 | + }); |
| 69 | + const pending = defined(layout.regions.pending, "pending"); |
| 70 | + const waiting = defined(layout.regions.worker_wait, "worker_wait"); |
| 71 | + const queued = defined(layout.regions.queued_input, "queued_input"); |
| 72 | + const prompt = defined(layout.regions.prompt, "prompt"); |
| 73 | + expect(pending.height).toBe(2); |
| 74 | + expect(waiting.height).toBe(1); |
| 75 | + expect(queued.height).toBe(1); |
| 76 | + expect(pending.y + pending.height).toBe(waiting.y); |
| 77 | + expect(waiting.y + waiting.height).toBe(queued.y); |
| 78 | + expect(queued.y + queued.height).toBe(prompt.y); |
| 79 | + expect(layout.transcriptHeight).toBeGreaterThanOrEqual( |
| 80 | + layout.transcriptFloor, |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + test("collapses before worker_wait under height pressure", () => { |
| 85 | + // Pending own-input rows cut after banners but before the queued-input |
| 86 | + // strip; the queued-input strip cuts before the worker-wait strip. |
| 87 | + expect(COLLAPSE_ORDER.indexOf("pending")).toBeLessThan( |
| 88 | + COLLAPSE_ORDER.indexOf("queued_input"), |
| 89 | + ); |
| 90 | + expect(COLLAPSE_ORDER.indexOf("queued_input")).toBeLessThan( |
| 91 | + COLLAPSE_ORDER.indexOf("worker_wait"), |
| 92 | + ); |
| 93 | + expect(COLLAPSE_ORDER.indexOf("worker_wait")).toBeLessThan( |
| 94 | + COLLAPSE_ORDER.indexOf("prompt"), |
| 95 | + ); |
| 96 | + const layout = resolveGeometry({ |
| 97 | + terminal: { columns: 80, rows: 18 }, |
| 98 | + visibility: { |
| 99 | + notice: true, |
| 100 | + pending: 6, |
| 101 | + agents: 11, |
| 102 | + task: 3, |
| 103 | + workerWait: true, |
| 104 | + queuedInput: true, |
| 105 | + }, |
| 106 | + }); |
| 107 | + expect(layout.heights.notice).toBe(0); |
| 108 | + expect(layout.heights.pending).toBe(0); |
| 109 | + expect(layout.heights.queued_input).toBe(0); |
| 110 | + // A parked worker stays visible: its row is the last optional cut. |
| 111 | + expect(layout.heights.worker_wait).toBe(1); |
| 112 | + expect(layout.transcriptHeight).toBeGreaterThanOrEqual( |
| 113 | + layout.transcriptFloor, |
| 114 | + ); |
| 115 | + }); |
| 116 | + |
| 117 | + test("restores when room returns after a constrained-height collapse", () => { |
| 118 | + const narrow = resolveGeometry({ |
| 119 | + terminal: { columns: 80, rows: 18 }, |
| 120 | + visibility: { |
| 121 | + notice: true, |
| 122 | + pending: 6, |
| 123 | + agents: 11, |
| 124 | + task: 3, |
| 125 | + workerWait: true, |
| 126 | + queuedInput: true, |
| 127 | + }, |
| 128 | + }); |
| 129 | + expect(narrow.heights.queued_input).toBe(0); |
| 130 | + // The ledger is untouched by collapse; the same visibility on a taller |
| 131 | + // terminal seats the strip again. |
| 132 | + const restored = resolveGeometry({ |
| 133 | + terminal: { columns: 80, rows: 24 }, |
| 134 | + visibility: { |
| 135 | + notice: true, |
| 136 | + pending: 6, |
| 137 | + agents: 11, |
| 138 | + task: 3, |
| 139 | + workerWait: true, |
| 140 | + queuedInput: true, |
| 141 | + }, |
| 142 | + }); |
| 143 | + expect(restored.heights.queued_input).toBe(1); |
| 144 | + expect(defined(restored.regions.queued_input).height).toBe(1); |
| 145 | + expect(restored.transcriptHeight).toBeGreaterThanOrEqual( |
| 146 | + IDLE_TRANSCRIPT_FLOOR, |
| 147 | + ); |
| 148 | + }); |
| 149 | + |
| 150 | + test("short terminal stays in bounds with no overlap", () => { |
| 151 | + const layout = resolveGeometry({ |
| 152 | + terminal: { columns: 12, rows: 10 }, |
| 153 | + visibility: { pending: 1, workerWait: true, queuedInput: true }, |
| 154 | + }); |
| 155 | + const prompt = defined(layout.regions.prompt, "prompt"); |
| 156 | + expect(prompt.y + prompt.height).toBeLessThanOrEqual(10); |
| 157 | + expect(layout.heights.prompt).toBeGreaterThanOrEqual(PROMPT_BASE_ROWS); |
| 158 | + // Whatever collapsed, the visible regions y-stack without overlap. |
| 159 | + const regions = PAINT_ORDER.map((id) => layout.regions[id]).filter( |
| 160 | + (region) => region !== undefined && region.height > 0, |
| 161 | + ); |
| 162 | + for (let index = 1; index < regions.length; index += 1) { |
| 163 | + const previous = regions[index - 1]; |
| 164 | + const current = regions[index]; |
| 165 | + if (previous === undefined || current === undefined) continue; |
| 166 | + expect(previous.y + previous.height).toBe(current.y); |
| 167 | + } |
| 168 | + expect(layout.regions.queued_input).toBeUndefined(); |
| 169 | + }); |
| 170 | + |
| 171 | + test("registry bounds match the zone declaration", () => { |
| 172 | + expect(ZONE_REGISTRY.queued_input.min).toBe(0); |
| 173 | + expect(ZONE_REGISTRY.queued_input.max).toBe(1); |
| 174 | + expect(ZONE_REGISTRY.queued_input.alwaysOn).toBe(false); |
| 175 | + }); |
| 176 | +}); |
0 commit comments