Repository navigation
Keep canary timeout diagnostics and incomplete failures visible #9001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89185a8
fix(canary): retain timeout diagnostics and keep incomplete checks fa…
loopx-agent d479f03
Merge remote-tracking branch 'origin/main' into codex/canary-timeout-…
loopx-agent 3ef1f37
fix(canary): require a completed ratchet failure for advisory
loopx-agent f7d7fa4
Merge commit '09d0fa13594235fcd3dc13c5bd63abaf35a2d9aa' into codex/ca…
loopx-agent 5a593ba
Merge commit '7bc56e74687a93ff4d5bcccb532c454bf2379c29' into codex/ca…
loopx-agent b5304e1
fix(canary): require a complete maintainability report
loopx-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from loopx.canary.planner import REPO_ROOT | ||
| from loopx.canary.premerge import _gate_status, _run_gate_check, downgrade_inherited_baseline_failures | ||
| from loopx.canary.runner import run_canary_smoke_check | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name != "posix", reason="POSIX subprocess partial timeout capture") | ||
| @pytest.mark.parametrize("entrypoint", ["catalog", "direct"]) | ||
| def test_timeout_retains_bounded_utf8_diagnostics(tmp_path: Path, entrypoint: str) -> None: | ||
| script = tmp_path / "examples" / "timeout.py" | ||
| script.parent.mkdir() | ||
| script.write_text( | ||
| "import sys, time\n" | ||
| "sys.stdout.reconfigure(encoding='utf-8')\n" | ||
| "sys.stderr.reconfigure(encoding='utf-8')\n" | ||
| "print('🔎' * 900 + 'validation started', flush=True)\n" | ||
| "print('正在校验', file=sys.stderr, flush=True)\n" | ||
| "time.sleep(60)\n", | ||
| encoding="utf-8", | ||
| ) | ||
| if entrypoint == "catalog": | ||
| result = run_canary_smoke_check( | ||
| {"command": "python3 examples/timeout.py"}, | ||
| repo_root=tmp_path, | ||
| timeout_seconds=2, | ||
| ) | ||
| else: | ||
| result = _run_gate_check( | ||
| check_id="timeout", | ||
| argv=[sys.executable, str(script)], | ||
| reason="Timeout evidence fixture", | ||
| execute=True, | ||
| timeout_seconds=2, | ||
| repo_root=tmp_path, | ||
| ) | ||
|
|
||
| assert result["status"] == "timed_out" | ||
| assert result["ok"] is False | ||
| assert result["returncode"] is None | ||
| assert result["stdout_tail"] == ("🔎" * 900 + "validation started\n")[-800:] | ||
| assert result["stderr_tail"] == "正在校验\n" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("status", "diagnostic"), | ||
| [("timed_out", "scanning started\n"), ("failed", "")], | ||
| ) | ||
| def test_incomplete_ratchet_stays_failed(status: str, diagnostic: str) -> None: | ||
| run = { | ||
| "ok": False, | ||
| "failure_count": 1, | ||
| "selected_checks": [{ | ||
| "ok": False, | ||
| "status": status, | ||
| "returncode": None if status == "timed_out" else 1, | ||
| "command": "python3 examples/control_plane/control-plane-maintainability-ratchet-smoke.py", | ||
| "stdout_tail": diagnostic, | ||
| }], | ||
| } | ||
|
|
||
| result = downgrade_inherited_baseline_failures(run, changed_files=["loopx/canary/premerge.py"]) | ||
|
|
||
| assert result is not None | ||
| assert result["ok"] is False | ||
| assert result["failure_count"] == 1 | ||
| assert result["selected_checks"][0]["status"] == status | ||
|
|
||
|
|
||
|
|
||
| def test_premerge_rejects_ratchet_config_error_before_report(tmp_path: Path) -> None: | ||
| relative_script = Path("examples/control_plane/control-plane-maintainability-ratchet-smoke.py") | ||
| script = tmp_path / relative_script | ||
| script.parent.mkdir(parents=True) | ||
| bad_baseline = tmp_path / "broken-baseline.json" | ||
| bad_baseline.write_text("{", encoding="utf-8") | ||
| script.write_text( | ||
| "import runpy\n" | ||
| "from pathlib import Path\n" | ||
| "from loopx.canary import maintainability_ratchet\n" | ||
| f"maintainability_ratchet.MODULE_METRIC_BASELINE_PATH = Path({str(bad_baseline)!r})\n" | ||
| f"runpy.run_path({str(REPO_ROOT / relative_script)!r}, run_name='__main__')\n", | ||
| encoding="utf-8", | ||
| ) | ||
| subprocess.run(["git", "init", "-q", str(tmp_path)], check=True) | ||
| result = run_canary_smoke_check( | ||
| {"command": f"python3 {relative_script.as_posix()}"}, | ||
| repo_root=tmp_path, | ||
| ) | ||
| assert result["returncode"] == 1 | ||
| assert "JSONDecodeError" in result["stderr_tail"] | ||
|
|
||
| changed_files = ["loopx/canary/premerge.py"] | ||
| run = downgrade_inherited_baseline_failures( | ||
| {"ok": False, "failure_count": 1, "selected_checks": [result]}, | ||
| changed_files=changed_files, | ||
| ) | ||
| assert run is not None | ||
| gate = _gate_status( | ||
| execute=True, | ||
| changed_files=changed_files, | ||
| direct_checks=[], | ||
| catalog_run=run, | ||
| risk_profile_run=None, | ||
| boundary_run=None, | ||
| manual_holds=[], | ||
| ) | ||
| assert gate["merge_gate_passed"] is False | ||
| assert result["status"] == "failed" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.