|
| 1 | +"""The failed-check finding must name Strix sandbox when the gate named it. |
| 2 | +
|
| 3 | +`#1953` gave the Strix sandbox bootstrap failure its own verdict token, |
| 4 | +`STRIX_SANDBOX_UNAVAILABLE`, precisely because reporting it as |
| 5 | +`contextual-orchestrator/orchestrator/free exhausted` sent readers to a |
| 6 | +component the run never reached. This consumer rendered one fixed finding for |
| 7 | +every `STRIX_PROVIDER_UNAVAILABLE` line, so the corrected verdict was being |
| 8 | +re-attributed to the gateway one step downstream, and no test covered the text |
| 9 | +at all. These tests pin both directions. |
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import subprocess |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +from tests.test_opencode_workflow_shell_syntax import _extract_run_block |
| 18 | + |
| 19 | +WORKFLOW = Path(".github/workflows/opencode-review-dispatch.yml") |
| 20 | +STEP_NAME = "Publish OpenCode review outcome" |
| 21 | +FUNCTION = "emit_strix_provider_failure_finding" |
| 22 | + |
| 23 | + |
| 24 | +def _emitter_source() -> str: |
| 25 | + """Return the emitter function's shell source from the published run block.""" |
| 26 | + script = _extract_run_block(WORKFLOW.read_text(encoding="utf-8"), STEP_NAME) |
| 27 | + start = script.index(f"{FUNCTION}() {{") |
| 28 | + # ``_extract_run_block`` dedents the YAML block scalar, leaving the |
| 29 | + # function body at two spaces and its closing brace on a line of its own. |
| 30 | + closing = "\n }\n" |
| 31 | + end = script.index(closing, start) + len(closing) |
| 32 | + return script[start:end] |
| 33 | + |
| 34 | + |
| 35 | +def _run_emitter(evidence: str, tmp_path: Path) -> str: |
| 36 | + """Run the production emitter against one evidence file and return its finding text.""" |
| 37 | + evidence_file = tmp_path / "strix-evidence.txt" |
| 38 | + evidence_file.write_text(evidence, encoding="utf-8") |
| 39 | + harness = tmp_path / "harness.sh" |
| 40 | + harness.write_text( |
| 41 | + "set -euo pipefail\n" |
| 42 | + f'strix_evidence_file="{evidence_file}"\n' |
| 43 | + f'repo_root="{tmp_path}"\n' |
| 44 | + "finding_index=0\n" |
| 45 | + f"{_emitter_source()}\n" |
| 46 | + f"{FUNCTION}\n", |
| 47 | + encoding="utf-8", |
| 48 | + ) |
| 49 | + result = subprocess.run( |
| 50 | + ["bash", str(harness)], capture_output=True, text=True, check=True |
| 51 | + ) |
| 52 | + return result.stdout |
| 53 | + |
| 54 | + |
| 55 | +def test_sandbox_token_reports_the_sandbox_not_the_gateway(tmp_path: Path) -> None: |
| 56 | + """A `STRIX_SANDBOX_UNAVAILABLE` verdict never blames the gateway or its provider pool.""" |
| 57 | + finding = _run_emitter( |
| 58 | + "STRIX_PROVIDER_UNAVAILABLE: STRIX_SANDBOX_UNAVAILABLE: the last Strix " |
| 59 | + "attempt ended in the sandbox bootstrap (Caido proxy on 127.0.0.1 " |
| 60 | + "unreachable through Strix's loginAsGuest attempts) after 1 " |
| 61 | + "sandbox-specific same-model retries (budget 1); this verdict names " |
| 62 | + "Strix's sandbox, not the LLM gateway.\n", |
| 63 | + tmp_path, |
| 64 | + ) |
| 65 | + |
| 66 | + assert "Strix sandbox bootstrap blocked current-head security evidence" in finding |
| 67 | + assert "STRIX_SANDBOX_UNAVAILABLE" in finding |
| 68 | + assert "names Strix sandbox, not the contextual-orchestrator gateway" in finding |
| 69 | + assert "gateway or its discovered provider pool was unavailable" not in finding |
| 70 | + # The reader must not be sent to change gateway configuration. |
| 71 | + assert "Do not change gateway or provider configuration" in finding |
| 72 | + assert finding.startswith("### 1. HIGH .github/workflows/strix.yml:") |
| 73 | + |
| 74 | + |
| 75 | +def test_gateway_failure_keeps_its_existing_finding(tmp_path: Path) -> None: |
| 76 | + """Without the sandbox token the previous gateway text is emitted unchanged.""" |
| 77 | + finding = _run_emitter( |
| 78 | + "STRIX_PROVIDER_UNAVAILABLE: contextual-orchestrator/orchestrator/free " |
| 79 | + "exhausted; the gateway owns provider discovery and failover.\n", |
| 80 | + tmp_path, |
| 81 | + ) |
| 82 | + |
| 83 | + assert ( |
| 84 | + "Contextual-orchestrator provider availability blocked current-head security evidence" |
| 85 | + in finding |
| 86 | + ) |
| 87 | + assert "gateway or its discovered provider pool was unavailable" in finding |
| 88 | + assert "STRIX_SANDBOX_UNAVAILABLE" not in finding |
| 89 | + assert "Strix sandbox bootstrap blocked" not in finding |
| 90 | + |
| 91 | + |
| 92 | +def test_unrelated_evidence_emits_no_finding(tmp_path: Path) -> None: |
| 93 | + """Evidence with no provider-unavailable signal still produces nothing.""" |
| 94 | + assert _run_emitter("Strix run succeeded for model 'x' in 12s.\n", tmp_path) == "" |
0 commit comments