claude-dev-env 8.3.0 → 8.4.1

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 (27) hide show
  1. package/.agents/skills/team-advisor/SKILL.md +9 -4
  2. package/_shared/advisor/reference/spawn-walk-log.md +2 -1
  3. package/_shared/advisor/scripts/config/advisor_scripts_constants/model_tier_run_validator_constants.py +3 -0
  4. package/_shared/advisor/scripts/model_tier_run_validator.py +169 -14
  5. package/_shared/advisor/scripts/tests/test_codex_astra_advisor.py +20 -0
  6. package/_shared/advisor/scripts/tests/test_model_tier_run_validator.py +99 -0
  7. package/bin/install.agents-home.test.mjs +10 -0
  8. package/bin/install.test.mjs +14 -0
  9. package/docs/references/advisor-tool.md +32 -0
  10. package/docs/references/team-advisor-skill.md +1 -1
  11. package/hooks/hooks_constants/precommit_code_rules_gate_constants.py +1 -1
  12. package/hooks/validators/README.md +0 -1
  13. package/hooks/validators/test_files/EXECUTIVE_SUMMARY.md +1 -2
  14. package/package.json +1 -1
  15. package/scripts/policy_lint/config/approved_test_pairs.py +9 -0
  16. package/scripts/tests/test_policy_lint_rules_pairing.py +16 -0
  17. package/scripts/windows/pstack/pstack-command-shim.ps1 +41 -0
  18. package/scripts/windows/pstack/ship-pr.cmd +3 -0
  19. package/scripts/windows/pstack/watch-pr.cmd +3 -0
  20. package/hooks/blocking/pii_payload_scan.py +0 -348
  21. package/hooks/blocking/precommit_code_rules_gate.py +0 -50
  22. package/hooks/blocking/test_pii_payload_scan.py +0 -231
  23. package/hooks/blocking/test_precommit_code_rules_gate.py +0 -63
  24. package/hooks/validators/VALIDATION_REPORT.md +0 -287
  25. package/hooks/validators/validator_defaults.py +0 -5
  26. package/scripts/dev_env_scripts_constants/test_code_review_constants.py +0 -12
  27. package/scripts/tests/test_code_review_constants.py +0 -80
