Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Reuse the complete contract index within each source lookup

pulse-triage[bot]c5d2cd08503c
diff --git a/scripts/release_control/canonical_completion_guard.py b/scripts/release_control/canonical_completion_guard.py
index 4ca908f24b..97b3943d07 100644
--- a/scripts/release_control/canonical_completion_guard.py
+++ b/scripts/release_control/canonical_completion_guard.py
@@ -364,14 +364,21 @@ def required_contract_updates(
*,
use_staged_contract_index: bool = False,
revision: str | None = None,
+ contract_index: Dict[str, dict] | None = None,
) -> Dict[str, dict]:
+ # A working-tree lookup already reads the complete index for its per-file
+ # references. Reuse that invocation's snapshot, not a process-wide cache.
+ # Commit/index guards must continue to read their own selected source.
+ if contract_index is not None and (use_staged_contract_index or revision is not None):
+ raise ValueError("a supplied contract index is only valid for a working-tree lookup")
impacted_subsystems = (
impacted
if impacted is not None
else infer_impacted_subsystems(staged_files, revision=revision)
)
required: Dict[str, dict] = {}
- contract_index = load_contract_index(staged=use_staged_contract_index, revision=revision)
+ if contract_index is None:
+ contract_index = load_contract_index(staged=use_staged_contract_index, revision=revision)
for subsystem_id, data in impacted_subsystems.items():
# Contract update requirement triggers on non-cycle-artifact touches
diff --git a/scripts/release_control/subsystem_contracts.py b/scripts/release_control/subsystem_contracts.py
index ef5a32788f..79bff0513e 100644
--- a/scripts/release_control/subsystem_contracts.py
+++ b/scripts/release_control/subsystem_contracts.py
@@ -264,7 +264,9 @@ def referenced_contracts_for_path(
path: str,
contract_index: dict[str, dict[str, Any]] | None = None,
) -> list[dict[str, Any]]:
- contracts_by_subsystem = contract_index or load_contract_index()
+ # An explicitly empty source snapshot is still authoritative: do not
+ # replace it with ambient working-tree contracts.
+ contracts_by_subsystem = contract_index if contract_index is not None else load_contract_index()
matches: list[dict[str, Any]] = []
for contract in contracts_by_subsystem.values():
referenced_paths = [
diff --git a/scripts/release_control/subsystem_contracts_test.py b/scripts/release_control/subsystem_contracts_test.py
index 7bc93f4608..55ba18d434 100644
--- a/scripts/release_control/subsystem_contracts_test.py
+++ b/scripts/release_control/subsystem_contracts_test.py
@@ -170,6 +170,17 @@ Stable.
self.assertTrue(contract_reference_matches_path("internal/example/runtime.go", "internal/example/runtime.go"))
self.assertFalse(contract_reference_matches_path("internal/example/runtime.go", "internal/example/other.go"))
+ def test_explicit_empty_reference_index_does_not_read_ambient_contracts(self) -> None:
+ with patch("subsystem_contracts.load_contract_index", side_effect=AssertionError("ambient read")):
+ self.assertEqual(referenced_contracts_for_path("go.mod", {}), [])
+
+ def test_omitted_reference_index_still_reads_fresh_contracts(self) -> None:
+ entry = {"subsystem_id": "example", "path_references": [{"path": "go.mod"}]}
+ with patch("subsystem_contracts.load_contract_index", side_effect=[{"example": entry}, {}]) as load:
+ self.assertEqual(len(referenced_contracts_for_path("go.mod")), 1)
+ self.assertEqual(referenced_contracts_for_path("go.mod"), [])
+ self.assertEqual(load.call_count, 2)
+
def test_referenced_contracts_for_path_returns_matching_subsystem(self) -> None:
contract_index = load_contract_index(
{
diff --git a/scripts/release_control/subsystem_lookup.py b/scripts/release_control/subsystem_lookup.py
index 0b42a670d4..cef0b233d6 100644
--- a/scripts/release_control/subsystem_lookup.py
+++ b/scripts/release_control/subsystem_lookup.py
@@ -257,7 +257,7 @@ def lookup_paths(paths: list[str], *, lean: bool = False) -> dict[str, Any]:
}
status_report = audit_status_payload(load_status_payload())
impacted = infer_impacted_subsystems(normalized)
- contract_updates = required_contract_updates(normalized, impacted)
+ contract_updates = required_contract_updates(normalized, impacted, contract_index=contract_index)
path_entries: list[dict[str, Any]] = []
unowned: list[str] = []
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 43caf5b25a..48c2d86fa9 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -5,9 +5,10 @@ import unittest
from pathlib import Path
from unittest.mock import patch
-from canonical_completion_guard import REPO_ROOT
+from canonical_completion_guard import REPO_ROOT, infer_impacted_subsystems, required_contract_updates
from repo_file_io import canonical_workspace_repos_root, strip_local_git_env
from subsystem_lookup import lookup_paths, normalize_input_path, parse_args, render_pretty
+from subsystem_contracts import load_contract_index
PATROL_PAGE_AND_STATE_EXACT_FILES = [
@@ -97,6 +98,59 @@ def _contract_reference(contract_path: str, needle: str, runtime_path: str) -> d
class SubsystemLookupTest(unittest.TestCase):
+ def test_lookup_reads_the_complete_contract_index_once(self) -> None:
+ path = "internal/unifiedresources/views.go"
+ with patch("subsystem_lookup.load_contract_index", wraps=load_contract_index) as load:
+ with patch("canonical_completion_guard.load_contract_index", side_effect=AssertionError("duplicate read")):
+ result = lookup_paths([path])
+ self.assertEqual(load.call_count, 1)
+ self.assertTrue(result["required_contract_updates"])
+ self.assertTrue(any(item["reason"] == "dependent-reference" for item in result["required_contract_updates"]))
+
+ def test_lookup_rereads_changed_and_removed_contracts_on_each_call(self) -> None:
+ path = "internal/unifiedresources/views.go"
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ contracts = root / "contracts"
+ contracts.mkdir()
+ contract = contracts / "dependent.md"
+ text = '# Example\n\n## Contract Metadata\n\n```json\n{"subsystem_id":"example"}\n```\n\n## Shared Boundaries\n\n1. `PATH`\n'
+ contract.write_text(text.replace("PATH", "internal/not-touched.go"), encoding="utf-8")
+ with patch("subsystem_contracts.REPO_ROOT", root), patch("subsystem_contracts.CONTRACTS_DIR", contracts):
+ before = lookup_paths([path])
+ contract.write_text(text.replace("PATH", path), encoding="utf-8")
+ changed = lookup_paths([path])
+ contract.unlink()
+ removed = lookup_paths([path])
+ def dependent(result):
+ return [item for item in result["required_contract_updates"] if item["contract"] == "contracts/dependent.md"]
+ self.assertEqual(dependent(before), [])
+ self.assertEqual(len(dependent(changed)), 1)
+ self.assertEqual(dependent(changed)[0]["touched_runtime_files"], [path])
+ self.assertEqual(dependent(changed)[0]["matched_reference_details"], [
+ {"heading": "## Shared Boundaries", "path": path, "line": 11, "heading_line": 9},
+ ])
+ self.assertEqual(dependent(removed), [])
+
+ def test_shared_index_preserves_every_current_owner_and_dependent_requirement(self) -> None:
+ index = load_contract_index()
+ paths = sorted({str(ref["path"]) for entry in index.values() for ref in entry["path_references"]})
+ impacted = infer_impacted_subsystems(paths)
+ expected = required_contract_updates(paths, impacted)
+ with patch("canonical_completion_guard.load_contract_index", side_effect=AssertionError("duplicate read")):
+ self.assertEqual(required_contract_updates(paths, impacted, contract_index=index), expected)
+
+ def test_standalone_guards_keep_their_selected_contract_source(self) -> None:
+ for options in ({}, {"use_staged_contract_index": True}, {"revision": "example-commit"}):
+ with self.subTest(options=options):
+ with patch("canonical_completion_guard.load_contract_index", return_value={}) as load:
+ self.assertEqual(required_contract_updates([], {}, **options), {})
+ load.assert_called_once_with(staged=options.get("use_staged_contract_index", False), revision=options.get("revision"))
+ for options in ({"use_staged_contract_index": True}, {"revision": "example-commit"}):
+ with self.subTest(options=options):
+ with self.assertRaisesRegex(ValueError, "working-tree lookup"):
+ required_contract_updates([], {}, contract_index={}, **options)
+
def test_replication_inventory_uses_complete_wire_and_consumer_proof(self):
paths = [
"frontend-modern/src/features/proxmox/proxmoxReplicationInventory.ts",