mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 23:01:30 +00:00
tui: coalesce sequential status messages (+ tests)
This commit is contained in:
parent
c214a33405
commit
8ebc4bcebe
2 changed files with 83 additions and 3 deletions
57
packages/coding-agent/test/interactive-mode-status.test.ts
Normal file
57
packages/coding-agent/test/interactive-mode-status.test.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { Container } from "@mariozechner/pi-tui";
|
||||
import { beforeAll, describe, expect, test, vi } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";
|
||||
import { initTheme } from "../src/modes/interactive/theme/theme.js";
|
||||
|
||||
function renderLastLine(container: Container, width = 120): string {
|
||||
const last = container.children[container.children.length - 1];
|
||||
if (!last) return "";
|
||||
return last.render(width).join("\n");
|
||||
}
|
||||
|
||||
describe("InteractiveMode.showStatus", () => {
|
||||
beforeAll(() => {
|
||||
// showStatus uses the global theme instance
|
||||
initTheme("dark");
|
||||
});
|
||||
|
||||
test("coalesces immediately-sequential status messages", () => {
|
||||
const fakeThis: any = {
|
||||
chatContainer: new Container(),
|
||||
ui: { requestRender: vi.fn() },
|
||||
lastStatusSpacer: null,
|
||||
lastStatusText: null,
|
||||
};
|
||||
|
||||
(InteractiveMode as any).prototype.showStatus.call(fakeThis, "STATUS_ONE");
|
||||
expect(fakeThis.chatContainer.children).toHaveLength(2);
|
||||
expect(renderLastLine(fakeThis.chatContainer)).toContain("STATUS_ONE");
|
||||
|
||||
(InteractiveMode as any).prototype.showStatus.call(fakeThis, "STATUS_TWO");
|
||||
// second status updates the previous line instead of appending
|
||||
expect(fakeThis.chatContainer.children).toHaveLength(2);
|
||||
expect(renderLastLine(fakeThis.chatContainer)).toContain("STATUS_TWO");
|
||||
expect(renderLastLine(fakeThis.chatContainer)).not.toContain("STATUS_ONE");
|
||||
});
|
||||
|
||||
test("appends a new status line if something else was added in between", () => {
|
||||
const fakeThis: any = {
|
||||
chatContainer: new Container(),
|
||||
ui: { requestRender: vi.fn() },
|
||||
lastStatusSpacer: null,
|
||||
lastStatusText: null,
|
||||
};
|
||||
|
||||
(InteractiveMode as any).prototype.showStatus.call(fakeThis, "STATUS_ONE");
|
||||
expect(fakeThis.chatContainer.children).toHaveLength(2);
|
||||
|
||||
// Something else gets added to the chat in between status updates
|
||||
fakeThis.chatContainer.addChild({ render: () => ["OTHER"], invalidate: () => {} });
|
||||
expect(fakeThis.chatContainer.children).toHaveLength(3);
|
||||
|
||||
(InteractiveMode as any).prototype.showStatus.call(fakeThis, "STATUS_TWO");
|
||||
// adds spacer + text
|
||||
expect(fakeThis.chatContainer.children).toHaveLength(5);
|
||||
expect(renderLastLine(fakeThis.chatContainer)).toContain("STATUS_TWO");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue