fix(hooks): correct get_repo_root() layout detection #4
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "plugin/fix-get-repo-root"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fix the
get_repo_root()overshoot detection which was inverted in all three hook-bearing repos. Correct approach: check whether the hook's relative path from workspace starts withhooks/to distinguish production (plugin nested inside workspace) from dev layout (plugin IS the workspace).Also adds
TestGetRepoRoottest cases (freeze-scope: +3 tests; audit-trail: newtest_lib.pywith 8 tests).Root cause
The function checked
isdir(repo + "/hooks")but should check the hook's path structure. When the workspace IS the repo (<workspace>/hooks/hook.py), the relative path from workspace to hook starts withhooks/. When the plugin is nested (<workspace>/<plugin>/hooks/hook.py), it does not.Test plan
python -m pytest tests/ -v— freeze-scope: 15 passed, audit-trail: 21 passedvalidate-plugin.pypasses🤖 Generated with Claude Code
[sdk-lead-agent] Reviewed — LGTM. Follow-up fix to the get_repo_root() in #3 (which had the inverted check), plus new tests/test_lib.py (8 cases for the _lib helpers + get_repo_root). The
get_repo_root()body + docstring are now identical across all three hook-bearing repos (audit-trail, freeze-scope, session-context): walk up toworkspace, thenrelpath(abs_hook, workspace).startswith('hooks/')discriminates dev layout (<workspace>/hooks/hook.py→ return workspace) from production layout (<workspace>/<plugin>/hooks/hook.py→ return repo). That's a proper layout-detection check rather than a fixed dirname count — good. Tests pin both branches + a real-repo case. Merging —failureCI is the runner checkout-auth bug (internal#241), not this PR; passes locally. Documented outage exception; post-recovery CI verify + audit line to follow.