"""Final report: missing required work fails, and delivery is never presented as done.""" import unittest from platform_ci.reporting import render_report from tests.support import event, example_configuration, plan_for RESULTS = ("success", "failure", "skipped", "cancelled") class ReportTest(unittest.TestCase): """The report compares expected work with actual results.""" def test_unrequested_verification_is_reported_honestly(self) -> None: """An unselected feature push expects both jobs to skip, says nothing passed, and fails if either ran anyway.""" plan = plan_for(example_configuration("maven.ci.yaml"), event("push", "refs/heads/feature-x")) text, passed = render_report(plan, "skipped", "skipped") self.assertTrue(passed) self.assertIn("NOT REQUESTED by configuration", text) self.assertIn("NOT VERIFIED", text) self.assertNotIn("Result: passed", text) for verify in RESULTS: for secrets in RESULTS: if (verify, secrets) != ("skipped", "skipped"): with self.subTest(verify=verify, secrets=secrets): self.assertFalse(render_report(plan, verify, secrets)[1]) def test_required_verification_and_secret_scan_must_both_succeed(self) -> None: """Only two successes pass; any other combination fails for every requested event.""" for context in (event(), event("push", "refs/heads/staging"), event("push", "refs/tags/v1.0.0")): plan = plan_for(example_configuration("maven.ci.yaml"), context) for verify in RESULTS: for secrets in RESULTS: with self.subTest(ref=context.ref, verify=verify, secrets=secrets): self.assertEqual(render_report(plan, verify, secrets)[1], (verify, secrets) == ("success", "success")) def test_missing_security_success_names_the_secret_scan(self) -> None: """A skipped or failed scan next to a passing build fails and says which result was missing.""" plan = plan_for(example_configuration("maven.ci.yaml"), event()) for secrets in ("skipped", "failure", "cancelled", ""): text, passed = render_report(plan, "success", secrets) self.assertFalse(passed) self.assertIn("FAILED (secret scan did not succeed)", text) self.assertIn(f"Secret scan result: {secrets}", text) self.assertIn("FAILED (verification did not succeed)", render_report(plan, "failure", "success")[0]) def test_passing_report_states_both_results(self) -> None: """A requested, fully successful run says so and still claims no delivery.""" text, passed = render_report(plan_for(example_configuration("maven.ci.yaml"), event()), "success", "success") self.assertTrue(passed) self.assertIn("Secret scan result: success", text) self.assertIn("Result: passed", text) def test_delivery_is_reported_as_not_performed_by_the_workflow(self) -> None: """An eligible release push names its channel but claims no signing, publication or deployment.""" plan = plan_for(example_configuration("maven.ci.yaml"), event("push", "refs/heads/develop")) text, passed = render_report(plan, "success", "success") self.assertTrue(passed) self.assertIn("Delivery: NOT PERFORMED BY THIS WORKFLOW. Channels eligible by configuration: snapshot.", text) self.assertNotIn("Published", text) self.assertNotIn("Deployed", text)