Skip to content

Commit b9b393a

Browse files
committed
refactor: Replace magic strings in phase2 tests (Fix 2/10)
- Uses TestDefaults.SESSION_ID instead of 'abc123' - Tests still pass (89/89 in phase2) - No API changes - Magic strings reduced: ~30 → 25
1 parent dcb34a8 commit b9b393a

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

tests/test_phase2/conftest.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010

1111
import orjson
1212
import pytest
13+
from tests.constants import TestDefaults
1314

1415
# Real hook JSON samples from Claude Code documentation
1516
HOOK_SAMPLES = {
1617
"PreToolUse": {
17-
"session_id": "abc123",
18+
"session_id": TestDefaults.SESSION_ID,
1819
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
1920
"cwd": "/Users/test/project",
2021
"hook_event_name": "PreToolUse",
2122
"tool_name": "Write",
2223
"tool_input": {"file_path": "/test.txt", "content": "test content"},
2324
},
2425
"PostToolUse": {
25-
"session_id": "abc123",
26+
"session_id": TestDefaults.SESSION_ID,
2627
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
2728
"cwd": "/Users/test/project",
2829
"hook_event_name": "PostToolUse",
@@ -31,42 +32,42 @@
3132
"tool_response": {"output": "file1.txt\nfile2.txt", "success": True},
3233
},
3334
"UserPromptSubmit": {
34-
"session_id": "abc123",
35+
"session_id": TestDefaults.SESSION_ID,
3536
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
3637
"cwd": "/Users/test/project",
3738
"hook_event_name": "UserPromptSubmit",
3839
"prompt": "Write a function to calculate factorial",
3940
},
4041
"Stop": {
41-
"session_id": "abc123",
42+
"session_id": TestDefaults.SESSION_ID,
4243
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
4344
"cwd": "/Users/test/project",
4445
"hook_event_name": "Stop",
4546
"stop_hook_active": False,
4647
},
4748
"SubagentStop": {
48-
"session_id": "abc123",
49+
"session_id": TestDefaults.SESSION_ID,
4950
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
5051
"cwd": "/Users/test/project",
5152
"hook_event_name": "SubagentStop",
5253
"stop_hook_active": False,
5354
},
5455
"Notification": {
55-
"session_id": "abc123",
56+
"session_id": TestDefaults.SESSION_ID,
5657
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
5758
"cwd": "/Users/test/project",
5859
"hook_event_name": "Notification",
5960
"message": "Claude needs your permission to use Bash",
6061
},
6162
"SessionStart": {
62-
"session_id": "abc123",
63+
"session_id": TestDefaults.SESSION_ID,
6364
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
6465
"cwd": "/Users/test/project",
6566
"hook_event_name": "SessionStart",
6667
"source": "startup",
6768
},
6869
"PreCompact": {
69-
"session_id": "abc123",
70+
"session_id": TestDefaults.SESSION_ID,
7071
"transcript_path": "/Users/test/.claude/projects/test/session.jsonl",
7172
"cwd": "/Users/test/project",
7273
"hook_event_name": "PreCompact",

tests/test_phase2/test_hook_input.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import pytest
12+
from tests.constants import TestDefaults
1213

1314

1415
def test_hook_input_parses_valid_json(mock_stdin, hook_sample):
@@ -21,7 +22,7 @@ def test_hook_input_parses_valid_json(mock_stdin, hook_sample):
2122
with mock_stdin(test_data):
2223
data = hook_input()
2324

24-
assert data.session_id == "abc123"
25+
assert data.session_id == TestDefaults.SESSION_ID
2526
assert data.hook_event_name == "PreToolUse"
2627
assert data.tool_name == "Write"
2728
assert data.tool_input["file_path"] == "/test.txt"
@@ -38,7 +39,7 @@ def test_hook_input_all_hook_types(mock_stdin, hook_sample, all_hook_types):
3839
data = hook_input()
3940

4041
assert data.hook_event_name == hook_type
41-
assert data.session_id == "abc123"
42+
assert data.session_id == TestDefaults.SESSION_ID
4243

4344

4445
def test_hook_input_invalid_json(mock_stdin, capsys):
@@ -127,7 +128,7 @@ def test_hook_input_performance(mock_stdin, hook_sample, performance_timer):
127128

128129
# Should be very fast - just JSON parsing and validation
129130
assert timer.elapsed < 0.01 # 10ms
130-
assert data.session_id == "abc123"
131+
assert data.session_id == TestDefaults.SESSION_ID
131132

132133

133134
def test_hook_input_validates_hook_type(mock_stdin, capsys):

tests/test_phase2/test_hook_models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import pytest
12+
from tests.constants import TestDefaults
1213

1314

1415
def test_single_model_all_hooks(hook_sample, all_hook_types):
@@ -21,7 +22,7 @@ def test_single_model_all_hooks(hook_sample, all_hook_types):
2122

2223
# Core fields always present
2324
assert data.hook_event_name == hook_type
24-
assert data.session_id == "abc123"
25+
assert data.session_id == TestDefaults.SESSION_ID
2526
assert data.transcript_path == "/Users/test/.claude/projects/test/session.jsonl"
2627
assert data.cwd == "/Users/test/project"
2728

0 commit comments

Comments
 (0)