Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(ingest): canonicalise the root `ix ingest <path>` is given

KageBinaryc7740dfe9690
diff --git a/ix-cli/src/cli/__tests__/ingest-files.test.ts b/ix-cli/src/cli/__tests__/ingest-files.test.ts
index 2704e7f3..5d87a977 100644
--- a/ix-cli/src/cli/__tests__/ingest-files.test.ts
+++ b/ix-cli/src/cli/__tests__/ingest-files.test.ts
@@ -3,7 +3,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createServer, type Server, type ServerResponse } from "node:http";
import type { AddressInfo } from "node:net";
-import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { execFileSync } from "node:child_process";
@@ -46,6 +46,8 @@ import { ingestMtimeCachePath, ingestRebuildPath } from "../config.js";
/** A backend that answers the endpoints an ingest touches, and records them. */
class FakeBackend {
readonly requests: Array<{ path: string; patches: number; code?: number }> = [];
+ /** `source.uri` of every patch sent in a commit request, accepted or not. */
+ readonly sourceUris: string[] = [];
/** Paths this fake does not implement. Asserted empty after every test. */
readonly unknownPaths: string[] = [];
@@ -239,6 +241,7 @@ class FakeBackend {
/* a body we cannot read is still a request */
}
this.requests.push({ path, patches: patches.length });
+ for (const { source } of patches) if (source?.uri) this.sourceUris.push(source.uri);
if (this.abortAfterCommits !== undefined && this.commitCount >= this.abortAfterCommits) {
this.aborter.abort();
}
@@ -981,6 +984,22 @@ describe("ingestFiles against a fake backend", () => {
expect(baselineFiles().sort(), "the TypeScript files keep their entries").toEqual([...everything].sort());
});
+ it("sends workspace-relative uris when the path it is given is a symlink", async () => {
+ // Discovery canonicalises every file with realpath; the root has to be
+ // canonical too, or every source_uri comes out as `../<real dir>/src/x.ts`
+ // (macOS /tmp -> /private/tmp, Windows 8.3 names, any symlinked checkout).
+ fixture(2);
+ const link = `${repo}-link`;
+ symlinkSync(repo, link, "dir");
+ try {
+ await ingestFiles(link, { format: "text", force: true, suppressOutput: true, printSummary: false });
+ } finally {
+ rmSync(link, { force: true });
+ }
+ expect(backend.sourceUris.length).toBeGreaterThan(0);
+ expect([...new Set(backend.sourceUris)].sort()).toEqual(["src/m000.ts", "src/m001.ts"]);
+ });
+
it("re-sends commits that lost the base-rev race to another writer", async () => {
// Two `ix map` runs against one backend: each commit that lands moves the
// rev under the other's in-flight commit, which is answered 200
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index 461c2e7b..bd5069cf 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -12,7 +12,7 @@ import { ParsePool } from './parse-pool.js';
import chalk from 'chalk';
import { IxClient } from '../../client/api.js';
import type { GraphPatchPayload } from '../../client/types.js';
-import { getEndpoint, resolveWorkspaceRoot, clearMapResultCache, clearStitchScopeCache } from '../config.js';
+import { canonicalWorkspacePath, getEndpoint, resolveWorkspaceRoot, clearMapResultCache, clearStitchScopeCache } from '../config.js';
import {
clearRebuildProgress, extractorChanged, isRev, loadIngestBaseline, loadRebuildProgress,
saveIngestBaseline, saveRebuildProgress,
@@ -1514,9 +1514,14 @@ export async function ingestFiles(
const moduleLoadMs = Math.round(performance.now() - trueStart);
- const resolvedPath = nodePath.isAbsolute(path)
+ // Canonical (realpath), because discovery canonicalises every file it finds:
+ // a root spelled through a symlink, macOS's /tmp or a Windows 8.3 name made
+ // every source_uri `../<real dir>/...` instead of workspace-relative. `ix
+ // map` hands in a canonical root already; `ix ingest <path>` did not. A path
+ // that does not exist stays as given, for the not-found error below.
+ const resolvedPath = canonicalWorkspacePath(nodePath.isAbsolute(path)
? path
- : nodePath.resolve(resolveWorkspaceRoot(opts.root), path);
+ : nodePath.resolve(resolveWorkspaceRoot(opts.root), path));
// Workspace identity for client-agnostic backend.
//