Skip to content

Commit 2a276ae

Browse files
wesmclaude
andcommitted
Fix truthy checks for zero-valued params and empty Write content
Use null checks instead of truthiness for offset/limit (preserves 0) and Write content (shows "(empty file)" marker for empty strings). Add tests for both edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2fa983a commit 2a276ae

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

frontend/src/lib/utils/tool-params.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ describe("extractToolParamMeta", () => {
140140
).toBeNull();
141141
});
142142

143+
it("preserves zero-valued offset and limit", () => {
144+
const meta = extractToolParamMeta("Read", {
145+
file_path: "/src/app.ts",
146+
offset: 0,
147+
limit: 0,
148+
});
149+
expect(meta).toEqual([
150+
{ label: "file", value: "/src/app.ts" },
151+
{ label: "offset", value: "0" },
152+
{ label: "limit", value: "0" },
153+
]);
154+
});
155+
143156
it("truncates long file paths", () => {
144157
const longPath = "/a".repeat(50);
145158
const meta = extractToolParamMeta("Read", {
@@ -207,6 +220,15 @@ describe("generateFallbackContent", () => {
207220
expect(result.length).toBeLessThanOrEqual(501);
208221
});
209222

223+
it("shows empty-file marker for Write with empty content", () => {
224+
expect(
225+
generateFallbackContent("Write", {
226+
file_path: "/src/empty.ts",
227+
content: "",
228+
}),
229+
).toBe("(empty file)");
230+
});
231+
210232
it("falls back to generic display for Write without content", () => {
211233
expect(
212234
generateFallbackContent("Write", {

frontend/src/lib/utils/tool-params.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export function extractToolParamMeta(
2626
label: "file",
2727
value: truncate(String(params.file_path), 80),
2828
});
29-
if (params.offset)
29+
if (params.offset != null)
3030
meta.push({
3131
label: "offset",
3232
value: String(params.offset),
3333
});
34-
if (params.limit)
34+
if (params.limit != null)
3535
meta.push({
3636
label: "limit",
3737
value: String(params.limit),
@@ -119,8 +119,9 @@ export function generateFallbackContent(
119119
}
120120
return lines.length ? lines.join("\n") : null;
121121
}
122-
if (toolName === "Write" && params.content) {
123-
return truncate(String(params.content), 500);
122+
if (toolName === "Write" && params.content != null) {
123+
const text = String(params.content);
124+
return text ? truncate(text, 500) : "(empty file)";
124125
}
125126
const lines: string[] = [];
126127
for (const [key, value] of Object.entries(params)) {

0 commit comments

Comments
 (0)