diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-11-06 17:49:51 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-09 20:07:54 +0000 |
| commit | cb66958137ed012ea742103e560738107ff53002 (patch) | |
| tree | 4668f0c11ef3f7010bf7a768717d54afd693681d /plugins | |
| parent | 8b45f783efb8cc363cc4c7d90616c3608b531d91 (diff) | |
security-guidance: tests read the session state file by name
The test helper opened the first JSON file in the state directory, which can
be the review model cache depending on directory order. Select the session
state file by its prefix and require exactly one.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/security-guidance/tests/test_repo_resolution.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/plugins/security-guidance/tests/test_repo_resolution.py b/plugins/security-guidance/tests/test_repo_resolution.py index 30c94a7c..bd1840f4 100644 --- a/plugins/security-guidance/tests/test_repo_resolution.py +++ b/plugins/security-guidance/tests/test_repo_resolution.py @@ -261,20 +261,15 @@ class TestHooksJson: def _read_state(env): + # The review model cache is JSON in this directory too. d = env["SECURITY_WARNINGS_STATE_DIR"] - files = [e.path for e in os.scandir(d) if e.name.endswith(".json")] - assert files, os.listdir(d) + files = [e.path for e in os.scandir(d) + if e.name.startswith("security_warnings_state_") and e.name.endswith(".json")] + assert len(files) == 1, os.listdir(d) with open(files[0]) as f: return json.load(f) -def _read_state_or_empty(env): - d = env["SECURITY_WARNINGS_STATE_DIR"] - if not any(e.name.endswith(".json") for e in os.scandir(d)): - return {} - return _read_state(env) - - class TestCommitReview: def test_cwd_is_repo_unchanged(self, workspace, hook_env, stub_api): ws, repo = workspace @@ -334,7 +329,7 @@ class TestCommitReview: m = metrics_of(so) assert m.get("skip_reason") is None, m assert m["repo_resolution"] == rr.RES_SHA_SCAN and m["files_reviewed"] == 1 - assert "repo_root_hint" not in _read_state_or_empty(hook_env) + assert "repo_root_hint" not in _read_state(hook_env) def test_workspace_cwd_sha_scan_via_project_dir(self, workspace, hook_env, tmp_path): ws, repo = workspace @@ -429,7 +424,7 @@ class TestPushSweep: m = metrics_of(so) assert m["push_sweep"] is True and m["repo_resolution"] == rr.RES_SHA_SCAN, m assert m.get("skip_reason") != 26 - assert "repo_root_hint" not in _read_state_or_empty(hook_env) + assert "repo_root_hint" not in _read_state(hook_env) def test_cwd_is_repo_dash_C_other_repo(self, workspace, hook_env, tmp_path): ws, repo = workspace |
