Просмотр исходного кода

test: align cli with benchmark report bundles

Problem: CLI integration tests still discovered root-level report files or traversed private backing bundles after reports moved to a published bundle symlink contract.

Risk: Tests now intentionally depend on the stable json_report/markdown_report stdout labels and the single public bundle symlink layout.
zhenyu.hu 2 недель назад
Родитель
Сommit
c8a0df3d20
1 измененных файлов с 46 добавлено и 11 удалено
  1. 46 11
      tests/test_benchmark_cli.py

+ 46 - 11
tests/test_benchmark_cli.py

@@ -101,6 +101,39 @@ class FailingTextStream(StringIO):
         super().flush()
 
 
+def _public_report_paths(output_dir: Path) -> tuple[Path, Path]:
+    published_entries = [
+        path for path in output_dir.iterdir() if not path.name.startswith(".")
+    ]
+    assert len(published_entries) == 1
+    published_bundle = published_entries[0]
+    assert published_bundle.is_symlink()
+    return (
+        published_bundle / "report.json",
+        published_bundle / "report.md",
+    )
+
+
+def _report_paths_from_stdout(
+    stdout: StringIO,
+    output_dir: Path,
+) -> tuple[Path, Path]:
+    report_paths: dict[str, Path] = {}
+    for line in stdout.getvalue().splitlines():
+        key, separator, value = line.partition("=")
+        if separator and key in {"json_report", "markdown_report"}:
+            assert key not in report_paths
+            report_paths[key] = Path(value)
+
+    assert set(report_paths) == {"json_report", "markdown_report"}
+    json_path = report_paths["json_report"]
+    markdown_path = report_paths["markdown_report"]
+    assert (json_path, markdown_path) == _public_report_paths(output_dir)
+    assert json_path.is_file()
+    assert markdown_path.is_file()
+    return json_path, markdown_path
+
+
 def _dependencies(
     cli,
     *,
@@ -139,6 +172,7 @@ def test_cli_overrides_json_and_repeatable_case_mode_replace_lists(tmp_path: Pat
         modes=["dual_agent", "chat_agent_tools"],
     )
     output_dir = tmp_path / "reports"
+    stdout = StringIO()
     runner_calls: list[dict[str, object]] = []
     dependencies = _dependencies(
         cli,
@@ -156,6 +190,7 @@ def test_cli_overrides_json_and_repeatable_case_mode_replace_lists(tmp_path: Pat
         ],
         api_key="env-key",
         runner_calls=runner_calls,
+        stdout=stdout,
     )
 
     exit_code = cli.run_cli(
@@ -194,8 +229,7 @@ def test_cli_overrides_json_and_repeatable_case_mode_replace_lists(tmp_path: Pat
         BenchmarkCaseId.SESSION_TERMINATE,
     ]
     assert config.modes == [BenchmarkMode.CHAT_AGENT_TOOLS]
-    assert len(list(output_dir.glob("*.json"))) == 1
-    assert len(list(output_dir.glob("*.md"))) == 1
+    _report_paths_from_stdout(stdout, output_dir)
 
 
 def test_mock_run_needs_no_api_key_and_exits_zero(tmp_path: Path):
@@ -225,8 +259,7 @@ def test_mock_run_needs_no_api_key_and_exits_zero(tmp_path: Path):
 
     assert exit_code == 0
     assert "attempted=1 passed=1 failed=0" in stdout.getvalue()
-    assert "json_report=" in stdout.getvalue()
-    assert "markdown_report=" in stdout.getvalue()
+    _report_paths_from_stdout(stdout, output_dir)
     assert stderr.getvalue() == ""
 
 
@@ -269,8 +302,9 @@ def test_partial_failed_run_exits_one_writes_redacted_reports(tmp_path: Path):
     assert "attempted=2 passed=1 failed=1" in stdout.getvalue()
     assert secret not in stdout.getvalue()
     assert stderr.getvalue() == ""
+    json_path, markdown_path = _report_paths_from_stdout(stdout, output_dir)
     report_text = "\n".join(
-        path.read_text() for path in sorted(output_dir.iterdir())
+        path.read_text() for path in (json_path, markdown_path)
     )
     assert secret not in report_text
     assert "[REDACTED]" in report_text
@@ -487,8 +521,9 @@ def test_summary_output_failure_after_report_write_exits_two_and_redacts_stderr(
     )
 
     assert exit_code == 2
-    assert any(output_dir.rglob("*.json"))
-    assert any(output_dir.rglob("*.md"))
+    json_path, markdown_path = _public_report_paths(output_dir)
+    assert json_path.is_file()
+    assert markdown_path.is_file()
     assert secret not in stderr.getvalue()
     assert "Bearer [REDACTED]" in stderr.getvalue()
 
@@ -519,8 +554,9 @@ def test_execution_error_stderr_failure_still_exits_two(tmp_path: Path):
     )
 
     assert exit_code == 2
-    assert any(output_dir.rglob("*.json"))
-    assert any(output_dir.rglob("*.md"))
+    json_path, markdown_path = _public_report_paths(output_dir)
+    assert json_path.is_file()
+    assert markdown_path.is_file()
     assert secret not in stderr.getvalue()
 
 
@@ -587,8 +623,7 @@ def test_runner_result_cardinality_mismatch_is_reported_and_exits_two(
     )
 
     assert exit_code == 2
-    json_path = next(output_dir.glob("*.json"))
-    markdown_path = next(output_dir.glob("*.md"))
+    json_path, markdown_path = _report_paths_from_stdout(stdout, output_dir)
     payload = json.loads(json_path.read_text())
     expected_error = (
         f"runner result count mismatch: expected 1, got {actual_count}"