From d32f7633c28fc31051fcdf34c584675492fc1984 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Sat, 29 Aug 2026 12:17:43 +0800 Subject: [PATCH 1/2] fix: sync downstream drift workflow pin tests Co-Authored-By: Codex --- scripts/open_downstream_qpk_pin_prs.py | 33 ++++++++++++++++++++++++++ tests/test_qpk_pin_consistency.py | 25 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/scripts/open_downstream_qpk_pin_prs.py b/scripts/open_downstream_qpk_pin_prs.py index ae80f4d2..2252f2f1 100644 --- a/scripts/open_downstream_qpk_pin_prs.py +++ b/scripts/open_downstream_qpk_pin_prs.py @@ -126,6 +126,33 @@ def update_qpk_revision_contract(repo_dir: Path, qpk_sha: str) -> bool: return True +def update_drift_workflow_test_contract( + repo_dir: Path, + *, + qpk_sha: str, + previous_qpk_refs: set[str], +) -> bool: + """Keep workflow-content assertions aligned with an updated reusable workflow pin. + + Strategy repositories deliberately test their pinned reusable drift workflow + reference. That test is a dependency surface just like ``pyproject.toml`` + and ``drift-check.yml``; leaving it stale makes an otherwise coherent pin + update fail CI. Only QPK SHAs observed before the update are replaced. + """ + path = repo_dir / "tests" / "test_drift_workflow_config.py" + if not path.is_file(): + return False + original = path.read_text(encoding="utf-8") + updated = original + for previous_ref in sorted(previous_qpk_refs): + if previous_ref != qpk_sha: + updated = updated.replace(previous_ref, qpk_sha) + if updated == original: + return False + path.write_text(updated, encoding="utf-8") + return True + + def update_strategy_dependency_pins( repo_dir: Path, strategy_heads: dict[str, str], @@ -281,6 +308,7 @@ def update_repo( strategy_heads: dict[str, str] | None = None, ) -> bool: script = SCRIPT_ROOT / "check_qpk_pin_consistency.py" + previous_qpk_refs = qpk_refs(repo_dir) run( ["python3", str(script), "--root", str(repo_dir), "--pin-file", str(qpk_pin), "--fix"], cwd=repo_dir, @@ -290,6 +318,11 @@ def update_repo( repo_dir, get_qpk_pin_sha(pin_file=qpk_pin), ) + update_drift_workflow_test_contract( + repo_dir, + qpk_sha=get_qpk_pin_sha(pin_file=qpk_pin), + previous_qpk_refs=previous_qpk_refs, + ) if strategy_heads: update_strategy_dependency_pins(repo_dir, strategy_heads) update_qsl_strategy_requires(repo_dir, strategy_heads) diff --git a/tests/test_qpk_pin_consistency.py b/tests/test_qpk_pin_consistency.py index 0863005a..14f0373f 100644 --- a/tests/test_qpk_pin_consistency.py +++ b/tests/test_qpk_pin_consistency.py @@ -19,6 +19,7 @@ update_qsl_metadata_test_contract, update_qsl_strategy_requires, update_qsl_compat_qpk_pin, + update_drift_workflow_test_contract, update_qpk_revision_contract, update_strategy_dependency_pins, ) @@ -216,6 +217,30 @@ def test_qpk_revision_contract_tracks_staged_pin(self) -> None: contract.read_text(encoding="utf-8"), ) + def test_drift_workflow_test_contract_tracks_previously_observed_qpk_refs(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + root.joinpath("tests").mkdir() + contract = root / "tests" / "test_drift_workflow_config.py" + contract.write_text( + f'QPK_REF = "{STALE}"\n' + f'assert "reusable-drift-check.yml@{STALE}" in workflow\n', + encoding="utf-8", + ) + + self.assertTrue( + update_drift_workflow_test_contract( + root, + qpk_sha=TARGET, + previous_qpk_refs={STALE, "unrelated"}, + ) + ) + updated = contract.read_text(encoding="utf-8") + + self.assertEqual(2, updated.count(TARGET)) + self.assertNotIn(STALE, updated) + self.assertIn("unrelated", updated) + def test_consumer_strategy_pins_update_as_one_bundle(self) -> None: with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) From fa241135edd4288d04182cd5fe11cedfd081b368 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Sat, 29 Aug 2026 12:19:56 +0800 Subject: [PATCH 2/2] fix: restrict drift test pin replacements Co-Authored-By: Codex --- scripts/open_downstream_qpk_pin_prs.py | 2 +- tests/test_qpk_pin_consistency.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/open_downstream_qpk_pin_prs.py b/scripts/open_downstream_qpk_pin_prs.py index 2252f2f1..1d3deeb9 100644 --- a/scripts/open_downstream_qpk_pin_prs.py +++ b/scripts/open_downstream_qpk_pin_prs.py @@ -145,7 +145,7 @@ def update_drift_workflow_test_contract( original = path.read_text(encoding="utf-8") updated = original for previous_ref in sorted(previous_qpk_refs): - if previous_ref != qpk_sha: + if re.fullmatch(r"[a-f0-9]{40}", previous_ref) and previous_ref != qpk_sha: updated = updated.replace(previous_ref, qpk_sha) if updated == original: return False diff --git a/tests/test_qpk_pin_consistency.py b/tests/test_qpk_pin_consistency.py index 14f0373f..bd82d1b2 100644 --- a/tests/test_qpk_pin_consistency.py +++ b/tests/test_qpk_pin_consistency.py @@ -224,7 +224,8 @@ def test_drift_workflow_test_contract_tracks_previously_observed_qpk_refs(self) contract = root / "tests" / "test_drift_workflow_config.py" contract.write_text( f'QPK_REF = "{STALE}"\n' - f'assert "reusable-drift-check.yml@{STALE}" in workflow\n', + f'assert "reusable-drift-check.yml@{STALE}" in workflow\n' + 'assert "unrelated" in workflow\n', encoding="utf-8", )