diff --git a/.github/workflows/community-ci.yml b/.github/workflows/community-ci.yml index 503e34f721..c9b7e720e5 100644 --- a/.github/workflows/community-ci.yml +++ b/.github/workflows/community-ci.yml @@ -347,7 +347,11 @@ jobs: fi deadline=$((SECONDS + 18000)) while [ "$SECONDS" -lt "$deadline" ]; do - run="$(gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$PIPELINE_RUN_ID")" + if ! run="$(gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$PIPELINE_RUN_ID")"; then + echo "::warning::Community CI observation is unavailable; the existing run is still authoritative." + sleep 30 + continue + fi if [ "$(jq -r '.status' <<< "$run")" = completed ]; then # GitHub may return a placeholder title while a newly dispatched # run is initializing. Verify identity before publishing its result. @@ -589,9 +593,9 @@ jobs: name: Community CPU / Unit / C++ and Python needs: authorize runs-on: ubuntu-24.04 - timeout-minutes: 65 + timeout-minutes: 120 env: - CPP_BUILD_TIMEOUT: 45m + CPP_BUILD_TIMEOUT: 60m permissions: contents: read steps: diff --git a/tools/e2e_report.py b/tools/e2e_report.py index 5e1bb9820b..1b0ec030af 100644 --- a/tools/e2e_report.py +++ b/tools/e2e_report.py @@ -143,7 +143,9 @@ def classification_index(logits: Any) -> tuple[int, int | float] | None: def _escape(value: Any) -> str: - return html.escape(str(value), quote=True) + # Keep malformed Unicode in recorded text from breaking the HTML document. + text = str(value).encode("utf-8", errors="backslashreplace").decode("utf-8") + return html.escape(text, quote=True) def _json(value: Any) -> str: diff --git a/tools/tests/test_community_ci.py b/tools/tests/test_community_ci.py index 2d155a7a18..94884966e5 100644 --- a/tools/tests/test_community_ci.py +++ b/tools/tests/test_community_ci.py @@ -1367,6 +1367,72 @@ def test_only_complete_pipeline_publishes_stable_and_dev_results( assert int((tmp_path / "counter").read_text()) == (2 if queued_first else 1) +def test_publisher_keeps_waiting_through_a_failed_run_lookup(tmp_path): + """A transient API error while observing the run must not publish a failure.""" + fake = tmp_path / "gh" + fake.write_text( + "#!/usr/bin/env python3\nimport json,os,sys\nfrom pathlib import Path\n" + "if any(a.startswith('/repos/') and '/actions/runs/' in a for a in sys.argv):\n" + " counter=Path(os.environ['COUNTER'])\n" + " count=int(counter.read_text())+1 if counter.exists() else 1\n" + " counter.write_text(str(count))\n" + " if count==1:\n" + " print('gh: Server Error (HTTP 502)', file=sys.stderr); sys.exit(1)\n" + " print(os.environ['RUN'])\n" + "else: Path(os.environ['CALLS']).write_text('\\n'.join(sys.argv[1:]))\n" + ) + fake.chmod(0o755) + sleep = tmp_path / "sleep" + sleep.write_text("#!/bin/sh\nexit 0\n") + sleep.chmod(0o755) + head, merge = "a" * 40, "b" * 40 + result = subprocess.run( + [ + "bash", + "-c", + _workflow_step_script( + "community-ci.yml", "dispatch", "Publish the complete workflow conclusion" + ), + ], + env={ + **os.environ, + "PATH": f"{tmp_path}:{os.environ['PATH']}", + "PIPELINE_RUN_ID": "42", + "CI_BRANCH": "main", + "LANE": "stable", + "PR_NUMBER": "17", + "HEAD_SHA": head, + "STATUS_CONTEXT": "Stable Community CI", + "SOURCE_SNAPSHOT": json.dumps({"merge_sha": merge}), + "GITHUB_SERVER_URL": "https://github.com", + "GITHUB_REPOSITORY": "example/source", + "GITHUB_OUTPUT": str(tmp_path / "output"), + "CALLS": str(tmp_path / "calls"), + "COUNTER": str(tmp_path / "counter"), + "RUN": json.dumps( + { + "path": ".github/workflows/community-ci.yml", + "event": "workflow_dispatch", + "head_branch": "main", + "display_title": f"Stable Community CI · PR #17 · head {head} · merge {merge}", + "status": "completed", + "conclusion": "success", + } + ), + }, + capture_output=True, + text=True, + ) + + assert result.returncode == 0, result.stderr + assert "observation is unavailable" in result.stdout + assert int((tmp_path / "counter").read_text()) == 2 + calls = (tmp_path / "calls").read_text().splitlines() + assert "state=success" in calls + assert "context=Stable Community CI" in calls + assert (tmp_path / "output").read_text() == "reported=true\n" + + @pytest.mark.parametrize("ready_after", [1, 2, 7]) def test_pr_trigger_waits_for_github_merge_generation_with_a_bounded_retry(tmp_path, ready_after): head, base, merge, tree = (value * 40 for value in "abcd") diff --git a/tools/tests/test_e2e_evidence.py b/tools/tests/test_e2e_evidence.py index 57cf23ed79..4a3f2cca3b 100644 --- a/tools/tests/test_e2e_evidence.py +++ b/tools/tests/test_e2e_evidence.py @@ -124,6 +124,31 @@ def test_html_escapes_observations_and_never_executes_active_artifacts(tmp_path: assert "fetch(" not in report +def test_report_writes_lone_surrogates_as_visible_escapes(tmp_path: Path) -> None: + from tools.e2e_report import main as render_main + + case = tmp_path / "artifacts" / "example-case" + case.mkdir(parents=True) + text = "caf\u00e9 \u4e2d\u6587 \U0001f600 lone surrogate: \ud800" + evidence = { + "schema_version": 1, + "family": "example", + "case": "example-case", + "status": "passed", + "native": {"text": text}, + } + # json.dumps escapes the surrogate; json.loads in the report restores it. + (case / "evidence.json").write_text(json.dumps(evidence), encoding="utf-8") + output = tmp_path / "report.html" + + assert render_main([str(tmp_path / "artifacts"), "-o", str(output)]) == 0 + + report = output.read_text(encoding="utf-8") + assert "caf\u00e9 \u4e2d\u6587 \U0001f600" in report + assert "lone surrogate: \\ud800" in report + assert "\ud800" not in report + + def test_json_bound_preserves_failed_check_before_passed_details( tmp_path: Path, monkeypatch ) -> None: