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(locate): exit non-zero for an unresolved target (#559)
KageBinarye8ab1926f47c
diff --git a/ix-cli/src/cli/__tests__/unresolved-machine-output.test.ts b/ix-cli/src/cli/__tests__/unresolved-machine-output.test.tsindex f4564b11..d91a2ec9 100644--- a/ix-cli/src/cli/__tests__/unresolved-machine-output.test.ts+++ b/ix-cli/src/cli/__tests__/unresolved-machine-output.test.ts@@ -156,4 +156,56 @@ describe("unresolved targets in machine formats", () => {targets: ["MissingFrom", "MissingTo"],});});++ // locate joins the same contract (#539) but deliberately keeps its own body+ // rather than adopting reportUnresolvedTarget's `{error, message}` shape:+ // shipped plugins read `diagnostics` off it, and the point of #539 is that+ // the exit code becomes informative without the payload going away.+ it("returns a non-zero status from ix locate while keeping its result body", async () => {+ const { registerLocateCommand } = await import("../commands/locate.js");+ const result = await run(registerLocateCommand, ["locate", "DefinitelyMissing", "--format", "json"]);++ expect(process.exitCode).toBe(1);+ expect(JSON.parse(result.stdout)).toEqual({+ resolvedTarget: null,+ resolutionMode: "none",+ systemPath: null,+ diagnostics: ["No graph entity found."],+ });+ });++ it("exits non-zero for an AMBIGUOUS locate, in every format (#547)", async () => {+ // The one command that used to disagree. This exited 0 in the first draft+ // of #539, reasoned as "several candidates is an answer, not a miss" --+ // #547 settled the opposite for the eight graph commands, and locate+ // reporting the same condition with a different status is worse than+ // either rule on its own. It is also the contradiction #539 opens with:+ // the llm branch already prints `error code=ambiguous_target`, so exiting+ // 0 told a machine caller the command succeeded while handing it an error.+ const { registerLocateCommand } = await import("../commands/locate.js");+ search.mockResolvedValue([+ { id: "first-id", kind: "function", name: "Duplicate", provenance: { sourceUri: "src/first.ts" } },+ { id: "second-id", kind: "function", name: "Duplicate", provenance: { sourceUri: "src/second.ts" } },+ ]);++ for (const format of ["json", "llm", "text"] as const) {+ process.exitCode = undefined;+ const result = await run(registerLocateCommand, ["locate", "Duplicate", "--format", format]);+ expect(process.exitCode, `format=${format}`).toBe(1);+ // ...and the body still says what it always said. The exit code becomes+ // informative without the payload going away, which is #539's whole point.+ if (format === "json") expect(JSON.parse(result.stdout).resolutionMode).toBe("ambiguous");+ if (format === "llm") expect(result.stdout).toContain("ambiguous_target");+ }+ });++ it("emits an llm error record and a non-zero status from ix locate", async () => {+ const { registerLocateCommand } = await import("../commands/locate.js");+ const result = await run(registerLocateCommand, ["locate", "DefinitelyMissing", "--format", "llm"]);++ expect(process.exitCode).toBe(1);+ // This record was already being emitted -- while exiting 0, which is the+ // contradiction #539 opens with.+ expect(result.stdout).toContain("unresolved_target");+ });});diff --git a/ix-cli/src/cli/commands/locate.ts b/ix-cli/src/cli/commands/locate.tsindex a4975e28..e4f9289a 100644--- a/ix-cli/src/cli/commands/locate.ts+++ b/ix-cli/src/cli/commands/locate.ts@@ -56,7 +56,23 @@ export function registerLocateCommand(program: Command): void {if (!target) {if (ambiguous) {- // Ambiguity already printed — stop cleanly+ // Printed above, in whichever format was asked for -- and exits 1,+ // like every other resolution failure.+ //+ // This was exit 0 in the first draft of #539, reasoned as "it+ // resolved to several candidates, which is an answer, not a miss".+ // #547 settled it the other way for the eight graph commands, and+ // being the one command that disagrees is worse than either rule:+ // `ix overview Duplicate` and `ix locate Duplicate` would report the+ // same condition with different statuses.+ //+ // It is also the same contradiction #539 opens with, one level up.+ // The llm branch above already prints `error code=ambiguous_target`,+ // and the json branch a record whose `resolvedTarget` is null -- a+ // machine caller that trusts the exit code is told the command+ // succeeded while being handed an error record. A `--pick <n>` that+ // is out of range lands here too, and that is a plain bad argument.+ process.exitCode = 1;return;}const output: LocateOutput = {@@ -66,6 +82,20 @@ export function registerLocateCommand(program: Command): void {diagnostics: ["No graph entity found."],};outputLocate(output, symbol, opts.format);+ // #539: a machine caller could not tell this from a successful command+ // that intentionally returned nothing. `context`, `explain`, `read`,+ // `trace` and `subsystems` all exit 1 here (#526, #532); locate was the+ // odd one out, and its llm output even emitted an `error` record while+ // exiting 0.+ //+ // The body is deliberately left as it is rather than replaced with+ // `reportUnresolvedTarget`'s `{error, message}` shape: shipped plugins+ // read `diagnostics` from it, and #539's whole point is that the exit+ // code should become informative without the payload going away.+ //+ // Ambiguity keeps its own path above -- a different message and a+ // different record -- but the same exit code, per #547.+ process.exitCode = 1;return;}