@agnishc/edb-agent-steer 0.10.6 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/component.test.ts +113 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { SteerPromptComponent } from "./component.js";
|
|
3
|
+
|
|
4
|
+
// Mock external dependencies
|
|
5
|
+
vi.mock("@earendil-works/pi-tui", () => ({
|
|
6
|
+
matchesKey: vi.fn((data: string, keyId: string) => data === keyId),
|
|
7
|
+
truncateToWidth: vi.fn((text: string, width: number) => (text.length > width ? `${text.slice(0, width)}…` : text)),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe("SteerPromptComponent", () => {
|
|
11
|
+
// Mock theme with simple fg function
|
|
12
|
+
const mockTheme = {
|
|
13
|
+
fg: (_key: string, val: string) => val,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Mock done callback
|
|
17
|
+
let done: (choice: string) => void;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
done = vi.fn();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("handleInput", () => {
|
|
24
|
+
it('calls done("steer") for "s"', () => {
|
|
25
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
26
|
+
component.handleInput("s");
|
|
27
|
+
expect(done).toHaveBeenCalledWith("steer");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('calls done("queue") for "q"', () => {
|
|
31
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
32
|
+
component.handleInput("q");
|
|
33
|
+
expect(done).toHaveBeenCalledWith("queue");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('calls done("discard") for "d"', () => {
|
|
37
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
38
|
+
component.handleInput("d");
|
|
39
|
+
expect(done).toHaveBeenCalledWith("discard");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('calls done("edit") for "e"', () => {
|
|
43
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
44
|
+
component.handleInput("e");
|
|
45
|
+
expect(done).toHaveBeenCalledWith("edit");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('calls done("edit") for "escape"', () => {
|
|
49
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
50
|
+
component.handleInput("escape");
|
|
51
|
+
expect(done).toHaveBeenCalledWith("edit");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("does not call done for unknown keys", () => {
|
|
55
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
56
|
+
component.handleInput("x");
|
|
57
|
+
component.handleInput("w");
|
|
58
|
+
component.handleInput("");
|
|
59
|
+
expect(done).not.toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("render", () => {
|
|
64
|
+
it("returns 5 lines", () => {
|
|
65
|
+
const component = new SteerPromptComponent("hello", mockTheme, done);
|
|
66
|
+
const lines = component.render(60);
|
|
67
|
+
expect(lines.length).toBe(5);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("includes key hints in last non-empty line", () => {
|
|
71
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
72
|
+
const lines = component.render(60);
|
|
73
|
+
// Keys should appear somewhere in rendered lines
|
|
74
|
+
const allText = lines.join(" ");
|
|
75
|
+
expect(allText).toContain("steer");
|
|
76
|
+
expect(allText).toContain("queue");
|
|
77
|
+
expect(allText).toContain("discard");
|
|
78
|
+
expect(allText).toContain("edit");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("caches result for same width", () => {
|
|
82
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
83
|
+
const lines1 = component.render(60);
|
|
84
|
+
const lines2 = component.render(60);
|
|
85
|
+
expect(lines1).toBe(lines2); // Same reference
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("invalidates cache when width changes", () => {
|
|
89
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
90
|
+
const lines1 = component.render(60);
|
|
91
|
+
const lines2 = component.render(80);
|
|
92
|
+
expect(lines1).not.toBe(lines2); // Different reference
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("invalidates cache after invalidate()", () => {
|
|
96
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
97
|
+
const lines1 = component.render(60);
|
|
98
|
+
component.invalidate();
|
|
99
|
+
const lines2 = component.render(60);
|
|
100
|
+
expect(lines1).not.toBe(lines2);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("invalidate", () => {
|
|
105
|
+
it("clears cached width", () => {
|
|
106
|
+
const component = new SteerPromptComponent("test", mockTheme, done);
|
|
107
|
+
component.render(60);
|
|
108
|
+
component.invalidate();
|
|
109
|
+
const lines = component.render(60);
|
|
110
|
+
expect(lines.length).toBe(5);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|