fix: 🎨 Prettier and Linting
This commit is contained in:
parent
820822196b
commit
7ffc6fb67d
10 changed files with 51 additions and 39 deletions
|
|
@ -19,4 +19,3 @@ export { singleFindAndReplaceTool } from "./singleFindAndReplace";
|
|||
export { viewDiffTool } from "./viewDiff";
|
||||
export { viewRepoMapTool } from "./viewRepoMap";
|
||||
export { viewSubdirectoryTool } from "./viewSubdirectory";
|
||||
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ export const readFileHeadTool: Tool = {
|
|||
],
|
||||
},
|
||||
defaultToolPolicy: "allowedWithoutPermission",
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
|||
export const readFileRangeTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Read File Range",
|
||||
wouldLikeTo: "read lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
isCurrently: "reading lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
hasAlready: "viewed lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
wouldLikeTo:
|
||||
"read lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
isCurrently:
|
||||
"reading lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
hasAlready:
|
||||
"viewed lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
|
|
@ -45,4 +48,4 @@ export const readFileRangeTool: Tool = {
|
|||
],
|
||||
},
|
||||
defaultToolPolicy: "allowedWithoutPermission",
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -88,8 +88,6 @@ test("readFileHeadImpl validates lines parameter", async () => {
|
|||
).rejects.toThrow("lines must be 1 or greater");
|
||||
});
|
||||
|
||||
|
||||
|
||||
test("readFileHead handles file not found errors", async () => {
|
||||
const { resolveRelativePathInDir } = await import("../../util/ideUtils");
|
||||
|
||||
|
|
@ -110,4 +108,4 @@ test("readFileHead handles file not found errors", async () => {
|
|||
mockExtras,
|
||||
),
|
||||
).rejects.toThrow('File "nonexistent.txt" does not exist');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@ export const readFileHeadImpl: ToolImpl = async (args, extras) => {
|
|||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ test("readFileHead validates input arguments", () => {
|
|||
|
||||
// Test missing arguments
|
||||
expect(() => getNumberArg({}, "lines")).toThrow(
|
||||
"Argument `lines` is required (type number)"
|
||||
"Argument `lines` is required (type number)",
|
||||
);
|
||||
|
||||
// Test invalid arguments
|
||||
expect(() => getNumberArg({ lines: "not-a-number" }, "lines")).toThrow(
|
||||
"Argument `lines` must be a valid number"
|
||||
"Argument `lines` must be a valid number",
|
||||
);
|
||||
expect(() => getNumberArg({ lines: true }, "lines")).toThrow(
|
||||
"Argument `lines` must be a valid number"
|
||||
"Argument `lines` must be a valid number",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -30,4 +30,4 @@ test("readFileHead handles line number conversion correctly", () => {
|
|||
|
||||
// Test that negative numbers are parsed (validation happens in implementation)
|
||||
expect(getNumberArg({ lines: -5 }, "lines")).toBe(-5);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -72,15 +72,21 @@ test("readFileRangeImpl handles out-of-bounds ranges gracefully", async () => {
|
|||
expect(result2[0].description).toBe("test.txt (lines 5-100)");
|
||||
|
||||
// Verify that IDE methods were called with correct 0-based ranges
|
||||
expect(mockIdeOutOfBounds.readRangeInFile).toHaveBeenCalledWith("file:///test.txt", {
|
||||
start: { line: 99, character: 0 }, // 100 - 1
|
||||
end: { line: 104, character: Number.MAX_SAFE_INTEGER }, // 105 - 1
|
||||
});
|
||||
expect(mockIdeOutOfBounds.readRangeInFile).toHaveBeenCalledWith(
|
||||
"file:///test.txt",
|
||||
{
|
||||
start: { line: 99, character: 0 }, // 100 - 1
|
||||
end: { line: 104, character: Number.MAX_SAFE_INTEGER }, // 105 - 1
|
||||
},
|
||||
);
|
||||
|
||||
expect(mockIdePartialRange.readRangeInFile).toHaveBeenCalledWith("file:///test.txt", {
|
||||
start: { line: 4, character: 0 }, // 5 - 1
|
||||
end: { line: 99, character: Number.MAX_SAFE_INTEGER }, // 100 - 1
|
||||
});
|
||||
expect(mockIdePartialRange.readRangeInFile).toHaveBeenCalledWith(
|
||||
"file:///test.txt",
|
||||
{
|
||||
start: { line: 4, character: 0 }, // 5 - 1
|
||||
end: { line: 99, character: Number.MAX_SAFE_INTEGER }, // 100 - 1
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("readFileRangeImpl validates line number constraints", async () => {
|
||||
|
|
@ -147,7 +153,9 @@ test("readFileRangeImpl validates line number constraints", async () => {
|
|||
},
|
||||
mockExtras,
|
||||
),
|
||||
).rejects.toThrow("endLine (5) must be greater than or equal to startLine (10)");
|
||||
).rejects.toThrow(
|
||||
"endLine (5) must be greater than or equal to startLine (10)",
|
||||
);
|
||||
});
|
||||
|
||||
test("readFileRangeImpl handles normal ranges correctly", async () => {
|
||||
|
|
@ -194,5 +202,3 @@ test("readFileRangeImpl handles normal ranges correctly", async () => {
|
|||
end: { line: 3, character: Number.MAX_SAFE_INTEGER }, // 4 - 1
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,19 @@ export const readFileRangeImpl: ToolImpl = async (args, extras) => {
|
|||
|
||||
// Validate that line numbers are positive integers
|
||||
if (startLine < 1) {
|
||||
throw new Error("startLine must be 1 or greater. Negative line numbers are not supported - use the terminal tool with 'tail' command for reading from file end.");
|
||||
throw new Error(
|
||||
"startLine must be 1 or greater. Negative line numbers are not supported - use the terminal tool with 'tail' command for reading from file end.",
|
||||
);
|
||||
}
|
||||
if (endLine < 1) {
|
||||
throw new Error("endLine must be 1 or greater. Negative line numbers are not supported - use the terminal tool with 'tail' command for reading from file end.");
|
||||
throw new Error(
|
||||
"endLine must be 1 or greater. Negative line numbers are not supported - use the terminal tool with 'tail' command for reading from file end.",
|
||||
);
|
||||
}
|
||||
if (endLine < startLine) {
|
||||
throw new Error(`endLine (${endLine}) must be greater than or equal to startLine (${startLine})`);
|
||||
throw new Error(
|
||||
`endLine (${endLine}) must be greater than or equal to startLine (${startLine})`,
|
||||
);
|
||||
}
|
||||
|
||||
const firstUriMatch = await resolveRelativePathInDir(filepath, extras.ide);
|
||||
|
|
@ -59,4 +65,4 @@ export const readFileRangeImpl: ToolImpl = async (args, extras) => {
|
|||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ test("readFileRange should validate positive line number arguments", () => {
|
|||
expect(() => getNumberArg({ startLine: 1 }, "startLine")).not.toThrow();
|
||||
expect(() => getNumberArg({ startLine: "1" }, "startLine")).not.toThrow();
|
||||
expect(() => getNumberArg({ startLine: 100 }, "startLine")).not.toThrow();
|
||||
|
||||
// Test positive endLine validation
|
||||
|
||||
// Test positive endLine validation
|
||||
expect(() => getNumberArg({ endLine: 5 }, "endLine")).not.toThrow();
|
||||
expect(() => getNumberArg({ endLine: "10" }, "endLine")).not.toThrow();
|
||||
expect(() => getNumberArg({ endLine: 1000 }, "endLine")).not.toThrow();
|
||||
|
||||
// Test missing arguments
|
||||
expect(() => getNumberArg({}, "startLine")).toThrow(
|
||||
"Argument `startLine` is required (type number)"
|
||||
"Argument `startLine` is required (type number)",
|
||||
);
|
||||
expect(() => getNumberArg({}, "endLine")).toThrow(
|
||||
"Argument `endLine` is required (type number)"
|
||||
"Argument `endLine` is required (type number)",
|
||||
);
|
||||
|
||||
// Test invalid arguments
|
||||
expect(() => getNumberArg({ startLine: "not-a-number" }, "startLine")).toThrow(
|
||||
"Argument `startLine` must be a valid number"
|
||||
);
|
||||
expect(() =>
|
||||
getNumberArg({ startLine: "not-a-number" }, "startLine"),
|
||||
).toThrow("Argument `startLine` must be a valid number");
|
||||
expect(() => getNumberArg({ endLine: true }, "endLine")).toThrow(
|
||||
"Argument `endLine` must be a valid number"
|
||||
"Argument `endLine` must be a valid number",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ test("readFileRange handles out-of-bounds ranges gracefully", () => {
|
|||
// - VS Code: Uses array.slice() which handles out-of-bounds gracefully
|
||||
// - IntelliJ: Uses lines.getOrNull() which returns null for out-of-bounds
|
||||
// Both return empty content or available content without throwing errors
|
||||
|
||||
|
||||
expect(() => {
|
||||
const startLine = getNumberArg({ startLine: 1000 }, "startLine");
|
||||
const endLine = getNumberArg({ endLine: 2000 }, "endLine");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
getNumberArg,
|
||||
getOptionalStringArg,
|
||||
getStringArg,
|
||||
safeParseToolCallArgs
|
||||
safeParseToolCallArgs,
|
||||
} from "./parseArgs";
|
||||
|
||||
describe("safeParseToolCallArgs", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue