stack/apps/e2e/tests/backend/endpoints/api/v1
Armaan Jain 81723c3d55
Usage page performance improvements (#1650)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/hexclave/hexclave/blob/dev/CONTRIBUTING.md

-->

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Speed up the Usage page by aggregating metered usage across owned
projects/tenancies with fewer queries and new indexes. Adds E2E tests to
verify team-owned rollups and calendar‑month windows.

- **Performance**
- Added concurrent indexes for `EmailOutbox(tenancyId,
startedSendingAt)` and `SessionReplay(tenancyId, startedAt)`; updated
Prisma schema.
- Group tenancies by (DB client, schema) and run one SQL per group that
counts both emails and session replays; uses `mapWithConcurrency` from
`@hexclave/shared` (concurrency 4, aborts on first error).
- Added helpers `getOwnedProjectAndTenancyIdsForBillingTeam` and
`getNonAnonymousUserCountForTenancies`; made `mapWithConcurrency`
null‑safe with bounds checks.

- **Tests**
- Added E2E tests for the internal plan-usage endpoint covering
team-owned rollups, calendar‑month boundaries, and zero‑usage cases.
- Added unit tests for ownership scope resolution and non‑anonymous user
counting.

<sup>Written for commit 5d6098006c.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/1650?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Performance Improvements**
* Improved plan usage rollups by aggregating metered emails and session
replays together across an owned scope.
* Added database indexes to speed up time-window metering lookups for
email outbox and session replays.
* **Tests**
* Extended unit tests for billing-team entitlement aggregation and
non-anonymous user counting.
* Added end-to-end coverage for the internal plan-usage endpoint,
including seeded scenarios and period validation.
* **Refactor**
* Reworked entitlement and usage calculations to reuse shared logic for
more consistent results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: armaan <armaan@stack-auth.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-24 12:25:20 -07:00
..
__snapshots__ Fix dev CI: docker prune missing template + cross-domain test failures (#1582) 2026-06-11 17:37:11 -07:00
auth fix: return 409 instead of 500 when signing up with duplicate email (#1637) 2026-06-22 17:29:08 -07:00
contact-channels feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
emails User ID filter for email outbox 2026-06-17 13:39:26 -07:00
integrations Rename STACK_* env vars to HEXCLAVE_* in env templates, with legacy dual-read (#1588) 2026-06-19 18:58:53 -07:00
internal Usage page performance improvements (#1650) 2026-06-24 12:25:20 -07:00
payments Better UX around hosted component errors 2026-06-04 17:27:04 -07:00
ai-query.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
analytics-config.test.ts Queries view (#1145) 2026-02-16 11:39:21 -08:00
analytics-events-batch.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
analytics-events.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
analytics-query.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
api-keys.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
auth-flows.test.ts Fix tests 2025-07-16 11:42:25 -07:00
check-feature-support.test.ts More backend endpoint implementations (#126) 2024-07-13 22:04:53 -07:00
connected-accounts.test.ts Fix GH tokens refresh & devtool tabs 2026-05-25 17:50:09 -07:00
data-vault.test.ts Speed up tests (#1063) 2025-12-28 11:25:04 -08:00
email-themes.test.ts feat(hexclave): PR 2 — visible rebrand (Hexclave brand goes public) (#1481) 2026-05-26 19:18:20 -07:00
external-db-sync-advanced.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
external-db-sync-basics.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
external-db-sync-high-volume.test.ts Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
external-db-sync-race.test.ts feat(hexclave): PR 1 — wire compatibility layer (invisible) (#1475) 2026-05-23 17:24:55 -07:00
external-db-sync-utils.ts feat(hexclave): PR 1 — wire compatibility layer (invisible) (#1475) 2026-05-23 17:24:55 -07:00
index.test.ts Update missing docs redirects 2026-06-03 17:14:22 -07:00
internal-metrics.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
internal-user-activity.test.ts feat(analytics): add route analytics heatmaps (#1520) 2026-06-15 12:06:16 -07:00
notification-preferences.test.ts Speed up tests (#1063) 2025-12-28 11:25:04 -08:00
oauth-providers.test.ts Fix OAuth provider disablement 2026-02-24 12:43:41 -08:00
project-permission-definitions.test.ts Config DB migration step 2 (#629) 2025-04-29 14:52:45 -07:00
project-permissions.test.ts Fix flaky tests and preexisting CI failures (#1443) 2026-05-20 10:00:11 -07:00
projects.test.ts Update missing docs redirects 2026-06-03 17:14:22 -07:00
render-email.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
restricted-users.test.ts Sign up rules (#1138) 2026-02-03 11:08:24 -08:00
risk-scores.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
send-email.test.ts feat(hexclave): PR 2 — visible rebrand (Hexclave brand goes public) (#1481) 2026-05-26 19:18:20 -07:00
session-replays.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
stripe-webhooks.test.ts feat(payments): quick-ack + idempotent webhooks (#1664) 2026-06-24 09:30:38 -07:00
support.test.ts [Apps] Adding support app alpha and dogfooding (#1368) 2026-05-13 11:36:11 -05:00
team-invitations.test.ts Improved PKCE support 2026-06-11 10:28:14 -07:00
team-member-profiles.test.ts Speed up tests (#1063) 2025-12-28 11:25:04 -08:00
team-memberships.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
team-permission-definitions.test.ts refactor(dashboard): unify AI chat surfaces on assistant-ui Thread (#1427) 2026-05-15 14:21:00 -07:00
team-permissions.test.ts Fix flaky tests and preexisting CI failures (#1443) 2026-05-20 10:00:11 -07:00
teams.test.ts feat(hexclave): PR 1 — wire compatibility layer (invisible) (#1475) 2026-05-23 17:24:55 -07:00
token-refresh-events.test.ts feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482) 2026-05-29 15:21:59 -07:00
unsubscribe-link.test.ts feat(hexclave): PR 1 — wire compatibility layer (invisible) (#1475) 2026-05-23 17:24:55 -07:00
users-primary-email.test.ts fix: clearer error when changing email to one already used for auth (#1569) 2026-06-15 13:55:26 -07:00
users.test.ts fix: return 409 instead of 500 when signing up with duplicate email (#1637) 2026-06-22 17:29:08 -07:00