DeepSeek V4.1 Flash · Heavy

feat-convert-insightsbookingservice-to-use-prisma-sql-raw-queries-cal-com

cal.com · TypeScript · M · 100–299 lines · 1 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
1 of 3
Comments published
4
Comments matching a bug
1
Comments not matching
3
Cost of this PR
$0.273

Published comments (4)

mediumbugpackages/lib/server/service/insightsBooking.ts:29-34

Public options type makes teamId optional, losing compile-time safety — A `team`-scope call that omits `teamId` now compiles and silently returns zero rows via `insightsBookingServiceOptionsSchema.safeParse`. Keep the constructor parameter typed as `InsightsBookingServiceOptions` and make `teamId` required for the `team` variant.

mediumbugpackages/lib/server/service/__tests__/insightsBooking.integration-test.ts:332-343

Org-scope test assertion depends on unordered array order — `TeamRepository.findAllByParentId` and `MembershipRepository.findAllByTeamIds` use no `orderBy`, so Postgres can return rows in any order and this assertion flaps. Assert the `teamIds` and `userIds` arrays order-independently, or add `orderBy` to the repositories.

mediumbugpackages/lib/server/service/__tests__/insightsBooking.integration-test.ts:426-434

Restore deleted caching tests for authorization and filter conditions — Deleting this block leaves no test that calls `getAuthorizationConditions()` or `getFilterConditions()` twice, so a broken memoization in `cachedAuthConditions` or `cachedFilterConditions` would pass CI. Restore both tests against the new `Prisma.Sql` return type.

mediumbugpackages/lib/server/service/__tests__/insightsBooking.integration-test.ts:295-299

Prisma.sql assertions compare internal structure instead of SQL — `toEqual` against a `Prisma.sql` template deep-compares the internal `strings`/`values` arrays, and the nested `conditions.reduce` templates partition `strings` differently, so the assertion can mismatch. Compare `conditions.sql` and `conditions.values` instead. **Also found in:** - `packages/lib/server/service/__tests__/insightsBooking.integration-test.ts:429-431`

Gold bugs found (1)

mediumThe new public options type makes teamId optional for team scope, so a missing teamId compiles and silently yields empty insights instead of a type error.

Gold bugs missed (2)

mediumThe getBaseConditions test uses a single booking matching both auth and filter conditions, so it would pass even if the conditions were not combined.
highClaims getBaseConditions returns OR fragments without parentheses, so a caller appending `AND <extra>` would leak rows outside the authorization scope.