-
Notifications
You must be signed in to change notification settings - Fork 0
fix(security): Strix provider 장애를 fail-closed로 유지 #587
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
Closed
+173
−49
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4937677
fix(security): keep Strix provider outages fail-closed
seonghobae 958e1d9
test(strix): derive workflow block indentation
seonghobae 47bb337
test(strix): skip extracted shell contract without bash
seonghobae d985c5d
test(strix): prove exact shell exit propagation
seonghobae 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Shared pytest collection safeguards for host-tool-dependent tests.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import shutil | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| _BASH_REQUIRED_TESTS = { | ||
| "test_strix_provider_outage_without_findings_fails_closed", | ||
| } | ||
|
|
||
|
|
||
| def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: | ||
| """Skip bash-backed contract tests when the host has no bash executable.""" | ||
| if shutil.which("bash") is not None: | ||
| return | ||
|
|
||
| bash_unavailable = pytest.mark.skip( | ||
| reason="bash is required to execute the extracted GitHub Actions run block" | ||
| ) | ||
| for item in items: | ||
| if item.name in _BASH_REQUIRED_TESTS: | ||
| item.add_marker(bash_unavailable) |
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,87 @@ | ||
| """Executable contracts for the Strix GitHub Actions shell wrapper.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
| import textwrap | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| BASH = shutil.which("bash") | ||
|
|
||
|
|
||
| def _workflow_text(name: str) -> str: | ||
| """Return one repository workflow as UTF-8 text.""" | ||
| return (REPO_ROOT / ".github" / "workflows" / name).read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def _workflow_step(workflow: str, name: str) -> str: | ||
| """Extract one named workflow step without interpreting its YAML body.""" | ||
| marker = f" - name: {name}\n" | ||
| start = workflow.index(marker) | ||
| try: | ||
| end = workflow.index("\n - name:", start + len(marker)) | ||
| except ValueError: | ||
| end = len(workflow) | ||
| return workflow[start:end] | ||
|
|
||
|
|
||
| def _run_script(step: str) -> str: | ||
| """Extract and dedent the literal run block from a workflow step.""" | ||
| lines = step.splitlines() | ||
| run_index = next( | ||
| (index for index, line in enumerate(lines) if line.lstrip() == "run: |"), | ||
| None, | ||
| ) | ||
| assert run_index is not None, "workflow step must contain a literal run block" | ||
|
|
||
| run_line = lines[run_index] | ||
| body_indent = f"{run_line[: len(run_line) - len(run_line.lstrip())]} " | ||
| body = lines[run_index + 1 :] | ||
| assert body, "workflow run block must not be empty" | ||
| assert all(not line or line.startswith(body_indent) for line in body) | ||
| return textwrap.dedent("\n".join(body)) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(BASH is None, reason="bash is required for workflow shell contracts") | ||
| def test_strix_wrapper_propagates_exact_nonzero_gate_status(tmp_path: Path) -> None: | ||
| """Preserve PIPESTATUS[0] under the same bash flags used by Actions.""" | ||
| assert BASH is not None | ||
| workflow = _workflow_text("strix.yml") | ||
| script = _run_script(_workflow_step(workflow, "Run Strix (quick)")) | ||
|
|
||
| fake_gate = tmp_path / "fake-strix-gate.sh" | ||
| fake_gate.write_text( | ||
| "#!/usr/bin/env bash\n" | ||
| "echo 'openai.RateLimitError: exceeded your current quota'\n" | ||
| "echo 'Configured model and fallback models were unavailable.'\n" | ||
| "exit 17\n", | ||
| encoding="utf-8", | ||
| ) | ||
| fake_gate.chmod(0o700) | ||
|
|
||
| result = subprocess.run( | ||
| [BASH, "--noprofile", "--norc", "-eo", "pipefail"], | ||
| input=script, | ||
| capture_output=True, | ||
| text=True, | ||
| env={ | ||
| **os.environ, | ||
| "RUNNER_TEMP": str(tmp_path), | ||
| "TRUSTED_STRIX_GATE": str(fake_gate), | ||
| }, | ||
| check=False, | ||
| ) | ||
|
|
||
| assert result.returncode == 17 | ||
| assert "Strix returned exit 17" in result.stdout | ||
| assert "not converted to success" in result.stdout | ||
| assert (tmp_path / "strix_gate_console.log").read_text(encoding="utf-8") == ( | ||
| "openai.RateLimitError: exceeded your current quota\n" | ||
| "Configured model and fallback models were unavailable.\n" | ||
| ) |
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.