refactor(shared): replace vi.mock with injected dep in resolve-users#822
refactor(shared): replace vi.mock with injected dep in resolve-users#822ColeMurray wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesDependency injection for resolveUserNames
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
There was a problem hiding this comment.
Summary
Reviewed PR #822, refactor(shared): replace vi.mock with injected dep in resolve-users, by @ColeMurray. The change is limited to 2 files with 42 additions and 34 deletions, replacing module-level Vitest mocking with an optional dependency injection seam for resolveUserNames.
Critical Issues
None found.
Suggestions
None blocking. The injected dependency keeps production callers unchanged while making the test seam explicit.
Nitpicks
None.
Positive Feedback
- The production default preserves existing behavior for current callers.
- The tests now avoid module-level mocking and exercise behavior through an explicit dependency seam.
- Existing edge cases are preserved, including empty input, Slack error envelopes, thrown errors, and the
real_nameexclusion.
Questions
None.
Verification
npm test -w @open-inspect/shared: 220 tests passed across 18 files.npx tsc --noEmitinpackages/shared: passed.
Verdict
Approve.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/shared/src/slack/resolve-users.ts (1)
3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider exporting
GetUserInfoto avoid duplicating the type in tests.The test file redefines an equivalent
GetUserInfotype (resolve-users.test.tsLine 5). Exporting it here lets the test import the single source of truth, preventing the two definitions from silently diverging.♻️ Proposed change
-type GetUserInfo = (token: string, userId: string) => ReturnType<typeof defaultGetUserInfo>; +export type GetUserInfo = (token: string, userId: string) => ReturnType<typeof defaultGetUserInfo>;🤖 Prompt for 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. In `@packages/shared/src/slack/resolve-users.ts` at line 3, Export the GetUserInfo type from resolve-users so the tests can import the same source of truth instead of redefining an equivalent local type. Update the type declaration near defaultGetUserInfo usage to be exported, then adjust resolve-users.test.ts to import GetUserInfo rather than duplicating its shape, keeping the test and implementation aligned if the signature changes.
🤖 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.
Nitpick comments:
In `@packages/shared/src/slack/resolve-users.ts`:
- Line 3: Export the GetUserInfo type from resolve-users so the tests can import
the same source of truth instead of redefining an equivalent local type. Update
the type declaration near defaultGetUserInfo usage to be exported, then adjust
resolve-users.test.ts to import GetUserInfo rather than duplicating its shape,
keeping the test and implementation aligned if the signature changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2f288d5e-cd4f-4395-87e8-31e8e723d858
📒 Files selected for processing (2)
packages/shared/src/slack/resolve-users.test.tspackages/shared/src/slack/resolve-users.ts
Terraform Validation Results
Pushed by: @open-inspect[bot], Action: |
What changed and why
packages/shared/src/slack/resolve-users.test.tswas usingvi.mock("./client", ...)withvi.hoistedto swap outgetUserInfoduring tests. This violates the project's testing standards, which require real seams (constructor/parameter injection, in-memory adapters) rather than module-level mocking.Approach
An optional
depsparameter was added toresolveUserNameswith a production default:{}, so all existing callers (e.g.slack-bot) continue to work without any changes.getUserInfoimported from./client.Test changes
vi.mock,vi.hoisted,vi.fn, andvi.mockedusage.viimport entirely.getUserInfofunction and passes it viadeps.Verification
npm test -w @open-inspect/shared— 220 tests pass across 18 files.npx tsc --noEmitinpackages/shared— no type errors.Created with Open-Inspect
Summary by CodeRabbit