Skip to content

Commit ad4e2a2

Browse files
fix: add cli/__main__.py + wrapper integration tests
The session dir wrapper calls `python -m studyctl.cli` which requires __main__.py in the cli package. Without it, Claude's studyctl topic calls fail with "No module named studyctl.cli.__main__". Added 3 wrapper-specific integration tests that use the actual session directory's studyctl wrapper (same path Claude Code uses), not uv run --project. These would have caught this bug. 25 integration tests now pass covering: creation, sidebar, cleanup, resume, error handling, and wrapper script correctness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 602bebf commit ad4e2a2

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Allow running studyctl CLI via ``python -m studyctl.cli``."""
2+
3+
from studyctl.cli import cli
4+
5+
cli()

‎packages/studyctl/tests/test_study_integration.py‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ def _make_mock_agent(tmp_path: Path, *, name: str = "mock-agent.sh") -> str:
146146
return str(script)
147147

148148

149+
def _make_wrapper_agent(tmp_path: Path) -> str:
150+
"""Create a mock agent that uses the session dir's studyctl wrapper.
151+
152+
This is the realistic test — Claude Code calls ``studyctl topic``
153+
which resolves to the wrapper script at ``$SESSION_DIR/studyctl``.
154+
If the wrapper is broken (e.g. missing __main__.py), this fails.
155+
"""
156+
script = tmp_path / "wrapper-agent.sh"
157+
script.write_text(
158+
textwrap.dedent("""\
159+
#!/bin/bash
160+
# Wrapper agent: uses the studyctl wrapper from the session dir
161+
# (same as what Claude Code does in a real session)
162+
sleep 2
163+
studyctl topic "Wrapper Test" --status learning --note "via wrapper"
164+
sleep 1
165+
studyctl park "Does the wrapper actually work?"
166+
# Wait for exit
167+
trap 'exit 0' INT TERM
168+
while true; do sleep 1; done
169+
""")
170+
)
171+
script.chmod(0o755)
172+
return str(script)
173+
174+
149175
def _make_fast_agent(tmp_path: Path) -> str:
150176
"""Create a minimal agent that exits quickly (for cleanup/resume tests)."""
151177
script = tmp_path / "fast-agent.sh"
@@ -537,3 +563,56 @@ def test_double_start_blocked(self, tmp_path):
537563
env_overrides={"STUDYCTL_TEST_AGENT_CMD": f"bash {agent2} {{persona_file}}"},
538564
)
539565
assert "already active" in result.stdout
566+
567+
568+
# ---------------------------------------------------------------------------
569+
# Test: Wrapper Script (realistic agent interaction)
570+
# ---------------------------------------------------------------------------
571+
572+
573+
class TestWrapperScript:
574+
"""Verify the studyctl wrapper in the session directory works.
575+
576+
This is the most realistic test — the mock agent calls ``studyctl``
577+
which resolves to the wrapper script at ``$SESSION_DIR/studyctl``,
578+
exactly as Claude Code does in a real study session. If the wrapper
579+
is broken (missing __main__.py, wrong Python path, etc.), these fail.
580+
"""
581+
582+
def test_wrapper_agent_can_log_topics(self, tmp_path):
583+
"""Agent using session dir wrapper can call studyctl topic."""
584+
agent = _make_wrapper_agent(tmp_path)
585+
_start_session(agent)
586+
587+
_wait_for(
588+
lambda: TOPICS_FILE.exists() and "Wrapper Test" in TOPICS_FILE.read_text(),
589+
timeout=15,
590+
desc="topic logged via session dir wrapper",
591+
)
592+
assert "status:learning" in TOPICS_FILE.read_text()
593+
594+
def test_wrapper_agent_can_park_topics(self, tmp_path):
595+
"""Agent using session dir wrapper can call studyctl park."""
596+
agent = _make_wrapper_agent(tmp_path)
597+
_start_session(agent)
598+
599+
_wait_for(
600+
lambda: PARKING_FILE.exists() and PARKING_FILE.stat().st_size > 0,
601+
timeout=15,
602+
desc="parked topic via session dir wrapper",
603+
)
604+
assert "wrapper" in PARKING_FILE.read_text().lower()
605+
606+
def test_wrapper_script_exists_and_executable(self, tmp_path):
607+
"""The studyctl wrapper is created in the session dir."""
608+
agent = _make_wrapper_agent(tmp_path)
609+
info = _start_session(agent)
610+
611+
wrapper = Path(info["session_dir"]) / "studyctl"
612+
assert wrapper.exists()
613+
assert os.access(wrapper, os.X_OK)
614+
615+
# Wrapper should point to a valid Python
616+
content = wrapper.read_text()
617+
assert "python" in content.lower()
618+
assert "-m studyctl.cli" in content

0 commit comments

Comments
 (0)