From 3efc896706a9ed95072bcd5889330e493c03c0c8 Mon Sep 17 00:00:00 2001 From: MrCakes931 Date: Mon, 2 Nov 2026 17:42:11 -0700 Subject: [PATCH 1/5] fix: detect same-index duplicates in cross-indexed records --- scripts/catalog_audit.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/catalog_audit.py b/scripts/catalog_audit.py index eafd83f..759b6c7 100644 --- a/scripts/catalog_audit.py +++ b/scripts/catalog_audit.py @@ -124,10 +124,16 @@ def audit_catalog(root: str | Path) -> dict: }) paths_by_repo: dict[str, list[str]] = defaultdict(list) + paths_by_repo_index: dict[str, dict[str, list[str]]] = defaultdict( + lambda: defaultdict(list) + ) indexes_by_repo: dict[str, set[str]] = defaultdict(set) for record in records: - paths_by_repo[record["repository"]].append(record["path"]) - indexes_by_repo[record["repository"]].add(record["index"]) + repository = record["repository"] + index_type = record["index"] + paths_by_repo[repository].append(record["path"]) + paths_by_repo_index[repository][index_type].append(record["path"]) + indexes_by_repo[repository].add(index_type) duplicate_references = [ {"repository": repository, "paths": sorted(paths)} @@ -138,9 +144,18 @@ def audit_catalog(root: str | Path) -> dict: item for item in duplicate_references if len(indexes_by_repo[item["repository"]]) > 1 ] + # A repository may be correctly cross-indexed and still be duplicated + # within one index. Evaluate each index independently rather than + # treating the presence of two indexes as proof that all repeats are valid. same_index_duplicates = [ - item for item in duplicate_references - if len(indexes_by_repo[item["repository"]]) == 1 + { + "repository": repository, + "index": index_type, + "paths": sorted(paths), + } + for repository, index_groups in sorted(paths_by_repo_index.items()) + for index_type, paths in sorted(index_groups.items()) + if len(paths) > 1 ] return { From 5416385f9c56f3caa1ea031bc2ce091895cfa8e4 Mon Sep 17 00:00:00 2001 From: MrCakes931 Date: Mon, 2 Nov 2026 17:42:15 -0700 Subject: [PATCH 2/5] test: cover same-index duplicates across dual indexes --- tests/test_catalog_audit.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_catalog_audit.py b/tests/test_catalog_audit.py index 6d98d69..3c4f7ba 100644 --- a/tests/test_catalog_audit.py +++ b/tests/test_catalog_audit.py @@ -38,6 +38,22 @@ def test_validates_cards_and_expected_cross_index_duplicates(self): self.assertEqual(report["same_index_duplicates"], []) self.assertEqual(report["normalized_interest_taxonomy"]["machine-learning"], 1) + def test_detects_same_index_duplicates_even_when_cross_indexed(self): + agency = self.root / "By_Agency" / "Example" + interest = self.root / "By_Interest_Area" / "ML" + agency.mkdir(parents=True) + interest.mkdir(parents=True) + (agency / "project-one.md").write_text(CARD, encoding="utf-8") + (agency / "project-two.md").write_text(CARD, encoding="utf-8") + (interest / "project.md").write_text(CARD, encoding="utf-8") + + report = audit_catalog(self.root) + + self.assertEqual(len(report["cross_index_references"]), 1) + self.assertEqual(len(report["same_index_duplicates"]), 1) + self.assertEqual(report["same_index_duplicates"][0]["index"], "By_Agency") + self.assertEqual(len(report["same_index_duplicates"][0]["paths"]), 2) + def test_rejects_noncanonical_or_malformed_urls(self): folder = self.root / "By_Agency" / "Example" folder.mkdir(parents=True) From d33a60fa154e5a7d21eb282f5b24d43db668e121 Mon Sep 17 00:00:00 2001 From: MrCakes931 Date: Mon, 2 Nov 2026 17:42:17 -0700 Subject: [PATCH 3/5] fix: fail closed on malformed upstream license metadata --- scripts/upstream_status.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/upstream_status.py b/scripts/upstream_status.py index 96ad44d..b41ed7a 100644 --- a/scripts/upstream_status.py +++ b/scripts/upstream_status.py @@ -30,7 +30,11 @@ def fetch_repository_status(repository: str, token: str | None = None, opener=ur payload = json.loads(response.read().decode("utf-8")) if not isinstance(payload, dict): return {"repository": repository, "status": "invalid_response"} - license_data = payload.get("license") or {} + license_data = payload.get("license") + if license_data is None: + license_data = {} + if not isinstance(license_data, dict): + return {"repository": repository, "status": "invalid_response"} return { "repository": repository, "status": "checked", From fa7a4431e470ed55600678a2b9f88c8415dd17ab Mon Sep 17 00:00:00 2001 From: MrCakes931 Date: Mon, 2 Nov 2026 17:42:20 -0700 Subject: [PATCH 4/5] test: cover malformed upstream API response shapes --- tests/test_upstream_status.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_upstream_status.py b/tests/test_upstream_status.py index 234d6e3..606ceca 100644 --- a/tests/test_upstream_status.py +++ b/tests/test_upstream_status.py @@ -63,6 +63,22 @@ def rate_limited(request, timeout): "rate_limited", ) + def test_rejects_malformed_json_shapes_without_crashing(self): + self.assertEqual( + fetch_repository_status( + "example/project", + opener=lambda request, timeout: FakeResponse([]), + )["status"], + "invalid_response", + ) + self.assertEqual( + fetch_repository_status( + "example/project", + opener=lambda request, timeout: FakeResponse({"license": "not-an-object"}), + )["status"], + "invalid_response", + ) + def test_defaults_to_small_unauthenticated_batch(self): calls = [] From 39ba8ea168c02dd705ed1733e7f66993341d4ad2 Mon Sep 17 00:00:00 2001 From: MrCakes931 Date: Mon, 2 Nov 2026 17:42:29 -0700 Subject: [PATCH 5/5] test: use catalog audit cross-index report field --- tests/test_catalog_audit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_catalog_audit.py b/tests/test_catalog_audit.py index 3c4f7ba..900fcf3 100644 --- a/tests/test_catalog_audit.py +++ b/tests/test_catalog_audit.py @@ -49,7 +49,7 @@ def test_detects_same_index_duplicates_even_when_cross_indexed(self): report = audit_catalog(self.root) - self.assertEqual(len(report["cross_index_references"]), 1) + self.assertEqual(len(report["expected_cross_index_references"]), 1) self.assertEqual(len(report["same_index_duplicates"]), 1) self.assertEqual(report["same_index_duplicates"][0]["index"], "By_Agency") self.assertEqual(len(report["same_index_duplicates"][0]["paths"]), 2)