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
test(ingest): prove the failed ingest reached its commit
KageBinary1bcb09139bb7
diff --git a/ix-cli/src/cli/__tests__/ingest-registration.test.ts b/ix-cli/src/cli/__tests__/ingest-registration.test.tsindex 5d8b99aa..6c25999f 100644--- a/ix-cli/src/cli/__tests__/ingest-registration.test.ts+++ b/ix-cli/src/cli/__tests__/ingest-registration.test.ts@@ -70,11 +70,12 @@ afterEach(() => {fs.rmSync(t, { recursive: true, force: true });});-async function run(register: (p: Command) => void, args: string[]): Promise<{ out: string; exitCode: number }> {+async function run(register: (p: Command) => void, args: string[]): Promise<{ out: string; err: string; exitCode: number }> {const out: string[] = [];+ const err: string[] = [];vi.spyOn(console, "log").mockImplementation((...a: unknown[]) => { out.push(a.join(" ")); });- vi.spyOn(console, "error").mockImplementation(() => {});- vi.spyOn(process.stderr, "write").mockImplementation(() => true);+ vi.spyOn(console, "error").mockImplementation((...a: unknown[]) => { err.push(a.join(" ")); });+ vi.spyOn(process.stderr, "write").mockImplementation((chunk: unknown) => { err.push(String(chunk)); return true; });vi.spyOn(process.stdout, "write").mockImplementation((chunk: unknown) => { out.push(String(chunk)); return true; });vi.spyOn(process, "exit").mockImplementation(((code?: number) => { throw new Error(`exit ${code ?? 0}`); }) as never);process.exitCode = undefined;@@ -84,13 +85,14 @@ async function run(register: (p: Command) => void, args: string[]): Promise<{ outry {await program.parseAsync(args, { from: "user" });exitCode = Number(process.exitCode ?? 0);- } catch (err) {- const m = /^exit (\d+)$/.exec((err as Error).message);+ } catch (thrown) {+ const m = /^exit (\d+)$/.exec((thrown as Error).message);+ if (!m) err.push((thrown as Error).message);exitCode = m ? Number(m[1]) : 1;}process.exitCode = undefined;vi.restoreAllMocks();- return { out: out.join("\n"), exitCode };+ return { out: out.join("\n"), err: err.join("\n"), exitCode };}describe("ix ingest registers a workspace only once something was ingested", () => {@@ -101,7 +103,11 @@ describe("ix ingest registers a workspace only once something was ingested", ()const first = await run(registerReadCommand, ["read", secret, "--root", ws, "--format", "json"]);expect(first.out).toContain("path_outside_workspace");- await run(registerIngestCommand, ["ingest", path.join(outside, "x.json")]);+ const ingest = await run(registerIngestCommand, ["ingest", path.join(outside, "x.json")]);+ // It got as far as the commit, which is where a registration made up+ // front would already be on disk. (An ingest that cannot load its parser+ // -- core-ingestion not built -- fails earlier and would prove nothing.)+ expect(ingest.err).toContain("committed nothing");expect(fs.readFileSync(config, "utf8")).toBe(before);const second = await run(registerReadCommand, ["read", secret, "--root", ws, "--format", "json"]);diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.tsindex 488d5859..467cb8bf 100644--- a/ix-cli/src/cli/commands/ingest.ts+++ b/ix-cli/src/cli/commands/ingest.ts@@ -3762,6 +3762,15 @@ export async function ingestFiles(const elapsed = ((performance.now() - start) / 1000).toFixed(2);+ // A new workspace is registered only now, and only if the backend took+ // something: see workspaceStateFor.+ if (registrationPending && patchesTheBackendTook > 0) {+ ensureWorkspaceIdState(workspaceRoot);+ if (!opts.suppressOutput && opts.format === 'text') {+ process.stderr.write(chalk.dim(`Registered workspace "${workspaceName}" (${workspaceRoot}).\n`));+ }+ }+// Reported before the suppressOutput return, and thrown when nothing landed.//// `ix map` passes suppressOutput unconditionally, so every commit failure@@ -3771,12 +3780,6 @@ export async function ingestFiles(// left the agent believing the graph was current while `ix search` and// `ix impact` answered from a stale one. A wrong answer nobody can see is// worse than a failed command.- if (registrationPending && patchesTheBackendTook > 0) {- ensureWorkspaceIdState(workspaceRoot);- if (!opts.suppressOutput && opts.format === 'text') {- process.stderr.write(chalk.dim(`Registered workspace "${workspaceName}" (${workspaceRoot}).\n`));- }- }const commitReport = describeCommitOutcome(commitErrors,patchesApplied,