fix(creditHelpers): use indexOf instead of findIndex in sortCrewPriority#2740
fix(creditHelpers): use indexOf instead of findIndex in sortCrewPriority#2740dougrathbone wants to merge 3 commits intoseerr-team:developfrom
Conversation
📝 WalkthroughWalkthroughChanged crew-sorting to use exact job equality for priority ranking, added unit tests covering filtering and ordering behavior, and introduced a new TypeScript path alias ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
🧹 Nitpick comments (1)
server/utils/creditHelpers.test.ts (1)
56-65: Tighten same-job assertions to ensure no entries are dropped.Current checks validate job ordering, but not explicit retention of both producer records.
Suggested test refinement
const result = sortCrewPriority(crew); + assert.equal(result.length, 3); assert.equal(result[0].job, 'Director'); assert.ok(result.slice(1).every((c) => c.job === 'Producer')); + assert.deepEqual( + result.slice(1).map((c) => c.name).sort(), + ['Producer A', 'Producer B'] + );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/utils/creditHelpers.test.ts` around lines 56 - 65, The test for sortCrewPriority doesn't assert that both Producer entries are retained; update the test (using the existing makeCrew and result variables) to assert the result includes two Producer records and that their names (e.g., 'Producer A' and 'Producer B') are present and not dropped—for example, check result.filter(r => r.job === 'Producer').length === 2 and that the set of producer names equals the expected names while still asserting the Director is first.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/utils/creditHelpers.test.ts`:
- Around line 56-65: The test for sortCrewPriority doesn't assert that both
Producer entries are retained; update the test (using the existing makeCrew and
result variables) to assert the result includes two Producer records and that
their names (e.g., 'Producer A' and 'Producer B') are present and not
dropped—for example, check result.filter(r => r.job === 'Producer').length === 2
and that the set of producer names equals the expected names while still
asserting the Director is first.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 76e8424e-9272-40e0-83cf-b1107f3dd3a8
📒 Files selected for processing (2)
server/tsconfig.jsonserver/utils/creditHelpers.test.ts
✅ Files skipped from review due to trivial changes (1)
- server/tsconfig.json
The sort comparator used findIndex with a substring predicate (job.includes(a.job)) to locate each job's rank. Since the preceding filter already guarantees every crew member's job is an exact member of priorityJobs, indexOf is correct and simpler. The substring approach is fragile: if a shorter title were ever added earlier in the list (e.g. "Pro" before "Producer"), the substring match would silently return the wrong index and mis-rank those crew members.
Adds @app/* to the server tsconfig paths so tests living under server/ can import src/ utilities without relative paths. Tests cover: priority-list filtering, empty input, sort ordering across all priority jobs, multiple crew members sharing the same job, and independent ranking of Producer, Co-Producer, and Executive Producer.
001c6bb to
08d5665
Compare
|
Good suggestion -- the test now also asserts |
|
@gauthier-th could i get help reviewing this? |
Can you provide an example where this fix is improving the sorting order of the crew of a media? |
There was a problem hiding this comment.
Pull request overview
This PR simplifies sortCrewPriority by replacing a substring-based findIndex ranking with an exact-match indexOf, and updates server TypeScript path aliases so server-side tests can import src/ utilities via @app/*.
Changes:
- Replace
findIndex(job.includes(...))withindexOf(...)insortCrewPriorityto avoid fragile substring matches. - Add a new
node:testsuite covering filtering and sorting behavior for crew job prioritization. - Extend
server/tsconfig.jsonpath mappings to include@app/*→src/*for server-side test imports.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/utils/creditHelpers.ts |
Uses indexOf for exact priority ranking, avoiding incorrect substring-based matches. |
server/utils/creditHelpers.test.ts |
Adds coverage for filtering and priority sorting behavior, including producer role distinctions. |
server/tsconfig.json |
Adds @app/* path mapping so server tests can import shared app utilities cleanly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@gauthier-th If you swap the order of Producer and Executive Producer in the priorityJobs array, a crew member with job "Producer" gets sorted at Executive Producer's rank, because "Executive Producer".includes("Producer") is true, and findIndex returns the first match. The old substring-based comparator only produces correct results by coincidence of the current list ordering. The test case "correctly ranks Producer, Co-Producer, and Executive Producer independently" demonstrates this. indexOf is the right fix - the .filter() above already guarantees exact membership, so the sort lookup should be exact too. |
Description
The sort comparator in
sortCrewPriorityusedfindIndexwith a substring predicate (job.includes(a.job)) to locate each job's priority rank. Since the preceding.filter()already guarantees every crew member's job is an exact member ofpriorityJobs,indexOfis correct and simpler.The substring approach is fragile: if a shorter title were ever added earlier in the list (e.g.
'Pro'before'Producer'), the substring match would silently return the wrong index and mis-rank those crew members.Also adds
@app/*to the server tsconfig paths so server-side tests can importsrc/utilities without relative paths.AI Disclosure: I used Claude Code to help write the tests. I reviewed and understood all generated code before submitting.
How Has This Been Tested?
New
node:testsuite atserver/utils/creditHelpers.test.tscovering:All 6 tests pass.
Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extract(no new UI strings added)