Skip to content

Commit 761f2a0

Browse files
committed
improve test debug messages
1 parent 6bb4c0c commit 761f2a0

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

bun/chat/chat.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,30 @@ export function init({ nvim, lsp }: { nvim: Nvim; lsp: Lsp }) {
222222
}
223223

224224
if (msg.msg.type == "diff-error") {
225-
const message = model.messages[msg.idx];
226-
const edit = message.edits[msg.msg.filePath];
227-
edit.status = {
228-
status: "error",
229-
message: msg.msg.message,
230-
};
231-
232-
// TODO: maybe update request status with error?
233-
// for (const requestId of edit.requestIds) {
234-
// }
225+
if (msg.msg.requestId) {
226+
const toolWrapper =
227+
model.toolManager.toolWrappers[msg.msg.requestId];
228+
if (toolWrapper) {
229+
toolWrapper.model.state = {
230+
state: "done",
231+
result: {
232+
type: "tool_result",
233+
id: msg.msg.requestId,
234+
result: {
235+
status: "error",
236+
error: msg.msg.message,
237+
},
238+
},
239+
};
240+
}
241+
} else {
242+
const message = model.messages[msg.idx];
243+
const edit = message.edits[msg.msg.filePath];
244+
edit.status = {
245+
status: "error",
246+
message: msg.msg.message,
247+
};
248+
}
235249
return [model];
236250
}
237251

bun/chat/message.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ToolRequestId } from "../tools/toolManager";
44
import { REVIEW_PROMPT } from "../tools/diff";
55

66
describe("bun/chat/message.spec.ts", () => {
7-
it("display multiple edits to the same file, and edit details", async () => {
7+
it.only("display multiple edits to the same file, and edit details", async () => {
88
await withDriver(async (driver) => {
99
await driver.showSidebar();
1010
await driver.inputMagentaText(
@@ -60,6 +60,7 @@ Edits:
6060
# assistant:
6161
ok, I will try to rewrite the poem in that file
6262
Replace [[ -2 / +1 ]] in bun/test/fixtures/poem.txt Awaiting user review.
63+
id: id1
6364
replace: {
6465
filePath: bun/test/fixtures/poem.txt
6566
match:
@@ -79,8 +80,7 @@ ${REVIEW_PROMPT}
7980
Replace [[ -2 / +1 ]] in bun/test/fixtures/poem.txt Awaiting user review.
8081
8182
Edits:
82-
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**
83-
`);
83+
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**`);
8484

8585
await driver.triggerDisplayBufferKey(reviewPos, "<CR>");
8686

bun/test/driver.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { pollUntil } from "../utils/async";
1212
import { calculatePosition } from "../tea/util";
1313
import type { BindingKey } from "../tea/bindings";
1414
import { getAllWindows, getCurrentWindow } from "../nvim/nvim";
15+
import { expect } from "bun:test";
1516

1617
export class NvimDriver {
1718
constructor(
@@ -88,23 +89,31 @@ export class NvimDriver {
8889
text: string,
8990
start: number = 0,
9091
): Promise<Position0Indexed> {
91-
return pollUntil(async () => {
92+
try {
93+
return await pollUntil(async () => {
94+
const displayBuffer = this.getDisplayBuffer();
95+
const lines = await displayBuffer.getLines({ start: 0, end: -1 });
96+
const content = lines.slice(start).join("\n");
97+
const index = Buffer.from(content).indexOf(text) as ByteIdx;
98+
if (index == -1) {
99+
throw new Error(
100+
`! Unable to find text after line ${start} in displayBuffer`,
101+
);
102+
}
103+
104+
return calculatePosition(
105+
{ row: start, col: 0 } as Position0Indexed,
106+
Buffer.from(content),
107+
index,
108+
);
109+
});
110+
} catch (e) {
92111
const displayBuffer = this.getDisplayBuffer();
93112
const lines = await displayBuffer.getLines({ start: 0, end: -1 });
94113
const content = lines.slice(start).join("\n");
95-
const index = Buffer.from(content).indexOf(text) as ByteIdx;
96-
if (index == -1) {
97-
throw new Error(
98-
`Unable to find text:\n"${text}"\nafter line ${start} in displayBuffer.\ndisplayBuffer content:\n${content}`,
99-
);
100-
}
101-
102-
return calculatePosition(
103-
{ row: start, col: 0 } as Position0Indexed,
104-
Buffer.from(content),
105-
index,
106-
);
107-
});
114+
expect(content, (e as Error).message).toEqual(text);
115+
throw e;
116+
}
108117
}
109118

110119
async assertInputBufferContains(

bun/tools/diff.spec.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ Paints its colors in the light.`,
414414
await driver.assertDisplayBufferContains(`\
415415
# assistant:
416416
ok, I will try to rewrite the poem in that file
417-
Replace [[ -1 / +1 ]] in bun/test/fixtures/poem.txt Awaiting user review.
417+
Replace [[ -1 / +1 ]] in bun/test/fixtures/poem.txt ⚠️ Error: "Unable to find text \\"bogus line...\\" in file bun/test/fixtures/poem.txt"
418+
id: id1
418419
replace: {
419420
filePath: bun/test/fixtures/poem.txt
420421
match:
@@ -426,27 +427,20 @@ bogus line...
426427
Replace text
427428
\`\`\`
428429
}
429-
Result:
430-
\`\`\`
431-
The user will review your proposed change.
432-
Assume that your change will be accepted and address other parts of the question, if any exist.
433-
Do not take more attempts at the same edit unless the user requests it.
434-
\`\`\`
430+
Error: Unable to find text "bogus line..." in file bun/test/fixtures/poem.txt
435431
Insert 1 lines. Awaiting user review.
436432
437433
Edits:
438-
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**
439-
Error applying edit: Unable to find text "bogus line..." in file bun/test/fixtures/poem.txt`);
434+
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**`);
440435
await driver.triggerDisplayBufferKey(detailsPos, "<CR>");
441436
await driver.assertDisplayBufferContains(`\
442437
# assistant:
443438
ok, I will try to rewrite the poem in that file
444-
Replace [[ -1 / +1 ]] in bun/test/fixtures/poem.txt Awaiting user review.
439+
Replace [[ -1 / +1 ]] in bun/test/fixtures/poem.txt ⚠️ Error: "Unable to find text \\"bogus line...\\" in file bun/test/fixtures/poem.txt"
445440
Insert 1 lines. Awaiting user review.
446441
447442
Edits:
448-
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**
449-
Error applying edit: Unable to find text "bogus line..." in file bun/test/fixtures/poem.txt`);
443+
bun/test/fixtures/poem.txt (2 edits). **[👀 review edits ]**`);
450444
});
451445
});
452446
});

0 commit comments

Comments
 (0)