claude-dev-env 8.11.1 → 8.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.agents/skills/e-code-review/SKILL.md +24 -71
  2. package/.agents/skills/e-code-review/reference/fix.md +7 -78
  3. package/.agents/skills/e-code-review/reference/high.md +129 -0
  4. package/.agents/skills/e-code-review/reference/low.md +20 -51
  5. package/.agents/skills/e-code-review/reference/max.md +169 -0
  6. package/.agents/skills/e-code-review/reference/medium.md +7 -191
  7. package/.agents/skills/e-code-review/reference/xhigh.md +47 -91
  8. package/bin/install.agents-home.test.mjs +9 -9
  9. package/commands/sr-loop.md +3 -1
  10. package/hooks/hooks_constants/code_rules_path_utils_constants.py +0 -1
  11. package/package.json +1 -1
  12. package/.agents/skills/e-code-review/preflight-proposal.contract.test.mjs +0 -20
  13. package/.agents/skills/e-code-review/reference/effort-evaluation.md +0 -35
  14. package/.agents/skills/e-code-review/reference/loop.md +0 -261
  15. package/.agents/skills/e-code-review/reference/mode-contract.test.mjs +0 -67
  16. package/.agents/skills/e-code-review/reference/preflight-proposal.md +0 -75
  17. package/.agents/skills/e-code-review/reference/runner-selection.md +0 -40
  18. package/.agents/skills/e-code-review/scripts/config/e_code_review_effort_constants/__init__.py +0 -41
  19. package/.agents/skills/e-code-review/scripts/config/e_code_review_effort_constants/effort_constants.py +0 -40
  20. package/.agents/skills/e-code-review/scripts/e_code_review_scripts_constants/__init__.py +0 -1
  21. package/.agents/skills/e-code-review/scripts/e_code_review_scripts_constants/finding_pipeline_constants.py +0 -49
  22. package/.agents/skills/e-code-review/scripts/e_code_review_scripts_constants/grok_code_review_constants.py +0 -55
  23. package/.agents/skills/e-code-review/scripts/effort_defaults_evidence.json +0 -186
  24. package/.agents/skills/e-code-review/scripts/effort_evaluation.py +0 -362
  25. package/.agents/skills/e-code-review/scripts/finding_pipeline.py +0 -140
  26. package/.agents/skills/e-code-review/scripts/fixtures/demanding.json +0 -26
  27. package/.agents/skills/e-code-review/scripts/fixtures/easy.json +0 -14
  28. package/.agents/skills/e-code-review/scripts/fixtures/medium.json +0 -20
  29. package/.agents/skills/e-code-review/scripts/grok_code_review.py +0 -230
  30. package/.agents/skills/e-code-review/scripts/test_effort_evaluation.py +0 -180
  31. package/.agents/skills/e-code-review/scripts/test_finding_pipeline.py +0 -197
  32. package/.agents/skills/e-code-review/scripts/test_grok_code_review.py +0 -289
