diff --git a/frontend/src/components/account/AccountUsageCell.vue b/frontend/src/components/account/AccountUsageCell.vue index e7e0a298fc..485b4b8701 100644 --- a/frontend/src/components/account/AccountUsageCell.vue +++ b/frontend/src/components/account/AccountUsageCell.vue @@ -1148,19 +1148,19 @@ const grokPlanLabelIsPaid = (value: string) => { const grokIsFree = computed(() => { if (props.account.platform !== 'grok' || props.account.type !== 'oauth') return false const billing = grokBilling.value + const plan = (billing?.plan || '').trim().toLowerCase() + const tier = (usageInfo.value?.subscription_tier || '').trim().toLowerCase() + const entitlement = (usageInfo.value?.grok_entitlement_status || '').toLowerCase() + if (grokPlanLabelIsFree(tier)) return true + if (grokPlanLabelIsPaid(tier)) return false if ( billing?.usage_percent != null || billing?.used_percent != null || (billing?.monthly_limit_cents != null && billing.monthly_limit_cents > 0) ) return false - - const plan = (billing?.plan || '').trim().toLowerCase() - const tier = (usageInfo.value?.subscription_tier || '').trim().toLowerCase() - const entitlement = (usageInfo.value?.grok_entitlement_status || '').toLowerCase() - if (grokPlanLabelIsPaid(plan) || grokPlanLabelIsPaid(tier)) return false + if (grokPlanLabelIsPaid(plan)) return false if ( grokPlanLabelIsFree(plan) || - grokPlanLabelIsFree(tier) || grokPlanLabelIsFree(entitlement) ) return true return billing != null diff --git a/frontend/src/components/account/__tests__/AccountUsageCell.spec.ts b/frontend/src/components/account/__tests__/AccountUsageCell.spec.ts index 46f3908254..ff0e94d664 100644 --- a/frontend/src/components/account/__tests__/AccountUsageCell.spec.ts +++ b/frontend/src/components/account/__tests__/AccountUsageCell.spec.ts @@ -903,6 +903,81 @@ describe('AccountUsageCell', () => { expect(wrapper.text()).not.toContain('250.0K') }) + it('Grok JWT free tier shows 24h bar even when leftover Heavy billing metrics remain', async () => { + getUsage.mockResolvedValue({ + grok_free_token_limit: 500_000, + subscription_tier: 'free', + grok_billing: { + plan: 'SuperGrok Heavy', + monthly_limit_cents: 150_000, + usage_percent: 10, + used_percent: 5 + }, + grok_local_usage_24h: { + requests: 2, + tokens: 250_000, + cost: 0, + standard_cost: 0 + } + }) + + const wrapper = mount(AccountUsageCell, { + props: { + account: makeAccount({ id: 4404, platform: 'grok', type: 'oauth', extra: {} }) + }, + global: { + stubs: { + UsageProgressBar: { + props: ['label', 'utilization'], + template: '
{{ label }}|{{ utilization }}
' + }, + AccountQuotaInfo: true + } + } + }) + + await flushPromises() + expect(wrapper.text()).toContain('24h|') + expect(wrapper.text()).not.toContain('7d|') + expect(wrapper.text()).not.toContain('30d|') + }) + + it('Grok SuperGrok Lite stays on paid 7d bar, not free 24h', async () => { + getUsage.mockResolvedValue({ + subscription_tier: 'supergrok_lite', + grok_billing: { + period_type: 'weekly', + plan: 'SuperGrok', + usage_percent: 20 + }, + grok_local_usage_24h: { + requests: 1, + tokens: 100, + cost: 0, + standard_cost: 0 + } + }) + + const wrapper = mount(AccountUsageCell, { + props: { + account: makeAccount({ id: 4405, platform: 'grok', type: 'oauth', extra: {} }) + }, + global: { + stubs: { + UsageProgressBar: { + props: ['label', 'utilization'], + template: '
{{ label }}|{{ utilization }}
' + }, + AccountQuotaInfo: true + } + } + }) + + await flushPromises() + expect(wrapper.text()).toContain('7d|') + expect(wrapper.text()).not.toContain('24h|') + }) + it('Grok credential Free tier keeps the 1M fallback when billing is unavailable', async () => { getUsage.mockResolvedValue({ grok_free_token_limit: 1_000_000, diff --git a/frontend/src/components/common/PlatformTypeBadge.vue b/frontend/src/components/common/PlatformTypeBadge.vue index d5af11f5d8..ef86879ae0 100644 --- a/frontend/src/components/common/PlatformTypeBadge.vue +++ b/frontend/src/components/common/PlatformTypeBadge.vue @@ -137,10 +137,16 @@ const planLabel = computed(() => { return props.platform === 'grok' ? 'Grok Free' : 'Free' case 'supergrok': return 'SuperGrok' + case 'supergroklite': + return 'SuperGrok Lite' + case 'supergrokplus': + return 'SuperGrok Plus' case 'supergrokheavy': return 'SuperGrok Heavy' case 'heavy': return 'Heavy' + case 'xbasic': + return 'X Basic' case 'abnormal': return t('admin.accounts.subscriptionAbnormal') default: @@ -150,7 +156,9 @@ const planLabel = computed(() => { const isGrokFreePlan = computed(() => props.platform === 'grok' && - (normalizedPlanType.value === 'free' || normalizedPlanType.value === 'basic') + (normalizedPlanType.value === 'free' || + normalizedPlanType.value === 'basic' || + normalizedPlanType.value === 'xbasic') ) const planIconName = computed<'bolt' | null>(() => { @@ -204,7 +212,11 @@ const planBadgeClass = computed(() => { return 'bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400' } // Free stays muted gray; paid Grok tiers get distinct colors. - if (normalizedPlanType.value === 'free' || normalizedPlanType.value === 'basic') { + if ( + normalizedPlanType.value === 'free' || + normalizedPlanType.value === 'basic' || + normalizedPlanType.value === 'xbasic' + ) { return 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300' } if (props.platform === 'grok' && normalizedPlanType.value) { @@ -235,7 +247,11 @@ const planBadgeClass = computed(() => { // Subscription expiration label (non-free only) const expiresLabel = computed(() => { if (!props.subscriptionExpiresAt || !props.planType) return '' - if (normalizedPlanType.value === 'free' || normalizedPlanType.value === 'basic') return '' + if ( + normalizedPlanType.value === 'free' || + normalizedPlanType.value === 'basic' || + normalizedPlanType.value === 'xbasic' + ) return '' try { const d = new Date(props.subscriptionExpiresAt) if (isNaN(d.getTime())) return '' diff --git a/frontend/src/components/common/__tests__/PlatformTypeBadge.grok.spec.ts b/frontend/src/components/common/__tests__/PlatformTypeBadge.grok.spec.ts index fc665316a8..e65c7f81de 100644 --- a/frontend/src/components/common/__tests__/PlatformTypeBadge.grok.spec.ts +++ b/frontend/src/components/common/__tests__/PlatformTypeBadge.grok.spec.ts @@ -76,6 +76,12 @@ describe('PlatformTypeBadge Grok plans', () => { expect(heavy.text()).toContain('Heavy') expect(heavy.html()).toContain('bg-purple-100') expect(heavy.find('[data-testid="grok-plan-icon"]').exists()).toBe(true) + + const lite = mount(PlatformTypeBadge, { + props: { platform: 'grok', type: 'oauth', planType: 'supergrok_lite' }, + }) + expect(lite.text()).toContain('SuperGrok Lite') + expect(lite.html()).toContain('bg-cyan-100') }) it('uses a dedicated 12px currentColor Grok mark with a Free sparkle', () => { diff --git a/frontend/src/views/admin/AccountsView.vue b/frontend/src/views/admin/AccountsView.vue index 3dfe2c2797..96e07688b4 100644 --- a/frontend/src/views/admin/AccountsView.vue +++ b/frontend/src/views/admin/AccountsView.vue @@ -1481,8 +1481,7 @@ const { pause: pauseAutoRefresh, resume: resumeAutoRefresh } = useIntervalFn( { immediate: false } ) -// Fresh billing/quota snapshots are authoritative. Imported credential tiers -// can be stale, so they remain fallbacks together with legacy plan_type fields. +// Persisted credentials.subscription_tier outranks lagging billing/quota snapshots. function getAccountPlanType(row: any): string | undefined { if (!row) return undefined if (row.platform === 'grok') { @@ -1490,9 +1489,9 @@ function getAccountPlanType(row: any): string | undefined { const billing = extra.grok_billing_snapshot as Record | undefined const quota = extra.grok_quota_snapshot as Record | undefined return ( + row.credentials?.subscription_tier || billing?.plan || quota?.subscription_tier || - row.credentials?.subscription_tier || extra.subscription_tier || row.credentials?.plan_type || row.parent_plan_type || diff --git a/frontend/src/views/admin/__tests__/AccountsView.sparkShadow.spec.ts b/frontend/src/views/admin/__tests__/AccountsView.sparkShadow.spec.ts index b6a1dc4650..d532301692 100644 --- a/frontend/src/views/admin/__tests__/AccountsView.sparkShadow.spec.ts +++ b/frontend/src/views/admin/__tests__/AccountsView.sparkShadow.spec.ts @@ -346,7 +346,7 @@ describe('admin AccountsView — 账号行展示', () => { wrapper.unmount() }) - it('passes fresh Grok billing and quota snapshots before stale credential fallbacks', async () => { + it('prefers persisted Grok JWT tier over lagging billing/quota snapshots', async () => { const grokAccounts = [ { id: 201, @@ -411,9 +411,9 @@ describe('admin AccountsView — 账号行展示', () => { const badges = wrapper.findAllComponents(PlatformTypeBadge) expect(badges.map((badge) => badge.props('planType'))).toEqual([ - 'SuperGrok', + 'FREE', 'SuperGrok Heavy', - 'SuperGrok', + 'FREE', 'BASIC', 'SuperGrok', ])