fix(coding-agent): handled discard no-op resolution and dynamic expand hints
- Updated tool expand-hint rendering to use `expandKeyHint()`, which pulls the `app.tools.expand` binding and formats collapsed previews as `<key>: Expand`. - Updated related tests in render utils and TUI regressions to assert the new hint string for default and remapped bindings. - Added a resolve-tool regression test and changelog note covering `action: "discard"` with no pending action as a successful cancellation.
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { beforeAll, describe, expect, it } from "bun:test";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "bun:test";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { getThemeByName, initTheme, theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
||||
import { KeybindingsManager } from "@oh-my-pi/pi-coding-agent/config/keybindings";
|
||||
import { getThemeByName, initTheme, theme, type Theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
||||
import {
|
||||
dedupeParseErrors,
|
||||
expandKeyHint,
|
||||
formatCodeFrameLine,
|
||||
formatDiagnostics,
|
||||
formatErrorMessage,
|
||||
formatExpandHint,
|
||||
formatParseErrors,
|
||||
formatScreenshot,
|
||||
truncateDiffByHunk,
|
||||
} from "@oh-my-pi/pi-coding-agent/tools/render-utils";
|
||||
import { getKeybindings, setKeybindings } from "@oh-my-pi/pi-tui";
|
||||
|
||||
describe("parse error formatting", () => {
|
||||
it("deduplicates parse errors while preserving order", () => {
|
||||
@@ -282,3 +286,39 @@ describe("formatErrorMessage (F4 sanitization)", () => {
|
||||
expect(out).toContain("Unknown error");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatExpandHint / expandKeyHint", () => {
|
||||
// Plain stub: `fg` is a passthrough and brackets are literal `[`/`]`, so the
|
||||
// rendered hint is deterministic regardless of the active theme's bracket glyphs.
|
||||
const plainTheme = {
|
||||
fg: (_color: unknown, text: string) => text,
|
||||
format: { bracketLeft: "[", bracketRight: "]" },
|
||||
} as unknown as Theme;
|
||||
|
||||
let previous: ReturnType<typeof getKeybindings>;
|
||||
beforeEach(() => {
|
||||
previous = getKeybindings();
|
||||
});
|
||||
afterEach(() => {
|
||||
setKeybindings(previous);
|
||||
});
|
||||
|
||||
it("reports the default tool-output expand key", () => {
|
||||
setKeybindings(KeybindingsManager.inMemory());
|
||||
expect(expandKeyHint()).toBe("Ctrl+O");
|
||||
// Single bracket pair from the theme, no double-wrapping around the key.
|
||||
expect(formatExpandHint(plainTheme, false, true)).toBe("[Ctrl+O: Expand]");
|
||||
});
|
||||
|
||||
it("tracks a user remap of the expand binding", () => {
|
||||
setKeybindings(KeybindingsManager.inMemory({ "app.tools.expand": "alt+e" }));
|
||||
expect(expandKeyHint()).toBe("Alt+E");
|
||||
expect(formatExpandHint(plainTheme, false, true)).toBe("[Alt+E: Expand]");
|
||||
});
|
||||
|
||||
it("renders nothing when expanded or there is no more content", () => {
|
||||
setKeybindings(KeybindingsManager.inMemory());
|
||||
expect(formatExpandHint(plainTheme, true, true)).toBe("");
|
||||
expect(formatExpandHint(plainTheme, false, false)).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user