-
Notifications
You must be signed in to change notification settings - Fork 0
feat(gates): gate-promotion lifecycle — list advisory checks ready to promote #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Slice for the gate-promotion lifecycle (issue #156) — `gates.promotion_candidates`. | ||
|
|
||
| An advisory check carrying `promote_after = N` earns promotion to gating once it has PASSED | ||
| in its N most-recent frozen cycles (a hint; the human flips `gating`). Frozen | ||
| `check-gates.json` records drive it; `state` is mocked COMPLETE so the test needn't assemble | ||
| full SUMMARY sign-offs. Run from the project root: | ||
| PYTHONPATH=src python -m unittest discover -s tests | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import shutil | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| from unittest import mock | ||
|
|
||
| from pdca_harness import gates, state | ||
| from pdca_harness.config import Config, LeafConfig | ||
|
|
||
| _CHECK = {"id": "C5-prod", "label": "test exercises production", "scope": "bundle", | ||
| "gating": False, "promote_after": 3} | ||
|
|
||
|
|
||
| def _cfg(root: Path, checks: list[dict]) -> Config: | ||
| return Config( | ||
| root=root, bundle_root=root / "results", process_dir=root / "process", | ||
| templates_dir=root / "templates", default_branch="main", tracker_system="github", | ||
| tracker_url="", issue_id_example="#1", | ||
| builder=LeafConfig(mode="stub"), reviewer=LeafConfig(mode="stub"), | ||
| gates_checks=checks) | ||
|
|
||
|
|
||
| class Promotion(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| self.tmp = Path(tempfile.mkdtemp()) | ||
|
|
||
| def tearDown(self) -> None: | ||
| shutil.rmtree(self.tmp, ignore_errors=True) | ||
|
|
||
| def _bundle(self, cfg: Config, name: str, date: str, result: str) -> None: | ||
| d = cfg.bundle(name) | ||
| d.mkdir(parents=True) | ||
| (d / "check-gates.json").write_text( | ||
| json.dumps({"rows": [{"rule_id": "C5-prod", "result": result}]}), | ||
| encoding="utf-8") | ||
| (d / "SUMMARY.md").write_text( | ||
| f"## 9. Check sign-off\n- By / date: t / {date}\n", encoding="utf-8") | ||
|
|
||
| def _candidates(self, cfg: Config) -> list[dict]: | ||
| with mock.patch.object(gates.state, "state", return_value=state.COMPLETE): | ||
| return gates.promotion_candidates(cfg) | ||
|
|
||
| def _three(self, cfg: Config, results: tuple[str, str, str]) -> None: | ||
| for (name, date), res in zip( | ||
| [("A", "2026-06-01"), ("B", "2026-06-02"), ("C", "2026-06-03")], results): | ||
| self._bundle(cfg, name, date, res) | ||
|
|
||
| def test_ready_when_clean_for_threshold(self) -> None: | ||
| cfg = _cfg(self.tmp, [_CHECK]) | ||
| self._three(cfg, ("pass", "pass", "pass")) | ||
| self.assertEqual([c["id"] for c in self._candidates(cfg)], ["C5-prod"]) | ||
|
|
||
| def test_not_ready_when_most_recent_failed(self) -> None: | ||
| cfg = _cfg(self.tmp, [_CHECK]) | ||
| self._three(cfg, ("pass", "pass", "fail")) # newest (C, 06-03) failed | ||
| self.assertEqual(self._candidates(cfg), []) | ||
|
|
||
| def test_unverifiable_breaks_the_streak(self) -> None: | ||
| cfg = _cfg(self.tmp, [_CHECK]) | ||
| self._three(cfg, ("pass", "pass", "unverifiable")) | ||
| self.assertEqual(self._candidates(cfg), []) | ||
|
|
||
| def test_not_ready_below_threshold(self) -> None: | ||
| cfg = _cfg(self.tmp, [_CHECK]) | ||
| self._bundle(cfg, "A", "2026-06-01", "pass") | ||
| self._bundle(cfg, "B", "2026-06-02", "pass") # only 2 runs, threshold is 3 | ||
| self.assertEqual(self._candidates(cfg), []) | ||
|
|
||
| def test_gating_check_not_a_candidate(self) -> None: | ||
| cfg = _cfg(self.tmp, [{**_CHECK, "gating": True}]) | ||
| self._three(cfg, ("pass", "pass", "pass")) | ||
| self.assertEqual(self._candidates(cfg), []) | ||
|
|
||
| def test_without_promote_after_not_a_candidate(self) -> None: | ||
| cfg = _cfg(self.tmp, [{k: v for k, v in _CHECK.items() if k != "promote_after"}]) | ||
| self._three(cfg, ("pass", "pass", "pass")) | ||
| self.assertEqual(self._candidates(cfg), []) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.