fix(hooks): use get_repo_root() to fix __file__ overshoot bug #4

Merged
sdk-lead merged 4 commits from plugin/fix-repo-root-overshoot into main 2026-05-10 15:23:55 +00:00

4 Commits

Author SHA1 Message Date
b957f557cb fix(hooks): correct get_repo_root() layout detection via relpath
Some checks failed
CI / validate (push) Failing after 1s
CI / validate (pull_request) Failing after 1s
The overshoot detection was inverted — it returned workspace when the
workspace had hooks/, and vice versa. Both freeze-scope and audit-trail
have the same bug.

Correct approach: check whether the hook's relative path from the
workspace starts with 'hooks/'. If yes, the workspace IS the repo
(dev layout). If no, the plugin is nested inside the workspace
(production layout → return the plugin repo, which is the workspace root).

Also update docstring and test names/assertions to match corrected logic.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 15:20:54 +00:00
39f4215a74 fix(hooks): correct get_repo_root() overshoot detection
Some checks failed
CI / validate (push) Failing after 1s
CI / validate (pull_request) Failing after 1s
The overshoot detection was inverted — it checked repo/hooks instead of
workspace/hooks. This caused the function to return the workspace parent
when the plugin is installed in a workspace (normal case), instead of
the plugin repo itself. Fixed: check os.path.isdir(workspace + "/hooks")
to determine whether we walked too far.

Also:
- Update docstring to explain the production vs dev layout distinction
- Update TestGetRepoRoot: fix mock return values to match corrected logic
- Drop invalid test_real_repo_path_in_this_repo assertion (checks wrong path)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 15:18:02 +00:00
e9e6c8c501 docs(tests): add rationale README for session-context tests
Some checks failed
CI / validate (push) Failing after 2s
CI / validate (pull_request) Failing after 1s
Commit f874929 added comprehensive test coverage (test_lib.py +
test_session_start_context.py) but omitted tests/README.md. This fills that gap.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 15:09:52 +00:00
79907b1f9f fix(hooks): use get_repo_root() to fix __file__ overshoot bug
Some checks failed
CI / validate (push) Failing after 1s
CI / validate (pull_request) Failing after 1s
The hook's REPO path used three dirname() calls from __file__, which
overshoots by one level when __file__ is absolute (Claude Code invokes
hooks with absolute paths). Fix: add get_repo_root() to _lib.py and
use it in session-start-context.py.

Also:
- Add TestGetRepoRoot to tests/test_lib.py (3 new cases)
- Append .pytest_cache/ to .gitignore

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 15:07:43 +00:00