CI: the cold cache clear fails when the warm leg starts after the start limit

start_overdue only looked at a leg that had not started, so a leg that
started 5 seconds past START_SECONDS and reached its save was let through
and the old entries were deleted. The script now exits 1 before the save
check when the leg's start time is more than START_SECONDS after the
script started.
This commit is contained in:
dotCooCoo committed 2026-11-28 00:45:19 -08:00
1 parent ada0e99dfc
commit ab260718f5
2 files changed
+32

No files matched your search

+23
View File
@@ -92,6 +92,13 @@ class Deadline(unittest.TestCase):
self.assertTrue(clear.start_overdue(queued, after_limit, self.began))
self.assertFalse(clear.gave_up(queued, after_limit))
def test_a_leg_that_starts_after_the_start_limit_fails(self):
at = lambda seconds: warm_job("in_progress", started_at=(self.began + timedelta(seconds=seconds)).isoformat())
self.assertTrue(clear.started_late(at(clear.START_SECONDS + 5), self.began))
self.assertFalse(clear.started_late(at(clear.START_SECONDS - 10), self.began))
self.assertFalse(clear.started_late(warm_job("queued"), self.began))
self.assertFalse(clear.started_late(None, self.began))
class Workflow(unittest.TestCase):
ci = (Path(__file__).resolve().parent.parent / ".github" / "workflows" / "ci.yml").read_text()
@@ -215,6 +222,22 @@ class AfterDeletion(unittest.TestCase):
canceled = warm_job("completed", "cancelled", [("Gate", "completed", "success"), ("Post Setup", "completed", "cancelled")])
self.assertEqual(self.run_main(canceled), 1)
def test_a_leg_that_starts_late_and_saves_deletes_nothing(self):
# Clock.now() is 04:00, so the leg starts 120 minutes 5 seconds after the script.
late = warm_job("in_progress", steps=self.SAVING, started_at="2026-11-28T06:00:05Z")
deleted = []
def run(args, **kwargs):
deleted.append(args[-1])
return subprocess.CompletedProcess(args, 0, "", "")
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
with mock.patch.object(clear, "gh", lambda url: {"jobs": ME + [late]}), mock.patch.object(clear.subprocess, "run", run), \
mock.patch.object(clear.time, "sleep"), mock.patch.object(clear, "datetime", Clock), mock.patch.dict(os.environ, env), \
contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(clear.main(), 1)
self.assertEqual(deleted, [])
def test_a_save_that_fails_after_the_deletion_exits_1(self):
failed = warm_job("completed", "failure", [("Gate", "completed", "success"), ("Post Setup", "completed", "failure")])
self.assertEqual(self.run_main(failed), 1)
+9
View File
@@ -103,6 +103,12 @@ def start_overdue(job, now, began):
return started_at(job) is None and (now - began).total_seconds() > START_SECONDS
def started_late(job, began):
"""True when the warm leg started more than START_SECONDS after `began` (this script's start)."""
started = started_at(job)
return started is not None and (started - began).total_seconds() > START_SECONDS
def gave_up(job, now):
"""True once GIVE_UP_SECONDS have passed since the warm leg started."""
started = started_at(job)
@@ -167,6 +173,9 @@ def main():
while True:
jobs = gh(jobs_url) or {}
job = warm_job(jobs.get('jobs', []))
if started_late(job, began):
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
return 1
if job and saving(job):
break
if job is None: