Merge main into screen-cursor-centre
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,25 @@
|
||||
import datetime as dt
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from tools.ci import nightly
|
||||
from tools.ci import nightly_set as ns
|
||||
|
||||
NOW = "2026-10-28T12:00:00+00:00"
|
||||
PATTERNS = ns.guarded_patterns((Path(__file__).resolve().parents[1] / ".github/CODEOWNERS").read_text())
|
||||
|
||||
|
||||
def pr(n, head="h", state="open", files=("crates/horizon-world/src/lib.rs",), base="main"):
|
||||
return ns.PullRequest(n, state, f"{head}{n}", f"Fix {n}", f"dev{n}", base, list(files))
|
||||
|
||||
|
||||
def lookup(*prs):
|
||||
known = {p.number: p for p in prs}
|
||||
return lambda n: known.get(n)
|
||||
|
||||
|
||||
def run(state, text, login="kacpherek", *prs):
|
||||
return ns.apply(state, ns.parse(text), login, NOW, lookup(*prs), PATTERNS)
|
||||
|
||||
T = dt.datetime(2026, 10, 28, 12, 0, tzinfo=dt.timezone.utc)
|
||||
|
||||
@@ -45,5 +63,96 @@ class NightlyTests(unittest.TestCase):
|
||||
self.assertIn("Everything in it is on main.", nightly.notes("2026-10-28", ref("main", "m" * 40, 0), []))
|
||||
|
||||
|
||||
|
||||
class ScheduledTests(unittest.TestCase):
|
||||
def test_the_scheduled_nightly_takes_new_heads_and_drops_closed_ones(self):
|
||||
state = run({}, "/nightly 1 2 3 4", "kacpherek", pr(1), pr(2), pr(3), pr(4)).state
|
||||
get = lookup(pr(1, head="new"), pr(2, state="merged"), pr(3, state="closed"),
|
||||
pr(4, files=[".github/workflows/x.yml"]))
|
||||
kept, left_out = nightly.refresh(state["prs"], get, PATTERNS)
|
||||
self.assertEqual([(e["number"], e["head"]) for e in kept], [(1, "new1")])
|
||||
self.assertEqual(len(left_out), 3)
|
||||
self.assertIn("merged", left_out[0])
|
||||
|
||||
def test_notes_list_each_pull_request_and_who_picked_it(self):
|
||||
prs = run({}, "/nightly 1 2", "kacpherek", pr(1), pr(2)).state["prs"]
|
||||
main = nightly.Ref("main", "m" * 40, None)
|
||||
text = nightly.set_notes("2026-10-28", nightly.Ref("nightly/build-2026-10-28-1", "b" * 40, None), main, prs,
|
||||
["#3 Fix 3: closed, left out"])
|
||||
self.assertIn("can include pull requests not reviewed yet, picked by trusted reviewers", text)
|
||||
self.assertIn("- Fix 1 (#1) by dev1, at h1, picked by kacpherek", text)
|
||||
self.assertIn("### Left out (1)", text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
WORKFLOWS = Path(__file__).resolve().parents[1] / ".github" / "workflows"
|
||||
|
||||
|
||||
class UntrustedBuildTests(unittest.TestCase):
|
||||
"""A nightly can hold unreviewed pull requests: nothing its build leaves may reach a release (game-build.yml)."""
|
||||
|
||||
def setUp(self):
|
||||
self.game = (WORKFLOWS / "game-build.yml").read_text()
|
||||
|
||||
def test_only_the_release_is_trusted(self):
|
||||
self.assertIn("trusted: true", (WORKFLOWS / "release.yml").read_text())
|
||||
nightly_build = (WORKFLOWS / "nightly-build.yml").read_text()
|
||||
self.assertIn("trusted: false", nightly_build)
|
||||
self.assertNotIn("trusted: true", nightly_build)
|
||||
self.assertIn("default: false", self.game.split("trusted:", 1)[1].split("developer_id:", 1)[0])
|
||||
|
||||
def test_an_untrusted_build_neither_shares_nor_saves_the_release_cache(self):
|
||||
self.assertIn("shared-key: ${{ inputs.trusted && 'release' || 'nightly' }}-${{ matrix.name }}", self.game)
|
||||
self.assertIn("save-if: ${{ inputs.trusted }}", self.game)
|
||||
self.assertEqual(self.game.count("Swatinem/rust-cache"), 1)
|
||||
|
||||
def test_an_untrusted_build_never_runs_on_the_release_runner(self):
|
||||
runs_on = [line for line in self.game.splitlines() if "runs-on:" in line]
|
||||
self.assertEqual(len(runs_on), 2)
|
||||
pr_runner = "fromJSON('[\"self-hosted\", \"macOS\", \"horizon-game\"]')"
|
||||
for line in runs_on:
|
||||
self.assertIn(f"inputs.trusted && vars.MAC_RUNNER || {pr_runner}", line)
|
||||
|
||||
def test_a_trusted_build_never_reads_the_shared_sccache(self):
|
||||
calls = self.game.count("bash tools/ci/runner-env.sh")
|
||||
self.assertEqual(self.game.count("HORIZON_NO_SCCACHE: ${{ inputs.trusted && '1' || '' }}"), calls)
|
||||
env = (Path(__file__).resolve().parents[1] / "tools/ci/runner-env.sh").read_text()
|
||||
self.assertEqual(env.count('-z "${HORIZON_NO_SCCACHE:-}"'), 2)
|
||||
|
||||
|
||||
class PruneBuildsTests(unittest.TestCase):
|
||||
TODAY = dt.date(2026, 11, 10)
|
||||
|
||||
def test_only_old_unpublished_builds_go(self):
|
||||
branches = {
|
||||
"nightly/build-2026-10-27-1": "a", # old: goes
|
||||
"nightly/build-2026-10-27-2": "pub", # old, but a published nightly-<date> points to it: stays
|
||||
"nightly/build-2026-11-02-1": "c", # old enough by one day: goes
|
||||
"nightly/build-2026-11-03-1": "d", # exactly 7 days: stays
|
||||
"nightly/build-2026-11-09-3": "e", # recent: stays
|
||||
}
|
||||
self.assertEqual(nightly.stale_builds(branches, {"pub"}, self.TODAY, 7),
|
||||
["nightly/build-2026-10-27-1", "nightly/build-2026-11-02-1"])
|
||||
|
||||
def test_the_newest_build_always_stays(self):
|
||||
branches = {"nightly/build-2026-10-01-1": "a", "nightly/build-2026-10-01-2": "b"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), ["nightly/build-2026-10-01-1"])
|
||||
self.assertEqual(nightly.stale_builds({"nightly/build-2026-10-01-1": "a"}, set(), self.TODAY, 7), [])
|
||||
# the newest by number, not by text: -10 is newer than -9
|
||||
branches = {"nightly/build-2026-10-01-9": "a", "nightly/build-2026-10-01-10": "b"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), ["nightly/build-2026-10-01-9"])
|
||||
|
||||
def test_nothing_else_is_touched(self):
|
||||
branches = {"nightly-state": "s", "nightly/build-x": "x", "main": "m", "nightly/build-2026-10-01-1-fix": "f",
|
||||
"feature/nightly/build-2026-10-01-1": "g", "nightly/build-2026-10-02-1": "n"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), [])
|
||||
|
||||
def test_the_workflow_prunes_on_schedule_only(self):
|
||||
build = (WORKFLOWS / "nightly-build.yml").read_text()
|
||||
step = build.split("Old nightly/build-* branches deleted", 1)[1].split("- uses:", 1)[0]
|
||||
self.assertIn("if: github.event_name == 'schedule'", step)
|
||||
self.assertIn("prune-builds --days 7", step)
|
||||
self.assertIn("GITHUB_STEP_SUMMARY", step)
|
||||
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from tools.ci import nightly_set as ns
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
NOW = "2026-10-28T12:00:00+00:00"
|
||||
PATTERNS = ns.guarded_patterns((ROOT / ".github/CODEOWNERS").read_text())
|
||||
|
||||
|
||||
def pr(n, head="h", state="open", files=("crates/horizon-world/src/lib.rs",), base="main"):
|
||||
return ns.PullRequest(n, state, f"{head}{n}", f"Fix {n}", f"dev{n}", base, list(files))
|
||||
|
||||
|
||||
def lookup(*prs):
|
||||
known = {p.number: p for p in prs}
|
||||
return lambda n: known.get(n)
|
||||
|
||||
|
||||
def run(state, text, login="kacpherek", *prs):
|
||||
return ns.apply(state, ns.parse(text), login, NOW, lookup(*prs), PATTERNS)
|
||||
|
||||
|
||||
class ParseTests(unittest.TestCase):
|
||||
def test_commands(self):
|
||||
self.assertEqual(ns.parse("/nightly 2640 #2642, 2640"), ns.Command("set", [2640, 2642]))
|
||||
self.assertEqual(ns.parse("/nightly add 2650"), ns.Command("add", [2650]))
|
||||
self.assertEqual(ns.parse("/Nightly REMOVE 2640"), ns.Command("remove", [2640]))
|
||||
self.assertEqual(ns.parse("/nightly clear"), ns.Command("clear", []))
|
||||
self.assertEqual(ns.parse("/nightly status"), ns.Command("status", []))
|
||||
self.assertEqual(ns.parse("/nightly"), ns.Command("status", []))
|
||||
self.assertEqual(ns.parse("/nightly dry-run 1 2"), ns.Command("dry-run", [1, 2]))
|
||||
self.assertEqual(ns.parse("\n /nightly 7\nthanks!"), ns.Command("set", [7]))
|
||||
|
||||
def test_other_comments_are_not_commands(self):
|
||||
for body in ("", "LGTM", "please /nightly 2640", "/nightlyx 1", "> /nightly 1"):
|
||||
self.assertIsNone(ns.parse(body), body)
|
||||
|
||||
def test_wrong_commands_are_answered(self):
|
||||
for body in ("/nightly please", "/nightly add", "/nightly clear 5", "/nightly 1 `rm -rf`",
|
||||
"/nightly " + " ".join(str(n) for n in range(1, 32))):
|
||||
with self.assertRaises(ns.Refused, msg=body):
|
||||
ns.parse(body)
|
||||
|
||||
def test_answers_never_quote_markdown_or_mentions(self):
|
||||
with self.assertRaises(ns.Refused) as e:
|
||||
ns.parse("/nightly @ludovic111`x`")
|
||||
self.assertNotIn("@", str(e.exception).split("isn't")[0])
|
||||
self.assertNotIn("`x`", str(e.exception))
|
||||
|
||||
|
||||
class AllowTests(unittest.TestCase):
|
||||
LIST = "# trusted\nkacpherek # added by Ludovic\nrdbtCVS\n\nnot a login!\n"
|
||||
|
||||
def test_listed_reviewers_and_ludovic(self):
|
||||
reviewers = ns.read_reviewers(self.LIST)
|
||||
ns.authorize("kacpherek", reviewers)
|
||||
ns.authorize("RDBTcvs", reviewers)
|
||||
ns.authorize("ludovic111", reviewers)
|
||||
for login in ("levzzz5154", "someone", "not"):
|
||||
with self.assertRaises(ns.Refused):
|
||||
ns.authorize(login, reviewers)
|
||||
|
||||
def test_paused_stops_reviewers_not_ludovic(self):
|
||||
reviewers = ns.read_reviewers(self.LIST + "paused # Ludovic, 2026-10-29\n")
|
||||
self.assertTrue(reviewers.paused)
|
||||
with self.assertRaises(ns.Refused):
|
||||
ns.authorize("kacpherek", reviewers)
|
||||
ns.authorize("ludovic111", reviewers)
|
||||
|
||||
def test_the_repos_list_names_the_three_reviewers(self):
|
||||
reviewers = ns.read_reviewers((ROOT / ns.REVIEWERS).read_text())
|
||||
self.assertEqual(reviewers.logins, {"kacpherek", "rdbtcvs", "online5277"})
|
||||
self.assertFalse(reviewers.paused)
|
||||
|
||||
class RefusalTests(unittest.TestCase):
|
||||
def test_what_codeowners_guards_is_refused(self):
|
||||
for path in (".github/workflows/x.yml", "tools/ci/nightly.py", "crates/horizon-release-sign/src/lib.rs",
|
||||
"crates/horizon-server/src/update.rs", "launcher/src/backend.rs", "launcher/links.json",
|
||||
"launcher/src/signed.rs", "tools/release_train.py"):
|
||||
self.assertTrue(ns.guarded(path, PATTERNS), path)
|
||||
for path in ("crates/horizon-client/src/game.rs", "launcher/src/main.rs", "tools/ci.py", "docs/x.md",
|
||||
"crates/horizon-server/src/main.rs"):
|
||||
self.assertFalse(ns.guarded(path, PATTERNS), path)
|
||||
self.assertTrue(ns.guarded("tools/ci/x.py", ns.guarded_patterns(""))) # even without CODEOWNERS
|
||||
|
||||
def test_a_set_with_a_refused_pull_request_changes_nothing(self):
|
||||
state = {"prs": []}
|
||||
bad = [pr(2, files=["tools/ci/nightly.py"]), pr(3, state="closed"), pr(4, state="merged"), pr(5, base="x")]
|
||||
for p in bad:
|
||||
with self.assertRaises(ns.Refused):
|
||||
run(state, f"/nightly 1 {p.number}", "kacpherek", pr(1), p)
|
||||
with self.assertRaises(ns.Refused):
|
||||
run(state, "/nightly 1 9", "kacpherek", pr(1)) # 9 doesn't exist
|
||||
|
||||
def test_at_most_thirty(self):
|
||||
state = {"prs": [ns.entry(pr(n), "a", NOW) for n in range(1, 31)]}
|
||||
with self.assertRaises(ns.Refused):
|
||||
run(state, "/nightly add 31", "kacpherek", pr(31))
|
||||
|
||||
|
||||
class SetTests(unittest.TestCase):
|
||||
def test_set_add_remove_clear(self):
|
||||
r = run({}, "/nightly 1 2", "kacpherek", pr(1), pr(2))
|
||||
self.assertTrue(r.build)
|
||||
self.assertEqual([e["number"] for e in r.state["prs"]], [1, 2])
|
||||
self.assertEqual(r.state["prs"][0]["asked_by"], "kacpherek")
|
||||
# add takes the newest head again and keeps its place
|
||||
r = run(r.state, "/nightly add 1 3", "rdbtCVS", pr(1, head="new"), pr(3))
|
||||
self.assertEqual([(e["number"], e["head"]) for e in r.state["prs"]], [(1, "new1"), (2, "h2"), (3, "h3")])
|
||||
r = run(r.state, "/nightly remove 2", "rdbtCVS")
|
||||
self.assertEqual([e["number"] for e in r.state["prs"]], [1, 3])
|
||||
r = run(r.state, "/nightly clear", "kacpherek")
|
||||
self.assertEqual(r.state["prs"], [])
|
||||
self.assertTrue(r.build)
|
||||
|
||||
def test_status_and_dry_run_change_nothing(self):
|
||||
state = run({}, "/nightly 1", "kacpherek", pr(1)).state
|
||||
status = run(state, "/nightly status", "levzzz5154")
|
||||
self.assertIs(status.state, state)
|
||||
self.assertFalse(status.build)
|
||||
self.assertIn("#1 Fix 1", status.answer)
|
||||
dry = run(state, "/nightly dry-run 2 3", "kacpherek", pr(2), pr(3))
|
||||
self.assertIs(dry.state, state)
|
||||
self.assertEqual([e["number"] for e in dry.dry_run], [2, 3])
|
||||
|
||||
def test_ludovics_remove_wins(self):
|
||||
state = run({}, "/nightly 1 2", "kacpherek", pr(1), pr(2)).state
|
||||
state = run(state, "/nightly remove 2", "ludovic111").state
|
||||
self.assertEqual(state["blocked"], [2])
|
||||
for text in ("/nightly add 2", "/nightly 1 2", "/nightly dry-run 2"):
|
||||
with self.assertRaises(ns.Refused):
|
||||
run(state, text, "kacpherek", pr(1), pr(2))
|
||||
state = run(state, "/nightly add 2", "ludovic111", pr(2)).state
|
||||
self.assertEqual(state["blocked"], [])
|
||||
self.assertEqual([e["number"] for e in run(state, "/nightly add 2", "kacpherek", pr(2)).state["prs"]], [1, 2])
|
||||
|
||||
def test_titles_never_mention_anyone(self):
|
||||
p = pr(1)
|
||||
p.title = "Fix @everyone\nsecond line"
|
||||
answer = run({}, "/nightly 1", "kacpherek", p).answer
|
||||
self.assertNotIn("@everyone", answer)
|
||||
self.assertNotIn("second line\n", answer)
|
||||
|
||||
def test_builds_are_numbered_per_day(self):
|
||||
self.assertEqual(ns.next_build("2026-10-28", []), "nightly/build-2026-10-28-1")
|
||||
self.assertEqual(ns.next_build("2026-10-28", ["nightly/build-2026-10-28-1", "nightly/build-2026-10-28-4"]),
|
||||
"nightly/build-2026-10-28-5")
|
||||
|
||||
|
||||
def sh(repo, *args, env=None):
|
||||
return subprocess.run(["git", *args], cwd=repo, check=True, capture_output=True, text=True,
|
||||
env={**os.environ, **(env or {})}).stdout.strip()
|
||||
|
||||
|
||||
class AssemblyTests(unittest.TestCase):
|
||||
"""A fixture repository: main and three pull requests, two of them touching the same line."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.repo = self.tmp.name
|
||||
ident = {"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t", "GIT_COMMITTER_NAME": "t",
|
||||
"GIT_COMMITTER_EMAIL": "t@t", "GIT_AUTHOR_DATE": "2026-10-28T10:00:00Z",
|
||||
"GIT_COMMITTER_DATE": "2026-10-28T10:00:00Z"}
|
||||
self.env = ident
|
||||
sh(self.repo, "init", "-q", "-b", "main")
|
||||
self.write({"a.txt": "a\n", "b.txt": "b\n", "c.txt": "c\n"})
|
||||
self.main = self.commit("main")
|
||||
self.p1 = self.branch("p1", {"a.txt": "a from p1\n"})
|
||||
self.p2 = self.branch("p2", {"b.txt": "b from p2\n", ".gitattributes": "* filter=evil\n"})
|
||||
self.p3 = self.branch("p3", {"a.txt": "a from p3\n"})
|
||||
sh(self.repo, "checkout", "-q", "main")
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def write(self, files):
|
||||
for name, text in files.items():
|
||||
Path(self.repo, name).write_text(text)
|
||||
|
||||
def commit(self, message):
|
||||
sh(self.repo, "add", "-A")
|
||||
sh(self.repo, "commit", "-q", "-m", message, env=self.env)
|
||||
return sh(self.repo, "rev-parse", "HEAD")
|
||||
|
||||
def branch(self, name, files):
|
||||
sh(self.repo, "checkout", "-q", "-b", name, self.main)
|
||||
self.write(files)
|
||||
return self.commit(name)
|
||||
|
||||
def test_clean_merges_in_order_and_the_same_inputs_give_the_same_commit(self):
|
||||
built = ns.assemble(self.main, [(1, self.p1), (2, self.p2)], cwd=self.repo)
|
||||
self.assertEqual(sh(self.repo, "show", f"{built}:a.txt"), "a from p1")
|
||||
self.assertEqual(sh(self.repo, "show", f"{built}:b.txt"), "b from p2")
|
||||
self.assertEqual(sh(self.repo, "rev-list", "--count", f"{self.main}..{built}", "--first-parent"), "2")
|
||||
self.assertEqual(ns.assemble(self.main, [(1, self.p1), (2, self.p2)], cwd=self.repo), built)
|
||||
# nothing was checked out: the working tree is still main's
|
||||
self.assertEqual(Path(self.repo, "a.txt").read_text(), "a\n")
|
||||
self.assertFalse(Path(self.repo, ".gitattributes").exists())
|
||||
|
||||
def test_two_pull_requests_that_conflict_are_named(self):
|
||||
with self.assertRaises(ns.Conflict) as e:
|
||||
ns.assemble(self.main, [(1, self.p1), (2, self.p2), (3, self.p3)], cwd=self.repo)
|
||||
self.assertEqual((e.exception.number, e.exception.other, e.exception.files), (3, 1, ["a.txt"]))
|
||||
self.assertIn("#1 and #3 conflict in `a.txt`", e.exception.text())
|
||||
|
||||
def test_a_conflict_with_main_says_so(self):
|
||||
sh(self.repo, "checkout", "-q", "main")
|
||||
self.write({"a.txt": "a from main\n"})
|
||||
main = self.commit("main moves")
|
||||
with self.assertRaises(ns.Conflict) as e:
|
||||
ns.assemble(main, [(1, self.p1)], cwd=self.repo)
|
||||
self.assertIsNone(e.exception.other)
|
||||
self.assertIn("conflicts with main", e.exception.text())
|
||||
|
||||
def test_changed_files_finds_guarded_paths(self):
|
||||
self.assertEqual(sorted(ns.changed_files(self.main, self.p2, cwd=self.repo)), [".gitattributes", "b.txt"])
|
||||
|
||||
|
||||
class StateTests(unittest.TestCase):
|
||||
"""The nightly-state branch on a local bare repository standing in for origin."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.origin, self.repo = Path(self.tmp.name, "origin.git"), Path(self.tmp.name, "work")
|
||||
subprocess.run(["git", "init", "-q", "--bare", str(self.origin)], check=True)
|
||||
subprocess.run(["git", "init", "-q", str(self.repo)], check=True)
|
||||
sh(self.repo, "remote", "add", "origin", str(self.origin))
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_first_save_then_load(self):
|
||||
self.assertEqual(ns.load_state(str(self.repo)), ({}, "", None))
|
||||
ns.update_state(lambda st, b: ({"prs": [1]}, b + "{}\n", "first"), "t", cwd=str(self.repo))
|
||||
state, builds, head = ns.load_state(str(self.repo))
|
||||
self.assertEqual((state, builds), ({"prs": [1]}, "{}\n"))
|
||||
self.assertIn("first", sh(self.repo, "log", "-1", "--format=%s", head))
|
||||
|
||||
def test_a_run_that_pushed_first_is_kept(self):
|
||||
ns.update_state(lambda st, b: ({"prs": [1]}, b, "one"), "t", cwd=str(self.repo))
|
||||
other = Path(self.tmp.name, "other")
|
||||
subprocess.run(["git", "init", "-q", str(other)], check=True)
|
||||
sh(other, "remote", "add", "origin", str(self.origin))
|
||||
seen = []
|
||||
|
||||
def add_two(st, b):
|
||||
seen.append(list(st.get("prs", [])))
|
||||
if len(seen) == 1: # meanwhile another run saves first
|
||||
ns.update_state(lambda s2, b2: ({"prs": s2["prs"] + [3]}, b2, "other"), "t", cwd=str(other))
|
||||
return {"prs": st["prs"] + [2]}, b, "two"
|
||||
final = ns.update_state(add_two, "t", cwd=str(self.repo))
|
||||
self.assertEqual(seen, [[1], [1, 3]])
|
||||
self.assertEqual(final["prs"], [1, 3, 2])
|
||||
self.assertEqual(ns.load_state(str(self.repo))[0]["prs"], [1, 3, 2])
|
||||
|
||||
def test_builds_today_lists_the_days_branches(self):
|
||||
sh(self.repo, "commit", "-q", "--allow-empty", "-m", "x", env={
|
||||
"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t", "GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t"})
|
||||
head = sh(self.repo, "rev-parse", "HEAD")
|
||||
for name in ("nightly/build-2026-10-28-1", "nightly/build-2026-10-28-2", "nightly/build-2026-10-27-1"):
|
||||
self.assertTrue(ns.push(head, name, "t", cwd=str(self.repo)))
|
||||
self.assertEqual(sorted(ns.builds_today("2026-10-28", cwd=str(self.repo))),
|
||||
["nightly/build-2026-10-28-1", "nightly/build-2026-10-28-2"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -145,6 +145,13 @@ class ParityRunnerTests(unittest.TestCase):
|
||||
with mock.patch.object(parity.sys, "platform", "darwin"):
|
||||
self.assertEqual(parity.platform_skips(config), {"options": "libm"})
|
||||
|
||||
def test_a_hosts_excludes_are_skipped_when_it_runs_parity_itself(self):
|
||||
config = {"hosts": {"playhorizon": {"exclude": {"remote_fireworks": "starved"}}, "macmini": {"exclude": {}}}}
|
||||
with mock.patch.object(parity.sys, "platform", "linux"):
|
||||
self.assertEqual(parity.platform_skips(config, "playhorizon"), {"remote_fireworks": "starved"})
|
||||
self.assertEqual(parity.platform_skips(config, "macmini"), {})
|
||||
self.assertEqual(parity.platform_skips(config, "elsewhere"), {})
|
||||
|
||||
def test_named_only_harnesses_are_listed_from_the_host_config(self):
|
||||
self.assertEqual(parity.named_only({"named_only": {"lan_integration": "slow"}}), {"lan_integration": "slow"})
|
||||
self.assertEqual(parity.named_only({}), {})
|
||||
|
||||
@@ -12,7 +12,7 @@ NOW = dt.datetime(2026, 10, 15, 12, 0, tzinfo=dt.timezone.utc)
|
||||
def pr(number, title="Fix a thing", labels=(), paths=("crates/horizon-client/src/game.rs",), issues=(), author="ludovic111",
|
||||
merged=dt.timedelta(hours=9)):
|
||||
return {"number": number, "title": title, "labels": list(labels), "paths": list(paths), "issues": list(issues),
|
||||
"author": author, "url": f"https://github.com/ludovic111/horizon/pull/{number}", "merged_at": NOW - merged}
|
||||
"author": author, "url": f"https://github.com/horizon-rust/horizon/pull/{number}", "merged_at": NOW - merged}
|
||||
|
||||
|
||||
class ReleaseTrainTests(unittest.TestCase):
|
||||
@@ -231,7 +231,7 @@ class ReleaseTrainTests(unittest.TestCase):
|
||||
# GitHub's latest is a game release: whoever lands on it is sent to the launcher first (#1647).
|
||||
_, body = train.notes("game", "v0.2.50", [pr(1)], ["- Sound cuts out after an hour."])
|
||||
self.assertTrue(body.startswith('<h3>Want to play? Download the <a href="https://playhorizon.dev">Horizon launcher'))
|
||||
self.assertIn('href="https://github.com/ludovic111/horizon/releases?q=launcher&expanded=true"', body)
|
||||
self.assertIn('href="https://github.com/horizon-rust/horizon/releases?q=launcher&expanded=true"', body)
|
||||
self.assertNotIn("\n", train.PLAYERS, "one line: one HTML block, which ends at the blank line after it")
|
||||
self.assertEqual(body.count("playhorizon.dev"), 1, "said once, at the top")
|
||||
_, body = train.notes("game", "v0.2.51", [], [])
|
||||
|
||||
@@ -26,7 +26,7 @@ class RemoteMiningTests(unittest.TestCase):
|
||||
struct Hit { pos: [i32; 3], face: u8 }
|
||||
struct Mining { pos: [i32; 3], progress: f32, ticks: u32 }
|
||||
#[derive(Default)]
|
||||
struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)> }
|
||||
struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)>, destroying_item: String }
|
||||
struct Ground { on_ground: bool }
|
||||
struct Player { ground: Ground }
|
||||
#[derive(Clone)]
|
||||
@@ -70,6 +70,8 @@ struct Game {
|
||||
hit: Hit, sequence: i32, packets: Vec<play::PlayerAction>,
|
||||
}
|
||||
impl Game {
|
||||
fn main_hand_key(&self) -> String { String::new() }
|
||||
fn reset_attack_strength(&mut self) {}
|
||||
fn new(hardness: f32, speed: f32, creative: bool) -> Self {
|
||||
Self {
|
||||
remote: Some(Remote::default()), mining: None, creative,
|
||||
|
||||
@@ -35,8 +35,8 @@ impl End { fn remote_eye_motion(&mut self, _id: u32, _v: [f64; 3]) {} }
|
||||
#[derive(Default)]
|
||||
struct Game {
|
||||
mobs: Vec<Entity>, dropped: Vec<Entity>, falling: Vec<Entity>, tnts: Vec<Entity>,
|
||||
creatures: Creatures, dragon_fireballs: Vec<Entity>, rockets: Vec<Entity>,
|
||||
remote: Option<Remote>,
|
||||
creatures: Creatures, dragon_fireballs: Vec<Entity>, tridents: Vec<Entity>,
|
||||
rockets: Vec<Entity>, remote: Option<Remote>,
|
||||
potions: Potions, end: End,
|
||||
}
|
||||
impl Game {
|
||||
|
||||
@@ -147,9 +147,9 @@ class Render(unittest.TestCase):
|
||||
self.assertIn("## Recently shipped", text)
|
||||
self.assertNotIn("## Later", text)
|
||||
self.assertIn("- **Fast**: Faster.", text)
|
||||
self.assertIn("Multiply, not divide ([#10](https://github.com/ludovic111/horizon/issues/10)).", text)
|
||||
self.assertIn("Multiply, not divide ([#10](https://github.com/horizon-rust/horizon/issues/10)).", text)
|
||||
# A link the technical text already gives isn't repeated; the others are listed after it.
|
||||
self.assertIn("More: [#12](https://github.com/ludovic111/horizon/issues/12)", text)
|
||||
self.assertIn("More: [#12](https://github.com/horizon-rust/horizon/issues/12)", text)
|
||||
self.assertIn("- **Old** (v0.2.1): Done.", text)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
import unittest
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from tools.ci import nightly_set as ns
|
||||
from tools.ci import triage_command as tc
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
NOW = datetime(2026, 10, 28, 12, tzinfo=timezone.utc)
|
||||
URL = "https://github.com/horizon-rust/horizon/issues/5#issuecomment-1"
|
||||
LIST = ns.read_reviewers("kacpherek\nrdbtCVS\n")
|
||||
|
||||
|
||||
def thread(state="open", user="dev", labels=("bug",), pr=False, merged=False, locked=False):
|
||||
t = {"state": state, "user": {"login": user}, "labels": [{"name": n} for n in labels], "locked": locked}
|
||||
if pr:
|
||||
t["pull_request"] = {"merged_at": "2026-10-27T00:00:00Z" if merged else None}
|
||||
return t
|
||||
|
||||
|
||||
class Fake:
|
||||
def __init__(self, threads=None, labels=("bug", "good first issue", "release-now", "skip-release"), past=()):
|
||||
self.threads = {5: thread()} if threads is None else threads
|
||||
self.labels, self.past, self.calls = list(labels), list(past), []
|
||||
|
||||
def issue(self, n):
|
||||
return self.threads.get(n)
|
||||
|
||||
def label(self, name):
|
||||
return next((l for l in self.labels if l.lower() == name.lower()), None)
|
||||
|
||||
def add_labels(self, n, names):
|
||||
self.calls.append(("add", n, names))
|
||||
|
||||
def remove_label(self, n, name):
|
||||
self.calls.append(("remove", n, name))
|
||||
|
||||
def close(self, n, reason):
|
||||
self.calls.append(("close", n, reason))
|
||||
|
||||
def reopen(self, n):
|
||||
self.calls.append(("reopen", n))
|
||||
|
||||
def comment(self, n, text):
|
||||
self.calls.append(("comment", n, text))
|
||||
|
||||
def recent_comments(self, since):
|
||||
return self.past
|
||||
|
||||
|
||||
def do(text, api=None, login="kacpherek", reviewers=LIST, n=5):
|
||||
api = api or Fake()
|
||||
return tc.run(api, tc.parse(text), login, n, URL, reviewers, NOW), api
|
||||
|
||||
|
||||
class ParseTests(unittest.TestCase):
|
||||
def test_commands_and_case(self):
|
||||
self.assertEqual(tc.parse("/close"), tc.Command("close", "completed"))
|
||||
self.assertEqual(tc.parse(" /CLOSE Not Planned "), tc.Command("close", "not_planned"))
|
||||
self.assertEqual(tc.parse("/close completed"), tc.Command("close", "completed"))
|
||||
self.assertEqual(tc.parse("/close duplicate of #123"), tc.Command("close", "duplicate", 123))
|
||||
self.assertEqual(tc.parse("/Close duplicate of 7"), tc.Command("close", "duplicate", 7))
|
||||
self.assertEqual(tc.parse("/reopen"), tc.Command("reopen"))
|
||||
self.assertEqual(tc.parse("/label bug, good first issue ,bug"), tc.Command("label", labels=("bug", "good first issue")))
|
||||
self.assertEqual(tc.parse("/unlabel bug"), tc.Command("unlabel", labels=("bug",)))
|
||||
|
||||
def test_first_line_only(self):
|
||||
self.assertEqual(tc.parse("/close\n/label release-now"), tc.Command("close", "completed"))
|
||||
self.assertIsNone(tc.parse("thanks\n/close"))
|
||||
self.assertEqual(tc.parse("\n\n/reopen\nwhy"), tc.Command("reopen"))
|
||||
|
||||
def test_not_commands(self):
|
||||
for text in ("", "hello", "/nightly 5", "/closed", "/labels bug", "/closer", "close", "/unlabeled x"):
|
||||
self.assertIsNone(tc.parse(text), text)
|
||||
|
||||
def test_malformed(self):
|
||||
for text in ("/close maybe", "/close duplicate of", "/reopen now", "/label", "/label ,", "/unlabel a, b",
|
||||
"/label " + ",".join(str(i) for i in range(11))):
|
||||
with self.assertRaises(tc.Refused, msg=text):
|
||||
tc.parse(text)
|
||||
|
||||
def test_quoting_is_safe(self):
|
||||
with self.assertRaises(tc.Refused) as e:
|
||||
tc.parse("/close @ludovic111 [x](http://evil)")
|
||||
self.assertNotIn("@", str(e.exception))
|
||||
self.assertNotIn("](", str(e.exception))
|
||||
|
||||
|
||||
class AllowTests(unittest.TestCase):
|
||||
def test_listed_and_ludovic(self):
|
||||
do("/close", login="RDBTcvs")
|
||||
do("/close", login="ludovic111")
|
||||
|
||||
def test_stranger_refused(self):
|
||||
with self.assertRaisesRegex(tc.Refused, "Only Ludovic"):
|
||||
do("/close", login="someone")
|
||||
|
||||
def test_paused(self):
|
||||
paused = ns.read_reviewers("kacpherek\npaused\n")
|
||||
with self.assertRaisesRegex(tc.Refused, "paused"):
|
||||
do("/close", reviewers=paused)
|
||||
do("/close", reviewers=paused, login="ludovic111")
|
||||
|
||||
def test_the_repos_list_is_the_nightlys(self):
|
||||
self.assertEqual(ns.REVIEWERS, ".github/trusted-reviewers.txt")
|
||||
listed = ns.read_reviewers((ROOT / ns.REVIEWERS).read_text())
|
||||
self.assertEqual(listed.logins, {"kacpherek", "rdbtcvs", "online5277"})
|
||||
self.assertFalse(listed.paused)
|
||||
|
||||
|
||||
class ActionTests(unittest.TestCase):
|
||||
def test_close_issue(self):
|
||||
text, api = do("/close not planned")
|
||||
self.assertEqual(api.calls, [("close", 5, "not_planned")])
|
||||
self.assertIn("on behalf of @kacpherek", text)
|
||||
self.assertIn(URL, text)
|
||||
self.assertTrue(text.startswith("🤖 Triage: "))
|
||||
|
||||
def test_close_pr_has_no_reason(self):
|
||||
api = Fake({5: thread(pr=True)})
|
||||
text, _ = do("/close", api)
|
||||
self.assertEqual(api.calls, [("close", 5, None)])
|
||||
self.assertIn("without merging", text)
|
||||
|
||||
def test_duplicate(self):
|
||||
api = Fake({5: thread(), 9: thread()})
|
||||
text, _ = do("/close duplicate of #9", api)
|
||||
self.assertEqual(api.calls, [("comment", 5, "Duplicate of #9"), ("close", 5, "duplicate")])
|
||||
self.assertIn("#9", text)
|
||||
|
||||
def test_duplicate_of_missing_or_itself(self):
|
||||
with self.assertRaisesRegex(tc.Refused, "no #9"):
|
||||
do("/close duplicate of #9")
|
||||
with self.assertRaisesRegex(tc.Refused, "itself"):
|
||||
do("/close duplicate of #5")
|
||||
|
||||
def test_reopen(self):
|
||||
_, api = do("/reopen", Fake({5: thread("closed")}))
|
||||
self.assertEqual(api.calls, [("reopen", 5)])
|
||||
with self.assertRaisesRegex(tc.Refused, "already open"):
|
||||
do("/reopen")
|
||||
with self.assertRaisesRegex(tc.Refused, "already closed"):
|
||||
do("/close", Fake({5: thread("closed")}))
|
||||
|
||||
def test_label_uses_the_real_name_and_skips_present(self):
|
||||
_, api = do("/label Good First Issue, BUG")
|
||||
self.assertEqual(api.calls, [("add", 5, ["good first issue"])])
|
||||
with self.assertRaisesRegex(tc.Refused, "already has"):
|
||||
do("/label bug")
|
||||
|
||||
def test_label_must_exist(self):
|
||||
with self.assertRaisesRegex(tc.Refused, "no label"):
|
||||
do("/label nonsense")
|
||||
|
||||
def test_unlabel(self):
|
||||
_, api = do("/unlabel BUG")
|
||||
self.assertEqual(api.calls, [("remove", 5, "bug")])
|
||||
with self.assertRaisesRegex(tc.Refused, "doesn't have"):
|
||||
do("/unlabel good first issue")
|
||||
|
||||
|
||||
class RefusalTests(unittest.TestCase):
|
||||
def test_release_and_parity_labels(self):
|
||||
for name in ("release-now", "Release-Blocker", "skip-release", "full-parity", "prerelease"):
|
||||
for verb in ("/label", "/unlabel"):
|
||||
with self.assertRaisesRegex(tc.Refused, "release or parity", msg=name):
|
||||
do(f"{verb} {name}", Fake(labels=(name,)))
|
||||
with self.assertRaises(tc.Refused):
|
||||
do("/label bug, release-now")
|
||||
|
||||
def test_ludovics_threads(self):
|
||||
for text in ("/close", "/label bug", "/unlabel bug", "/reopen"):
|
||||
for t in (thread(user="ludovic111", state="closed" if text == "/reopen" else "open"),
|
||||
thread(user="Ludovic111", pr=True)):
|
||||
with self.assertRaisesRegex(tc.Refused, "Ludovic's"):
|
||||
do(text, Fake({5: t}))
|
||||
|
||||
def test_merged_pr(self):
|
||||
for text in ("/close", "/reopen", "/label bug", "/unlabel bug"):
|
||||
with self.assertRaisesRegex(tc.Refused, "merged"):
|
||||
do(text, Fake({5: thread("closed", pr=True, merged=True)}))
|
||||
|
||||
def test_locked(self):
|
||||
for text in ("/close", "/label good first issue", "/unlabel bug"):
|
||||
with self.assertRaisesRegex(tc.Refused, "locked"):
|
||||
do(text, Fake({5: thread(locked=True)}))
|
||||
|
||||
def test_missing_thread(self):
|
||||
with self.assertRaisesRegex(tc.Refused, "no such"):
|
||||
do("/close", Fake({}))
|
||||
|
||||
def test_nothing_written_on_refusal(self):
|
||||
api = Fake({5: thread(user="ludovic111")})
|
||||
with self.assertRaises(tc.Refused):
|
||||
do("/close", api)
|
||||
self.assertEqual(api.calls, [])
|
||||
|
||||
|
||||
def past(login, n, who="github-actions[bot]"):
|
||||
return [{"user": who, "body": f"🤖 Triage: closed as completed, on behalf of @{login} ([their comment](u))."}
|
||||
for _ in range(n)]
|
||||
|
||||
|
||||
class LimitTests(unittest.TestCase):
|
||||
def test_sixty_a_day(self):
|
||||
with self.assertRaisesRegex(tc.Refused, "60"):
|
||||
do("/close", Fake(past=past("kacpherek", 60)))
|
||||
do("/close", Fake(past=past("kacpherek", 59)))
|
||||
|
||||
def test_other_reviewers_and_forged_comments_dont_count(self):
|
||||
do("/close", Fake(past=past("rdbtcvs", 80)))
|
||||
do("/close", Fake(past=past("kacpherek", 80, who="someone")))
|
||||
|
||||
def test_refusals_dont_count(self):
|
||||
refusals = [{"user": "github-actions[bot]", "body": "🤖 Triage: refused, nope (asked by @kacpherek)"}] * 70
|
||||
do("/close", Fake(past=refusals))
|
||||
|
||||
def test_counts_case_insensitively(self):
|
||||
with self.assertRaises(tc.Refused):
|
||||
do("/close", Fake(past=past("kacpherek", 60)), login="Kacpherek")
|
||||
|
||||
def test_ludovic_is_unlimited(self):
|
||||
do("/close", Fake(past=past("ludovic111", 100)), login="ludovic111")
|
||||
|
||||
|
||||
class WorkflowTests(unittest.TestCase):
|
||||
def test_workflow_is_safe(self):
|
||||
text = (ROOT / ".github/workflows/triage-command.yml").read_text()
|
||||
run_lines = [l for l in text.splitlines() if l.strip().startswith("run:")]
|
||||
self.assertEqual(run_lines, [" run: python3 tools/ci/triage_command.py command"])
|
||||
self.assertIn("persist-credentials: false", text)
|
||||
self.assertNotIn("pull_request_target", text)
|
||||
for perm in ("issues: write", "pull-requests: write", "contents: read"):
|
||||
self.assertIn(perm, text)
|
||||
self.assertNotIn("contents: write", text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user