Skip to content

fix(ui): stub useIsOrgAdmin in UsageTab tests so useCan needs no QueryClient - #36565

Merged
ryan-crabbe-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_fix_usagetab_test_queryclient
Aug 11, 2026
Merged

fix(ui): stub useIsOrgAdmin in UsageTab tests so useCan needs no QueryClient#36565
ryan-crabbe-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_fix_usagetab_test_queryclient

Conversation

@ryan-crabbe-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • ui-unit-tests is red on litellm_internal_staging itself
  • All 18 UsageTab tests fail with "No QueryClient set"
  • Every open PR inherits the red check from the base

How it solves it:

  • Stub useIsOrgAdmin, the leg of useCan that needs react-query
  • Role gating still runs through the real hasCapability

User Flow

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Commit 255d651 added useCan to UsageTab. useCan calls useIsOrgAdmin, which calls useOrganizations, a react-query hook, and the test renders UsageTab without a QueryClientProvider, so the whole suite throws before asserting anything

On origin/litellm_internal_staging (cbf85a0):

npx vitest run "src/app/(dashboard)/cost-optimization/_components/UsageTab.test.tsx"
# -> Tests  18 failed (18), every case: "No QueryClient set, use QueryClientProvider to set one"

With this fix:

npx vitest run "src/app/(dashboard)/cost-optimization/_components/UsageTab.test.tsx"
# -> Tests  18 passed (18)

The stub returns false, the value a non org admin gets, so the role-varied cases the gating commit added (Admin vs Internal User on the spend-by-tool card) still exercise the real hasCapability path

Type

✅ Test

Caveats (if any)

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

…yClient

255d651 added useCan to UsageTab, whose useIsOrgAdmin leg calls
useOrganizations (react-query), so every UsageTab test died with 'No
QueryClient set'. Stub the org-admin leg; role gating still flows through
the real hasCapability with the varied userRole.
@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the UsageTab unit-test suite by stubbing the React Query-dependent organization-admin hook while leaving the relevant role-capability checks active.

  • Adds a test-local useIsOrgAdmin mock returning the non-organization-admin state.
  • Avoids requiring a QueryClientProvider in the 18 existing UsageTab tests.
  • Preserves the real hasCapability path used by the spend-by-tool role-gating cases.

Confidence Score: 5/5

The PR appears safe to merge because the new test stub does not alter the capability outcomes covered by UsageTab.

The only gated capability in these tests is determined by the user-role branch of hasCapability, so forcing the unrelated organization-admin hook to false removes the missing-QueryClient failure while preserving the tested Admin, Internal User, Internal Viewer, and Org Admin behavior.

Important Files Changed

Filename Overview
ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/UsageTab.test.tsx Adds a narrowly scoped hook stub that removes the unintended React Query dependency without changing the authorization outcome exercised by the existing tests.

Reviews (1): Last reviewed commit: "fix(ui): stub useIsOrgAdmin in UsageTab ..." | Re-trigger Greptile

@ryan-crabbe-berri
ryan-crabbe-berri merged commit 65fbeb5 into litellm_internal_staging Aug 11, 2026
76 checks passed
@ryan-crabbe-berri
ryan-crabbe-berri deleted the litellm_fix_usagetab_test_queryclient branch August 11, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants