b22837f898
- Consolidated grep, ast-grep, and ast-edit on required `path`, replacing `glob`/`lang`/`sel` with inline file, dir, glob, list, and URL targets. - Changed ast-grep and grep schemas to require a single `pat` string and use `skip` pagination instead of array patterns or offsets. - Updated argument validation to reject empty `path` and invalid `skip`, and routed grep context to session settings only. - Updated tool prompts and tests to reflect new path globbing semantics and `first N` truncation output text.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { sanitizeText } from "@oh-my-pi/pi-natives";
|
|
import { getThemeByName } from "../../src/modes/theme/theme";
|
|
import { grepToolRenderer } from "../../src/tools/grep";
|
|
|
|
describe("grepToolRenderer", () => {
|
|
it("keeps summary and truncation rows inside the collapsed line budget", async () => {
|
|
const theme = await getThemeByName("dark");
|
|
expect(theme).toBeDefined();
|
|
const uiTheme = theme!;
|
|
|
|
const result = {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: ["alpha:1", "alpha:2", "", "beta:1", "beta:2", "", "gamma:1", "gamma:2"].join("\n"),
|
|
},
|
|
],
|
|
details: {
|
|
matchCount: 6,
|
|
fileCount: 3,
|
|
meta: {
|
|
limits: {
|
|
matchLimit: { reached: 6 },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const collapsed = grepToolRenderer.renderResult(result as never, { expanded: false, isPartial: false }, uiTheme, {
|
|
pattern: "needle",
|
|
});
|
|
const renderedLines = sanitizeText(collapsed.render(200).join("\n")).split("\n");
|
|
const bodyLines = renderedLines.slice(1);
|
|
|
|
expect(bodyLines).toHaveLength(6);
|
|
expect(bodyLines.at(-1)).toContain("truncated: first 6 matches");
|
|
expect(bodyLines.some(line => line.includes("1 more match"))).toBe(true);
|
|
expect(bodyLines.some(line => line.includes("gamma:1"))).toBe(false);
|
|
});
|
|
});
|