Skip to content

Commit 8178ebf

Browse files
committed
test(core): add iterm2 session preservation and restore assertions
- add test_dedup_preserves_iterm2_session_id to verify timestamp rewrites keep session id - enhance tab notification test to verify osascript restore in execute chain - update tests.context.md with new test count (71 total, 62 core)
1 parent 84ba285 commit 8178ebf

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

tests/test_core.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ def test_notify_sent_when_same_iterm2_window_but_different_tab(self, tmp_path):
524524
]
525525
assert len(terminal_notifier_calls) >= 1
526526

527+
# Verify iTerm2 restore script is included in -execute chain
528+
execute_args = terminal_notifier_calls[0]
529+
execute_idx = execute_args.index("-execute")
530+
assert "osascript" in execute_args[execute_idx + 1]
531+
assert "w0t0p0" in execute_args[execute_idx + 1]
532+
527533
def test_cleanup_workflow_removes_session(self, tmp_path):
528534
"""Test complete cleanup workflow: JSON input → real age-based file cleanup."""
529535
test_input = {"session_id": "cleanup123"}
@@ -585,6 +591,20 @@ def test_wrapper_performance(self):
585591
f"Wrapper took {duration_ms:.1f}ms, expected <{MAX_WRAPPER_DURATION_MS}ms"
586592
)
587593

594+
def test_dedup_preserves_iterm2_session_id(self, tmp_path):
595+
"""check_deduplication must preserve the iTerm2 session ID on rewrite."""
596+
session_dir = tmp_path / "cc_notifier"
597+
session_dir.mkdir()
598+
session_file = session_dir / "dedup-iterm"
599+
# Timestamp old enough to bypass the dedup window
600+
session_file.write_text("win123\n/Applications/iTerm.app\n0\n$20\nw0t1p0")
601+
602+
assert cc_notifier.check_deduplication(session_file) is False
603+
604+
lines = session_file.read_text().strip().split("\n")
605+
assert len(lines) == 5
606+
assert lines[4] == "w0t1p0"
607+
588608
def test_file_locking_prevents_race_conditions(self, tmp_path):
589609
"""Test file locking prevents race conditions between concurrent processes."""
590610
# Setup session file with 4-line format

tests/tests.context.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Associated with: all tests in the codebase
88

99
**Format**: `test_name` - [concise description of what's being tested] - [rationale for why test is needed]
1010

11-
**Status**: **70 total tests** (61 core + 9 integration) across 2 files - All tests properly accounted for and documented
11+
**Status**: **71 total tests** (62 core + 9 integration) across 2 files - All tests properly accounted for and documented
1212

1313
**Structure**: Tests are organized by functionality and concerns, emphasizing behavior-focused testing over implementation details. The 2-file structure matches the natural architectural boundary between core logic and external system integration.
1414

1515
---
1616

17-
## test_core.py (59 tests) - Core Functionality & Essential Business Logic
17+
## test_core.py (62 tests) - Core Functionality & Essential Business Logic
1818

1919
### TestCLIInterface (9 tests) - Essential CLI Contract Testing
2020
- `test_main_with_no_args_exits_with_error` - CLI error handling when no command provided - CLI must provide helpful usage info and exit gracefully
@@ -27,7 +27,7 @@ Associated with: all tests in the codebase
2727
- `test_main_blocks_direct_execution_without_wrapper_env` - Prevents direct execution without wrapper environment variable - Critical for preventing Claude Code hooks from blocking
2828
- `test_main_allows_execution_with_wrapper_env` - Allows execution when wrapper environment variable is set - Ensures proper wrapper integration works correctly
2929

30-
### TestCoreWorkflows (14 tests) - End-to-End Workflow Validation
30+
### TestCoreWorkflows (15 tests) - End-to-End Workflow Validation
3131
- `test_init_workflow_captures_and_saves_window` - Complete init workflow from JSON input to file creation including tmux session ID - End-to-end validation of session initialization
3232
- `test_init_workflow_without_hammerspoon` - Init falls back to UNAVAILABLE but still captures tmux session ID - Validates graceful degradation
3333
- `test_init_workflow_captures_iterm2_session_id` - Init captures iTerm2 focused session ID alongside window metadata - Enables same-window tab restoration for iTerm2
@@ -40,6 +40,7 @@ Associated with: all tests in the codebase
4040
- `test_wrapper_performance` - Bash wrapper returns immediately without waiting for Python - Critical for non-blocking hook execution in Claude Code
4141
- `test_notify_sent_when_same_window_but_tmux_detached` - Notify sends notification when same window but user switched tmux sessions - Detects intra-window tmux session switches
4242
- `test_notify_sent_when_same_iterm2_window_but_different_tab` - Notify sends local notification when iTerm2 tab changed in same window - Enables tab-level away detection in iTerm2
43+
- `test_dedup_preserves_iterm2_session_id` - check_deduplication preserves iTerm2 session ID on timestamp rewrite - Prevents silent loss of tab restore on second-and-later notifications
4344
- `test_file_locking_prevents_race_conditions` - File locking prevents race conditions and preserves tmux session ID - Essential for preventing duplicate notifications
4445
- `test_push_uses_extended_intervals_when_tmux_attached_desktop` - Desktop mode uses extended idle check intervals when tmux attached - Ensures attached tmux sessions use attached idle check intervals
4546

0 commit comments

Comments
 (0)