Skip to content

armgit / Ix

Public Imported from GitHub
0

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

fix(ix-cli): stop ambient home-dir markers from vetoing multi-repo detection (#601)

Alot1z7541ad499d45
diff --git a/ix-cli/src/cli/__tests__/system.test.ts b/ix-cli/src/cli/__tests__/system.test.ts
index b891f7ff..e19995d1 100644
--- a/ix-cli/src/cli/__tests__/system.test.ts
+++ b/ix-cli/src/cli/__tests__/system.test.ts
@@ -164,6 +164,22 @@ describe("git-aware system detection (no flags, monorepo vs separate repos)", ()
expect(d).toBeTruthy();
expect(d!.members.sort()).toEqual(["proj-a", "proj-b"]);
});
+
+ it("ignores a stray DIRECTORY named like a workspace marker (WORKSPACE/ is not a Bazel root)", () => {
+ // An ancestor whose only "marker" is a directory named WORKSPACE (an app's
+ // data folder, not a Bazel WORKSPACE file) must not veto system detection
+ // for the independent clones collected beneath it.
+ const wsroot = nodePath.join(base, "wsdir");
+ fs.mkdirSync(nodePath.join(wsroot, "WORKSPACE"), { recursive: true });
+ fs.writeFileSync(nodePath.join(wsroot, "WORKSPACE", "default"), "x");
+ mk(nodePath.join("wsdir", "collection", "repo-a", ".git"));
+ mk(nodePath.join("wsdir", "collection", "repo-b", ".git"));
+ wf(nodePath.join("wsdir", "collection", "repo-a", "package.json"), '{"name":"repo-a"}');
+ wf(nodePath.join("wsdir", "collection", "repo-b", "package.json"), '{"name":"repo-b"}');
+ const d = detectSystem(nodePath.join(wsroot, "collection"));
+ expect(d).toBeTruthy();
+ expect(d!.members.sort()).toEqual(["repo-a", "repo-b"]);
+ });
});
describe("workspace_id convergence (solo vs co-ingest)", () => {
diff --git a/ix-cli/src/cli/system.ts b/ix-cli/src/cli/system.ts
index d4fbc487..4f4fc67c 100644
--- a/ix-cli/src/cli/system.ts
+++ b/ix-cli/src/cli/system.ts
@@ -88,7 +88,11 @@ function hasOwnGit(dir: string): boolean {
* explicit "these subdirs are MY packages, not separate repos" declaration.
*/
function hasWorkspaceMarker(dir: string): boolean {
- const has = (f: string) => { try { return fs.existsSync(nodePath.join(dir, f)); } catch { return false; } };
+ // All of these markers are FILES (a Bazel WORKSPACE, nx.json, a package.json
+ // declaring workspaces). Presence alone is not enough: a stray DIRECTORY named
+ // `WORKSPACE` or `nx.json` (e.g. an app's data folder) is not a workspace root
+ // and must not make `dir` look like one.
+ const has = (f: string) => { try { return fs.statSync(nodePath.join(dir, f)).isFile(); } catch { return false; } };
const reads = (f: string): string | null => readManifest(dir, f);
// Dedicated workspace/monorepo config files.
if (has("pnpm-workspace.yaml") || has("lerna.json") || has("nx.json") ||
@@ -115,6 +119,31 @@ function hasWorkspaceMarker(dir: string): boolean {
function isInsideSingleRepo(dir: string): boolean {
let cur = nodePath.resolve(dir);
// Walk up to the filesystem root, checking each level.
+ //
+ // Deliberately NOT stopped at `os.homedir()`. An earlier revision of the
+ // #601 fix did that, to keep an ambient marker at the user's home -- a
+ // dotfiles `.git`, a stray `npm init` -- from classifying every path beneath
+ // it as one repository. The motivating report is fixed by `hasWorkspaceMarker`
+ // requiring a FILE instead, and the home boundary turned out to cost more
+ // than it bought:
+ //
+ // - it makes this answer depend on WHO is running. Same tree, two
+ // independent clones under a directory whose parent carries a real
+ // `package.json` with `workspaces`: a `SYSTEM` when `$HOME` is that
+ // parent, `undefined` when it is not. `detectSystem` returns a
+ // `systemId` that gets persisted, so a CI job running as root and a
+ // developer mapping the same checkout would disagree about whether the
+ // path is a system at all.
+ // - a workspace config is an EXPLICIT declaration ("these subdirs are my
+ // packages"), and the boundary cannot tell one at `$HOME` from an
+ // ambient `.git`, so it ignores both.
+ // - nothing pinned it: removing the line left all 20 tests in
+ // system.test.ts green.
+ //
+ // If the ambient-`.git`-at-home case is worth fixing, it needs its own
+ // failing test and a narrower rule -- skipping only `hasOwnGit` at home while
+ // still honouring an explicit workspace declaration, or stopping at the git
+ // boundary rather than at `$HOME`.
while (true) {
if (hasOwnGit(cur) || hasWorkspaceMarker(cur)) return true;
const parent = nodePath.dirname(cur);