Repository navigation
test(hooks): decouple resolveProject tests from checkout directory name - #1138
Conversation
test/hook-project.test.ts asserted that resolveProject() returns the literal "agentmemory", which only holds when the repository is cloned into a directory named exactly "agentmemory". Any fork, worktree or rename made five tests fail on a clean checkout, blocking the "npm test must pass" gate in CONTRIBUTING.md. Run the git-toplevel cases against a throwaway repo created under tmpdir() with a name the test controls, and stub process.cwd() with vi.spyOn for the cwd-fallback cases. The assertions still exercise the real behaviour: dropping the git-toplevel branch or the process.cwd() default from resolveProject() still fails the suite. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
|
@dmazhukov is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe tests now create a temporary initialized Git repository with a controlled basename. They validate Git-root, nested-directory, fallback-basename, environment override, and default-directory behavior without depending on the checkout directory name. ChangesProject resolution test portability
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/hook-project.test.ts`:
- Line 14: Update the test cleanup in the hook-project suite’s afterEach block
to restore process.env.AGENTMEMORY_PROJECT_NAME from the captured originalEnv
value after each test, while retaining the existing Vitest mock cleanup.
- Around line 69-75: Update the fallback fixture in the resolveProject test so
Git cannot discover a parent worktree: create it outside any repository or
temporarily set and restore GIT_CEILING_DIRECTORIES around the assertion,
ensuring cleanup and environment restoration occur in all cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 42801fd0-9518-4f98-a6d3-05db21d6ea4a
📒 Files selected for processing (1)
test/hook-project.test.ts
The fallback case created its fixture under os.tmpdir() and assumed that is outside any repository. It is not guaranteed: with TMPDIR pointing at a working directory, git rev-parse walks up from the fixture, finds the enclosing repo and returns its basename, so the fallback under test never runs. Verified by pointing TMPDIR at a checkout — the assertion failed with the repository's name in place of the fixture's. Set GIT_CEILING_DIRECTORIES to the fixture's parent for the duration of the assertion and restore it afterwards. The path is resolved first because git compares ceiling entries after resolving symlinks, and os.tmpdir() is a symlink on macOS. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
The managed-hook assertion matched the substring 'agentmemory', which only holds when the repo is cloned into a directory literally named agentmemory; worktrees and fork checkouts with other names failed it. Assert the <pluginRoot>/scripts/<hook>.mjs command shape instead — same decoupling upstream applied to resolveProject tests in rohitg00#1138.
Fixes #1137.
test/hook-project.test.tsasserted thatresolveProject()returns the literal string"agentmemory". SinceresolveProject()returnsbasename(git rev-parse --show-toplevel), that holds only when the working copy lives in a directory named exactlyagentmemory, so 5 of the 8 tests fail on a cleanmainfor anyone working in a fork or a worktree under a different name.The tests now use a fixture they control instead of the checkout path.
src/hooks/_project.tsis unchanged.beforeAllcreates a repo underos.tmpdir()namedamem-fixture-repowith a nestedsrc/hookssubdirectory and runsgit init --quietin it. The git-toplevel cases resolve against that repo, so the expected name is one the test picked.process.cwd()" cases stub the call withvi.spyOn(process, "cwd").mockReturnValue(repoDir)and restore it inafterEach. They still check thatresolveProject()consultsprocess.cwd()when given no argument, an empty string, or whitespace.basename(dir)fromnode:pathinstead ofdir.split("/").pop().Deriving the expected value from
basename(process.cwd())would have been shorter, but then the test would compute its expectation the same way the implementation does and could never fail. The tmpdir fixture keeps the two independent.How to verify
Clone into a directory not named
agentmemoryand run the file before and after this change to see the original failure.To check the tests still bite, I broke
src/hooks/_project.tstwo ways and reverted both:if (top) return basename(top);fails "returns git toplevel basename from a nested subdir" (expected 'hooks' to be 'amem-fixture-repo')process.cwd()default with a literal path fails both "defaults toprocess.cwd()" testsSummary by CodeRabbit