Skip to content
Merged
2 changes: 2 additions & 0 deletions apps/billing-web/e2e/fixtures/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function capabilitiesWith(
overrides: Partial<BillingCapabilitiesResponse['capabilities']>
): BillingCapabilitiesResponse {
return {
auto_top_up_enabled: false,
capabilities: {
can_cancel: true,
can_change_seats: false,
Expand Down Expand Up @@ -141,6 +142,7 @@ export function challengeRequiredOperation(
export function defaultScenario(): CloudScenario {
return {
status: {
ended_at: null,
is_active: true,
has_funds: true,
max_seats: 1,
Expand Down
42 changes: 41 additions & 1 deletion apps/billing-web/src/session/billingWebClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { datadogRum } from '@datadog/browser-rum'

import type { BillingStatusResponse } from '@comfyorg/ingest-types'
import type { BillingSession } from '@comfyorg/account-core/billing'
import type { BillingClient } from '@comfyorg/account-ui/billing'
import { disposeBillingClient } from '@comfyorg/account-ui/billing'
Expand Down Expand Up @@ -134,13 +135,14 @@ describe('createBillingWebClient', () => {

const STATUS_BODY = {
billing_rail: 'stripe',
ended_at: null,
has_funds: true,
is_active: true,
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
team_credit_stop: null
}
} satisfies BillingStatusResponse

/** The network edge: the billing routes the lifecycle reads, answered by route. */
function stubBillingRoutes(operation: Record<string, unknown>) {
Expand Down Expand Up @@ -180,6 +182,44 @@ function authenticatedSession(): BillingSession {
const issueOperation = async () =>
({ status: 'ok', value: { operationId: 'op_1' } }) as const

describe('billing status wire compatibility', () => {
it('reads older status without an end date through the authenticated billing web client', async () => {
const body = { ...STATUS_BODY, ended_at: undefined }
vi.mocked(fetch).mockResolvedValue(
new Response(JSON.stringify(body), { status: 200 })
)
const client = createBillingWebClient(authenticatedSession())

const result = await client.status.read()

expect(result).toMatchObject({
status: 'ok',
value: { status: { has_funds: true } }
})
expect(client.status.getSnapshot()?.status).not.toHaveProperty('ended_at')
disposeBillingClient(client)
})

it('rejects a malformed supplied end date through the authenticated billing web client', async () => {
vi.mocked(fetch).mockResolvedValue(
new Response(JSON.stringify({ ...STATUS_BODY, ended_at: 'not-a-date' }), {
status: 200
})
)
const client = createBillingWebClient(authenticatedSession())

const result = await client.status.read()

expect(result).toEqual({
status: 'error',
code: 'MALFORMED_RESPONSE',
httpStatus: 200
})
expect(client.status.getSnapshot()).toBeUndefined()
disposeBillingClient(client)
})
Comment on lines +203 to +220

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3, Nit: Delete this duplicate parser-rejection case. The new core row rejects a malformed date without replacing valid status in status.test.ts already exercises the real reader, checks MALFORMED_RESPONSE, and verifies snapshot retention. composeBillingWebClient constructs that same reader without a date adapter. Keep the preceding older-response test as the hosted transport/composition regression and keep the core rejection table. This avoids maintaining the same malformed-date contract at two levels.

Suggested change
it('rejects a malformed supplied end date through the authenticated billing web client', async () => {
vi.mocked(fetch).mockResolvedValue(
new Response(JSON.stringify({ ...STATUS_BODY, ended_at: 'not-a-date' }), {
status: 200
})
)
const client = createBillingWebClient(authenticatedSession())
const result = await client.status.read()
expect(result).toEqual({
status: 'error',
code: 'MALFORMED_RESPONSE',
httpStatus: 200
})
expect(client.status.getSnapshot()).toBeUndefined()
disposeBillingClient(client)
})

})

describe('SDK operation telemetry', () => {
beforeEach(() => {
vi.mocked(datadogRum.getInitConfiguration).mockReturnValue({
Expand Down
1 change: 1 addition & 0 deletions apps/billing-web/src/test/fakeBillingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function createFakeBillingClient(
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null
},
topupQuote = { status: 'error', code: 'REQUEST_FAILED' },
Expand Down
4 changes: 3 additions & 1 deletion apps/billing-web/src/views/CheckoutView.streams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen, waitFor } from '@testing-library/vue'
import { defineComponent, h, ref } from 'vue'
import { createMemoryHistory, createRouter } from 'vue-router'

import type { BillingStatusResponse } from '@comfyorg/ingest-types'
import type { BillingSession } from '@comfyorg/account-core/billing'
import type { AccountCredential } from '@comfyorg/account-core/session'
import {
Expand Down Expand Up @@ -120,13 +121,14 @@ function stubBillingRoutes() {
const answers: Record<string, unknown> = {
'/api/billing/status': {
billing_rail: 'stripe',
ended_at: null,
has_funds: true,
is_active: true,
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
team_credit_stop: null
},
} satisfies BillingStatusResponse,
'/api/billing/preview-subscribe': previewOf({
quote_id: 'q_1',
quote_version: 3,
Expand Down
2 changes: 2 additions & 0 deletions apps/billing-web/src/views/CheckoutView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ describe('CheckoutView', () => {
max_seats: 20,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null
}
})
Expand Down Expand Up @@ -1050,6 +1051,7 @@ describe('CheckoutView', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
cancel_at: '2026-10-25T00:00:00.000Z'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ describe('the full-page checkout journey', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
cancel_at: '2026-07-28T00:00:00.000Z'
}
Expand Down
3 changes: 3 additions & 0 deletions apps/billing-web/src/views/FullPageCheckoutView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ describe('FullPageCheckoutView', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: scheduled,
ended_at: null,
team_credit_stop: null
}
})
Expand Down Expand Up @@ -1451,6 +1452,7 @@ describe('FullPageCheckoutView outcomes after Pay', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
cancel_at: '2026-07-28T00:00:00.000Z'
}
Expand Down Expand Up @@ -3327,6 +3329,7 @@ describe('FullPageCheckoutView promo codes', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
cancel_at: '2026-07-28T00:00:00.000Z'
}
Expand Down
3 changes: 3 additions & 0 deletions apps/billing-web/src/views/SubscriptionView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe('SubscriptionView', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
subscription_status: 'canceled',
cancel_at: '2026-10-24T12:00:00.000Z'
Expand Down Expand Up @@ -186,6 +187,7 @@ describe('SubscriptionView', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
cancel_at: '2026-10-24T12:00:00.000Z'
},
Expand All @@ -207,6 +209,7 @@ describe('SubscriptionView', () => {
max_seats: 1,
occupied_seats: 1,
scheduled_change: null,
ended_at: null,
team_credit_stop: null,
subscription_status: 'canceled',
cancel_at: '2026-10-24T12:00:00.000Z'
Expand Down
24 changes: 22 additions & 2 deletions browser_tests/fixtures/agentTurnLockFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { webSocketFixture } from '@e2e/fixtures/ws'

const zAnswerRequest = z.object({ selected: z.array(z.string()) })
const zWireInteger = z.coerce.number().int().safe()

function pendingAskForWire(
ask: z.infer<typeof zAgentPendingAsk>
): AgentPendingAsk {
if (ask.kind !== 'run_approval') return ask
return {
...ask,
context: {
...ask.context,
doc_seq:
ask.context.doc_seq === undefined
? undefined
: zWireInteger.parse(ask.context.doc_seq)
}
}
}

const THREAD_ID = 'b9d0a2a1-0f2c-4f1a-9a5e-6b0f4f2c1d77'
const TURN_ID = '2dd4f367-3399-4cb4-8127-547f531c289a'
Expand Down Expand Up @@ -180,7 +197,7 @@ class TurnLockServer {
private rejected = 0
private posts = 0
private readonly answered: string[][] = []
private pendingAsk: AgentPendingAsk | undefined
private pendingAsk: z.infer<typeof zAgentPendingAsk> | undefined
private heldTranscript:
| {
threadId?: string
Expand Down Expand Up @@ -371,7 +388,10 @@ class TurnLockServer {
role: 'assistant',
status: 'streaming',
workflow_id: WORKFLOW_ID,
pending_ask: this.pendingAsk
pending_ask:
this.pendingAsk === undefined
? undefined
: pendingAskForWire(this.pendingAsk)
})
return rows
}
Expand Down
1 change: 1 addition & 0 deletions browser_tests/fixtures/apiKeyAuthFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const apiKeyAuthFixture = base.extend<{
occupied_seats: 1,
subscription_status: 'active',
subscription_tier: 'TEAM',
ended_at: null,
team_credit_stop: null,
scheduled_change: null
} satisfies BillingStatusResponse)
Expand Down
1 change: 1 addition & 0 deletions browser_tests/fixtures/data/billingCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function createBillingCapabilities(
overrides: Partial<BillingCapabilities> = {}
): BillingCapabilitiesResponse {
return {
auto_top_up_enabled: false,
resolved_for: {
// The signed-in uid `CloudAuthHelper` mocks. Capabilities resolve per
// (user, workspace) and the SDK reader checks both halves
Expand Down
3 changes: 3 additions & 0 deletions browser_tests/fixtures/data/cloudWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const LEGACY_PERSONAL_BILLING_STATUS = {
occupied_seats: 1,
subscription_status: 'ended',
subscription_tier: 'FREE',
ended_at: null,
team_credit_stop: null,
scheduled_change: null
} satisfies IngestBillingStatusResponse
Expand Down Expand Up @@ -109,6 +110,7 @@ export const TEAM_BILLING_STATUS = {
billing_status: 'paid',
has_funds: true,
renewal_date: '2099-02-20T00:00:00Z',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 30,
Expand All @@ -124,6 +126,7 @@ export const ENDED_STANDARD_BILLING_STATUS = {
subscription_duration: 'MONTHLY',
subscription_status: 'ended',
subscription_tier: 'STANDARD',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 1,
Expand Down
1 change: 1 addition & 0 deletions browser_tests/fixtures/data/retentionFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const PERSONAL_PRO_BILLING_STATUS = {
billing_status: 'paid',
has_funds: true,
renewal_date: '2099-02-20T00:00:00Z',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 1,
Expand Down
1 change: 1 addition & 0 deletions browser_tests/fixtures/data/subscriptionFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function createSubscriptionStatus(
billing_rail: 'legacy_stripe',
max_seats: 0,
occupied_seats: 0,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
...overrides
Expand Down
1 change: 1 addition & 0 deletions browser_tests/fixtures/utils/cloudBillingMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const DEFAULT_BILLING_STATUS: BillingStatusResponse = {
billing_status: 'paid',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null
}
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/agent/agentPanelMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const FUNDED_BILLING_STATUS = {
subscription_duration: 'MONTHLY',
subscription_status: 'active',
subscription_tier: 'STANDARD',
ended_at: null,
team_credit_stop: null
} satisfies BillingStatusResponse

Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/billingFacadeConsumers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function mockCloudBoot(
has_funds: false,
max_seats: 0,
occupied_seats: 0,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
...subscriptionStatus,
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/currentUserPopoverCredits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const mockBillingStatus: BillingStatusResponse = {
is_active: true,
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
subscription_status: 'canceled',
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/dialogs/billingPortalOrigin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ACTIVE_PRO_STATUS: BillingStatusResponse = {
renewal_date: '2099-02-20T12:00:00Z',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const ACTIVE_STANDARD = {
billing_status: 'paid',
has_funds: true,
renewal_date: '2099-02-20T00:00:00Z',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ACTIVE_STANDARD = {
billing_status: 'paid',
has_funds: true,
renewal_date: '2099-02-20T00:00:00Z',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 1,
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/dialogs/billingReadsSdkRail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const ACTIVE_STATUS: BillingStatusResponse = {
billing_status: 'paid',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
plan_slug: 'pro-monthly',
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/dialogs/billingRecoverySdkRail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function billingStatus(
billing_status: 'paid',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
...fields
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/dialogs/billingSessionSdkRail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ACTIVE_STATUS = {
billing_status: 'paid',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
plan_slug: 'pro-monthly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const SUBSCRIPTION_STATUS: BillingStatusResponse = {
billing_status: 'paid',
max_seats: 1,
occupied_seats: 1,
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
plan_slug: 'pro-monthly',
Expand Down
1 change: 1 addition & 0 deletions browser_tests/tests/dialogs/checkoutRecovery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const LEGACY_ACTIVE_STANDARD_STATUS = {
billing_status: 'paid',
has_funds: true,
renewal_date: '2099-02-20T00:00:00Z',
ended_at: null,
team_credit_stop: null,
scheduled_change: null,
max_seats: 1,
Expand Down
Loading
Loading