Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
+7 -3
View File
@@ -13,8 +13,12 @@ It reads three environment variables and fails, naming each that is missing:
{chr(10).join(f' {name}: {meaning}' for name, meaning in settings.MEANING.items())}
It prints a line per check, and exits 0 only where every check held."""
EpicMade = typing.Callable[[settings.Sandbox, str], typing.ContextManager[str | Failure]]
Run = typing.Callable[[settings.Sandbox, str, pathlib.Path, typing.Mapping[str, str]], scenario.Report]
def main(argv: list[str], env: typing.Mapping[str, str], launcher: pathlib.Path) -> int:
def main(argv: list[str], env: typing.Mapping[str, str], launcher: pathlib.Path, epic_made: EpicMade, run: Run) -> int:
"""Runs do-epic-e2e: epic_made makes the sandbox epic, as sandbox.epic_made does, and run drives do-epic against it, as scenario.run does."""
if argv:
print(HELP, file=sys.stdout if argv in (["-h"], ["--help"]) else sys.stderr)
return 0 if argv in (["-h"], ["--help"]) else 1
@@ -25,12 +29,12 @@ def main(argv: list[str], env: typing.Mapping[str, str], launcher: pathlib.Path)
report = scenario.Report()
left: sandbox.Leftover | None = None
try:
with sandbox.epic_made(found, "do-epic e2e sandbox epic") as key:
with epic_made(found, "do-epic e2e sandbox epic") as key:
if isinstance(key, Failure):
print(f"do-epic-e2e: {key.reason}", file=sys.stderr)
return 1
print(f"Sandbox epic {key} in {found.jira_url}")
report = scenario.run(found, key, launcher, env)
report = run(found, key, launcher, env)
except sandbox.Leftover as failure:
left = failure
# The checks are printed even where the epic could not be deleted.
+9 -6
View File
@@ -1,6 +1,5 @@
import contextlib
import io
from unittest import mock
import pathlib
import sys
import tempfile
@@ -18,7 +17,7 @@ class MainTest(unittest.TestCase):
def run_main(self, argv: list[str]) -> tuple[int, str, str]:
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.main(argv, {}, pathlib.Path("do-epic"))
code = main.main(argv, {}, pathlib.Path("do-epic"), sandbox.epic_made, scenario.run)
return code, out.getvalue(), err.getvalue()
def test_fails_naming_each_missing_setting_before_it_touches_anything(self) -> None:
@@ -56,10 +55,14 @@ class ReportedTest(unittest.TestCase):
out, err = io.StringIO(), io.StringIO()
report = report or scenario.Report(["a check held"], ["a check broke"])
with mock.patch.object(sandbox, "epic_made", epic_made), mock.patch.object(scenario, "run", return_value=report) as ran:
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.main([], self.env, pathlib.Path("do-epic"))
self.ran_with = ran.call_args.args if ran.called else None
self.ran_with = None
def ran(*args: object) -> scenario.Report:
self.ran_with = args
return report
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main.main([], self.env, pathlib.Path("do-epic"), epic_made, ran)
return code, out.getvalue(), err.getvalue()
def test_prints_each_check_and_fails_where_one_broke(self) -> None: