Repository navigation
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
Conversation
…许碰开发机真实文件 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test hygiene, found the hard way tonight: running
tests/test_background_service_gates.pyandtests/test_harness_ownership.pyon the dev machine rewrote the real~/.claude/settings.jsonand removed the fish's nine Claude Code hooks. Those tests build a realAppShell/AgentLinkManagerwith the product defaults (Claude link on since 11-14) and then turn the link off, which since #84 uninstalls the hooks — throughClaudeCodeMonitor.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 pointsget_settings_pathat each test'stmp_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_scanfixture takestmp_pathand setsClaudeCodeMonitor.get_settings_pathtotmp_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.jsonmtime2026-11-20 00:09:40(the moment the hooks were lost) before and after runningtest_hooks_test_isolation,test_background_service_gates,test_harness_ownership,test_claude_hooks_missing,test_agent_link,test_claude_link,test_app_rename_migrationon 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 testsandgit diff --checkclean. Full suite not run: conftest change only touches the fixture every test already runs; no product code changed.Docs
🤖 Generated with Claude Code