fix(webui): keep multi-file apply_patch edits

This commit is contained in:
chengyongru
2026-06-24 20:04:39 +08:00
committed by Xubin Ren
parent c915e98c15
commit 943191f0c0
6 changed files with 227 additions and 12 deletions
@@ -513,6 +513,50 @@ describe("AgentActivityCluster", () => {
expect(screen.getByText("-3")).toBeInTheDocument();
});
it("renders every file from one apply_patch call", () => {
render(
<AgentActivityCluster
messages={[{
id: "t-file-many",
role: "tool",
kind: "trace",
content: "apply_patch()",
traces: ["apply_patch()"],
fileEdits: [
{
call_id: "call-patch",
tool: "apply_patch",
path: "USER.md",
phase: "end",
added: 0,
deleted: 3,
approximate: false,
status: "done",
},
{
call_id: "call-patch",
tool: "apply_patch",
path: "MEMORY.md",
phase: "end",
added: 0,
deleted: 4,
approximate: false,
status: "done",
},
],
createdAt: 3,
}]}
isTurnStreaming={false}
hasBodyBelow={false}
/>,
);
const fileRefs = screen.getAllByTestId("activity-file-reference");
expect(fileRefs).toHaveLength(2);
expect(fileRefs[0]).toHaveTextContent("USER.md");
expect(fileRefs[1]).toHaveTextContent("MEMORY.md");
});
it("renders CLI app runs as dedicated activity rows", () => {
const line = 'run_cli_app({"name":"blender","args":["--background","scene.blend"],"json":true})';
render(
+56
View File
@@ -596,6 +596,62 @@ describe("useNanobotStream", () => {
expect(result.current.messages[0].toolEvents).toBeUndefined();
});
it("keeps every file from one apply_patch call", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-apply-patch-many", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
act(() => {
fake.emit("chat-apply-patch-many", {
event: "message",
chat_id: "chat-apply-patch-many",
text: "apply_patch()",
kind: "tool_hint",
tool_events: [{
phase: "start",
call_id: "call-patch",
name: "apply_patch",
arguments: { edits: [] },
}],
});
fake.emit("chat-apply-patch-many", {
event: "file_edit",
chat_id: "chat-apply-patch-many",
edits: [
{
call_id: "call-patch",
tool: "apply_patch",
path: "USER.md",
phase: "end",
added: 0,
deleted: 3,
approximate: false,
status: "done",
},
{
call_id: "call-patch",
tool: "apply_patch",
path: "MEMORY.md",
phase: "end",
added: 0,
deleted: 4,
approximate: false,
status: "done",
},
],
});
});
expect(result.current.messages).toHaveLength(1);
expect(result.current.messages[0].traces).toEqual([]);
expect(result.current.messages[0].toolEvents).toBeUndefined();
expect(result.current.messages[0].fileEdits?.map((edit) => edit.path)).toEqual([
"USER.md",
"MEMORY.md",
]);
});
it("upgrades pending file_edit placeholders when the path arrives", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-file-edit-pending", EMPTY_MESSAGES), {