121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
"""Static and armed-transition regressions for the handoff CLI."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from testing.tests.test_hermes_handoff_acceptance import (
|
|
HEALTHY_CLUSTER,
|
|
REVIEWED,
|
|
VALID_ARGS,
|
|
acceptance,
|
|
harness_run,
|
|
model,
|
|
policy,
|
|
read_report,
|
|
run_cli,
|
|
)
|
|
|
|
|
|
def test_an_empty_catalog_fails_before_any_subprocess(monkeypatch, tmp_path) -> None:
|
|
output = tmp_path / "report.json"
|
|
monkeypatch.setattr(harness_run, "build_catalog", lambda _targets: [])
|
|
monkeypatch.setattr(acceptance, "build_catalog", lambda _targets: [])
|
|
monkeypatch.setattr(harness_run, "vantage_problems", lambda _records: [])
|
|
|
|
status, _ = run_cli(
|
|
monkeypatch, ["--output", str(output), "--json-only"], HEALTHY_CLUSTER
|
|
)
|
|
|
|
assert status == acceptance.EXIT_NO_GO
|
|
assert read_report(output)["decision"] == model.NO_GO
|
|
|
|
|
|
def test_armed_success_path_replaces_placeholders_only_after_a_go(monkeypatch) -> None:
|
|
base = model.CheckSpec(
|
|
id="release.pass", title="pass", group="release", rule="allowed"
|
|
)
|
|
placeholder = model.CheckSpec(
|
|
id="ephemeral.cleanup-verified",
|
|
title="pending",
|
|
group="ephemeral",
|
|
rule="not_armed",
|
|
mandatory=False,
|
|
scope=model.EPHEMERAL,
|
|
)
|
|
report = model.Report(
|
|
mode=policy.ARMED,
|
|
started_at="2026-08-17T00:00:00Z",
|
|
results=[
|
|
model.CheckResult(base, model.PASS),
|
|
model.CheckResult(placeholder, model.NOT_RUN),
|
|
],
|
|
)
|
|
armed_spec = model.CheckSpec(
|
|
id="ephemeral.cleanup-verified",
|
|
title="clean",
|
|
group="ephemeral",
|
|
rule="armed",
|
|
scope=model.EPHEMERAL,
|
|
)
|
|
armed = model.CheckResult(armed_spec, model.PASS)
|
|
monkeypatch.setattr(
|
|
acceptance, "resolve_vantages", lambda *_args: ({"operator": object()}, [])
|
|
)
|
|
monkeypatch.setattr(acceptance, "preflight", lambda *_args: None)
|
|
monkeypatch.setattr(acceptance, "build_report", lambda *_args: report)
|
|
monkeypatch.setattr(acceptance, "_armed_results", lambda *_args: [armed])
|
|
monkeypatch.setattr(acceptance, "emit", lambda *_args: [])
|
|
status = acceptance.main(
|
|
[
|
|
*VALID_ARGS,
|
|
"--arm-ephemeral-push",
|
|
"--confirm",
|
|
acceptance.CONFIRMATION,
|
|
"--ephemeral-token",
|
|
"acceptance-20260817a",
|
|
]
|
|
)
|
|
assert status == acceptance.EXIT_GO
|
|
assert (
|
|
next(
|
|
result
|
|
for result in report.results
|
|
if result.spec.id.startswith("ephemeral")
|
|
).status
|
|
== model.PASS
|
|
)
|
|
monkeypatch.setattr(acceptance, "emit", lambda *_args: ["screening-failure"])
|
|
assert (
|
|
acceptance.main(
|
|
[
|
|
*VALID_ARGS,
|
|
"--arm-ephemeral-push",
|
|
"--confirm",
|
|
acceptance.CONFIRMATION,
|
|
"--ephemeral-token",
|
|
"acceptance-20260817b",
|
|
]
|
|
)
|
|
== acceptance.EXIT_NO_GO
|
|
)
|
|
|
|
|
|
def test_armed_results_are_bound_to_operator_and_exact_reviewed_head(
|
|
monkeypatch,
|
|
) -> None:
|
|
arguments = acceptance.build_parser().parse_args(
|
|
[
|
|
*VALID_ARGS,
|
|
"--confirm",
|
|
acceptance.CONFIRMATION,
|
|
"--ephemeral-token",
|
|
"acceptance-20260817a",
|
|
]
|
|
)
|
|
calls = []
|
|
monkeypatch.setattr(acceptance, "preflight", lambda *args: calls.append(args))
|
|
monkeypatch.setattr(acceptance, "run_armed", lambda *args: [args])
|
|
operator = object()
|
|
result = acceptance._armed_results(arguments, object(), {"operator": operator})
|
|
assert calls[0][0].expected_head == REVIEWED
|
|
assert result[0][1] is operator
|