@@ -1,63 +0,0 @@
1
- """Behavior tests for the precommit_code_rules_gate library module.
2
-
3
- The module carries no hook entry point of its own; it exports
4
- ``resolve_repository_root`` for its importers (``pii_prevention_blocker.py``,
5
- ``pii_payload_scan.py``, ``session_edit_stage_gate.py``).
6
- """
7
-
8
- import subprocess
9
- import sys
10
- from pathlib import Path
11
-
12
- try:
13
- import precommit_code_rules_gate as gate_module
14
- from precommit_code_rules_gate import resolve_repository_root
15
- except ModuleNotFoundError:
16
- _BLOCKING_DIR = str(Path(__file__).resolve().parent)
17
- if _BLOCKING_DIR not in sys.path:
18
- sys.path.insert(0, _BLOCKING_DIR)
19
- import precommit_code_rules_gate as gate_module
20
- from precommit_code_rules_gate import resolve_repository_root
21
-
22
-
23
- def run_git(repository_root: Path, *git_arguments: str) -> None:
24
- subprocess.run(
25
- ["git", "-C", str(repository_root), *git_arguments],
26
- check=True,
27
- capture_output=True,
28
- )
29
-
30
-
31
- def initialize_repository(repository_root: Path) -> None:
32
- run_git(repository_root, "init")
33
- run_git(repository_root, "config", "user.email", "tests@example.com")
34
- run_git(repository_root, "config", "user.name", "Gate Tests")
35
- run_git(repository_root, "commit", "--allow-empty", "-m", "initial")
36
-
37
-
38
- def test_resolve_repository_root_returns_root_for_directory_inside_repository(
39
- tmp_path: Path,
40
- ) -> None:
41
- initialize_repository(tmp_path)
42
- nested_directory = tmp_path / "nested"
43
- nested_directory.mkdir()
44
- resolved_root = resolve_repository_root(str(nested_directory))
45
- assert resolved_root == tmp_path.resolve()
46
-
47
-
48
- def test_resolve_repository_root_returns_none_outside_a_repository(
49
- tmp_path: Path,
50
- ) -> None:
51
- non_repository_directory = tmp_path / "not_a_repo"
52
- non_repository_directory.mkdir()
53
- assert resolve_repository_root(str(non_repository_directory)) is None
54
-
55
-
56
- def test_module_carries_no_main_entry_point() -> None:
57
- """The module has no dispatcher-facing hook entry point."""
58
- assert not hasattr(gate_module, "main")
59
-
60
-
61
- def test_module_carries_no_commit_invocation_detector() -> None:
62
- """The commit-detection helper lives in block_main_commit, not duplicated here."""
63
- assert not hasattr(gate_module, "is_git_commit_invocation")
@@ -1,287 +0,0 @@
1
- # Test Safety Checks Validator - Comprehensive Validation Report
2
-
3
- ## Executive Summary
4
-
5
- **Critical Gaps Found: 2**
6
- **Minor Issues: 1**
7
- **Tests Passed: 14/17**
8
-
9
- ---
10
-
11
- ## Check 1: No Skip Decorators
12
-
13
- ### Test Results
14
-
15
- | Test Case | Expected | Result | Status |
16
- |-----------|----------|--------|--------|
17
- | `@skip` | CAUGHT | CAUGHT | PASS |
18
- | `@pytest.mark.skipif(...)` | CAUGHT | CAUGHT | PASS |
19
- | `@unittest.skipIf(...)` | CAUGHT | CAUGHT | PASS |
20
- | `@skip()` with parentheses | CAUGHT | CAUGHT | PASS |
21
- | `@pytest.mark.xfail` | ALLOWED | ALLOWED | PASS |
22
- | `@skip_on_windows` custom | ALLOWED | ALLOWED | PASS |
23
- | `@Skip` (capital S) | CAUGHT | **ALLOWED** | **FAIL** |
24
- | `@unittest.skipUnless(...)` | CAUGHT | CAUGHT | PASS |
25
- | `@pytest.mark.skip` (no args) | CAUGHT | CAUGHT | PASS |
26
-
27
- ### GAP #1: Case-Sensitive Decorator Matching
28
-
29
- **Severity: MEDIUM**
30
-
31
- **Issue:** The validator uses case-sensitive matching, so `@Skip` (capital S) is NOT caught.
32
-
33
- **Current Code (lines 16-22):**
34
- ```python
35
- SKIP_DECORATOR_NAMES = frozenset([
36
- "skip",
37
- "skipif",
38
- "skipunless",
39
- "skipIf",
40
- "skipUnless",
41
- ])
42
- ```
43
-
44
- **Problem:** This misses decorators with different capitalization like `@Skip`, `@SkipIf`, `@SKIP`, etc.
45
-
46
- **Recommended Fix:**
47
- ```python
48
- def _get_decorator_name(decorator: ast.expr) -> str:
49
- """Extract the name from a decorator node (lowercase for comparison)."""
50
- # ... existing logic ...
51
- return name.lower() # Convert to lowercase for case-insensitive matching
52
- ```
53
-
54
- Then update the frozenset to all lowercase:
55
- ```python
56
- SKIP_DECORATOR_NAMES = frozenset([
57
- "skip",
58
- "skipif",
59
- "skipunless",
60
- ])
61
- ```
62
-
63
- **Impact:** Currently allows `@Skip`, `@SkipIf`, `@SkipUnless` to slip through.
64
-
65
- ---
66
-
67
- ## Check 2: DEBUG Guard in Management Commands
68
-
69
- ### Test Results
70
-
71
- | Test Case | Expected | Result | Status |
72
- |-----------|----------|--------|--------|
73
- | No DEBUG check | CAUGHT | CAUGHT | PASS |
74
- | `if not settings.DEBUG: raise` | ALLOWED | ALLOWED | PASS |
75
- | `if not settings.DEBUG: return` | ALLOWED | ALLOWED | PASS |
76
- | Using imported `DEBUG` variable | CAUGHT | CAUGHT | PASS |
77
- | DEBUG check in helper function | CAUGHT | CAUGHT | PASS |
78
- | DEBUG check after 5 statements | CAUGHT | CAUGHT | PASS |
79
- | `if settings.DEBUG: ... else: raise` | ALLOWED | **CAUGHT** | **FAIL** |
80
- | `if not settings.DEBUG and X:` | DEBATABLE | CAUGHT | WARN |
81
- | File not in `management/commands/` | IGNORED | IGNORED | PASS |
82
-
83
- ### GAP #2: Positive DEBUG Check Pattern Rejected
84
-
85
- **Severity: HIGH**
86
-
87
- **Issue:** The validator incorrectly rejects the pattern `if settings.DEBUG: ... else: raise`.
88
-
89
- **Test File:** `cmd_07_positive_debug_check.py`
90
- ```python
91
- def handle(self, *args, **options):
92
- if settings.DEBUG:
93
- print("Running in DEBUG mode")
94
- else:
95
- raise CommandError("This command can only be run in DEBUG mode")
96
- ```
97
-
98
- **Expected:** ALLOWED (this is a valid DEBUG guard)
99
- **Actual:** CAUGHT (flagged as violation)
100
-
101
- **Root Cause (lines 186-187):**
102
- ```python
103
- if _is_debug_check(test) and stmt.orelse:
104
- return False # This returns False when it should return True!
105
- ```
106
-
107
- **The Logic Flaw:**
108
- - Line 186: Detects `if settings.DEBUG:` and checks if there's an `else` clause
109
- - Line 187: Returns `False` (no DEBUG guard found)
110
- - **BUG:** This should return `True` because the pattern IS a valid guard!
111
-
112
- **Recommended Fix:**
113
- ```python
114
- def _has_debug_guard(func: ast.FunctionDef) -> bool:
115
- """Check if a function has a settings.DEBUG guard at the start."""
116
- if not func.body:
117
- return False
118
-
119
- for stmt in func.body[:5]:
120
- if isinstance(stmt, ast.If):
121
- test = stmt.test
122
-
123
- # Pattern 1: if not settings.DEBUG: raise/return
124
- if isinstance(test, ast.UnaryOp) and isinstance(test.op, ast.Not):
125
- if _is_debug_check(test.operand):
126
- return True
127
-
128
- # Pattern 2: if settings.DEBUG: ... else: raise/return
129
- if _is_debug_check(test):
130
- if stmt.orelse:
131
- # Check if else clause has raise/return
132
- if _has_early_exit(stmt.orelse):
133
- return True
134
- # if settings.DEBUG: with no else is also valid
135
- return True
136
-
137
- return False
138
-
139
-
140
- def _has_early_exit(statements: List[ast.stmt]) -> bool:
141
- """Check if statements contain raise or return."""
142
- for stmt in statements:
143
- if isinstance(stmt, (ast.Raise, ast.Return)):
144
- return True
145
- # Check nested if/else
146
- if isinstance(stmt, ast.If):
147
- if _has_early_exit(stmt.body) or (stmt.orelse and _has_early_exit(stmt.orelse)):
148
- return True
149
- return False
150
- ```
151
-
152
- **Impact:** Currently REJECTS valid DEBUG guard patterns, forcing developers to use only negative checks.
153
-
154
- ### MINOR ISSUE: Complex Boolean Expressions
155
-
156
- **Severity: LOW**
157
-
158
- **Issue:** The validator rejects `if not settings.DEBUG and other_condition:`.
159
-
160
- **Test File:** `cmd_08_debug_with_and.py`
161
- ```python
162
- if not settings.DEBUG and True:
163
- raise CommandError("This command can only be run in DEBUG mode")
164
- ```
165
-
166
- **Expected:** DEBATABLE (could be allowed if DEBUG is the primary condition)
167
- **Actual:** CAUGHT (flagged as violation)
168
-
169
- **Analysis:**
170
- - Current code only checks for simple `UnaryOp(Not)` with `settings.DEBUG`
171
- - Doesn't handle `BoolOp` (and/or) expressions
172
- - This is arguably correct behavior - keeps the check simple and strict
173
-
174
- **Recommendation:** Document this limitation. Developers should use:
175
- ```python
176
- if not settings.DEBUG:
177
- raise CommandError("...")
178
- # Then check other conditions separately
179
- ```
180
-
181
- ---
182
-
183
- ## Additional Edge Cases Tested
184
-
185
- ### Nested Directory Structure
186
- - File in `management/commands/subdir/command.py` - NOT tested
187
- - **Recommendation:** Add test case to verify path matching works with subdirectories
188
-
189
- ### File Encoding Issues
190
- - Files with syntax errors - Handled gracefully (returns empty violations)
191
- - Files that don't exist - Handled with error message
192
-
193
- ### Multiple Commands in One File
194
- - NOT tested
195
- - **Recommendation:** Add test case with multiple Command classes in one file
196
-
197
- ---
198
-
199
- ## Recommended Priority Fixes
200
-
201
- 1. **HIGH PRIORITY:** Fix GAP #2 (positive DEBUG check pattern)
202
- - Current behavior rejects valid code
203
- - Breaking change for developers using this pattern
204
-
205
- 2. **MEDIUM PRIORITY:** Fix GAP #1 (case-sensitive skip decorators)
206
- - Low probability but easy to fix
207
- - Prevents trivial evasion
208
-
209
- 3. **LOW PRIORITY:** Add test for nested management commands
210
- - Verify path matching works with subdirectories
211
-
212
- ---
213
-
214
- ## Test Coverage Summary
215
-
216
- **Skip Decorators:**
217
- - Simple decorators: TESTED
218
- - Attribute decorators: TESTED
219
- - Called decorators: TESTED
220
- - Case variations: **GAP FOUND**
221
- - Custom decorators: TESTED (correctly allowed)
222
-
223
- **DEBUG Guards:**
224
- - No check: TESTED
225
- - Negative check (`if not`): TESTED
226
- - Positive check (`if ... else`): **GAP FOUND**
227
- - Imported DEBUG: TESTED (correctly rejected)
228
- - Helper function: TESTED (correctly rejected)
229
- - Late check (>5 statements): TESTED (correctly rejected)
230
- - Path matching: TESTED
231
- - Complex boolean: TESTED (debatable behavior)
232
-
233
- ---
234
-
235
- ## Files Created for Testing
236
-
237
- ### Skip Decorators (9 files)
238
- ```
239
- test_files/skip_decorators/
240
- ├── test_01_simple_skip.py
241
- ├── test_02_pytest_skipif.py
242
- ├── test_03_unittest_skipIf.py
243
- ├── test_04_skip_with_parens.py
244
- ├── test_05_xfail.py
245
- ├── test_06_custom_skip.py
246
- ├── test_07_capital_Skip.py (GAP)
247
- ├── test_08_skipUnless.py
248
- └── test_09_pytest_mark_skip_simple.py
249
- ```
250
-
251
- ### Management Commands (9 files)
252
- ```
253
- test_files/management/commands/
254
- ├── cmd_01_no_debug_check.py
255
- ├── cmd_02_proper_debug_check.py
256
- ├── cmd_03_debug_check_with_return.py
257
- ├── cmd_04_imported_DEBUG.py
258
- ├── cmd_05_debug_check_in_helper.py
259
- ├── cmd_06_debug_check_late.py
260
- ├── cmd_07_positive_debug_check.py (GAP)
261
- ├── cmd_08_debug_with_and.py
262
- test_files/
263
- └── not_management_command.py
264
- ```
265
-
266
- ---
267
-
268
- ## Conclusion
269
-
270
- The validator is **mostly effective** but has **2 critical gaps**:
271
-
272
- 1. **Case-sensitive decorator matching** - Easy fix, low impact
273
- 2. **Positive DEBUG check rejection** - HIGH PRIORITY, rejects valid code
274
-
275
- The implementation correctly handles:
276
- - Most skip decorator patterns
277
- - Simple DEBUG guard patterns
278
- - Path filtering for management commands
279
- - Graceful error handling
280
-
281
- **Overall Assessment: 82% effective (14/17 test cases passed)**
282
-
283
- **Action Required:**
284
- 1. Fix GAP #2 immediately (breaking valid code)
285
- 2. Fix GAP #1 for completeness
286
- 3. Add test for nested management command directories
287
- 4. Document the complex boolean limitation
@@ -1,5 +0,0 @@
1
- """Shared constants for the validators package."""
2
-
3
- # pragma: no-tdd-gate
4
-
5
- DEFAULT_BASE_BRANCH_WHEN_UNKNOWN = "main"
@@ -1,12 +0,0 @@
1
- """Behavioral tests for the host-aware code-review invoker constants module."""
2
-
3
- from __future__ import annotations
4
-
5
- from dev_env_scripts_constants import code_review_constants as review_constants
6
-
7
-
8
- def test_default_effort_is_a_known_token() -> None:
9
- assert (
10
- review_constants.DEFAULT_CODE_REVIEW_EFFORT
11
- in review_constants.ALL_EFFORT_TOKENS_IN_ASCENDING_ORDER
12
- )
@@ -1,80 +0,0 @@
1
- """Specifications for the permission modes the review binary is asked for.
2
-
3
- The review binary accepts one permission mode for an ordinary caller and a
4
- different one for root. Naming the wrong mode means the binary refuses the
5
- call, no review runs, and no stamp is ever minted.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import importlib
11
- import os
12
-
13
- import pytest
14
-
15
- from dev_env_scripts_constants import code_review_constants
16
-
17
-
18
- BYPASS_MODE_TOKEN: str = "bypassPermissions"
19
- ACCEPT_EDITS_MODE_TOKEN: str = "acceptEdits"
20
- ROOT_USER_ID: int = 0
21
- UNPRIVILEGED_USER_ID: int = 1000
22
-
23
-
24
- def _permission_mode_seen_by(
25
- monkeypatch: pytest.MonkeyPatch, effective_user_id: int
26
- ) -> str:
27
- """Read the review permission mode a caller with this user id resolves."""
28
- monkeypatch.setattr(os, "geteuid", lambda: effective_user_id)
29
- reloaded_constants = importlib.reload(code_review_constants)
30
- return str(reloaded_constants.REVIEW_PERMISSION_MODE)
31
-
32
-
33
- def test_root_detection_agrees_with_this_process(
34
- monkeypatch: pytest.MonkeyPatch,
35
- ) -> None:
36
- monkeypatch.setattr(os, "geteuid", lambda: ROOT_USER_ID)
37
- reloaded_constants = importlib.reload(code_review_constants)
38
-
39
- assert reloaded_constants.IS_ROOT_CALLER is True
40
- assert reloaded_constants.ROOT_EFFECTIVE_USER_ID == ROOT_USER_ID
41
-
42
-
43
- def test_bypass_mode_names_the_token_the_binary_reads() -> None:
44
- assert code_review_constants.PERMISSION_MODE_BYPASS == BYPASS_MODE_TOKEN
45
-
46
-
47
- def test_accept_edits_mode_names_the_token_the_binary_reads() -> None:
48
- assert code_review_constants.PERMISSION_MODE_ACCEPT_EDITS == ACCEPT_EDITS_MODE_TOKEN
49
-
50
-
51
- def test_a_root_caller_resolves_the_mode_the_binary_accepts(
52
- monkeypatch: pytest.MonkeyPatch,
53
- ) -> None:
54
- assert _permission_mode_seen_by(monkeypatch, ROOT_USER_ID) == (
55
- ACCEPT_EDITS_MODE_TOKEN
56
- )
57
-
58
-
59
- def test_an_ordinary_caller_resolves_the_bypass_mode(
60
- monkeypatch: pytest.MonkeyPatch,
61
- ) -> None:
62
- assert _permission_mode_seen_by(monkeypatch, UNPRIVILEGED_USER_ID) == (
63
- BYPASS_MODE_TOKEN
64
- )
65
-
66
-
67
- def test_a_platform_without_a_user_id_still_loads_the_constants(
68
- monkeypatch: pytest.MonkeyPatch,
69
- ) -> None:
70
- """Windows exposes no ``os.geteuid``, and the module still imports.
71
-
72
- Reading a missing ``os.geteuid`` raises, and every caller of the review
73
- invoker dies at import. A platform that reports no user id is never the
74
- root the review binary refuses, so it reads as an ordinary caller.
75
- """
76
- monkeypatch.delattr(os, "geteuid", raising=False)
77
- reloaded_constants = importlib.reload(code_review_constants)
78
-
79
- assert reloaded_constants.IS_ROOT_CALLER is False
80
- assert reloaded_constants.REVIEW_PERMISSION_MODE == BYPASS_MODE_TOKEN