From 780b07eca562f1d64c26f0fdf721ca25cc3a8ee7 Mon Sep 17 00:00:00 2001 From: teahubxyz Date: Sun, 18 Oct 2026 16:20:49 +0000 Subject: [PATCH] tests: the fake forge ignores unknown label filters like Gitea does; exactly three stale; test_unknown_label Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017K4vyY3yUD3GsvoZaAtKkD --- .github/time/test_housekeeping.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/time/test_housekeeping.py b/.github/time/test_housekeeping.py index 5c458a9..d27930c 100644 --- a/.github/time/test_housekeeping.py +++ b/.github/time/test_housekeeping.py @@ -23,13 +23,15 @@ LOG = 57 class Forge: - def __init__(self, branches=(), prs=(), issues=(), milestones=(), reactions=None, comments=None): + def __init__(self, branches=(), prs=(), issues=(), milestones=(), reactions=None, comments=None, repo_labels=None): self.branches = [{"name": b} if isinstance(b, str) else b for b in branches] self.prs = list(prs) self.issues = {i["number"]: {"state": "open", "labels": [], "created_at": iso(0), "updated_at": iso(0), "body": "", **i} for i in issues} self.milestones = [dict(m) for m in milestones] self.reactions = reactions or {} self.cmts = comments or {} + # the repo's labels; by default the ones its issues carry. Gitea ignores a filter on any other label. + self.repo_labels = set(repo_labels) if repo_labels is not None else {l for i in self.issues.values() for l in i["labels"]} self.writes = [] # every non-GET call self.posted = [] # (issue, body) @@ -72,7 +74,7 @@ class Forge: if route == "/repos/o/r/issues" and method == "GET": rows = [i for i in self.issues.values() if (q.get("state", ["open"])[0] in ("all", i["state"])) - and all(l in [x for x in i["labels"]] for l in q.get("labels", [""])[0].split(",") if l)] + and all(l in i["labels"] for l in q.get("labels", [""])[0].split(",") if l and l in self.repo_labels)] return self.page([{**i, "labels": [{"name": l} for l in i["labels"]]} for i in rows], path) if route.startswith("/repos/o/r/issues/") and method == "PATCH": self.issues[int(route.split("/")[-1])].update(body) @@ -161,12 +163,26 @@ def test_stale(): t = texts[0] assert "#30" in t and "#40" in t and "#32" in t, t assert "#31" not in t and "#41" not in t and "#33" not in t, t - assert any("3 stale" in b for _, b in f.posted) or any("4 stale" in b for _, b in f.posted), f.posted + assert any("3 stale" in b for _, b in f.posted), f.posted # #30, #32, #40: exactly three # an empty list posts no stale comment, only the one summary line f = Forge(); f.run() assert [b for _, b in f.posted if "stale list" in b] == [] and len(f.posted) == 1 and "0 stale" in f.posted[0][1] +def test_unknown_label(): + """No `parked` label in the repo: Gitea answers `labels=parked` with every open issue. None of them is stale, and + a `signal` filter answered with everything must not close an old issue that only looks like a signal.""" + f = Forge(issues=[{"number": 57, "title": "Astra log", "labels": ["astra"], "updated_at": iso(9)}, + {"number": 72, "title": "a parent", "labels": ["planned"], "updated_at": iso(9)}, + {"number": 96, "title": "queued card", "labels": ["queued"], "updated_at": iso(9)}, + {"number": 99, "title": "old note", "labels": [], "created_at": iso(30), "body": "see ?venture=spent"}], + repo_labels={"astra", "planned", "queued"}) + f.run() + assert [b for _, b in f.posted if "stale list" in b] == [], f.posted + assert any("0 stale" in b for _, b in f.posted) and f.issues[99]["state"] == "open", f.posted + assert [n for n, _ in f.posted] == [LOG], "the summary goes to the Astra log, found by its own label" + + def test_dry_run(): f = Forge(branches=["main", "time/card-53"], prs=[pr(1, "time/card-53", "closed", True)], issues=[sig(10, "spent", 8), {"number": 30, "labels": ["needs-human"], "updated_at": iso(9)}], @@ -178,7 +194,7 @@ def test_dry_run(): if __name__ == "__main__": - tests = [test_branches, test_signals, test_milestones, test_stale, test_dry_run] + tests = [test_branches, test_signals, test_milestones, test_stale, test_unknown_label, test_dry_run] for t in tests: t() print("ok", t.__name__)