@@ -1,26 +0,0 @@
1
- {
2
- "fixture_id": "demanding-multi-surface",
3
- "band": "demanding",
4
- "description": "Cross-file review with three seeded findings across hooks and tests.",
5
- "target_summary": "Hook change drifts docstring, drops a paired test path, and uses a banned identifier.",
6
- "seeded_findings": [
7
- {
8
- "file": "hooks/blocking/sample_gate.py",
9
- "line": 88,
10
- "category": "docstring-vs-impl",
11
- "severity": "high"
12
- },
13
- {
14
- "file": "hooks/blocking/test_sample_gate.py",
15
- "line": 1,
16
- "category": "paired-test-coverage",
17
- "severity": "blocker"
18
- },
19
- {
20
- "file": "hooks/blocking/sample_gate.py",
21
- "line": 15,
22
- "category": "banned-identifier",
23
- "severity": "medium"
24
- }
25
- ]
26
- }
@@ -1,14 +0,0 @@
1
- {
2
- "fixture_id": "easy-comment-preservation",
3
- "band": "easy",
4
- "description": "Single-file comment-preservation miss with one seeded finding.",
5
- "target_summary": "Production helper drops an existing inline comment on an unchanged line.",
6
- "seeded_findings": [
7
- {
8
- "file": "sample_helper.py",
9
- "line": 12,
10
- "category": "comment-preservation",
11
- "severity": "medium"
12
- }
13
- ]
14
- }
@@ -1,20 +0,0 @@
1
- {
2
- "fixture_id": "medium-constants-and-types",
3
- "band": "medium",
4
- "description": "Two seeded findings: bare type-ignore and a magic timeout literal.",
5
- "target_summary": "Service module adds a bare type ignore and a hard-coded timeout.",
6
- "seeded_findings": [
7
- {
8
- "file": "order_service.py",
9
- "line": 24,
10
- "category": "type-ignore-justification",
11
- "severity": "high"
12
- },
13
- {
14
- "file": "order_service.py",
15
- "line": 41,
16
- "category": "magic-value",
17
- "severity": "medium"
18
- }
19
- ]
20
- }
@@ -1,230 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Grok medium-review discovery and verification orchestration.
3
-
4
- Dispatches exactly eight named finder angles at one target head, binds each
5
- finder to an isolated identity (worktree path, leader socket, advisor session),
6
- deduplicates candidates, verifies them, and retains CONFIRMED plus unresolved
7
- PLAUSIBLE findings with severity. Head drift rejects the whole batch.
8
- """
9
-
10
- from __future__ import annotations
11
-
12
- from dataclasses import dataclass, field
13
-
14
- from e_code_review_scripts_constants.grok_code_review_constants import (
15
- ALL_MEDIUM_FINDER_ANGLES,
16
- ALL_SEVERITIES,
17
- ALL_VERIFICATION_VERDICTS,
18
- MEDIUM_REVIEW_FINDER_COUNT,
19
- MEDIUM_REVIEW_SCHEMA_VERSION,
20
- VERDICT_CONFIRMED,
21
- VERDICT_PLAUSIBLE,
22
- VERDICT_REFUTED,
23
- )
24
-
25
-
26
- @dataclass(frozen=True)
27
- class FinderCandidate:
28
- """One candidate finding from a discovery angle."""
29
-
30
- angle: str
31
- file_path: str
32
- line_number: int
33
- mechanism: str
34
- scenario: str
35
- worktree_path: str
36
- leader_socket: str
37
- advisor_session_id: str
38
- reviewed_head: str
39
-
40
-
41
- @dataclass(frozen=True)
42
- class VerifiedFinding:
43
- """A retained finding after verification."""
44
-
45
- file_path: str
46
- line_number: int
47
- mechanism: str
48
- scenario: str
49
- verdict: str
50
- severity: str
51
- reviewed_head: str
52
-
53
-
54
- @dataclass
55
- class MediumReviewBatch:
56
- """Result of one medium-review run at a single head."""
57
-
58
- schema_version: str = MEDIUM_REVIEW_SCHEMA_VERSION
59
- target_head: str = ""
60
- diff_base: str = ""
61
- all_finder_angles: tuple[str, ...] = ALL_MEDIUM_FINDER_ANGLES
62
- all_retained_findings: list[VerifiedFinding] = field(default_factory=list)
63
- is_rejected: bool = False
64
- rejection_reason: str | None = None
65
-
66
-
67
- def require_exact_finder_set(all_angles: tuple[str, ...] | list[str]) -> None:
68
- """Require exactly the eight named finder angles.
69
-
70
- Args:
71
- all_angles: Angle names present in a run.
72
-
73
- Raises:
74
- ValueError: When the set is not exactly the eight angles.
75
- """
76
- angle_set = set(all_angles)
77
- expected = set(ALL_MEDIUM_FINDER_ANGLES)
78
- if angle_set != expected or len(all_angles) != MEDIUM_REVIEW_FINDER_COUNT:
79
- raise ValueError(
80
- f"finder angles must be exactly {MEDIUM_REVIEW_FINDER_COUNT}: "
81
- f"got {sorted(angle_set)}"
82
- )
83
-
84
-
85
- def deduplicate_candidates(
86
- all_candidates: list[FinderCandidate],
87
- ) -> list[FinderCandidate]:
88
- """Keep the most concrete scenario per file/line/mechanism.
89
-
90
- Args:
91
- all_candidates: Raw finder outputs.
92
-
93
- Returns:
94
- Deduplicated candidates preserving the longest scenario text.
95
- """
96
- best_by_key: dict[tuple[str, int, str], FinderCandidate] = {}
97
- for each_candidate in all_candidates:
98
- key = (
99
- each_candidate.file_path,
100
- each_candidate.line_number,
101
- each_candidate.mechanism,
102
- )
103
- existing = best_by_key.get(key)
104
- if existing is None or len(each_candidate.scenario) > len(existing.scenario):
105
- best_by_key[key] = each_candidate
106
- return list(best_by_key.values())
107
-
108
-
109
- def retain_verified_findings(
110
- *,
111
- all_candidates: list[FinderCandidate],
112
- verdict_by_key: dict[tuple[str, int, str], str],
113
- severity_by_key: dict[tuple[str, int, str], str],
114
- ) -> list[VerifiedFinding]:
115
- """Retain CONFIRMED and unresolved PLAUSIBLE findings with severity.
116
-
117
- Args:
118
- all_candidates: Deduplicated candidates.
119
- verdict_by_key: Verification verdict per file/line/mechanism.
120
- severity_by_key: Severity per file/line/mechanism.
121
-
122
- Returns:
123
- Retained findings.
124
-
125
- Raises:
126
- ValueError: When a retained finding lacks a legal severity or verdict.
127
- """
128
- all_retained: list[VerifiedFinding] = []
129
- for each_candidate in all_candidates:
130
- key = (
131
- each_candidate.file_path,
132
- each_candidate.line_number,
133
- each_candidate.mechanism,
134
- )
135
- verdict = verdict_by_key.get(key)
136
- if verdict not in ALL_VERIFICATION_VERDICTS:
137
- raise ValueError(f"missing or illegal verdict for {key}")
138
- if verdict == VERDICT_REFUTED:
139
- continue
140
- if verdict not in {VERDICT_CONFIRMED, VERDICT_PLAUSIBLE}:
141
- continue
142
- severity = severity_by_key.get(key)
143
- if severity not in ALL_SEVERITIES:
144
- raise ValueError(f"missing or illegal severity for {key}")
145
- all_retained.append(
146
- VerifiedFinding(
147
- file_path=each_candidate.file_path,
148
- line_number=each_candidate.line_number,
149
- mechanism=each_candidate.mechanism,
150
- scenario=each_candidate.scenario,
151
- verdict=verdict,
152
- severity=severity,
153
- reviewed_head=each_candidate.reviewed_head,
154
- )
155
- )
156
- return all_retained
157
-
158
-
159
- def run_medium_review(
160
- *,
161
- target_head: str,
162
- diff_base: str,
163
- all_finder_candidates: list[FinderCandidate],
164
- verdict_by_key: dict[tuple[str, int, str], str],
165
- severity_by_key: dict[tuple[str, int, str], str],
166
- live_head: str,
167
- is_any_advisor_blocked: bool = False,
168
- ) -> MediumReviewBatch:
169
- """Run discovery and verification for one medium-review head.
170
-
171
- Args:
172
- target_head: Reviewed head OID.
173
- diff_base: Diff base OID.
174
- all_finder_candidates: Outputs from the eight finder angles.
175
- verdict_by_key: Verification results keyed by file/line/mechanism.
176
- severity_by_key: Severities for retained findings.
177
- live_head: Live head OID; must match target_head.
178
- is_any_advisor_blocked: True when any finder ended advisor_blocked.
179
-
180
- Raises:
181
- ValueError: When finder angles are incomplete or duplicated.
182
-
183
- Returns:
184
- The medium-review batch (possibly rejected).
185
- """
186
- batch = MediumReviewBatch(target_head=target_head, diff_base=diff_base)
187
- if is_any_advisor_blocked:
188
- batch.is_rejected = True
189
- batch.rejection_reason = "advisor_blocked"
190
- return batch
191
- if live_head != target_head:
192
- batch.is_rejected = True
193
- batch.rejection_reason = "head_drift"
194
- return batch
195
- for each_candidate in all_finder_candidates:
196
- if each_candidate.reviewed_head != target_head:
197
- batch.is_rejected = True
198
- batch.rejection_reason = "finder_head_mismatch"
199
- return batch
200
- all_angles = sorted({each.angle for each in all_finder_candidates})
201
- finder_count = len(all_angles)
202
- all_identities = {
203
- (
204
- each.angle,
205
- each.leader_socket,
206
- each.advisor_session_id,
207
- each.worktree_path,
208
- )
209
- for each in all_finder_candidates
210
- }
211
- all_sockets = {each.leader_socket for each in all_finder_candidates}
212
- all_sessions = {each.advisor_session_id for each in all_finder_candidates}
213
- all_worktrees = {each.worktree_path for each in all_finder_candidates}
214
- if (
215
- len(all_identities) != finder_count
216
- or len(all_sockets) != finder_count
217
- or len(all_sessions) != finder_count
218
- or len(all_worktrees) != finder_count
219
- ):
220
- batch.is_rejected = True
221
- batch.rejection_reason = "non_unique_finder_identity"
222
- return batch
223
- require_exact_finder_set(tuple(all_angles))
224
- deduped = deduplicate_candidates(all_finder_candidates)
225
- batch.all_retained_findings = retain_verified_findings(
226
- all_candidates=deduped,
227
- verdict_by_key=verdict_by_key,
228
- severity_by_key=severity_by_key,
229
- )
230
- return batch
@@ -1,180 +0,0 @@
1
- """Behavior tests for the effort evaluation harness."""
2
-
3
- from __future__ import annotations
4
-
5
- import sys
6
- from pathlib import Path
7
-
8
- _SCRIPTS_DIRECTORY = Path(__file__).resolve().parent
9
- _CONSTANTS_PARENT = _SCRIPTS_DIRECTORY / "config"
10
- for each_path in (_SCRIPTS_DIRECTORY, _CONSTANTS_PARENT):
11
- path_text = str(each_path)
12
- if path_text not in sys.path:
13
- sys.path.insert(0, path_text)
14
-
15
- from e_code_review_effort_constants import ( # noqa: E402
16
- ALL_EFFORT_LEVELS,
17
- ALL_FIXTURE_BANDS,
18
- ALL_SKILL_EFFORT_LEVELS,
19
- MINIMUM_QUALITY_HOLD_SCORE,
20
- THINKING_ENABLED_DEFAULT,
21
- WORKFLOW_FAMILY_E_CODE_REVIEW,
22
- )
23
- from effort_evaluation import ( # noqa: E402
24
- build_synthetic_row,
25
- evaluation_evidence_path,
26
- fixtures_directory,
27
- load_evaluation_evidence,
28
- load_fixtures,
29
- map_evaluation_effort_to_skill_level,
30
- quality_holds,
31
- recommend_effort_by_band,
32
- resolve_skill_effort_for_band,
33
- skill_defaults_from_recommendation,
34
- validate_evaluation_row,
35
- )
36
-
37
-
38
- def test_fixtures_directory_points_at_frozen_json() -> None:
39
- directory = fixtures_directory()
40
- assert directory.is_dir()
41
- assert directory.name == "fixtures"
42
- assert (directory / "easy.json").is_file()
43
-
44
-
45
- def test_loads_three_frozen_fixture_bands() -> None:
46
- all_fixtures = load_fixtures()
47
- assert len(all_fixtures) == len(ALL_FIXTURE_BANDS)
48
- bands = {str(each_fixture["band"]) for each_fixture in all_fixtures}
49
- assert bands == set(ALL_FIXTURE_BANDS)
50
- for each_fixture in all_fixtures:
51
- assert each_fixture["fixture_id"]
52
- assert isinstance(each_fixture["seeded_findings"], list)
53
- assert len(each_fixture["seeded_findings"]) >= 1
54
-
55
-
56
- def test_validate_row_accepts_complete_row_and_rejects_thinking_off() -> None:
57
- good_row = build_synthetic_row(
58
- fixture_id="easy-comment-preservation",
59
- fixture_band="easy",
60
- effort="low",
61
- quality_score=0.9,
62
- finding_recall=1.0,
63
- finding_precision=1.0,
64
- visible_tokens=1200,
65
- latency_ms=4000,
66
- )
67
- assert validate_evaluation_row(good_row) == []
68
- assert good_row["thinking_enabled"] is THINKING_ENABLED_DEFAULT
69
- bad_row = dict(good_row)
70
- bad_row["thinking_enabled"] = False
71
- problems = validate_evaluation_row(bad_row)
72
- assert any("thinking_enabled" in each_problem for each_problem in problems)
73
- bool_score_row = dict(good_row)
74
- bool_score_row["quality_score"] = True
75
- bool_problems = validate_evaluation_row(bool_score_row)
76
- assert any("quality_score" in each_problem for each_problem in bool_problems)
77
-
78
-
79
- def test_recommend_picks_lowest_effort_that_holds_quality() -> None:
80
- all_rows = [
81
- build_synthetic_row("easy-a", "easy", "low", 0.5, 0.5, 0.5, 100, 1000),
82
- build_synthetic_row("easy-a", "easy", "medium", 0.95, 0.95, 0.95, 200, 2000),
83
- build_synthetic_row("easy-a", "easy", "xhigh", 0.99, 0.99, 0.99, 400, 5000),
84
- build_synthetic_row("medium-a", "medium", "high", 0.9, 0.9, 0.9, 300, 3000),
85
- build_synthetic_row(
86
- "demanding-a", "demanding", "max", 0.85, 0.85, 0.85, 800, 9000
87
- ),
88
- ]
89
- for each_row in all_rows:
90
- assert validate_evaluation_row(each_row) == []
91
- recommendation = recommend_effort_by_band(all_rows)
92
- by_band = recommendation["recommendation_by_band"]
93
- assert isinstance(by_band, dict)
94
- assert by_band["easy"]["recommended_effort"] == "medium"
95
- assert by_band["easy"]["cited_row"]["effort"] == "medium"
96
- assert by_band["medium"]["recommended_effort"] == "high"
97
- assert by_band["demanding"]["recommended_effort"] == "max"
98
- assert recommendation["thinking_enabled"] is True
99
- assert recommendation["cost_latency_lever"] == "effort"
100
- assert recommendation["defaults_unchanged"] is True
101
-
102
-
103
- def test_recommend_blocks_band_without_holding_row() -> None:
104
- all_rows = [
105
- build_synthetic_row("easy-a", "easy", "low", 0.1, 0.1, 0.1, 50, 500),
106
- ]
107
- recommendation = recommend_effort_by_band(all_rows)
108
- easy = recommendation["recommendation_by_band"]["easy"]
109
- assert easy["recommended_effort"] is None
110
- assert easy["cited_row"] is None
111
- assert "quality floor" in str(easy["blocker"])
112
-
113
-
114
- def test_quality_holds_uses_named_floor() -> None:
115
- holding = build_synthetic_row(
116
- "x", "easy", "low", MINIMUM_QUALITY_HOLD_SCORE, 1.0, 1.0, 1, 1
117
- )
118
- failing = build_synthetic_row(
119
- "x", "easy", "low", MINIMUM_QUALITY_HOLD_SCORE - 0.01, 1.0, 1.0, 1, 1
120
- )
121
- assert quality_holds(holding) is True
122
- assert quality_holds(failing) is False
123
-
124
-
125
- def test_effort_levels_cover_cli_set() -> None:
126
- assert "low" in ALL_EFFORT_LEVELS
127
- assert "max" in ALL_EFFORT_LEVELS
128
- assert len(ALL_EFFORT_LEVELS) == 5
129
-
130
-
131
- def test_evidence_rows_validate_and_skill_defaults_cite_rows() -> None:
132
- evidence_path = evaluation_evidence_path()
133
- assert evidence_path.is_file()
134
- assert evidence_path.name == "effort_defaults_evidence.json"
135
- evidence = load_evaluation_evidence()
136
- assert evidence["workflow_family"] == WORKFLOW_FAMILY_E_CODE_REVIEW
137
- assert evidence["thinking_enabled"] is True
138
- all_rows = evidence["all_rows"]
139
- assert isinstance(all_rows, list)
140
- for each_row in all_rows:
141
- assert isinstance(each_row, dict)
142
- assert validate_evaluation_row(each_row) == []
143
- recommendation = recommend_effort_by_band(all_rows)
144
- skill_defaults = skill_defaults_from_recommendation(recommendation)
145
- assert skill_defaults["workflow_family"] == WORKFLOW_FAMILY_E_CODE_REVIEW
146
- default_by_band = skill_defaults["default_by_band"]
147
- assert isinstance(default_by_band, dict)
148
- for each_band in ALL_FIXTURE_BANDS:
149
- band_default = default_by_band[each_band]
150
- assert band_default["skill_effort"] in ALL_SKILL_EFFORT_LEVELS
151
- assert band_default["cited_row"] is not None
152
- assert band_default["cited_row"]["thinking_enabled"] is True
153
-
154
-
155
- def test_committed_skill_defaults_match_resolver() -> None:
156
- assert resolve_skill_effort_for_band("easy") == "medium"
157
- assert resolve_skill_effort_for_band("medium") == "xhigh"
158
- assert resolve_skill_effort_for_band("demanding") == "xhigh"
159
- evidence = load_evaluation_evidence()
160
- committed = evidence["skill_defaults"]["default_by_band"]
161
- for each_band in ALL_FIXTURE_BANDS:
162
- assert committed[each_band]["skill_effort"] == resolve_skill_effort_for_band(
163
- each_band
164
- )
165
- assert committed[each_band]["cited_row"]["effort"] is not None
166
-
167
-
168
- def test_map_high_and_max_to_skill_xhigh() -> None:
169
- assert map_evaluation_effort_to_skill_level("high") == "xhigh"
170
- assert map_evaluation_effort_to_skill_level("max") == "xhigh"
171
- assert map_evaluation_effort_to_skill_level("medium") == "medium"
172
-
173
-
174
- def test_resolve_rejects_unknown_band() -> None:
175
- try:
176
- resolve_skill_effort_for_band("not-a-band")
177
- except ValueError as error:
178
- assert "unknown fixture band" in str(error)
179
- else:
180
- raise AssertionError("expected ValueError for unknown band")
@@ -1,197 +0,0 @@
1
- """Red fixtures: low-severity findings survive collection; filter is separate."""
2
-
3
- from __future__ import annotations
4
-
5
- import sys
6
- from pathlib import Path
7
-
8
- import pytest
9
-
10
- _SCRIPTS_DIR = Path(__file__).resolve().parent
11
- if str(_SCRIPTS_DIR) not in sys.path:
12
- sys.path.insert(0, str(_SCRIPTS_DIR))
13
-
14
- from e_code_review_scripts_constants.finding_pipeline_constants import (
15
- ALL_COLLECTION_SEVERITIES,
16
- COLLECTION_STAGE_NAME,
17
- FILTER_STAGE_NAME,
18
- FINDING_FIELD_CATEGORY,
19
- FINDING_FIELD_EVIDENCE,
20
- FINDING_FIELD_FILE,
21
- FINDING_FIELD_LINE,
22
- FINDING_FIELD_SEVERITY,
23
- REPORT_EVERY_FINDING_INSTRUCTION,
24
- SEVERITY_BLOCKER,
25
- SEVERITY_HIGH,
26
- SEVERITY_LOW,
27
- SEVERITY_MEDIUM,
28
- SEVERITY_NIT,
29
- )
30
- from finding_pipeline import (
31
- CollectedFinding,
32
- FindingCollection,
33
- collect_findings,
34
- filter_findings_by_severity,
35
- )
36
-
37
-
38
- def _seeded_findings() -> list[CollectedFinding]:
39
- return [
40
- CollectedFinding(
41
- file_path="pkg/a.py",
42
- line_number=10,
43
- severity=SEVERITY_BLOCKER,
44
- category="correctness",
45
- evidence="raises on empty input",
46
- ),
47
- CollectedFinding(
48
- file_path="pkg/b.py",
49
- line_number=20,
50
- severity=SEVERITY_HIGH,
51
- category="security",
52
- evidence="shell=True with user text",
53
- ),
54
- CollectedFinding(
55
- file_path="pkg/c.py",
56
- line_number=30,
57
- severity=SEVERITY_MEDIUM,
58
- category="api-contracts",
59
- evidence="return type narrowed",
60
- ),
61
- CollectedFinding(
62
- file_path="pkg/d.py",
63
- line_number=40,
64
- severity=SEVERITY_LOW,
65
- category="simplification",
66
- evidence="duplicated helper body",
67
- ),
68
- CollectedFinding(
69
- file_path="pkg/e.py",
70
- line_number=50,
71
- severity=SEVERITY_NIT,
72
- category="conventions",
73
- evidence="typo in comment",
74
- ),
75
- ]
76
-
77
-
78
- def test_collection_retains_every_seeded_severity_including_low_and_nit() -> None:
79
- all_seeded = _seeded_findings()
80
- collection = collect_findings(all_seeded)
81
-
82
- assert collection.stage_name == COLLECTION_STAGE_NAME
83
- all_severities = {
84
- each.severity for each in collection.all_findings
85
- }
86
- assert all_severities == set(ALL_COLLECTION_SEVERITIES)
87
- assert len(collection.all_findings) == len(all_seeded)
88
- low_finding = next(
89
- each for each in collection.all_findings if each.severity == SEVERITY_LOW
90
- )
91
- assert low_finding.file_path == "pkg/d.py"
92
- assert low_finding.line_number == 40
93
- assert low_finding.evidence == "duplicated helper body"
94
- assert low_finding.category == "simplification"
95
-
96
-
97
- def test_each_collected_finding_keeps_file_line_evidence_and_category() -> None:
98
- collection = collect_findings(_seeded_findings())
99
- for each_finding in collection.all_findings:
100
- as_mapping = each_finding.as_mapping()
101
- assert as_mapping[FINDING_FIELD_FILE]
102
- assert as_mapping[FINDING_FIELD_LINE] > 0
103
- assert as_mapping[FINDING_FIELD_EVIDENCE]
104
- assert as_mapping[FINDING_FIELD_CATEGORY]
105
- assert as_mapping[FINDING_FIELD_SEVERITY] in ALL_COLLECTION_SEVERITIES
106
-
107
-
108
- def test_filter_is_explicit_later_stage_and_does_not_mutate_collection() -> None:
109
- collection = collect_findings(_seeded_findings())
110
- collected_snapshot = [
111
- (
112
- each.file_path,
113
- each.line_number,
114
- each.severity,
115
- each.category,
116
- each.evidence,
117
- )
118
- for each in collection.all_findings
119
- ]
120
-
121
- filtered = filter_findings_by_severity(
122
- collection,
123
- minimum_severity=SEVERITY_MEDIUM,
124
- )
125
-
126
- assert filtered.stage_name == FILTER_STAGE_NAME
127
- all_filtered_severities = {each.severity for each in filtered.all_findings}
128
- assert SEVERITY_LOW not in all_filtered_severities
129
- assert SEVERITY_NIT not in all_filtered_severities
130
- assert SEVERITY_MEDIUM in all_filtered_severities
131
- assert SEVERITY_BLOCKER in all_filtered_severities
132
-
133
- after_filter_snapshot = [
134
- (
135
- each.file_path,
136
- each.line_number,
137
- each.severity,
138
- each.category,
139
- each.evidence,
140
- )
141
- for each in collection.all_findings
142
- ]
143
- assert after_filter_snapshot == collected_snapshot
144
- assert len(collection.all_findings) == 5
145
-
146
-
147
- def test_filter_rejects_unknown_minimum_severity() -> None:
148
- collection = collect_findings(_seeded_findings())
149
- with pytest.raises(ValueError, match="unknown minimum severity"):
150
- filter_findings_by_severity(collection, minimum_severity="P1")
151
-
152
-
153
- def test_filter_rejects_unknown_finding_severity_with_value_error() -> None:
154
- collection = FindingCollection(
155
- stage_name=COLLECTION_STAGE_NAME,
156
- all_findings=(
157
- CollectedFinding(
158
- file_path="pkg/x.py",
159
- line_number=1,
160
- severity="P0",
161
- category="correctness",
162
- evidence="bypass collect",
163
- ),
164
- ),
165
- )
166
- with pytest.raises(ValueError, match="unknown collection severity"):
167
- filter_findings_by_severity(collection, minimum_severity=SEVERITY_LOW)
168
-
169
-
170
- def test_collect_rejects_finding_missing_required_fields() -> None:
171
- with pytest.raises(ValueError, match="file"):
172
- collect_findings(
173
- [
174
- CollectedFinding(
175
- file_path="",
176
- line_number=1,
177
- severity=SEVERITY_LOW,
178
- category="correctness",
179
- evidence="x",
180
- )
181
- ]
182
- )
183
-
184
-
185
- def test_report_every_finding_instruction_names_all_severities() -> None:
186
- for each_severity in ALL_COLLECTION_SEVERITIES:
187
- assert each_severity in REPORT_EVERY_FINDING_INSTRUCTION
188
- assert "consumer stage" in REPORT_EVERY_FINDING_INSTRUCTION
189
- assert "Do not drop findings by severity during collection" in (
190
- REPORT_EVERY_FINDING_INSTRUCTION
191
- )
192
-
193
-
194
- def test_collection_record_type_is_immutable() -> None:
195
- collection = collect_findings(_seeded_findings())
196
- assert isinstance(collection, FindingCollection)
197
- assert collection.stage_name == COLLECTION_STAGE_NAME