|
| 1 | +/** |
| 2 | + * Flash notices stay on the status row and are mirrored into the OpenTUI |
| 3 | + * console overlay. Rows stay on the transcript and are not mirrored. |
| 4 | + * The overlay stays hidden, so the mirror must not add frame rows. |
| 5 | + */ |
| 6 | +import { EventEmitter } from "node:events"; |
| 7 | +import { describe, expect, test } from "bun:test"; |
| 8 | +import { ManualClock } from "@opentui/core/testing"; |
| 9 | + |
| 10 | +import { createHarness } from "./harness.js"; |
| 11 | +import { mountProductHost } from "./product-host.js"; |
| 12 | + |
| 13 | +const cleanHook = { |
| 14 | + type: "hook.updated", |
| 15 | + hook: { |
| 16 | + id: "fmt", |
| 17 | + name: "format", |
| 18 | + type: "shell", |
| 19 | + path: "/hooks/format.sh", |
| 20 | + enabled: true, |
| 21 | + lastFiredAt: 1, |
| 22 | + lastKind: "postTurn", |
| 23 | + lastExitStatus: { code: 0, signal: null, stderr: "" }, |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +const failingHook = { |
| 28 | + type: "hook.updated", |
| 29 | + hook: { |
| 30 | + ...cleanHook.hook, |
| 31 | + lastExitStatus: { code: 2, signal: null, stderr: "prettier not found" }, |
| 32 | + }, |
| 33 | +}; |
| 34 | + |
| 35 | +describe("runtime notice console mirror", () => { |
| 36 | + test("a flash stays on the status row and in the hidden console cache", async () => { |
| 37 | + const clock = new ManualClock(); |
| 38 | + const harness = await createHarness({ |
| 39 | + width: 100, |
| 40 | + height: 30, |
| 41 | + consoleMode: "console-overlay", |
| 42 | + clock, |
| 43 | + }); |
| 44 | + const emitter = new EventEmitter(); |
| 45 | + const host = await mountProductHost({ |
| 46 | + title: "test-session", |
| 47 | + eventEmitter: emitter, |
| 48 | + send: () => undefined, |
| 49 | + interrupt: () => undefined, |
| 50 | + deliver: () => undefined, |
| 51 | + createRenderer: async () => harness.renderer, |
| 52 | + }); |
| 53 | + try { |
| 54 | + expect(harness.renderer.consoleMode).toBe("console-overlay"); |
| 55 | + harness.renderer.console.clear(); |
| 56 | + emitter.emit("hook", cleanHook); |
| 57 | + await harness.renderOnce(); |
| 58 | + const frame = harness.captureCharFrame(); |
| 59 | + expect(frame).toContain("format"); |
| 60 | + expect(frame).not.toContain("Console"); |
| 61 | + expect(host.shell.streamLog).toEqual([]); |
| 62 | + expect(host.shell.statusFlash).toContain("format"); |
| 63 | + expect(harness.renderer.console.getCachedLogs()).toContain( |
| 64 | + "hook format ran", |
| 65 | + ); |
| 66 | + clock.advance(0); |
| 67 | + } finally { |
| 68 | + host.dispose(); |
| 69 | + harness.destroy(); |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + test("a row notice stays on the transcript and is not mirrored", async () => { |
| 74 | + const harness = await createHarness({ |
| 75 | + width: 100, |
| 76 | + height: 30, |
| 77 | + consoleMode: "console-overlay", |
| 78 | + clock: new ManualClock(), |
| 79 | + }); |
| 80 | + const emitter = new EventEmitter(); |
| 81 | + const host = await mountProductHost({ |
| 82 | + title: "test-session", |
| 83 | + eventEmitter: emitter, |
| 84 | + send: () => undefined, |
| 85 | + interrupt: () => undefined, |
| 86 | + deliver: () => undefined, |
| 87 | + createRenderer: async () => harness.renderer, |
| 88 | + }); |
| 89 | + try { |
| 90 | + harness.renderer.console.clear(); |
| 91 | + emitter.emit("hook", failingHook); |
| 92 | + await harness.renderOnce(); |
| 93 | + const frame = harness.captureCharFrame(); |
| 94 | + expect(frame).toMatch(/format[^\n]*\b2\b/); |
| 95 | + expect(frame).not.toContain("Console"); |
| 96 | + expect(harness.renderer.console.getCachedLogs()).not.toContain( |
| 97 | + "prettier not found", |
| 98 | + ); |
| 99 | + } finally { |
| 100 | + host.dispose(); |
| 101 | + harness.destroy(); |
| 102 | + } |
| 103 | + }); |
| 104 | +}); |
0 commit comments