ci: keep registry classifications stable across line-only rebases (#996)

Merge note (pull_request_target spec-trace workflow has a startup_failure on every branch since 2026-12-02 22:45Z, so its checks run locally):
- Test run 47143803892 succeeded (go test (linux), process-level tests (real binaries)) on head d7e51484 against main fefd83d0, the current main head.
- spec-trace-check.sh and public-text-check.sh, run with the main branch's scripts against this head and body: both exit 0.
- Code review ACCEPT on 1682bcba: 271 bound classifications, citations and notes and 289 trace bindings compared unchanged; source lines are diagnostic only, while a renamed or moved function still changes its key and needs a classification; the union merge keeps concurrent additions and the checker keeps rows sorted and unique.
This commit is contained in:
pingqiu-cpu authored and GitHub committed 2026-12-03 08:25:32 -08:00
1 parent c273e07beb
commit 41de8a137e
8 files changed
+557 -464

No files matched your search

+43
View File
@@ -35,6 +35,19 @@ class ModelTraceTests(unittest.TestCase):
def test_unmapped_files_keep_existing_policy(self):
self.assertEqual(checker.check("existing prose", ["docs/a.md", "core/a.go.bak"], self.mapping), [])
def test_line_only_rebase_keeps_committed_mapping_and_obligations(self):
with tempfile.TemporaryDirectory() as tmp:
source = Path(tmp) / "a.go"
mapping = Path(tmp) / "model-code-trace.tsv"
mapping.write_text("core/a.go\tEngineAdapter.Begin\n", encoding="utf-8")
committed = mapping.read_bytes()
for padding in ("", "// unrelated rebase\n\n\n"):
source.write_text(padding + "package a\nfunc begin() {}\n", encoding="utf-8")
actual = checker.read_mapping(mapping)
self.assertEqual(checker.check("EngineAdapter.Begin", ["core/a.go"], actual), [])
self.assertEqual(len(checker.check("Other.Begin", ["core/a.go"], actual)), 1)
self.assertEqual(mapping.read_bytes(), committed)
def test_repository_map_covers_claimed_head_create(self):
mapping = checker.read_mapping(SCRIPT.parent.parent / "model-code-trace.tsv")
paths = ["core/frontend/chunkstore/layout/create.go"]
@@ -72,6 +85,36 @@ class ModelTraceTests(unittest.TestCase):
with self.assertRaises(ValueError):
checker.read_mapping(mapping)
def test_mapping_requires_sorted_unique_rows_after_a_union(self):
with tempfile.TemporaryDirectory() as tmp:
mapping = Path(tmp) / "map.tsv"
a = "core/a.go\tEngineAdapter.Begin\n"
b = "core/b.go\tMoveAdmission.Revoke\n"
for content in (b + a, a + a):
with self.subTest(content=content):
mapping.write_text(content, encoding="utf-8")
with self.assertRaisesRegex(ValueError, "sorted and unique"):
checker.read_mapping(mapping)
mapping.write_text(a + b, encoding="utf-8")
self.assertEqual(set(checker.read_mapping(mapping)), {"core/a.go", "core/b.go"})
def test_union_merge_retains_concurrent_model_rows(self):
with tempfile.TemporaryDirectory() as tmp:
paths = [Path(tmp) / name for name in ("ours", "base", "theirs")]
a = "core/a.go\tEngineAdapter.Begin\n"
b = "core/b.go\tMoveAdmission.Revoke\n"
c = "core/c.go\tVolumeCreate.Claim\n"
for path, content in zip(paths, (a + b, a, a + c)):
path.write_text(content, encoding="utf-8")
merged = subprocess.run(["git", "merge-file", "--union", "-p", *map(str, paths)],
capture_output=True, check=True, text=True).stdout
self.assertEqual(set(merged.splitlines()), {a.strip(), b.strip(), c.strip()})
paths[0].write_text("\n".join(sorted(set(merged.splitlines()))) + "\n", encoding="utf-8")
self.assertEqual(set(checker.read_mapping(paths[0])), {"core/a.go", "core/b.go", "core/c.go"})
attr = subprocess.run(["git", "check-attr", "merge", "--", ".github/model-code-trace.tsv"],
cwd=SCRIPT.parent.parent.parent, capture_output=True, check=True, text=True)
self.assertEqual(attr.stdout.strip(), ".github/model-code-trace.tsv: merge: union")
if __name__ == "__main__":
unittest.main()
+4
View File
@@ -11,6 +11,7 @@ PURE = re.compile(rf"NONE \(pure function of ({IDENT})\)")
def read_mapping(path):
mapping = {}
previous = None
for number, line in enumerate(Path(path).read_text(encoding="utf-8").splitlines(), 1):
if not line.strip() or line.startswith("#"):
continue
@@ -25,6 +26,9 @@ def read_mapping(path):
raise ValueError(f"mapping line {number}: expected a repository-relative exact path")
if not ACTION.fullmatch(action):
raise ValueError(f"mapping line {number}: invalid Module.Action")
if previous is not None and line <= previous:
raise ValueError(f"mapping line {number}: rows must be sorted and unique; sort and deduplicate the union")
previous = line
mapping.setdefault(file, set()).add(action)
if not mapping:
raise ValueError("model mapping is empty; populate it before enabling this gate")