Fix minimal TUI submitted-line duplicate appearance

This commit is contained in:
William Valentin
2026-02-22 17:21:22 -08:00
parent 0775c9ede2
commit 9a9375ef5d
3 changed files with 72 additions and 2 deletions
+42
View File
@@ -39,6 +39,7 @@ function minimalTuiPrivates(value: MinimalTui): {
handleCommand: (command: unknown) => Promise<void>;
handleEscapeAction: () => boolean;
handleCtrlCPress: (nowMs?: number) => boolean;
clearSubmittedPromptLine: () => boolean;
prompt: (text: string) => Promise<string>;
rl: {
once: (event: string, cb: () => void) => void;
@@ -61,6 +62,7 @@ function minimalTuiPrivates(value: MinimalTui): {
handleCommand: (command: unknown) => Promise<void>;
handleEscapeAction: () => boolean;
handleCtrlCPress: (nowMs?: number) => boolean;
clearSubmittedPromptLine: () => boolean;
prompt: (text: string) => Promise<string>;
rl: {
once: (event: string, cb: () => void) => void;
@@ -428,6 +430,46 @@ describe('MinimalTui backend command', () => {
});
describe('MinimalTui prompt cancellation', () => {
it('omits leading newline when submitted prompt line was cleared', async () => {
const mockSession = {
id: 'test',
getHistory: () => [],
addMessage: vi.fn(),
clear: vi.fn(),
replaceHistory: vi.fn(),
};
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
const writeSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
try {
const mockAgent = {
process: vi.fn(async () => 'ok'),
};
const tui = new MinimalTui({
session: asSession(mockSession),
modelClient: asRouter({}),
agent: asAgent(mockAgent),
systemPrompt: 'test',
});
const clearSpy = vi.fn(() => true);
minimalTuiPrivates(tui).clearSubmittedPromptLine = clearSpy;
await minimalTuiPrivates(tui).handleCommand({ type: 'message', content: 'hello' });
expect(clearSpy).toHaveBeenCalledOnce();
const userHeader = writeSpy.mock.calls
.map(([chunk]) => String(chunk))
.find((chunk) => chunk.includes('You'));
expect(userHeader).toBeDefined();
expect(userHeader?.startsWith('\n')).toBe(false);
} finally {
writeSpy.mockRestore();
logSpy.mockRestore();
}
});
it('cancels an active prompt without closing the TUI', async () => {
const mockSession = {
id: 'test',