Skip to content

Commit 5265d8e

Browse files
committed
fix(tools): fix TS type errors for no-op write/edit results
- Add explicit 'details: undefined' to no-op returns (AgentToolResult requires details) - Fix test type narrowing for 'text' property access on result.content[0] - Keep existing behavior for real changes Fixes #96983 Signed-off-by: 赵旺0668001248 <[email protected]>
1 parent a212e2f commit 5265d8e

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/agents/sessions/tools/edit.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ describe("edit tool", () => {
191191
undefined,
192192
);
193193

194-
expect(result.content[0].text).toContain("No changes made");
194+
const textContent = result.content[0];
195+
expect("text" in textContent ? textContent.text : "").toContain("No changes made");
195196
// File must not be rewritten
196197
await expect(fs.readFile(filePath, "utf-8")).resolves.toBe("unchanged content\n");
197198
});
@@ -209,7 +210,8 @@ describe("edit tool", () => {
209210
undefined,
210211
);
211212

212-
expect(result.content[0].text).toContain("Successfully replaced");
213+
const textContent = result.content[0];
214+
expect("text" in textContent ? textContent.text : "").toContain("Successfully replaced");
213215
await expect(fs.readFile(filePath, "utf-8")).resolves.toBe("new content\n");
214216
});
215217
});

src/agents/sessions/tools/edit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ export function createEditToolDefinition(
487487
text: `No changes made to ${path}. The replacement produced identical content.`,
488488
},
489489
],
490+
details: undefined,
490491
};
491492
}
492493
throw normalizedError;

src/agents/sessions/tools/write.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ describe("write tool", () => {
134134
undefined,
135135
);
136136

137-
expect(result.content[0].text).toContain("No changes made");
138-
expect(result.content[0].text).toContain("identical");
137+
const textContent = result.content[0];
138+
expect("text" in textContent ? textContent.text : "").toContain("No changes made");
139+
expect("text" in textContent ? textContent.text : "").toContain("identical");
139140
// File content must not change
140141
await expect(fs.readFile(filePath, "utf-8")).resolves.toBe("hello\n");
141142
});
@@ -151,7 +152,8 @@ describe("write tool", () => {
151152
undefined,
152153
);
153154

154-
expect(result.content[0].text).toContain("Successfully wrote");
155+
const textContent = result.content[0];
156+
expect("text" in textContent ? textContent.text : "").toContain("Successfully wrote");
155157
await expect(fs.readFile(filePath, "utf-8")).resolves.toBe("new\n");
156158
});
157159
});

src/agents/sessions/tools/write.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ export function createWriteToolDefinition(
417417
text: `No changes made to ${path}. File content is identical.`,
418418
},
419419
],
420+
details: undefined,
420421
};
421422
}
422423
await ops.mkdir(dir);

0 commit comments

Comments
 (0)