Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(cli): cap ix callers text-fallback snippets too (HR-01)
KageBinary373212568441
diff --git a/ix-cli/src/cli/__tests__/callers-text-fallback-snippet-cap.test.ts b/ix-cli/src/cli/__tests__/callers-text-fallback-snippet-cap.test.tsnew file mode 100644index 00000000..c73dc538--- /dev/null+++ b/ix-cli/src/cli/__tests__/callers-text-fallback-snippet-cap.test.ts@@ -0,0 +1,83 @@+// Copyright 2026 Ix Infrastructure Inc.++import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { Command } from "commander";++import { registerCallersCommand } from "../commands/callers.js";+import { SNIPPET_MAX_CHARS } from "../commands/text.js";++/**+ * With no graph callers, `ix callers` falls back to a text search and prints+ * each matching line as a snippet. A minified bundle line can be tens of KB,+ * so the fallback caps snippets the way `ix text` does.+ */++const { expand, rgLines } = vi.hoisted(() => ({ expand: vi.fn(), rgLines: { value: [] as string[] } }));++vi.mock("../../client/factory.js", () => ({+ createClient: () => ({ expand: (...args: unknown[]) => expand(...args) }),+}));+vi.mock("../resolve.js", async (importOriginal) => ({+ ...await importOriginal<typeof import("../resolve.js")>(),+ resolveFileOrReport: async () => ({ id: "11111111-0000-0000-0000-000000000000", kind: "function", name: "foo", resolutionMode: "exact" }),+ printResolved: () => {},+}));+vi.mock("../graph-health.js", async (importOriginal) => ({+ ...await importOriginal<typeof import("../graph-health.js")>(),+ checkGraphHealth: async () => ({ status: "healthy" }),+}));+vi.mock("../config.js", async (importOriginal) => ({+ ...await importOriginal<typeof import("../config.js")>(),+ resolveWorkspaceRoot: () => "/ws",+}));+vi.mock("node:child_process", async (importOriginal) => ({+ ...await importOriginal<typeof import("node:child_process")>(),+ execFile: (_file: string, _args: string[], _opts: unknown, cb: (err: unknown, out: { stdout: string; stderr: string }) => void) => {+ cb(null, { stdout: rgLines.value.join("\n"), stderr: "" });+ },+}));++function match(path: string, line: number, text: string): string {+ const start = Buffer.byteLength(text.slice(0, text.indexOf("foo(")), "utf8");+ return JSON.stringify({+ type: "match",+ data: { path: { text: path }, line_number: line, lines: { text: `${text}\n` }, submatches: [{ match: { text: "foo" }, start, end: start + 3 }] },+ });+}++async function run(args: string[]): Promise<string[]> {+ const program = new Command().name("ix").exitOverride();+ registerCallersCommand(program);+ const out: string[] = [];+ vi.spyOn(console, "log").mockImplementation((...parts) => { out.push(parts.join(" ")); });+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);+ await program.parseAsync(["callers", "foo", ...args], { from: "user" });+ return out;+}++describe("ix callers text fallback caps long snippets", () => {+ const long = `${"a".repeat(20_000)};foo(1);${"b".repeat(20_000)}`;++ beforeEach(() => {+ expand.mockReset();+ expand.mockResolvedValue({ nodes: [], edges: [] });+ rgLines.value = [match("dist/bundle.min.js", 1, long), match("src/a.ts", 3, "foo(2);")];+ });+ afterEach(() => vi.restoreAllMocks());++ it("json: a minified line is clipped around the match; a short line is unchanged", async () => {+ const out = JSON.parse((await run(["--format", "json"])).join("\n"));+ const snippets = new Map<string, string>(out.results.map((r: any) => [r.path, r.attrs.snippet]));+ const clipped = snippets.get("dist/bundle.min.js")!;+ expect(clipped.length).toBeLessThanOrEqual(SNIPPET_MAX_CHARS + 2);+ expect(clipped).toContain("foo(1)");+ expect(clipped.startsWith("…")).toBe(true);+ expect(snippets.get("src/a.ts")).toBe("foo(2);");+ });++ it("llm: no row carries the whole line", async () => {+ const out = await run(["--format", "llm"]);+ expect(out.join("\n")).not.toContain("a".repeat(1000));+ expect(out.some((l) => l.includes("foo(1)"))).toBe(true);+ });+});diff --git a/ix-cli/src/cli/commands/callers.ts b/ix-cli/src/cli/commands/callers.tsindex 1c24f9d8..3fa1485f 100644--- a/ix-cli/src/cli/commands/callers.ts+++ b/ix-cli/src/cli/commands/callers.ts@@ -15,6 +15,7 @@ import { llmLine } from "../llm.js";import { edgeTargetFor, rankTextUses, withEdgeSites } from "../edge-sites.js";import { renderWarning } from "../ui.js";import { currentRunSignal } from "../../client/run-signal.js";+import { clipSnippet } from "./text.js";const execFileAsync = promisify(execFile);@@ -95,7 +96,10 @@ export function registerCallersCommand(program: Command): void {resolved: false,path: relativePath(data.path?.text) ?? "",line: data.line_number ?? 0,- attrs: { snippet: data.lines?.text?.trim() ?? "" },+ // Capped like `ix text`: one minified line must not flood+ // the context. Ranking still reads the whole line.+ attrs: { snippet: clipSnippet(data.lines?.text ?? "", data.submatches).trim() },+ fullLine: data.lines?.text?.trim() ?? "",});}} catch { /* skip malformed lines */ }@@ -107,9 +111,9 @@ export function registerCallersCommand(program: Command): void {// Calls first and the definition out: an unranked fallback led with// import lines and the target's own signature.const ranked = rankTextUses(- allTextResults.map((r) => ({ ...r, snippet: r.attrs.snippet as string })),+ allTextResults.map((r) => ({ ...r, snippet: r.fullLine as string })),target.name,- ).map(({ snippet: _snippet, ...r }) => r);+ ).map(({ snippet: _snippet, fullLine: _fullLine, ...r }) => r);const candidatesFound = ranked.length;const textResults = ranked.slice(0, 10);