Skip to content

armgit / Ix

Public Imported from GitHub
0

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

fix(resolve): label non-boundary path suffixes fuzzy; qualified reading for Class.ext names

KageBinaryae31ddf98b15
diff --git a/docs/llm-format.md b/docs/llm-format.md
index a2b5d9d8..5fbc2ecd 100644
--- a/docs/llm-format.md
+++ b/docs/llm-format.md
@@ -109,10 +109,16 @@ default and adds a `pick_out_of_range` diagnostic, still exiting 0.
`Class.method` and `Class#method` resolve only to a member of that class: one
of the class's `CONTAINS` children in the graph or, when the graph has none
for it, a symbol in the class's own source file (the same path, not a
-substring of it). A same-named method elsewhere is not returned; the target is
-a miss instead. A match on
-a name that is not an exact one is `diagnostic code=fuzzy_match
-resolution=fuzzy ...`, and json carries `resolutionMode: "fuzzy"`. In json the
+substring of it). A same-named method elsewhere is not returned: the target is
+a miss instead, unless the name as typed matches something fuzzily, which
+resolves as a fuzzy match (exit 0). A name whose last part is a file extension
+(`Response.json`, `Template.html`, `Tree.go`) is a file when a file has exactly
+that name, and otherwise gets the same class-member reading.
+
+A match on a name that is not an exact one, or a path that ends in the target
+without a `/` before it (`site/package.json` matching `docs-site/package.json`),
+is `diagnostic code=fuzzy_match resolution=fuzzy ...`, and json carries
+`resolutionMode: "fuzzy"`. In json the
notices are a top-level `resolutionNotices` array merged into the command's
object; an `{error}` record never carries one.
diff --git a/ix-cli/src/cli/__tests__/target-resolution.test.ts b/ix-cli/src/cli/__tests__/target-resolution.test.ts
index 4ec9c0d6..68ea0066 100644
--- a/ix-cli/src/cli/__tests__/target-resolution.test.ts
+++ b/ix-cli/src/cli/__tests__/target-resolution.test.ts
@@ -150,6 +150,47 @@ describe("acceptance 3: a suffix stops at a path segment", () => {
});
});
+describe("a suffix not on a '/' boundary is labelled fuzzy (review round 5)", () => {
+ const nodes = [file("docs-site/package.json"), file("package.json")];
+
+ it("site/package.json resolves to docs-site/package.json as fuzzy, with a fuzzy_match notice, exit 0", async () => {
+ const [a, b] = await inBothOrders(nodes, (c) => full(c, "site/package.json"));
+ for (const r of [a, b]) {
+ expect(r.resolved && r.entity.path).toBe("docs-site/package.json");
+ expect(r.resolved && r.entity.resolutionMode).toBe("fuzzy");
+ expect(r.resolved && r.notices?.map((n) => n.code)).toEqual(["fuzzy_match"]);
+ }
+ expect(process.exitCode).toBeUndefined();
+ });
+
+ it("a suffix on a boundary stays scored with no notice", async () => {
+ const deeper = [file("apps/docs-site/package.json"), file("package.json")];
+ const [a, b] = await inBothOrders(deeper, (c) => full(c, "docs-site/package.json"));
+ for (const r of [a, b]) {
+ expect(r.resolved && r.entity.path).toBe("apps/docs-site/package.json");
+ expect(r.resolved && r.entity.resolutionMode).toBe("scored");
+ expect(r.resolved && r.notices).toBeUndefined();
+ }
+ });
+
+ it("a longer path ending in the uri on a boundary is not fuzzy", async () => {
+ const r = await full(client(nodes), "repo/docs-site/package.json");
+ expect(r.resolved && r.entity.path).toBe("docs-site/package.json");
+ expect(r.resolved && r.entity.resolutionMode).not.toBe("fuzzy");
+ expect(r.resolved && r.notices).toBeUndefined();
+ });
+
+ it("a non-boundary tie keeps the ambiguous_target notice and adds fuzzy_match", async () => {
+ const tie = [file("a-site/package.json"), file("b-site/package.json")];
+ const [a, b] = await inBothOrders(tie, (c) => full(c, "site/package.json"));
+ for (const r of [a, b]) {
+ expect(r.resolved && r.entity.path).toBe("a-site/package.json");
+ expect(r.resolved && r.entity.resolutionMode).toBe("fuzzy");
+ expect(r.resolved && r.notices?.map((n) => n.code)).toEqual(["ambiguous_target", "fuzzy_match"]);
+ }
+ });
+});
+
describe("acceptance 4: two functions named render stay ambiguous (exit 1)", () => {
const nodes = [node("r2", "render", "function", "src/z.ts", 5), node("r1", "render", "function", "src/a.ts", 9)];
@@ -442,6 +483,46 @@ describe("a fuzzy literal hit does not hide the qualified reading", () => {
});
});
+describe("a method whose name ends in a file extension (review round 5)", () => {
+ for (const [cls, method] of [["Response", "json"], ["Template", "html"], ["Tree", "go"]]) {
+ const target = `${cls}.${method}`;
+
+ it(`${target} with no such file resolves to the class member`, async () => {
+ const nodes = [
+ node("cls", cls, "class", `src/${cls.toLowerCase()}.ts`, 1),
+ node("m", method, "method", `src/${cls.toLowerCase()}.ts`, 10),
+ node("other", method, "method", "src/other.ts", 10),
+ ];
+ const [a, b] = await inBothOrders(nodes, (c) => full(c, target));
+ for (const r of [a, b]) {
+ expect(r.resolved && r.entity.id).toBe("m");
+ expect(r.resolved && r.entity.name).toBe(target);
+ }
+ expect(process.exitCode).toBeUndefined();
+ });
+
+ it(`${target} is still the file when a file has that name`, async () => {
+ const nodes = [
+ file(`assets/${target}`),
+ node("cls", cls, "class", `src/${cls.toLowerCase()}.ts`, 1),
+ node("m", method, "method", `src/${cls.toLowerCase()}.ts`, 10),
+ ];
+ const [a, b] = await inBothOrders(nodes, (c) => full(c, target));
+ for (const r of [a, b]) {
+ expect(r.resolved && r.entity.kind).toBe("file");
+ expect(r.resolved && r.entity.path).toBe(`assets/${target}`);
+ }
+ });
+ }
+
+ it("with neither the file nor the member it is still a file miss", async () => {
+ const nodes = [node("cls", "Response", "class", "src/response.ts", 1)];
+ const r = await full(client(nodes), "Response.json");
+ expect(r.resolved).toBe(false);
+ expect(!r.resolved && !r.ambiguous && r.reason).toBe("file_not_found");
+ });
+});
+
describe("acceptance 6: fuzzy matches are labelled", () => {
const nodes = [
node("fn", "reparseConfig", "function", "src/parse-pool.ts", 3),
diff --git a/ix-cli/src/cli/resolve.ts b/ix-cli/src/cli/resolve.ts
index 9efc02e8..97202230 100644
--- a/ix-cli/src/cli/resolve.ts
+++ b/ix-cli/src/cli/resolve.ts
@@ -1003,9 +1003,14 @@ function camelToSnake(s: string): string {
* the `Class.method` / `Class#method` spellings (JS, Java, Python docs).
* Splits on the *last* separator so nested scopes like `ns::Class::method`
* resolve to `{ className: "ns::Class", methodName: "method" }`. `.` and `#`
- * need identifier parts on both sides and a target that is not a file name.
+ * need identifier parts on both sides and a target that is not a file name;
+ * `allowFileName` lifts the last rule, for `Response.json` once no file of
+ * that name is found.
*/
-function parseScopedSymbol(symbol: string): { className: string; methodName: string; sep: "::" | "." | "#" } | null {
+function parseScopedSymbol(
+ symbol: string,
+ allowFileName = false,
+): { className: string; methodName: string; sep: "::" | "." | "#" } | null {
const idx = symbol.lastIndexOf('::');
if (idx >= 1) {
const className = symbol.slice(0, idx);
@@ -1013,7 +1018,7 @@ function parseScopedSymbol(symbol: string): { className: string; methodName: str
if (className && methodName) return { className, methodName, sep: "::" };
return null;
}
- if (looksFileLike(symbol)) return null;
+ if (!allowFileName && looksFileLike(symbol)) return null;
const at = Math.max(symbol.lastIndexOf('#'), symbol.lastIndexOf('.'));
if (at < 1) return null;
const className = symbol.slice(0, at);
@@ -1104,6 +1109,17 @@ export async function resolveFileOrEntityFull(
// 2. File-like input → try graph file search
if (looksFileLike(target)) {
const fileResult = await tryFileGraphMatch(client, target, opts);
+ // `Response.json`, `Template.html`, `Tree.go`: a method name can end in a
+ // file extension. When no file has exactly that name, the qualified
+ // reading is tried before a weaker file match or a miss; a file that has
+ // the name still wins.
+ const dotted = /[\\/]/.test(target) ? null : parseScopedSymbol(target, true);
+ const namesFile = fileResult?.resolved && fileResult.entity.name.toLowerCase() === target.toLowerCase();
+ if (fileResult && (!dotted || namesFile)) return fileResult;
+ if (dotted) {
+ const qualified = await resolveQualified(client, dotted, opts, true);
+ if (qualified?.resolved) return qualified;
+ }
if (fileResult) return fileResult;
// Fall through to symbol resolution
}
@@ -1484,7 +1500,9 @@ export async function resolveFileOrReport(
* filename inside --path
* quality: 1 a path suffix on a '/' boundary (`src/index.ts` in `pkg/src/index.ts`)
* quality: 2 a suffix not on a boundary (`li/config.ts`): kept so a path
- * that names one file is not sent to the file miss
+ * that names one file is not sent to the file miss, but
+ * labelled fuzzy with a fuzzy_match notice (`site/package.json`
+ * is not `docs-site/package.json`)
* quality: 3 the exact filename
* quality: 4 the filename without its extension
* Within a tier, the shortest uri, then uri, then id. It never returns
@@ -1526,11 +1544,11 @@ async function tryFileGraphMatch(
catch { fromCwd = ""; }
}
- const matches: Array<{ node: any; quality: number; uri: string }> = [];
+ const matches: Array<{ node: any; quality: number; uri: string; fuzzy?: boolean }> = [];
for (const n of nodes as any[]) {
const name = (n.name || "").toLowerCase();
const uri = normalizeForPathMatch(n.provenance?.sourceUri ?? n.provenance?.source_uri ?? "");
- const add = (quality: number) => { matches.push({ node: n, quality, uri }); };
+ const add = (quality: number, fuzzy = false) => { matches.push({ node: n, quality, uri, fuzzy }); };
if (targetHasPath && (uri === targetLower || (fromCwd && uri === fromCwd))) {
add(0);
@@ -1546,8 +1564,9 @@ async function tryFileGraphMatch(
add(1);
}
// Suffix that is not on a boundary
+ // (a target longer than the uri, ending in it on a boundary, is not fuzzy)
else if (targetHasPath && (uri.endsWith(targetLower) || (uri.includes("/") && targetLower.endsWith(uri)))) {
- add(2);
+ add(2, !targetLower.endsWith("/" + uri));
}
// Exact filename match
else if (name === basenameLower) {
@@ -1587,12 +1606,17 @@ async function tryFileGraphMatch(
tied.push(m);
}
const entityOf = (m: typeof best, mode: ResolutionMode) => nodeToResolved(m.node, m.node.name || basename, mode);
+ const fuzzy = !!best.fuzzy;
if (tied.length <= 1) {
+ if (fuzzy) {
+ const entity = entityOf(best, "fuzzy");
+ return { resolved: true, entity, notices: [fuzzyNotice(target, entity)] };
+ }
return { resolved: true, entity: entityOf(best, best.quality === 0 ? "exact" : "scored") };
}
const truncated = nodes.length >= limit;
const amb = buildAmbiguous(tied.map((m) => m.node), undefined, { total: tied.length, truncated });
- const chosen = entityOf(best, "scored");
+ const chosen = entityOf(best, fuzzy ? "fuzzy" : "scored");
const notice: ResolutionNotice = {
code: "ambiguous_target",
target,
@@ -1602,5 +1626,6 @@ async function tryFileGraphMatch(
total: tied.length,
...(truncated ? { truncated: true } : {}),
};
- return pickFromNotice({ resolved: true, entity: chosen, notices: [notice] }, opts);
+ const notices = fuzzy ? [notice, fuzzyNotice(target, chosen)] : [notice];
+ return pickFromNotice({ resolved: true, entity: chosen, notices }, opts);
}