Files
DroidDeck/tools/tests/test_retire_test_builds.py
T
Kurt Himebauch 6f7d7f827f fix(ci): no 404 window when a test build is replaced; merged PRs keep their build until Preview has it (#2635)
* fix(ci): a test build's files outlive the catalog that names them, and a merged PR's build lasts until Preview carries it

- A new push's PR release keeps the previous push's files until the catalog names the new
  ones, then five minutes more, so a download started from the old catalog still finds its APK.
  The app also reloads the catalog and retries once when a test build's download fails.
- Closing a PR without merging still deletes its test build. A merged PR's build stays, and
  stays listed, until the newest Preview build was built from a main holding the merge, or
  three days pass (docs-only merges build no Preview). Main's build, the PR cleanup and the
  sweep share one script for this.

* fix(ci): name the current push's APK in the catalog and prune nothing it still names

* fix(ci): only a Preview with every APK carries a merge or is offered

* fix(ci): publish no preview while none has every APK

* test(ci): build_catalog publishes no preview while its APKs are uploading
2026-11-14 23:40:08 -05:00

53 lines
2.1 KiB
Python

import unittest
from tools.release.update_catalog import ApiError, in_preview, iso_millis, keeps_test_build
from tools.release.retire_test_builds import retired
MERGED = "2026-11-14T20:00:00Z"
NOW = iso_millis(MERGED) + 3600_000
class FakeSource:
def __init__(self, status=None):
self.status = status
self.asked = []
def get(self, path):
self.asked.append(path)
if self.status is None:
raise ApiError(404, "no")
return {"status": self.status}
def pull(state="closed", merged_at=MERGED, draft=False, base="main"):
return {"state": state, "merged_at": merged_at, "merge_commit_sha": "a" * 40, "draft": draft, "base": {"ref": base}}
class RetireTestBuildsTest(unittest.TestCase):
def test_an_open_pr_keeps_its_build(self):
self.assertFalse(retired(pull(state="open", merged_at=None), FakeSource("ahead"), "o/r", "b" * 40))
def test_a_closed_unmerged_pr_loses_it_at_once(self):
self.assertTrue(retired(pull(merged_at=None), FakeSource(), "o/r", None))
def test_a_merged_pr_keeps_it_until_a_preview_carries_the_merge(self):
self.assertFalse(in_preview(FakeSource("behind"), "o/r", pull(), "b" * 40, NOW))
self.assertFalse(in_preview(FakeSource(), "o/r", pull(), "b" * 40, NOW))
self.assertFalse(in_preview(FakeSource("ahead"), "o/r", pull(), None, NOW))
self.assertTrue(in_preview(FakeSource("ahead"), "o/r", pull(), "b" * 40, NOW))
self.assertTrue(in_preview(FakeSource("identical"), "o/r", pull(), "a" * 40, NOW))
def test_a_merge_no_preview_ever_carries_is_let_go_after_the_grace(self):
self.assertTrue(in_preview(FakeSource(), "o/r", pull(), None, NOW + 4 * 86_400_000))
def test_the_catalog_lists_open_and_merged_main_prs(self):
self.assertTrue(keeps_test_build(pull(state="open", merged_at=None)))
self.assertTrue(keeps_test_build(pull()))
self.assertFalse(keeps_test_build(pull(merged_at=None)))
self.assertFalse(keeps_test_build(pull(draft=True)))
self.assertFalse(keeps_test_build(pull(base="release")))
if __name__ == "__main__":
unittest.main()