test: cover easy missing branches in report/config/credentials/ssh/wait/job
Lint / pssa (push) Successful in 34s
Lint / python (push) Successful in 41s

This commit is contained in:
2026-05-14 23:23:55 +02:00
parent b2b31f4b6e
commit dc8449a0d7
6 changed files with 371 additions and 0 deletions
+104
View File
@@ -106,3 +106,107 @@ def test_report_job_unknown_id(tmp_path: Path) -> None:
)
assert result.exit_code == 1
assert "No JSONL log" in result.output
# ── helpers ────────────────────────────────────────────────────────────────
import ci_orchestrator.commands.report as report_module # noqa: E402
def test_read_events_oserror_returns_empty(tmp_path: Path) -> None:
p = tmp_path / "d" # directory: read_text raises OSError
p.mkdir()
assert report_module._read_events(p) == []
def test_read_events_skips_blank_invalid_and_non_dict(tmp_path: Path) -> None:
p = tmp_path / "x.jsonl"
p.write_text(
"\n" # blank
"{not json\n" # invalid JSON
"[1, 2]\n" # not a dict
'{"phase": "job", "status": "start", "ts": "t"}\n'
'{"phase": "job", "status": "success", "data": {"elapsedSec": 1.5, "error": "e"}}\n',
encoding="utf-8",
)
events = report_module._read_events(p)
assert len(events) == 2
assert events[1].elapsed_sec == 1
assert events[1].error == "e"
def test_format_hms_negative_returns_question_mark() -> None:
assert report_module._format_hms(-1) == "?"
def test_format_hms_with_hours() -> None:
assert report_module._format_hms(3725) == "1h02m05s"
assert report_module._format_hms(45) == "0m45s"
def test_summarise_in_progress_when_no_terminal_event() -> None:
events = [
report_module._Event(
phase="job", status="start", ts="t", elapsed_sec=None, error=None,
raw={"jobId": "jx"},
)
]
row = report_module._summarise(events, "default")
assert row.status == "in-progress"
assert row.job_id == "jx"
def test_summarise_uses_default_id_when_jobid_missing() -> None:
events = [
report_module._Event(
phase="job", status="start", ts="t", elapsed_sec=None, error=None,
raw={},
)
]
row = report_module._summarise(events, "fallback")
assert row.job_id == "fallback"
def test_summarise_truncates_long_error() -> None:
long_err = "x" * 100
events = [
report_module._Event(
phase="job", status="failure", ts="t", elapsed_sec=10, error=long_err,
raw={"jobId": "j"},
)
]
row = report_module._summarise(events, "d")
assert row.status == "FAILED"
assert row.error.endswith("...")
assert len(row.error) == 60
def test_report_job_detail_json_emits_raw_events(tmp_path: Path) -> None:
_write_jsonl(tmp_path / "r1" / "invoke-ci.jsonl", _success_events("r1"))
result = CliRunner().invoke(
cli, ["report", "job", "--log-dir", str(tmp_path), "--job-id", "r1", "--json"]
)
assert result.exit_code == 0
payload = json.loads(result.output.strip())
assert isinstance(payload, list)
assert payload[0]["phase"] == "job"
def test_report_job_detail_empty_jsonl(tmp_path: Path) -> None:
p = tmp_path / "empty" / "invoke-ci.jsonl"
p.parent.mkdir(parents=True)
p.write_text("")
result = CliRunner().invoke(
cli, ["report", "job", "--log-dir", str(tmp_path), "--job-id", "empty"]
)
assert result.exit_code == 1
assert "empty or unreadable" in result.output
def test_report_job_failed_filter_no_results(tmp_path: Path) -> None:
_write_jsonl(tmp_path / "r1" / "invoke-ci.jsonl", _success_events("r1"))
result = CliRunner().invoke(
cli, ["report", "job", "--log-dir", str(tmp_path), "--failed"]
)
assert result.exit_code == 0
assert "No matching jobs" in result.output