Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/account-core/src/core/billing/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ describe('createCapabilitiesReader', () => {
expect(result.value.rolloutDefaultsApplied.can_top_up).toBe(true)
})

it.for([
{ served: true, expected: true },
{ served: false, expected: false },
{ served: undefined, expected: undefined }
])(
'keeps payment_recovery_available $served instead of dropping it',
async ({ served, expected }) => {
const { scopeSource } = fakeSession()
const { transport } = fakeTransport([
httpOk(
capabilitiesBody(
served === undefined ? {} : { payment_recovery_available: served }
)
)
])
const reader = createCapabilitiesReader({ transport, scopeSource })

const result = await reader.read()

expect(result.status).toBe('ok')
if (result.status !== 'ok') return
expect(result.value.paymentRecoveryAvailable).toBe(expected)
}
)

it.for([true, false])(
'preserves can_manage_members=%s from the server',
async (allowed) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/account-core/src/core/billing/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
import {
zBillingCapabilities,
zBillingCapabilitiesResponse,
zBillingCapabilityRolloutDefaults,
zBillingCapabilityScope
} from '@comfyorg/ingest-types/zod'
Expand Down Expand Up @@ -59,6 +60,8 @@ export type CapabilityRolloutDefaults = z.infer<
const CapabilitiesBodySchema = z.object({
capabilities: zBillingCapabilities,
expires_at: z.string(),
payment_recovery_available:
zBillingCapabilitiesResponse.shape.payment_recovery_available,
resolved_for: zBillingCapabilityScope,
revision: z.number(),
rollout_defaults_applied: zBillingCapabilityRolloutDefaults
Expand All @@ -75,6 +78,10 @@ export interface CapabilitiesSnapshot {
* key never implies the capability was granted — read `capabilities`.
*/
readonly denials: CapabilityDenials
/**
* As received. Absent when the server omits it: unknown, not a refusal.
*/
readonly paymentRecoveryAvailable?: boolean
/** True values are rollout guidance, not evidence a write will succeed. */
readonly rolloutDefaultsApplied: CapabilityRolloutDefaults
readonly revision: number
Expand Down Expand Up @@ -179,6 +186,7 @@ export function createCapabilitiesReader(
value: {
capabilities: data.capabilities,
denials,
paymentRecoveryAvailable: data.payment_recovery_available,
rolloutDefaultsApplied: data.rollout_defaults_applied,
revision: data.revision,
scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { useBillingContext } from '@/composables/billing/useBillingContext'
import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { BillingStatus } from '@/platform/workspace/api/workspaceApi'
import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities'

Check warning on line 12 in src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'cloud/presentation' to zone 'billing/application' is not allowed. src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts -> src/platform/workspace/composables/useBillingCapabilities.ts Route the import through an allowed zone or restructure the dependency.
import { usePaymentRecoveryDialog } from '@/platform/workspace/composables/usePaymentRecoveryDialog'

import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue'
Expand All @@ -32,6 +33,7 @@
)

vi.mock(import('@/platform/workspace/composables/usePaymentRecoveryDialog'))
vi.mock(import('@/platform/workspace/composables/useBillingCapabilities'))

Check warning on line 36 in src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'cloud/presentation' to zone 'billing/application' is not allowed. src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts -> src/platform/workspace/composables/__mocks__/useBillingCapabilities.ts Route the import through an allowed zone or restructure the dependency.

vi.mock<unknown>(
import('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue'),
Expand Down Expand Up @@ -119,6 +121,8 @@
mockSubscriptionTier.value = null
mockIsFreeTier.value = true
mockPaymentRecoveryLock.value = null
useBillingCapabilities().canRunWorkflows = computed(() => false)
useBillingCapabilities().hasResolvedCapabilities = computed(() => true)
vi.mocked(usePaymentRecoveryDialog).mockReturnValue({
showPaymentRecoveryDialog,
updatePayment: vi.fn(),
Expand Down Expand Up @@ -201,6 +205,18 @@
).not.toBeInTheDocument()
})

it('unlocks Run when resolved capabilities say the actor can run', () => {
mockCanRunWorkflows.value = false
mockPaymentRecoveryLock.value = 'owner'
useBillingCapabilities().canRunWorkflows = computed(() => true)
renderWrapper()

expect(screen.getByTestId('queue-button')).toHaveTextContent('Run')
expect(
screen.queryByTestId('subscribe-to-run-button')
).not.toBeInTheDocument()
})

it('locks the run button when the subscription is inactive', () => {
mockCanRunWorkflows.value = false
renderWrapper()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<ComfyQueueButton
v-if="
v-if="canRunWorkflows"
:payment-recovery-lock="null"
@payment-recovery-click="showPaymentRecoveryDialog(refreshOnReturn)"
/>
<ComfyQueueButton
v-else-if="
!showsSubscribeToRunPrompt || paymentRecoveryLock || isSalesManagedPlan
"
:payment-recovery-lock="paymentRecoveryLock"
Expand All @@ -16,10 +21,12 @@
import { useBillingContext } from '@/composables/billing/useBillingContext'
import SubscribeToRunButton from '@/platform/cloud/subscription/components/SubscribeToRun.vue'
import { isSalesManagedTier } from '@/platform/cloud/subscription/constants/tierPricing'
import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities'

Check warning on line 24 in src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'cloud/presentation' to zone 'billing/application' is not allowed. src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue -> src/platform/workspace/composables/useBillingCapabilities.ts Route the import through an allowed zone or restructure the dependency.
import { usePaymentRecoveryDialog } from '@/platform/workspace/composables/usePaymentRecoveryDialog'

const { showsSubscribeToRunPrompt, subscription, fetchStatus, fetchBalance } =
useBillingContext()
const { canRunWorkflows } = useBillingCapabilities()
const { paymentRecoveryLock, refreshCapabilities, showPaymentRecoveryDialog } =
usePaymentRecoveryDialog()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ describe('projectBillingCapabilities', () => {
rollout_defaults_applied: SNAPSHOT.rolloutDefaultsApplied
})
})

it.for([true, false])(
'passes payment_recovery_available %s through to the capabilities read',
(served) => {
expect(
projectBillingCapabilities({
...SNAPSHOT,
paymentRecoveryAvailable: served
}).payment_recovery_available
).toBe(served)
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function projectBillingCapabilities(
workspace_id: snapshot.scope.workspaceId
},
revision: snapshot.revision,
rollout_defaults_applied: snapshot.rolloutDefaultsApplied
rollout_defaults_applied: snapshot.rolloutDefaultsApplied,
...(snapshot.paymentRecoveryAvailable === undefined
? {}
: { payment_recovery_available: snapshot.paymentRecoveryAvailable })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const defaults: ReturnType<typeof realUseBillingCapabilities> = {
receiveServerFact('can_manage_auto_top_up', false)
),
autoTopUpSetup: computed(() => null),
canRunWorkflows: computed(() => false),
paymentRecoveryAvailable: computed(() =>
receiveServerFact('payment_recovery_available', false)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ function useBillingCapabilitiesInternal() {
const autoTopUpSetup = computed(
() => resolvedResponse.value?.auto_top_up_setup ?? null
)
const canRunWorkflows = computed(
() => capabilities.value?.can_run_workflows ?? false
)
const paymentRecoveryAvailable = computed(() =>
receiveServerFact(
'payment_recovery_available',
Expand Down Expand Up @@ -553,6 +556,7 @@ function useBillingCapabilitiesInternal() {
canDowngradeToPersonal,
canManageAutoTopUp,
autoTopUpSetup,
canRunWorkflows,
paymentRecoveryAvailable,
runDeniedPaymentPastDue,
isReady,
Expand Down
Loading