-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(cli): --run-name for deterministic, resumable run dirs #792
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
Open
seanturner83
wants to merge
2
commits into
usestrix:main
Choose a base branch
from
seanturner83:feat/cli-run-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Tests for the --run-name CLI argument (deterministic run dirs).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| import sys | ||
| from types import SimpleNamespace | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| cli_main: Any = importlib.import_module("strix.interface.main") | ||
|
|
||
|
|
||
| def _stub_settings(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr( | ||
| cli_main, | ||
| "load_settings", | ||
| lambda: SimpleNamespace(runtime=SimpleNamespace(max_local_copy_mb=1024)), | ||
| ) | ||
|
|
||
|
|
||
| def test_run_name_accepts_single_segment(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| _stub_settings(monkeypatch) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-t", "https://example.com/", "-n", "--run-name", "my-scan-42"] | ||
| ) | ||
| args = cli_main.parse_arguments() | ||
| assert args.run_name == "my-scan-42" | ||
|
|
||
|
|
||
| def test_run_name_defaults_to_none(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| # Absent flag → None; main() then falls back to --resume / generate_run_name. | ||
| _stub_settings(monkeypatch) | ||
| monkeypatch.setattr(sys, "argv", ["strix", "-t", "https://example.com/", "-n"]) | ||
| args = cli_main.parse_arguments() | ||
| assert args.run_name is None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("bad", ["a/b", "../escape", "sub/dir/name", "/abs"]) | ||
| def test_run_name_rejects_path_traversal(bad: str, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| # run_dir_for() joins straight onto ./strix_runs/, so a separator or a | ||
| # parent hop would escape the runs tree — must be a single segment. | ||
| _stub_settings(monkeypatch) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-t", "https://example.com/", "-n", "--run-name", bad] | ||
| ) | ||
| with pytest.raises(SystemExit): | ||
| cli_main.parse_arguments() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dotted", [".", ".."]) | ||
| def test_run_name_rejects_dot_segments(dotted: str, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| _stub_settings(monkeypatch) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-t", "https://example.com/", "-n", "--run-name", dotted] | ||
| ) | ||
| with pytest.raises(SystemExit): | ||
| cli_main.parse_arguments() | ||
|
|
||
|
|
||
| def test_run_name_conflicting_with_resume_is_rejected(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| # --run-name and --resume that name different dirs would resume one run and | ||
| # persist to another — require them to agree. | ||
| _stub_settings(monkeypatch) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-n", "--resume", "run-a", "--run-name", "run-b"] | ||
| ) | ||
| with pytest.raises(SystemExit): | ||
| cli_main.parse_arguments() | ||
|
|
||
|
|
||
| def test_fresh_run_name_on_existing_dir_is_rejected( | ||
| tmp_path: Any, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| # A fresh (non-resume) --run-name that names an existing run dir would | ||
| # overwrite run.json but leave the prior run's findings/state — reject it. | ||
| _stub_settings(monkeypatch) | ||
| (tmp_path / "strix_runs" / "already-here").mkdir(parents=True) | ||
| monkeypatch.setattr(cli_main, "run_dir_for", lambda name: tmp_path / "strix_runs" / name) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-t", "https://example.com/", "-n", "--run-name", "already-here"] | ||
| ) | ||
| with pytest.raises(SystemExit): | ||
| cli_main.parse_arguments() | ||
|
|
||
|
|
||
| def test_fresh_run_name_on_new_dir_is_accepted( | ||
| tmp_path: Any, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| # A name that does NOT collide is fine. | ||
| _stub_settings(monkeypatch) | ||
| (tmp_path / "strix_runs").mkdir(parents=True) | ||
| monkeypatch.setattr(cli_main, "run_dir_for", lambda name: tmp_path / "strix_runs" / name) | ||
| monkeypatch.setattr( | ||
| sys, "argv", ["strix", "-t", "https://example.com/", "-n", "--run-name", "brand-new"] | ||
| ) | ||
| args = cli_main.parse_arguments() | ||
| assert args.run_name == "brand-new" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a fresh invocation passes a name already present under
strix_runs, this selection enters thenot args.resumepath._persist_run_record()then replaces the priorrun.json, while old vulnerability and state files can remain, so repeated use of a deterministic name can destroy metadata and mix artifacts from separate scans. The fresh path should reject an existing run directory and require--resume, or explicitly replace the directory as one unit.Prompt To Fix With AI