"""The do-epic-e2e command: runs do-epic's commands that need no tmux session and no worker against a sandbox epic on a real Jira site (docs/decisions.md → `do-epic: drives one Jira epic …`).""" import pathlib import sys import typing from failure import Failure from do_epic.e2e import sandbox, scenario, settings HELP = f"""usage: do-epic-e2e Makes an epic in the Jira sandbox, with issues and sub-tasks, drives do-epic against it and deletes it, whatever the outcome. 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, 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 found = settings.read(env) if isinstance(found, Failure): print(f"do-epic-e2e cannot start: {found.reason}", file=sys.stderr) return 1 report = scenario.Report() left: sandbox.Leftover | None = None try: 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 = run(found, key, launcher, env) except sandbox.Leftover as failure: left = failure # The checks are printed even where the epic could not be deleted. for line in report.held: print(f"ok {line}") for line in report.broke: print(f"FAIL {line}") print(f"{len(report.held)} held, {len(report.broke)} broke") if left: print(f"do-epic-e2e: {left}", file=sys.stderr) return 1 if report.broke or left else 0