fix(6495): a name defined in two packages counts only in the canon's own
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / integration (push) Successful in 1m22s
CI & Build / Python tests (push) Successful in 1m59s
CI & Build / Build & push image (push) Successful in 43s

A by-name reference edge could not tell two definitions of one name apart:
in a Go repo that defines `file` as importRun.file (internal/files, the
canon) and as sftpRun.file (internal/replication), a mirror test calling
`m.file(` was recorded as a use of the canon.

names_canon now takes defined_at, every repo path that defines each name,
in place of the shape file's own names. The own-file rule is unchanged.
When the repo also defines the canon's name somewhere the canon is not
recorded, a mention counts only from the canon's own package: the
directory of a file location exactly, or under a directory location.
A name defined once resolves as before. Proposer version 8 -> 9, so the
next coverage refresh re-reads every row and replaces its reference edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 20:05:09 -04:00
co-authored by Claude Opus 5.5
parent 2a6d9080ba
commit b87178d261
2 changed files with 77 additions and 22 deletions
+26 -3
View File
@@ -590,12 +590,35 @@ def test_a_name_the_file_defines_itself_resolves_there():
canon = Canon(7, "sym", "run_helper", (("src/tools.py", "run_helper"),),
"def run_helper(x):", _norm_text("x"), 2, "python")
body = "def test_a():\n run_helper(1)\n"
local = frozenset({"run_helper", "test_a"})
assert reference_canons("sym", "tests/test_a.py", "test_a", body, [canon], local_names=local) == []
assert reference_canons("sym", "src/tools.py", "caller", body, [canon], local_names=local) == [7]
own = {"run_helper": frozenset({"tests/test_a.py", "src/tools.py"})}
assert reference_canons("sym", "tests/test_a.py", "test_a", body, [canon], defined_at=own) == []
assert reference_canons("sym", "src/tools.py", "caller", body, [canon], defined_at=own) == [7]
assert reference_canons("sym", "tests/test_b.py", "test_a", body, [canon]) == [7]
def test_a_name_defined_in_two_packages_counts_only_in_the_canons_own():
"""`m.file(` in the replication package is its own `sftpRun.file`, not the
files package's canon `importRun.file`; a name defined once is unaffected."""
from grimoire.services.shape_ledger import Canon, _norm_text, reference_canons
canon = Canon(5, "sym", "file", (("internal/files/nextcloud.go", "file"),),
"func (r *importRun) file(", _norm_text("x"), 0, "go")
both = {"file": frozenset({"internal/files/nextcloud.go", "internal/replication/mirror.go"})}
once = {"file": frozenset({"internal/files/nextcloud.go"})}
other = "err := m.file(local, rpath, nil)"
assert reference_canons("sym", "internal/replication/mirror_test.go", "TestX", other, [canon],
defined_at=both) == []
assert reference_canons("sym", "internal/replication/mirror_test.go", "TestX", other, [canon],
defined_at=once) == [5]
call = "return nil, r.file(ctx, src)"
assert reference_canons("sym", "internal/files/nextcloud.go", "entry", call, [canon],
defined_at=both) == [5]
assert reference_canons("sym", "internal/files/import.go", "run", call, [canon],
defined_at=both) == [5]
# A subdirectory is another Go package.
assert reference_canons("sym", "internal/files/sub/x.go", "run", call, [canon],
defined_at=both) == []
def test_a_plain_word_counts_only_where_it_is_called():
"""`file`, `seen`: everyone's variable. `seal(...)` is still a call."""
from grimoire.services.shape_ledger import Canon, _norm_text, reference_canons