Skip to content

test(conftest): point Claude's settings.json at a temp dir in every test — turning the link off must never touch the developer's real hooks - #91

Merged
LiminCode merged 1 commit into
mainfrom
hooks-test-guard
Nov 20, 2026
Merged

LiminCode merged 1 commit into
mainfrom
hooks-test-guard

Conversation

@LiminCode

Copy link
Copy Markdown
Owner

Summary

Test hygiene, found the hard way tonight: running tests/test_background_service_gates.py and tests/test_harness_ownership.py on the dev machine rewrote the real ~/.claude/settings.json and removed the fish's nine Claude Code hooks. Those tests build a real AppShell / AgentLinkManager with the product defaults (Claude link on since 11-14) and then turn the link off, which since #84 uninstalls the hooks — through ClaudeCodeMonitor.get_settings_path(), i.e. the developer's real home. The existing conftest guard only stopped the read (CHECK_HOOKS_PRESENT), not the write. Now the same autouse fixture points get_settings_path at each test's tmp_path (no extra autouse fixture: the full-suite native crash note in the conftest comment still applies); tests that exercise install/uninstall keep overriding it with their own file as before.

What changed and why

  • tests/conftest.py: the existing _no_real_session_history_scan fixture takes tmp_path and sets ClaudeCodeMonitor.get_settings_path to tmp_path / "claude-home" / "settings.json", with a comment recording why.
  • tests/test_hooks_test_isolation.py (new, 2): the path is under the test's temp dir and is not the real one; a real manager turning the Claude link on then off (the uninstall path) leaves the real file's mtime untouched.

Performance

Exempt: tests only.

Real-machine run

Real ~/.claude/settings.json mtime 2026-11-20 00:09:40 (the moment the hooks were lost) before and after running test_hooks_test_isolation, test_background_service_gates, test_harness_ownership, test_claude_hooks_missing, test_agent_link, test_claude_link, test_app_rename_migration on this branch: unchanged (306 passed, 2 skipped). The lost hooks are reinstalled by the user through the panorama's "修复" (consent, ADR 0006), not by this PR.

Tests

The new file is red on main (the default path is the real home) and green here; the seven hook-related families above pass; ruff check tests and git diff --check clean. Full suite not run: conftest change only touches the fixture every test already runs; no product code changed.

Docs

  • CHANGELOG.md: not needed (tests only)
  • Topic doc: not needed (the conftest comment is the record)
  • ADR: not needed

🤖 Generated with Claude Code

…许碰开发机真实文件

2026-11-20 凌晨跑 test_background_service_gates / test_harness_ownership 把本机 ~/.claude/settings.json 里肥鱼的 hooks 清掉了
(#84 起关联动会卸 hooks)。在既有的 autouse 总夹具里把 ClaudeCodeMonitor.get_settings_path 指到 tmp_path,不另加夹具;
加一个回归测试:真管理器把 claude 关掉,真实文件的 mtime 不变。

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@LiminCode
LiminCode merged commit f59ecc4 into main Nov 20, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant