Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

fix(fingerprints): detect callable receiver changes

Lum110418814d37296e
diff --git a/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts b/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts
index c093d997..a3254b8c 100644
--- a/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts
+++ b/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts
@@ -67,6 +67,19 @@ describe("contentHash", () => {
});
describe("extractFileFingerprint", () => {
+ it("classifies receiver changes as structural without a local class declaration", () => {
+ const fingerprint = (owner: string | undefined, content: string) => extractFileFingerprint("a.go", content, {
+ functions: [{ name: "Run", owner, lineRange: [2, 2], params: [] }],
+ classes: [], imports: [], exports: [],
+ });
+ const original = fingerprint("A", "func (a A) Run() {}");
+ const changed = fingerprint("B", "func (a B) Run() {}");
+ expect(changed.functions[0].owner).toBe("B");
+ expect(compareFingerprints(original, changed).changeLevel).toBe("STRUCTURAL");
+ expect(compareFingerprints(fingerprint(undefined, "old evidence"), changed).changeLevel).toBe("STRUCTURAL");
+ expect(compareFingerprints(changed, fingerprint("B", "body edit")).changeLevel).toBe("COSMETIC");
+ });
+
it("extracts function fingerprints from analysis", () => {
const analysis: StructuralAnalysis = {
functions: [
diff --git a/understand-anything-plugin/packages/core/src/fingerprint.ts b/understand-anything-plugin/packages/core/src/fingerprint.ts
index a43242c4..2f4fe298 100644
--- a/understand-anything-plugin/packages/core/src/fingerprint.ts
+++ b/understand-anything-plugin/packages/core/src/fingerprint.ts
@@ -8,6 +8,7 @@ import type { PluginRegistry } from "./plugins/registry.js";
export interface FunctionFingerprint {
name: string;
+ owner?: string | null;
params: string[];
returnType?: string;
exported: boolean;
@@ -95,6 +96,7 @@ export function extractFileFingerprint(
const functions: FunctionFingerprint[] = analysis.functions.map((fn) => ({
name: fn.name,
+ ...(fn.owner !== undefined ? { owner: fn.owner } : {}),
params: [...fn.params],
returnType: fn.returnType,
exported: exportedNames.has(fn.name),
@@ -159,6 +161,13 @@ export function compareFingerprints(
}
// Compare function signatures
+ // Receiver changes matter even when the type is declared in another file.
+ // Also conservatively reanalyze changed files with older ownerless evidence.
+ const ownership = (functions: FunctionFingerprint[]) => functions
+ .map(fn => JSON.stringify([fn.name, fn.owner])).sort();
+ if (JSON.stringify(ownership(oldFp.functions)) !== JSON.stringify(ownership(newFp.functions))) {
+ details.push("function ownership changed");
+ }
const oldFuncNames = new Set(oldFp.functions.map((f) => f.name));
const newFuncNames = new Set(newFp.functions.map((f) => f.name));