60c9c80e53
- Removed the newline guard for `replace.with` in atom edit parsing so multiline replacement text is accepted. - Updated atom tests to assert replacing a matching line with multiline content now succeeds. - Stopped clearing `optimisticUserMessageSignature` during session-context rendering so interactive status preserves in-progress signatures.
81 lines
3.0 KiB
TypeScript
81 lines
3.0 KiB
TypeScript
import { beforeAll, describe, expect, test, vi } from "bun:test";
|
|
import { initTheme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
|
import type { InteractiveModeContext } from "@oh-my-pi/pi-coding-agent/modes/types";
|
|
import { UiHelpers } from "@oh-my-pi/pi-coding-agent/modes/utils/ui-helpers";
|
|
import { buildSessionContext } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import { Container } from "@oh-my-pi/pi-tui";
|
|
|
|
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();
|
|
});
|
|
|
|
test("coalesces immediately-sequential status messages", () => {
|
|
const ctx = {
|
|
chatContainer: new Container(),
|
|
ui: { requestRender: vi.fn() },
|
|
isBackgrounded: false,
|
|
lastStatusSpacer: undefined,
|
|
lastStatusText: undefined,
|
|
} as unknown as InteractiveModeContext;
|
|
const helpers = new UiHelpers(ctx);
|
|
|
|
helpers.showStatus("STATUS_ONE");
|
|
expect(ctx.chatContainer.children).toHaveLength(2);
|
|
expect(renderLastLine(ctx.chatContainer)).toContain("STATUS_ONE");
|
|
|
|
helpers.showStatus("STATUS_TWO");
|
|
// second status updates the previous line instead of appending
|
|
expect(ctx.chatContainer.children).toHaveLength(2);
|
|
expect(renderLastLine(ctx.chatContainer)).toContain("STATUS_TWO");
|
|
expect(renderLastLine(ctx.chatContainer)).not.toContain("STATUS_ONE");
|
|
});
|
|
|
|
test("appends a new status line if something else was added in between", () => {
|
|
const ctx = {
|
|
chatContainer: new Container(),
|
|
ui: { requestRender: vi.fn() },
|
|
isBackgrounded: false,
|
|
lastStatusSpacer: undefined,
|
|
lastStatusText: undefined,
|
|
} as unknown as InteractiveModeContext;
|
|
const helpers = new UiHelpers(ctx);
|
|
|
|
helpers.showStatus("STATUS_ONE");
|
|
expect(ctx.chatContainer.children).toHaveLength(2);
|
|
|
|
// Something else gets added to the chat in between status updates
|
|
ctx.chatContainer.addChild({ render: () => ["OTHER"], invalidate: () => {} });
|
|
expect(ctx.chatContainer.children).toHaveLength(3);
|
|
|
|
helpers.showStatus("STATUS_TWO");
|
|
// adds spacer + text
|
|
expect(ctx.chatContainer.children).toHaveLength(5);
|
|
expect(renderLastLine(ctx.chatContainer)).toContain("STATUS_TWO");
|
|
});
|
|
|
|
test("preserves optimistic user signatures when rebuilding transcript state", () => {
|
|
const ctx = {
|
|
chatContainer: new Container(),
|
|
pendingTools: new Map(),
|
|
ui: { requestRender: vi.fn() },
|
|
optimisticUserMessageSignature: "hello\u00001",
|
|
} as unknown as InteractiveModeContext;
|
|
const helpers = new UiHelpers(ctx);
|
|
|
|
helpers.renderSessionContext(buildSessionContext([]));
|
|
|
|
// renderSessionContext must not clear the signature — the message_start
|
|
// handler owns this lifecycle and uses it to guard against clearing the
|
|
// user's in-progress editor draft during an optimistic send (#783).
|
|
expect(ctx.optimisticUserMessageSignature).toBe("hello\u00001");
|
|
});
|
|
});
|