Fix Claude agent test for file change event detection

The test was failing because it only checked for file changes in a
structured `output.files` array, but the actual implementation returns
file changes in different formats depending on the tool type.

The test now checks for file changes in two ways:
1. Structured `output.files` array (original check)
2. Structured tool outputs with `type: "file_write"` or `type: "file_edit"`
   which include a `filePath` field

This matches how the claude-agent implementation structures tool results
in the `buildStructuredToolResult` method (lines 1081-1162), which creates
different output structures for file write/edit tools that include the
filePath directly in the output object rather than in a files array.

The test now properly detects when Claude creates files using either:
- Legacy file change tracking via output.files array
- Modern structured outputs for write_file/edit_file tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-11-30 01:25:09 +00:00
parent 20cdf4788e
commit 9993c73f90

View File

@@ -247,14 +247,24 @@ describe("ClaudeAgentClient (SDK integration)", () => {
!item.displayName.startsWith("permission:")
);
const fileChangeEvent = toolCalls.find((item) => {
if (!item.output || typeof item.output !== "object") {
return false;
// Check for file changes in structured output.files array
if (item.output && typeof item.output === "object") {
const files = (item.output as Record<string, unknown>).files;
if (Array.isArray(files) && files.some((file) => typeof file?.path === "string" && file.path.includes("tool-test.txt"))) {
return true;
}
}
const files = (item.output as Record<string, unknown>).files;
if (!Array.isArray(files)) {
return false;
// Also check for file path in output structure (write/edit tools)
if (item.output && typeof item.output === "object") {
const output = item.output as Record<string, unknown>;
if (output.type === "file_write" || output.type === "file_edit") {
const filePath = output.filePath;
if (typeof filePath === "string" && filePath.includes("tool-test.txt")) {
return true;
}
}
}
return files.some((file) => typeof file?.path === "string" && file.path.includes("tool-test.txt"));
return false;
});
const sawPwdCommand = commandEvents.some(