Skip to content

Commit 53cba41

Browse files
Pigbibicodex
andcommitted
fix: sync explicit consumer QPK pin test contracts
Co-Authored-By: Codex <noreply@openai.com>
1 parent 6e14465 commit 53cba41

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

scripts/open_downstream_qpk_pin_prs.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,43 @@ def update_drift_workflow_test_contract(
166166
return True
167167

168168

169+
def update_qpk_test_pin_contracts(
170+
repo_dir: Path,
171+
*,
172+
qpk_sha: str,
173+
previous_qpk_refs: set[str],
174+
) -> bool:
175+
"""Refresh explicit QPK SHA assertions in consumer test contracts only.
176+
177+
Some P1 pipelines assert their declared QPK revision in a test instead of
178+
reading the declaration dynamically. Those assertions are part of the
179+
dependency surface, but must not leave a generated update red. Restrict
180+
replacement to test files that explicitly name QuantPlatformKit and to an
181+
SHA that was already declared by the repository before this sync.
182+
"""
183+
tests_dir = repo_dir / "tests"
184+
if not tests_dir.is_dir():
185+
return False
186+
187+
changed = False
188+
previous = {
189+
sha
190+
for sha in previous_qpk_refs
191+
if re.fullmatch(r"[a-f0-9]{40}", sha) and sha != qpk_sha
192+
}
193+
for path in sorted(tests_dir.rglob("test_*.py")):
194+
original = path.read_text(encoding="utf-8")
195+
if "QuantPlatformKit" not in original:
196+
continue
197+
updated = original
198+
for prior_sha in sorted(previous):
199+
updated = updated.replace(prior_sha, qpk_sha)
200+
if updated != original:
201+
path.write_text(updated, encoding="utf-8")
202+
changed = True
203+
return changed
204+
205+
169206
def update_strategy_dependency_pins(
170207
repo_dir: Path,
171208
strategy_heads: dict[str, str],
@@ -337,6 +374,11 @@ def update_repo(
337374
previous_qpk_refs=previous_qpk_refs,
338375
)
339376
if strategy_heads:
377+
update_qpk_test_pin_contracts(
378+
repo_dir,
379+
qpk_sha=get_qpk_pin_sha(pin_file=qpk_pin),
380+
previous_qpk_refs=previous_qpk_refs,
381+
)
340382
update_strategy_dependency_pins(repo_dir, strategy_heads)
341383
update_qsl_strategy_requires(repo_dir, strategy_heads)
342384
update_qsl_metadata_test_contract(

tests/test_qpk_pin_consistency.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
update_qsl_strategy_requires,
2323
update_qsl_compat_qpk_pin,
2424
update_drift_workflow_test_contract,
25+
update_qpk_test_pin_contracts,
2526
update_qpk_revision_contract,
2627
update_strategy_dependency_pins,
2728
)
@@ -130,6 +131,29 @@ def test_detect_reusable_workflow_qpk_pin_drift(self) -> None:
130131
self.assertGreater(mismatches, 0)
131132
self.assertTrue(any(".github/workflows/drift-check.yml" in err for err in errors))
132133

134+
def test_update_qpk_test_pin_contracts_only_touches_explicit_contracts(self) -> None:
135+
with tempfile.TemporaryDirectory() as tmp:
136+
root = Path(tmp)
137+
tests_dir = root / "tests"
138+
tests_dir.mkdir()
139+
contract = tests_dir / "test_qpk_contract.py"
140+
contract.write_text(
141+
f'EXPECTED = "{STALE}"\nassert "QuantPlatformKit"\n',
142+
encoding="utf-8",
143+
)
144+
unrelated = tests_dir / "test_unrelated.py"
145+
unrelated.write_text(f'EXPECTED = "{STALE}"\n', encoding="utf-8")
146+
147+
changed = update_qpk_test_pin_contracts(
148+
root,
149+
qpk_sha=TARGET,
150+
previous_qpk_refs={STALE},
151+
)
152+
153+
self.assertTrue(changed)
154+
self.assertIn(TARGET, contract.read_text(encoding="utf-8"))
155+
self.assertIn(STALE, unrelated.read_text(encoding="utf-8"))
156+
133157
def test_override_must_match_pin(self) -> None:
134158
pyproject = """
135159
[tool.uv]

0 commit comments

Comments
 (0)