claude-dev-env 8.46.9 → 8.46.10
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.
- package/hooks/conftest.py +18 -0
- package/hooks/test_conftest.py +29 -0
- package/package.json +1 -1
package/hooks/conftest.py
CHANGED
|
@@ -18,10 +18,28 @@ _is_ephemeral_script_path = importlib.import_module("code_rules_shared").is_ephe
|
|
|
18
18
|
_EPHEMERAL_EXEMPT_DISABLE_ENVIRONMENT_VARIABLE_NAME = importlib.import_module(
|
|
19
19
|
"hooks_constants.code_rules_enforcer_constants"
|
|
20
20
|
).EPHEMERAL_EXEMPT_DISABLE_ENVIRONMENT_VARIABLE_NAME
|
|
21
|
+
_CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME = importlib.import_module(
|
|
22
|
+
"hooks_constants.harness_scratchpad_constants"
|
|
23
|
+
).CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME
|
|
21
24
|
|
|
22
25
|
_ROOT_ANCHORED_PROBE_PATH = "/tmp/scratch.py"
|
|
23
26
|
|
|
24
27
|
|
|
28
|
+
@pytest.fixture(autouse=True)
|
|
29
|
+
def isolate_from_live_session_scratchpad(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
30
|
+
"""Remove the live harness session id before each hooks test.
|
|
31
|
+
|
|
32
|
+
A Claude Code session exports ``CLAUDE_CODE_SESSION_ID``. When this checkout
|
|
33
|
+
sits inside that session's scratchpad, the scratchpad predicate classifies
|
|
34
|
+
every repository file as throwaway scratch, and the gates under test step
|
|
35
|
+
aside. Tests that exercise the scratchpad match set their own session id.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
monkeypatch: Pytest's environment-variable patcher, torn down after the test.
|
|
39
|
+
"""
|
|
40
|
+
monkeypatch.delenv(_CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME, raising=False)
|
|
41
|
+
|
|
42
|
+
|
|
25
43
|
@pytest.fixture
|
|
26
44
|
def ephemeral_exempt_off(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
27
45
|
"""Turn off the ephemeral scratch-path exemption for the current test.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Tests for the shared fixtures in hooks/conftest.py."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from hooks_constants.harness_scratchpad_constants import (
|
|
10
|
+
CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_live_session_id_is_absent_inside_each_test() -> None:
|
|
15
|
+
assert CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME not in os.environ
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_hook_subprocess_inherits_no_live_session_id() -> None:
|
|
19
|
+
completed = subprocess.run(
|
|
20
|
+
[
|
|
21
|
+
sys.executable,
|
|
22
|
+
"-c",
|
|
23
|
+
f"import os; print(os.environ.get('{CLAUDE_SESSION_ID_ENVIRONMENT_VARIABLE_NAME}', ''))",
|
|
24
|
+
],
|
|
25
|
+
capture_output=True,
|
|
26
|
+
text=True,
|
|
27
|
+
check=True,
|
|
28
|
+
)
|
|
29
|
+
assert completed.stdout.strip() == ""
|