diff --git a/src/main/hosted-sandbox/hosted-sandbox-recipe.test.ts b/src/main/hosted-sandbox/hosted-sandbox-recipe.test.ts index 07e56fb0a07..617acf4a607 100644 --- a/src/main/hosted-sandbox/hosted-sandbox-recipe.test.ts +++ b/src/main/hosted-sandbox/hosted-sandbox-recipe.test.ts @@ -87,6 +87,23 @@ describe('Orca Cloud built-in recipe steps', () => { expect(result.failure?.errorCode).toBe('cloudPlanRequired') }) + it.each([ + 'no_subscription', + 'included_hours_exhausted', + 'overage_cap_reached', + 'payment_past_due' + ] as const)( + 'JA-21: a %s refusal creates no sandbox, so a blocked create uses no hours', + async (reason) => { + const { plane, step } = setup() + plane.denyNextStart(reason) + const result = await step({ mode: 'create', repoPath, context }) + expect(result.failure?.errorCode).toBe('cloudPlanRequired') + expect(result.stderr).toContain(`Orca Cloud: ${reason}`) + expect(plane.sandboxes.size).toBe(0) + } + ) + it('tells the user to free a slot, not to buy a plan, when the member is at their cap', async () => { const { plane, step } = setup() plane.denyNextStart('member_concurrency_limit') diff --git a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx index c1b2d5f4a91..f220a47c0ce 100644 --- a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx +++ b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx @@ -1,6 +1,5 @@ import { OrcaCloudNeedsRepoLine } from './run-on/OrcaCloudNeedsRepoLine' import { ORCA_CLOUD_NEEDS_REPO_ID } from './run-on/cloud-start-view' -import { OrcaCloudWallLine } from './run-on/OrcaCloudWallLine' import React from 'react' import { FolderPlus, LoaderCircle, PlugZap } from 'lucide-react' import { Button } from '@/components/ui/button' @@ -230,7 +229,6 @@ export function NewWorkspaceComposerProjectSection({ {ephemeralVmRecipeError}

) : null} - {cloudStart?.wall ? : null} ) : null} diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx index 329c2a31610..ab624fb9556 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx @@ -64,7 +64,7 @@ function Preview({ recipes?: EphemeralVmRecipeOption[] recipeValue?: string | null access?: OrcaCloudRunTargetAccess - /** The composer's picker: setup comes after Start, JA-21's preflight applies when flagged. */ + /** The composer's picker: setup and billing come after Create. */ composer?: boolean }): React.JSX.Element { return ( @@ -286,82 +286,30 @@ export const rowActions = defineFixture({ interact: pressKeys('ArrowDown', 'ArrowDown') }) -// JA-21 (flagged): the composer's picker for an owner at a billing wall, flag off then on. -const preflight = (on: boolean): void => { - if (on) { - localStorage.setItem('orca:dev:runOnPreflight', '1') - } else { - localStorage.removeItem('orca:dev:runOnPreflight') - } +// JA-21 (Neil): progressive billing. In the composer Orca Cloud is pickable whatever billing says, +// with no plan, hours or payment words; the creating sheet shows any blocker after Create. +function composerWith(access: OrcaCloudRunTargetAccess, width = 420) { + return defineFixture({ + width, + render: () => , + interact: open + }) } -export const composerOutOfHoursPreflightOff = defineFixture({ - width: 420, - render: () => { - preflight(false) - return ( - - ) - }, - interact: open +export const composerOwnerOutOfHours = composerWith({ + state: 'out-of-hours', + cause: 'hours', + canManageBilling: true }) -export const composerOutOfHoursPreflight = defineFixture({ - width: 420, - render: () => { - preflight(true) - return ( - - ) - }, - interact: open +export const composerMemberOutOfHours = composerWith({ + state: 'out-of-hours', + cause: 'hours', + canManageBilling: false }) -export const composerPaymentIssuePreflight = defineFixture({ - width: 420, - render: () => { - preflight(true) - return ( - - ) - }, - interact: open -}) -export const composerLapsedPreflight = defineFixture({ - width: 420, - render: () => { - preflight(true) - return ( - - ) - }, - interact: open -}) -// The composer's Run on column is narrow (~300px): "Orca Cloud" stays whole, the reason wraps. -export const composerOutOfHoursPreflightNarrow = defineFixture({ - width: 320, - render: () => { - preflight(true) - return ( - - ) - }, - interact: open +export const composerMemberPaymentIssue = composerWith({ + state: 'payment-issue', + canManageBilling: false }) +export const composerMemberPlanEnded = composerWith( + { state: 'no-plan', lapsed: true, canManageBilling: false }, + 320 +) diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.preflight.test.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.progressive-billing.test.tsx similarity index 62% rename from src/renderer/src/components/new-workspace/RunTargetCombobox.preflight.test.tsx rename to src/renderer/src/components/new-workspace/RunTargetCombobox.progressive-billing.test.tsx index fad0c495352..d19e0a1e0d5 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.preflight.test.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.progressive-billing.test.tsx @@ -16,7 +16,9 @@ vi.mock('@/components/ui/popover', () => ({ PopoverAnchor: ({ children }: { children: React.ReactNode }) => <>{children}, PopoverContent: ({ children }: { children: React.ReactNode }) =>
{children}
})) -vi.mock('@/components/billing/plans/plans-page-store', () => ({ openPlansPage: vi.fn() })) +vi.mock('@/components/billing/plans/plans-page-store', () => ({ + openPlansPage: vi.fn() +})) const hosts: ProjectHostSetupOption[] = [ { @@ -90,11 +92,13 @@ function cloudRow(): HTMLElement | null { ) } -const outOfHours: OrcaCloudRunTargetAccess = { - state: 'out-of-hours', - cause: 'hours', - canManageBilling: true -} +const blocked: [string, OrcaCloudRunTargetAccess][] = [ + ['owner out of hours', { state: 'out-of-hours', cause: 'hours', canManageBilling: true }], + ['member out of hours', { state: 'out-of-hours', cause: 'hours', canManageBilling: false }], + ['member at the spend cap', { state: 'out-of-hours', cause: 'cap', canManageBilling: false }], + ['member, payment failed', { state: 'payment-issue', canManageBilling: false }], + ['member, plan ended', { state: 'no-plan', lapsed: true, canManageBilling: false }] +] beforeEach(() => { resetOrcaCloudBillingCache() @@ -110,42 +114,30 @@ afterEach(() => { root.unmount() }) container.remove() - localStorage.removeItem('orca:dev:runOnPreflight') }) -describe('Run on preflight (JA-21, flagged)', () => { - it('flag off: nothing changes, the composer picks Orca Cloud and setup comes after Start', () => { - const onSelectOrcaCloud = vi.fn() - renderComposer(outOfHours, onSelectOrcaCloud) - expect(cloudRow()?.getAttribute('aria-disabled')).toBeNull() - expect(container.textContent).not.toContain('Turn on overage') - press('ArrowDown') - press('Enter') - expect(onSelectOrcaCloud).toHaveBeenCalledOnce() - }) - - it('flag on: a billing wall disables the row with its reason and one fix, and Enter runs the fix', () => { - localStorage.setItem('orca:dev:runOnPreflight', '1') - const onSelectOrcaCloud = vi.fn() - renderComposer(outOfHours, onSelectOrcaCloud) - expect(cloudRow()?.getAttribute('aria-disabled')).toBe('true') - expect(cloudRow()?.textContent).toContain('Out of sandbox hours') - expect(cloudRow()?.textContent).toContain('Turn on overage') - press('ArrowDown') - press('Enter') - expect(onSelectOrcaCloud).not.toHaveBeenCalled() - expect(openSettingsTarget).toHaveBeenCalledWith( - expect.objectContaining({ pane: 'cloud-billing' }) - ) - }) - - it('flag on: a plan not started yet is setup, not a wall, so it stays pickable', () => { - localStorage.setItem('orca:dev:runOnPreflight', '1') - const onSelectOrcaCloud = vi.fn() - renderComposer({ state: 'no-plan', lapsed: false, canManageBilling: true }, onSelectOrcaCloud) - expect(cloudRow()?.getAttribute('aria-disabled')).toBeNull() - press('ArrowDown') - press('Enter') - expect(onSelectOrcaCloud).toHaveBeenCalledOnce() - }) +describe('progressive billing in Run on (JA-21, Neil)', () => { + it.each(blocked)( + '%s: Orca Cloud stays pickable with no billing words, and Enter picks it', + (_name, access) => { + const onSelectOrcaCloud = vi.fn() + renderComposer(access, onSelectOrcaCloud) + expect(cloudRow()?.getAttribute('aria-disabled')).toBeNull() + const text = cloudRow()?.textContent ?? '' + for (const word of [ + 'sandbox hours', + 'overage', + 'spend cap', + 'Payment', + 'plan ended', + 'Ask an owner' + ]) { + expect(text).not.toContain(word) + } + press('ArrowDown') + press('Enter') + expect(onSelectOrcaCloud).toHaveBeenCalledOnce() + expect(openSettingsTarget).not.toHaveBeenCalled() + } + ) }) diff --git a/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx b/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx index fd3216ff3fa..89df16ba08c 100644 --- a/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx @@ -14,7 +14,6 @@ import { type OrcaCloudRunTargetAccess } from './orca-cloud-run-target-access' import { ORCA_CLOUD_SANDBOX_SPEC } from '../../../../shared/hosted-sandbox/hosted-sandbox-wire' -import { orcaCloudNeedsFixFirst, useRunOnPreflightEnabled } from '@/lib/orca-cloud/run-on-preflight' /** * Looks like a button but is plain option content: focus stays in the combobox input, Enter on the @@ -94,7 +93,9 @@ export function useOrcaCloudHoursLeft(access: OrcaCloudRunTargetAccess): string 'Trial · {{hours}} sandbox hours left · No card needed', { count: offered, - hours: new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(offered), + hours: new Intl.NumberFormat(locale, { + maximumFractionDigits: 1 + }).format(offered), defaultValue_one: 'Trial · {{hours}} sandbox hour left · No card needed' } ) @@ -110,7 +111,9 @@ export function useOrcaCloudHoursLeft(access: OrcaCloudRunTargetAccess): string 'Trial · {{hours}} sandbox hours left', { count, - hours: new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(count), + hours: new Intl.NumberFormat(locale, { + maximumFractionDigits: 1 + }).format(count), defaultValue_one: 'Trial · {{hours}} sandbox hour left' } ) @@ -294,28 +297,6 @@ function OrcaCloudMeta({ } } -/** - * In the composer, hours and plan details wait until after create (Neil): the row only keeps what - * explains why it can't be picked, "Ask an owner or admin". - */ -function showsMetaAfterStart(access: OrcaCloudRunTargetAccess, preflight: boolean): boolean { - // JA-21 (flagged): a billing wall is fixed here, before Start, not on the setup page after it. - if (preflight && orcaCloudNeedsFixFirst(access)) { - return true - } - switch (access.state) { - case 'no-plan': - case 'out-of-hours': - case 'payment-issue': - return !access.canManageBilling - case 'loading': - case 'entitled': - case 'signed-out': - case 'unknown': - return false - } -} - /** Orca Cloud as a first-class Run-on target, with the fix for what blocks it (and hours, behind RUN_ON_SHOWS_HOURS_LEFT). */ export function RunTargetOrcaCloudRow({ recipe, @@ -343,41 +324,44 @@ export function RunTargetOrcaCloudRow({ setupAfterStart?: boolean }): React.JSX.Element { const t = useTranslate() - const preflight = useRunOnPreflightEnabled() && setupAfterStart - // A billing wall keeps "Orca Cloud" whole and wraps its reason under it (design-squad). - const wallShown = preflight && orcaCloudNeedsFixFirst(access) + // JA-21 (Neil): the composer says nothing about plan, hours or payment; Create checks and the + // creating sheet shows any blocker. Outside the composer the row still names the fix. + const shown: OrcaCloudRunTargetAccess = + setupAfterStart && + (access.state === 'no-plan' || + access.state === 'out-of-hours' || + access.state === 'payment-issue') + ? { state: 'unknown' } + : access return ( } label={recipe?.name ?? ORCA_CLOUD_LABEL} labelBadge={ - access.state === 'no-plan' && !access.lapsed ? ( + shown.state === 'no-plan' && !shown.lapsed ? ( {t('auto.components.new.workspace.RunTargetCombobox.orcaCloudTeamBadge', 'Team')} ) : undefined } detail="" - detailNode={} + detailNode={} armed={armed} current={current} disabled={ - ((access.state === 'no-plan' || - access.state === 'out-of-hours' || - access.state === 'payment-issue') && - !access.canManageBilling) || - wallShown + (shown.state === 'no-plan' || + shown.state === 'out-of-hours' || + shown.state === 'payment-issue') && + !shown.canManageBilling } optionId={optionId} - wrapDetail={wallShown} busy={pending} onArm={onArm} onCommit={onSelect} - description={orcaCloudRowHint(access, t)} + description={orcaCloudRowHint(shown, t)} trailing={ - setupAfterStart && !showsMetaAfterStart(access, preflight) ? undefined : ( - - ) + // The composer walks sign-in on its setup page after Start: no inline meta here. + setupAfterStart ? undefined : } /> ) diff --git a/src/renderer/src/components/new-workspace/orca-cloud-billing-cache.ts b/src/renderer/src/components/new-workspace/orca-cloud-billing-cache.ts index c8fcc8c98ca..00ce2cbcce9 100644 --- a/src/renderer/src/components/new-workspace/orca-cloud-billing-cache.ts +++ b/src/renderer/src/components/new-workspace/orca-cloud-billing-cache.ts @@ -15,7 +15,6 @@ import { toOrcaCloudRunTargetAccess, type OrcaCloudRunTargetAccess } from './orca-cloud-run-target-access' -import { devBillingFaultAccess } from '@/lib/orca-cloud/run-on-preflight' /** * The Run-on picker's and selection hint's view of the shared billing store. The composer prefetches @@ -46,11 +45,6 @@ export function invalidateOrcaCloudBilling({ refetchNow = true } = {}): void { } function accessFrom(snapshot: BillingStoreState): OrcaCloudRunTargetAccess { - // Dev/QA: a simulated billing wall for real-app shots (never in production builds). - const fault = devBillingFaultAccess() - if (fault) { - return fault - } if (!snapshot.result && snapshot.loading) { return { state: 'loading' } } diff --git a/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.fixture.tsx b/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.fixture.tsx deleted file mode 100644 index b15761f136c..00000000000 --- a/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.fixture.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { defineFixture } from '../../../component-fixtures/component-fixture' -import { OrcaCloudWallLine } from './OrcaCloudWallLine' - -// The Run on column is half the composer: about 230px. The reason wraps, never truncates. -function Column({ children }: { children: React.ReactNode }): React.JSX.Element { - return
{children}
-} - -export const ownerOutOfHours = defineFixture({ - width: 260, - render: () => ( - - {} } - }} - /> - - ) -}) -export const ownerPaymentFailed = defineFixture({ - width: 260, - render: () => ( - - {} } - }} - /> - - ) -}) -export const memberPlanEnded = defineFixture({ - width: 260, - render: () => ( - - - - ) -}) diff --git a/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.tsx b/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.tsx deleted file mode 100644 index 997b4754d7a..00000000000 --- a/src/renderer/src/components/new-workspace/run-on/OrcaCloudWallLine.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react' -import { Button } from '@/components/ui/button' -import { useTranslate } from '@/i18n/use-translate' -import type { OrcaCloudWallNotice } from '@/lib/orca-cloud/run-on-preflight' - -/** - * JA-21b (flagged): under Run on when Orca Cloud is the selected target and a billing wall applies. - * The reason, then the one fix (or who can fix it) on its own line, flush with the reason: one - * layout in the narrow column, never a dangling separator (design-squad). Create waits until fixed. - */ -export function OrcaCloudWallLine({ wall }: { wall: OrcaCloudWallNotice }): React.JSX.Element { - const t = useTranslate() - return ( -
- {/* Wraps rather than truncating: the glossary reason is never cut. */} -

{wall.reason}

- {wall.action ? ( - // statusAction pads its label by px-1; the wrapper's -mx-1 puts the text flush-left. -
- -
- ) : ( -

- {t( - 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskOwnerOrAdmin', - 'Ask an owner or admin' - )} -

- )} -
- ) -} diff --git a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts index 71d1f4f0a35..4584ff4baf7 100644 --- a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts +++ b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts @@ -58,41 +58,48 @@ describe('setup rows and the setup page', () => { expect(page(steps)).toBe('sign-in') }) - it('owner without a plan chooses one in the browser; lapsed renews there', () => { - const noPlan = deriveCloudSetupSteps({ - availability: 'needs-capability', - access: { state: 'no-plan', lapsed: false, canManageBilling: true } - }) - expect(page(noPlan)).toBe('choose-plan') - const lapsed = deriveCloudSetupSteps({ - availability: 'offered', - access: { state: 'no-plan', lapsed: true, canManageBilling: true } - }) - expect(page(lapsed)).toBe('choose-plan') - expect(lapsed.find((s) => s.id === 'plan')?.need).toBe('renew-plan') - }) - - it('a member who cannot fix billing is told to ask an owner, with no agent row', () => { - const steps = deriveCloudSetupSteps({ - availability: 'needs-capability', - access: { state: 'no-plan', lapsed: false, canManageBilling: false } - }) - expect(steps.some((s) => s.id === 'agent')).toBe(false) - expect(page(steps)).toBe('ask-owner') - const outOfHours = deriveCloudSetupSteps({ - availability: 'offered', - access: { state: 'out-of-hours', cause: 'hours', canManageBilling: false } - }) - expect(page(outOfHours)).toBe('ask-owner') - }) - - it('an owner out of hours fixes it in billing', () => { - const steps = deriveCloudSetupSteps({ - availability: 'offered', - access: { state: 'out-of-hours', cause: 'hours', canManageBilling: true } - }) - expect(page(steps)).toBe('fix-billing') - }) + it.each([ + [ + 'owner, no plan', + 'needs-capability', + { state: 'no-plan', lapsed: false, canManageBilling: true } + ], + ['owner, plan ended', 'offered', { state: 'no-plan', lapsed: true, canManageBilling: true }], + [ + 'member, no plan', + 'needs-capability', + { state: 'no-plan', lapsed: false, canManageBilling: false } + ], + [ + 'owner, trial used up', + 'offered', + { state: 'no-plan', lapsed: false, canManageBilling: true, trialUsedUp: true } + ], + [ + 'member, trial used up', + 'offered', + { state: 'no-plan', lapsed: false, canManageBilling: false, trialUsedUp: true } + ], + [ + 'owner out of hours', + 'offered', + { state: 'out-of-hours', cause: 'hours', canManageBilling: true } + ], + [ + 'member out of hours', + 'offered', + { state: 'out-of-hours', cause: 'hours', canManageBilling: false } + ], + ['member, payment failed', 'offered', { state: 'payment-issue', canManageBilling: false }] + ] as const)( + 'JA-21 progressive billing: %s is not a setup step; Create goes on and the sheet shows any blocker', + (_name, availability, access) => { + const steps = deriveCloudSetupSteps({ availability, access }) + expect(steps.find((s) => s.id === 'plan')?.state).toBe('done') + expect(steps.some((s) => s.id === 'agent')).toBe(true) + expect(cloudSetupRequired(steps)).toBe(false) + } + ) it('a missing GitHub grant alone is the GitHub step', () => { expect( @@ -108,29 +115,24 @@ describe('setup rows and the setup page', () => { it('a team that can still get its trial claims it in the app (B1)', () => { const steps = deriveCloudSetupSteps({ availability: 'offered', - access: { state: 'no-plan', lapsed: false, canManageBilling: false, trialOfferSeconds: 7200 } + access: { + state: 'no-plan', + lapsed: false, + canManageBilling: false, + trialOfferSeconds: 7200 + } }) const plan = steps.find((s) => s.id === 'plan') - expect(plan).toMatchObject({ need: 'trial', trialSeconds: 7200, canFix: true }) + expect(plan).toMatchObject({ + need: 'trial', + trialSeconds: 7200, + canFix: true + }) // Members aren't blocked from the trial: the agent row stays. expect(steps.some((s) => s.id === 'agent')).toBe(true) expect(page(steps)).toBe('start-trial') }) - it('trial used up: owner chooses a plan; member asks an owner (T2, C1)', () => { - const owner = deriveCloudSetupSteps({ - availability: 'offered', - access: { state: 'no-plan', lapsed: false, canManageBilling: true, trialUsedUp: true } - }) - expect(owner.find((s) => s.id === 'plan')?.need).toBe('trial-used-up') - expect(page(owner)).toBe('choose-plan') - const member = deriveCloudSetupSteps({ - availability: 'offered', - access: { state: 'no-plan', lapsed: false, canManageBilling: false, trialUsedUp: true } - }) - expect(page(member)).toBe('ask-owner') - }) - it('signed out: the trial row is included and GitHub is checked up front (A1)', () => { const steps = deriveCloudSetupSteps({ availability: 'needs-sign-in', @@ -147,7 +149,12 @@ describe('setup rows and the setup page', () => { const steps = deriveCloudSetupSteps({ availability: 'offered', access: { state: 'entitled', remainingSeconds: 3600 }, - github: { id: 'github', state: 'pending', need: 'github', blocksStart: true } + github: { + id: 'github', + state: 'pending', + need: 'github', + blocksStart: true + } }) expect(cloudSetupRequired(steps)).toBe(true) expect(page(steps)).toBe('github-waiting') @@ -157,7 +164,12 @@ describe('setup rows and the setup page', () => { const steps = deriveCloudSetupSteps({ availability: 'needs-sign-in', access: { state: 'signed-out' }, - github: { id: 'github', state: 'failed', need: 'github', blocksStart: true } + github: { + id: 'github', + state: 'failed', + need: 'github', + blocksStart: true + } }) expect(steps.map((s) => s.id)).toEqual(['github']) expect(page(steps)).toBe('needs-repository') @@ -170,7 +182,10 @@ describe('setup rows and the setup page', () => { github: { id: 'github', state: 'loading' } }) expect(page(github)).toBe('checking') - const billing = deriveCloudSetupSteps({ availability: 'offered', access: { state: 'loading' } }) + const billing = deriveCloudSetupSteps({ + availability: 'offered', + access: { state: 'loading' } + }) expect(page(billing)).toBe('checking') }) diff --git a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.ts b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.ts index 22137588ce5..cffe1f8019e 100644 --- a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.ts +++ b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.ts @@ -133,21 +133,12 @@ function derivePlanStep( trialSeconds: access.trialOfferSeconds } } - return { - id: 'plan', - state: 'needed', - need: access.trialUsedUp ? 'trial-used-up' : access.lapsed ? 'renew-plan' : 'plan', - canFix: access.canManageBilling - } + // JA-21 (Neil): billing is progressive. A plan, hours, cap or payment problem isn't a setup + // step; Create goes ahead and the creating sheet shows the blocker with its fix. + return { id: 'plan', state: 'done' } case 'out-of-hours': - return { - id: 'plan', - state: 'needed', - need: access.cause === 'cap' ? 'spend-cap' : 'hours', - canFix: access.canManageBilling - } case 'payment-issue': - return { id: 'plan', state: 'needed', need: 'payment', canFix: access.canManageBilling } + return { id: 'plan', state: 'done' } } } diff --git a/src/renderer/src/components/new-workspace/run-on/cloud-start-view.ts b/src/renderer/src/components/new-workspace/run-on/cloud-start-view.ts index a593e7b5c73..49f884d781e 100644 --- a/src/renderer/src/components/new-workspace/run-on/cloud-start-view.ts +++ b/src/renderer/src/components/new-workspace/run-on/cloud-start-view.ts @@ -1,7 +1,6 @@ // What the composer card needs for Orca Cloud, shared by the hook and the card. Picking Orca Cloud // changes nothing else in the dialog (composer-redo): setup lives on its own page after Start. import type { CloudOnlyRepo } from './use-cloud-only-repo' -import type { OrcaCloudWallNotice } from '@/lib/orca-cloud/run-on-preflight' export type CloudStartView = { /** Picks Orca Cloud even while the account still needs setup; Start walks it on a page. */ @@ -11,8 +10,6 @@ export type CloudStartView = { cloudOnly?: CloudOnlyRepo /** The project is a plain folder: Orca Cloud needs a GitHub repository instead (D3/D4). */ folderProject?: boolean - /** JA-21b (flagged): Orca Cloud is selected and a billing wall applies; Create waits for the fix. */ - wall?: OrcaCloudWallNotice | null /** * RR-c1: Orca Cloud is selected but the project is a plain folder. Both selections stay and Create * stays enabled; Create (button or ⌘↵) then stops before submitting and this error shows under diff --git a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts index 67feb4e00c6..d16b86d780f 100644 --- a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts +++ b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts @@ -31,7 +31,6 @@ import { orcaCloudNeedsGitHubRepo, type CloudStartView } from './cloud-start-view' -import { orcaCloudWallNotice, useRunOnPreflightEnabled } from '@/lib/orca-cloud/run-on-preflight' export type { CloudStartView } from './cloud-start-view' @@ -86,12 +85,7 @@ export function useCloudStartComposer({ const cloudSelected = selectedRecipeId === ORCA_CLOUD_RECIPE_ID const fetched = useOrcaCloudRunTargetAccess(segment === 'enabled' && !accessOverride) const access = accessOverride ?? fetched - const preflight = useRunOnPreflightEnabled() const githubProjectCount = useAppStore((s) => s.repos.filter(isGitHubBackedProject).length) - const wall = useMemo( - () => (cloudSelected && preflight ? orcaCloudWallNotice(access) : null), - [access, cloudSelected, preflight] - ) const cloudOnly = useCloudOnlyRepo({ repoId, cloudSelected, @@ -108,7 +102,9 @@ export function useCloudStartComposer({ githubOverride: cloudOnly.githubStep }) const { steps, held: switchTeam } = useSwitchTeamSteps(rowSteps, cloudSelected) - const setupNeeded = cloudSetupRequired(steps, { teamSwitch: switchTeam !== null }) + const setupNeeded = cloudSetupRequired(steps, { + teamSwitch: switchTeam !== null + }) // An agent with no Orca Cloud account is still created with the workspace: its launch holds on // the pane's "Set up once" strip and never reaches the agent's own /login (PC-3b, #385). In the // workspace the strip asks; away, the sidebar row's mark does (N-03: no toast follows the user). @@ -207,7 +203,6 @@ export function useCloudStartComposer({ onUserPick: markTouched, cloudOnly, folderProject: cloudOnly.folderProject, - wall, needsGitHubRepo: orcaCloudNeedsGitHubRepo({ cloudSelected, folderProject: cloudOnly.folderProject, @@ -216,7 +211,7 @@ export function useCloudStartComposer({ githubProjectCount }) }, - [cloudOnly, cloudSelected, githubProjectCount, markTouched, onSelectOrcaCloud, segment, wall] + [cloudOnly, cloudSelected, githubProjectCount, markTouched, onSelectOrcaCloud, segment] ) if (!view || !cloudSelected) { return { view, onPrimary: null, recordCreated } diff --git a/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts b/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts index 2c2bd3df141..20dd1e818eb 100644 --- a/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts +++ b/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts @@ -46,7 +46,11 @@ export function useComposerCloudStart({ // see that edit. const runCreate = useCallback(() => void handleCreate(), [handleCreate]) const composerSnapshot = useCallback( - () => buildComposerSnapshot(modalData, cardProps, { ...quickAgentPick, agent: quickAgent }), + () => + buildComposerSnapshot(modalData, cardProps, { + ...quickAgentPick, + agent: quickAgent + }), [cardProps, modalData, quickAgent, quickAgentPick] ) const cloudStart = useCloudStartComposer({ @@ -79,8 +83,7 @@ export function useComposerCloudStart({ return { cloudStart: { ...cloudStart, view }, // Local and Orca Cloud share one button: same label, same rules for when it's enabled. - // JA-21b: a billing wall on the selected Orca Cloud holds Create until it's fixed. - primaryCreateDisabled: createDisabled || Boolean(cloudStart.view?.wall), + primaryCreateDisabled: createDisabled, onPrimary: guard.onPrimary } } diff --git a/src/renderer/src/components/new-workspace/use-run-target-orca-cloud.ts b/src/renderer/src/components/new-workspace/use-run-target-orca-cloud.ts index db55859e945..a8ae841bbe8 100644 --- a/src/renderer/src/components/new-workspace/use-run-target-orca-cloud.ts +++ b/src/renderer/src/components/new-workspace/use-run-target-orca-cloud.ts @@ -1,5 +1,4 @@ import { useCallback, useEffect, useRef, useState } from 'react' -import { orcaCloudNeedsFixFirst, useRunOnPreflightEnabled } from '@/lib/orca-cloud/run-on-preflight' import type { OrcaCloudAvailability } from '../../../../shared/orca-yaml-hook-types' import { isOrcaCloudRecipe, type EphemeralVmRecipeOption } from './run-target-options' import { getOrcaCloudPick, type OrcaCloudRunTargetAccess } from './orca-cloud-run-target-access' @@ -71,8 +70,6 @@ export function useRunTargetOrcaCloud({ runBlockedAction: () => void select: (recipe: EphemeralVmRecipeOption | null) => void } { - // JA-21 (flagged): in the composer a billing wall routes to its fix instead of picking Orca Cloud. - const preflight = useRunOnPreflightEnabled() && Boolean(onSelectOrcaCloud) const fetched = useOrcaCloudRunTargetAccess( !override && (recipes.some(isOrcaCloudRecipe) || offer?.state === 'no-plan') ) @@ -102,16 +99,14 @@ export function useRunTargetOrcaCloud({ ) const pickFor = useCallback( (resolved: OrcaCloudRunTargetAccess, recipe: EphemeralVmRecipeOption | null): void => { - const pick = getOrcaCloudPick(resolved) - if ( - onSelectOrcaCloud && - pick.kind !== 'blocked' && - !(preflight && orcaCloudNeedsFixFirst(resolved)) - ) { + // JA-21 (Neil): in the composer Orca Cloud is always pickable; billing is checked after + // Create, on the creating sheet, so owners and members alike can start a draft. + if (onSelectOrcaCloud) { close() onSelectOrcaCloud() return } + const pick = getOrcaCloudPick(resolved) if (pick.kind === 'act') { close() // The fix finishes elsewhere (plans, portal, settings): reread billing on return. @@ -121,7 +116,7 @@ export function useRunTargetOrcaCloud({ selectRecipe(recipe.id) } }, - [close, onSelectOrcaCloud, preflight, selectRecipe] + [close, onSelectOrcaCloud, selectRecipe] ) const runBlockedAction = useCallback((): void => pickFor(access, null), [access, pickFor]) const select = useCallback( diff --git a/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.test.tsx b/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.test.tsx new file mode 100644 index 00000000000..bf36d87646d --- /dev/null +++ b/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.test.tsx @@ -0,0 +1,157 @@ +// @vitest-environment happy-dom + +import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { + OrcaBillingOverageResult, + OrcaBillingStatusResult +} from '../../../../shared/orca-billing' +import { sampleTeam } from '../billing/plan-billing-fixtures' +import { VmBuildBillingBlocker, type BillingBlockKind } from './VmBuildBillingBlocker' + +const setOverage = + vi.fn<(args: { enabled: boolean; spendCapCents?: number }) => Promise>() +const billingStatus = vi.fn<() => Promise>() +const openPortal = vi.fn(() => Promise.resolve({ status: 'opened' as const })) + +beforeEach(() => { + setOverage.mockReset() + billingStatus.mockReset() + openPortal.mockClear() + Object.assign(window, { + api: { + orcaProfiles: { + billingSetOverage: setOverage, + billingStatus, + billingOpenPortal: openPortal + } + } + }) +}) + +afterEach(() => { + cleanup() +}) + +function renderBlocker( + kind: BillingBlockKind, + { canManageBilling = true, capCents = 2500 } = {} +): { + onContinue: ReturnType + onBackToDraft: ReturnType + onComparePlans: ReturnType +} { + const onContinue = vi.fn() + const onBackToDraft = vi.fn() + const onComparePlans = vi.fn() + render( + + ) + return { onContinue, onBackToDraft, onComparePlans } +} + +describe('billing blocker on the creating sheet (JA-21)', () => { + it('out of hours: Turn on with a $25 cap saves overage and continues the create', async () => { + setOverage.mockResolvedValue({ status: 'ok', entitlement: sampleTeam }) + const { onContinue } = renderBlocker('hoursUsed') + expect(screen.getByRole('heading', { name: 'Out of sandbox hours' })).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Turn on with a $25 cap' })) + await waitFor(() => expect(onContinue).toHaveBeenCalledOnce()) + expect(setOverage).toHaveBeenCalledWith({ + enabled: true, + spendCapCents: 2500 + }) + }) + + it('a failed save shows inline and does not continue', async () => { + setOverage.mockResolvedValue({ status: 'failed', error: 'boom' }) + const { onContinue } = renderBlocker('hoursUsed') + fireEvent.click(screen.getByRole('button', { name: 'Turn on with a $25 cap' })) + await waitFor(() => expect(screen.getByRole('status').textContent).not.toBe('')) + expect(onContinue).not.toHaveBeenCalled() + }) + + it('spend cap reached: the field starts at the cap plus $25 and saving continues', async () => { + setOverage.mockResolvedValue({ status: 'ok', entitlement: sampleTeam }) + const { onContinue } = renderBlocker('spendCap', { capCents: 4000 }) + const field = screen.getByLabelText('Monthly spend cap') + expect(field).toHaveProperty('value', '65') + fireEvent.change(field, { target: { value: '100' } }) + fireEvent.click(screen.getByRole('button', { name: 'Raise spend cap and continue' })) + await waitFor(() => expect(onContinue).toHaveBeenCalledOnce()) + expect(setOverage).toHaveBeenCalledWith({ + enabled: true, + spendCapCents: 10_000 + }) + }) + + it('payment failed: Update payment method opens billing, and returning re-checks once', async () => { + billingStatus.mockResolvedValue({ + status: 'ok', + entitlement: { ...sampleTeam, canStartSandbox: true } + }) + const { onContinue } = renderBlocker('payment') + fireEvent.click(screen.getByRole('button', { name: 'Update payment method' })) + expect(openPortal).toHaveBeenCalledOnce() + expect(screen.getByText('Finish in your browser.')).toBeTruthy() + act(() => { + window.dispatchEvent(new Event('focus')) + }) + await waitFor(() => expect(onContinue).toHaveBeenCalledOnce()) + expect(billingStatus).toHaveBeenCalledOnce() + }) + + it('still blocked after the browser: stays on the card with Check again', async () => { + billingStatus.mockResolvedValue({ + status: 'ok', + entitlement: { ...sampleTeam, canStartSandbox: false } + }) + const { onContinue } = renderBlocker('payment') + fireEvent.click(screen.getByRole('button', { name: 'Update payment method' })) + fireEvent.click(screen.getByRole('button', { name: 'Check again' })) + await waitFor(() => + expect( + screen.getByText('Not updated yet. Finish in your browser, then check again.') + ).toBeTruthy() + ) + expect(onContinue).not.toHaveBeenCalled() + }) + + it('no plan: Compare plans is the way forward', () => { + const { onComparePlans } = renderBlocker('plan') + expect(screen.getByRole('heading', { name: 'Choose a plan' })).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Compare plans' })) + expect(onComparePlans).toHaveBeenCalledOnce() + }) + + it.each([ + ['hoursUsed', 'Ask an owner or admin to add hours.'], + ['spendCap', 'Ask an owner or admin to raise the spend cap.'], + ['payment', 'Ask an owner or admin to update the payment method.'], + ['plan', 'Ask an owner or admin to choose a plan.'] + ] as const)('member, %s: says who can fix it and offers only Back to draft', (kind, ask) => { + renderBlocker(kind, { canManageBilling: false }) + expect(screen.getByText(ask)).toBeTruthy() + expect(screen.getAllByRole('button').map((button) => button.textContent)).toEqual([ + 'Back to draft' + ]) + }) + + it('Back to draft hands the draft back without saving anything', () => { + const { onBackToDraft, onContinue } = renderBlocker('hoursUsed') + fireEvent.click(screen.getByRole('button', { name: 'Back to draft' })) + expect(onBackToDraft).toHaveBeenCalledOnce() + expect(setOverage).not.toHaveBeenCalled() + expect(onContinue).not.toHaveBeenCalled() + }) +}) diff --git a/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.tsx b/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.tsx new file mode 100644 index 00000000000..e802e89ada7 --- /dev/null +++ b/src/renderer/src/components/worktree-creation/VmBuildBillingBlocker.tsx @@ -0,0 +1,347 @@ +import React from 'react' +import { AlertTriangle, Loader2 } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { useIntlLocale, useTranslate, type Translate } from '@/i18n/use-translate' +import type { + OrcaBillingEntitlement, + OrcaBillingOverageResult +} from '../../../../shared/orca-billing' +import { overageFailureCopy } from '../billing/plan-billing-copy' +import { formatCents } from '../billing/plans/plans-pricing' + +/** The four ways billing can refuse a create (JA-21 progressive billing). */ +export type BillingBlockKind = 'plan' | 'hoursUsed' | 'spendCap' | 'payment' + +/** Overage turned on from the blocker: the same $25 cap as Plan & billing's off state. */ +export const BLOCKER_OVERAGE_CAP_CENTS = 2500 +/** Raising a reached cap suggests this much more. */ +export const BLOCKER_CAP_STEP_CENTS = 2500 + +export type BillingBlockerPhase = + | { kind: 'idle' } + | { kind: 'saving' } + | { kind: 'error'; message: string } + /** A fix in the browser (portal): re-check on return, or with Check again. */ + | { kind: 'browser'; checking: boolean; stillBlocked: boolean } + +function blockerCopy( + kind: BillingBlockKind, + t: Translate +): { title: string; body: string; ask: string } { + switch (kind) { + case 'plan': + return { + title: t('worktreeCreation.billingBlock.plan.title', 'Choose a plan'), + body: t( + 'worktreeCreation.billingBlock.plan.body', + 'Your team needs a plan to start cloud workspaces.' + ), + ask: t('worktreeCreation.billingBlock.plan.ask', 'Ask an owner or admin to choose a plan.') + } + case 'hoursUsed': + return { + title: t('worktreeCreation.billingBlock.hours.title', 'Out of sandbox hours'), + body: t( + 'worktreeCreation.billingBlock.hours.body', + 'Your team has used all of this month’s sandbox hours.' + ), + ask: t('worktreeCreation.billingBlock.hours.ask', 'Ask an owner or admin to add hours.') + } + case 'spendCap': + return { + title: t('worktreeCreation.billingBlock.cap.title', 'Spend cap reached'), + body: t( + 'worktreeCreation.billingBlock.cap.body', + 'Overage is on, and this month’s spend cap is used.' + ), + ask: t( + 'worktreeCreation.billingBlock.cap.ask', + 'Ask an owner or admin to raise the spend cap.' + ) + } + case 'payment': + return { + title: t('worktreeCreation.billingBlock.payment.title', 'Payment failed'), + body: t('worktreeCreation.billingBlock.payment.body', 'New sandboxes can’t start.'), + ask: t( + 'worktreeCreation.billingBlock.payment.ask', + 'Ask an owner or admin to update the payment method.' + ) + } + } +} + +export type VmBuildBillingBlockerViewProps = { + kind: BillingBlockKind + canManageBilling: boolean + phase: BillingBlockerPhase + /** Spend cap reached: the field's starting value, in whole dollars. */ + suggestedCapDollars: number + onTurnOnOverage: () => void + onRaiseCap: (dollars: number) => void + onComparePlans: () => void + onUpdatePayment: () => void + onCheckAgain: () => void + onBackToDraft: () => void +} + +/** + * The creating sheet's billing blocker: replaces the steps when billing refuses a create. Nothing + * was created and no hours were used; the draft is kept, and an in-app fix continues the create. + */ +export function VmBuildBillingBlockerView({ + kind, + canManageBilling, + phase, + suggestedCapDollars, + onTurnOnOverage, + onRaiseCap, + onComparePlans, + onUpdatePayment, + onCheckAgain, + onBackToDraft +}: VmBuildBillingBlockerViewProps): React.JSX.Element { + const t = useTranslate() + const locale = useIntlLocale() + const copy = blockerCopy(kind, t) + const capId = React.useId() + const [cap, setCap] = React.useState(String(suggestedCapDollars)) + const headingRef = React.useRef(null) + React.useLayoutEffect(() => { + headingRef.current?.focus({ preventScroll: true }) + }, [kind]) + const saving = phase.kind === 'saving' + const capDollars = Number(cap) + const capValid = /^\d+$/.test(cap.trim()) && capDollars > 0 + const inBrowser = phase.kind === 'browser' + + return ( +
+
+ +
+
+

+ {copy.title} +

+

{copy.body}

+
+ {canManageBilling ? ( + inBrowser ? ( +
+

+ {phase.stillBlocked + ? t( + 'worktreeCreation.billingBlock.browserStill', + 'Not updated yet. Finish in your browser, then check again.' + ) + : t('worktreeCreation.billingBlock.browser', 'Finish in your browser.')} +

+ +
+ ) : kind === 'spendCap' ? ( +
{ + event.preventDefault() + if (!saving && capValid) { + onRaiseCap(capDollars) + } + }} + > +
+ +
+ $ + setCap(event.target.value)} + /> +
+
+ +
+ ) : ( +
+ {kind === 'hoursUsed' ? ( + + ) : null} + {kind === 'payment' ? ( + + ) : ( + + )} +
+ ) + ) : ( +

{copy.ask}

+ )} + {phase.kind === 'error' ? ( +

+ {phase.message} +

+ ) : null} +
+
+ +
+ ) +} + +/** + * The live blocker: in-app fixes (overage, a higher cap) save and continue the create at once; a + * browser fix (payment) re-checks once when Orca regains focus, or on Check again. + */ +export function VmBuildBillingBlocker({ + kind, + canManageBilling, + entitlement, + onContinue, + onComparePlans, + onBackToDraft +}: { + kind: BillingBlockKind + canManageBilling: boolean + entitlement: OrcaBillingEntitlement | null + /** Starts the create again from "Checking your plan…". */ + onContinue: () => void + onComparePlans: () => void + onBackToDraft: () => void +}): React.JSX.Element { + const t = useTranslate() + const locale = useIntlLocale() + const [phase, setPhase] = React.useState({ + kind: 'idle' + }) + const currentCap = entitlement?.overage.spendCapCents ?? 0 + const suggestedCapDollars = Math.round((currentCap + BLOCKER_CAP_STEP_CENTS) / 100) + const maxCap = entitlement?.offers?.team.maxSpendCapCents ?? null + + const saveOverage = async (spendCapCents: number): Promise => { + setPhase({ kind: 'saving' }) + const outcome = await window.api.orcaProfiles + .billingSetOverage({ enabled: true, spendCapCents }) + .catch((error: unknown): OrcaBillingOverageResult => ({ + status: 'failed', + error: String(error) + })) + if (outcome.status === 'ok') { + onContinue() + return + } + setPhase({ + kind: 'error', + message: + overageFailureCopy(outcome, t, maxCap, locale) ?? + t( + 'worktreeCreation.billingBlock.saveFailed', + 'Couldn’t save that. Try again, or change it in Plan & billing.' + ) + }) + } + + const checkBilling = React.useCallback(async (): Promise => { + setPhase({ kind: 'browser', checking: true, stillBlocked: false }) + const status = await window.api.orcaProfiles.billingStatus().catch(() => null) + // The service's own verdict: a fixed payment makes new sandboxes startable again. + if (status?.status === 'ok' && status.entitlement.canStartSandbox) { + onContinue() + return + } + setPhase({ kind: 'browser', checking: false, stillBlocked: true }) + }, [onContinue]) + + // Back from the browser: check once; if billing is fine the create continues on its own. + const waitingOnBrowser = phase.kind === 'browser' + React.useEffect(() => { + if (!waitingOnBrowser) { + return + } + const onFocus = (): void => { + window.removeEventListener('focus', onFocus) + void checkBilling() + } + window.addEventListener('focus', onFocus) + return () => window.removeEventListener('focus', onFocus) + }, [waitingOnBrowser, checkBilling]) + + return ( + void saveOverage(BLOCKER_OVERAGE_CAP_CENTS)} + onRaiseCap={(dollars) => void saveOverage(dollars * 100)} + onComparePlans={onComparePlans} + onUpdatePayment={() => { + setPhase({ kind: 'browser', checking: false, stillBlocked: false }) + void window.api.orcaProfiles.billingOpenPortal().catch(() => {}) + }} + onCheckAgain={() => void checkBilling()} + onBackToDraft={onBackToDraft} + /> + ) +} diff --git a/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx b/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx index 76913f8d83b..f002b021bec 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx @@ -20,6 +20,7 @@ import { formatEnvironmentDoctorChecks } from '../../../../shared/environment-do import { VmBuildStepRow } from './VmBuildStepRow' import { firstBuildLogErrorLine, VmBuildLog } from './VmBuildLog' import { VmBuildFailureCard } from './VmBuildFailureCard' +import { VmBuildBillingBlocker } from './VmBuildBillingBlocker' import { VmBuildAgentSignInRow } from './VmBuildAgentSignInRow' import { VmBuildSecretsRow } from '../cloud-secrets-ask/VmBuildSecretsRow' import { OrcaCloudQueuedPrompt } from '@/components/orca-cloud/OrcaCloudQueuedPrompt' @@ -154,6 +155,9 @@ export function VmBuildSheet({ const failure = classifyVmBuildFailure({ entry, error, cloud }) const gated = isAccountGate(failure) const billing = useOrcaBillingStatus(isBillingFailure(failure)) + // JA-21: on Orca Cloud a billing refusal is a blocker card in place of the steps, under the + // sheet's own title; nothing was created and the draft is kept. + const billingBlock = cloud && failure && isBillingFailure(failure) ? failure.kind : null // Unknown roles get the owner's copy; only a known member is told to ask someone else. const canManageBilling = billing.result?.status !== 'ok' || billing.result.entitlement.canManageBilling @@ -210,7 +214,7 @@ export function VmBuildSheet({
{/* JA-24: on Orca Cloud a failure card carries the one title; no page title above it. */} - {cloud && failure ? null : ( + {cloud && failure && !billingBlock ? null : (
@@ -240,7 +244,9 @@ export function VmBuildSheet({ aria-live={failure ? 'off' : 'polite'} className="text-sm font-medium text-foreground outline-none" > - {headerTitle(state, cloud, t, failure?.kind === 'create')} + {billingBlock + ? headerTitle('building', cloud, t) + : headerTitle(state, cloud, t, failure?.kind === 'create')} {/* Orca Cloud: each step carries its own timer, so the header has none. */} {gated || cloud ? null : ( @@ -258,117 +264,137 @@ export function VmBuildSheet({
)} -
- {/* An account refusal happens before anything starts, so there are no steps to show. */} - {gated ? null : ( -
    - {steps.map((step) => ( - candidate.id === 'provision')?.elapsedMs ?? 0} - /> - ))} - {/* Orca Cloud: agent setup happens after create (the setup page and the workspace's - sign-in strip), so the build card has no agent row. Other VMs keep the host's own. */} - {agentSignInRow ?? - (!cloud && entry.vmEnvironmentId ? ( - - ) : null)} - {secretsRow !== undefined ? ( - secretsRow - ) : cloud ? ( - - ) : null} -
- )} - - { - if (recipe) { - startFixWithAgent({ - repoId: recipe.sourceRepoId, - recipeId: recipe.recipeId, - failure: fixContext(failure, derived, entry, error, cloud, t) - }) - } - }, - onRetry: - failure?.kind === 'checks' - ? () => resolveVmEnvironmentCheckDecision(creationId, 'retry') - : onRetry, - onEditRecipe, - onOpenAnyway: () => resolveVmEnvironmentCheckDecision(creationId, 'open-anyway'), - // A paused create deletes this sandbox and starts over; one already gone just retries. - onStartAgain: () => - isAwaitingVmEnvironmentCheckDecision(creationId) - ? resolveVmEnvironmentCheckDecision(creationId, 'restart') - : onRetry(), - // Nothing was created, so leaving a billing refusal hands the typed prompt back. - onDismiss: - isBillingFailure(failure) && typedComposerPrompt(entry).trim() - ? () => onReturnToComposer({ local: false }) - : onDismiss, - onSeePlans: () => { - // Once paid, the plans dialog closes and retries this create. - requestOrcaCloudAfterCheckout({ kind: 'retry', creationId }) - openPlansPage('sandbox') - }, - onCreateLocally: () => onReturnToComposer({ local: true }), - onOpenBilling: () => { - const store = useAppStore.getState() - store.openSettingsTarget({ - pane: 'cloud-billing', - repoId: null, - // "Turn on overage" / "Raise spend cap" land on the overage card itself; the - // payment notice is at the top of the section already. - ...(failure?.kind === 'payment' - ? {} - : { sectionId: ORCA_BILLING_OVERAGE_SECTION_ID }) - }) - store.openSettingsPage() - }, - onSignIn: signIn, - // Your workspaces on Home, where you can put one to sleep or delete it. - onShowWorkspaces: () => openCloudWorkspacesHome({ running: true }), - onContactSupport: () => openAppHttpLink(SUPPORT_URL), - onConnectGitHub: connectGitHub, - onPushToGitHub: () => openAppHttpLink(PUSH_TO_GITHUB_URL) + entitlement={billing.result?.status === 'ok' ? billing.result.entitlement : null} + onContinue={onRetry} + onComparePlans={() => { + // Once paid, the plans page closes and continues this create. + requestOrcaCloudAfterCheckout({ kind: 'retry', creationId }) + openPlansPage('sandbox') }} + onBackToDraft={() => onReturnToComposer({ local: false })} /> -
+ ) : ( +
+ {/* An account refusal happens before anything starts, so there are no steps to show. */} + {gated ? null : ( +
    + {steps.map((step) => ( + candidate.id === 'provision')?.elapsedMs ?? 0 + } + /> + ))} + {/* Orca Cloud: agent setup happens after create (the setup page and the workspace's + sign-in strip), so the build card has no agent row. Other VMs keep the host's own. */} + {agentSignInRow ?? + (!cloud && entry.vmEnvironmentId ? ( + + ) : null)} + {secretsRow !== undefined ? ( + secretsRow + ) : cloud ? ( + + ) : null} +
+ )} + + { + if (recipe) { + startFixWithAgent({ + repoId: recipe.sourceRepoId, + recipeId: recipe.recipeId, + failure: fixContext(failure, derived, entry, error, cloud, t) + }) + } + }, + onRetry: + failure?.kind === 'checks' + ? () => resolveVmEnvironmentCheckDecision(creationId, 'retry') + : onRetry, + onEditRecipe, + onOpenAnyway: () => resolveVmEnvironmentCheckDecision(creationId, 'open-anyway'), + // A paused create deletes this sandbox and starts over; one already gone just retries. + onStartAgain: () => + isAwaitingVmEnvironmentCheckDecision(creationId) + ? resolveVmEnvironmentCheckDecision(creationId, 'restart') + : onRetry(), + // Nothing was created, so leaving a billing refusal hands the typed prompt back. + onDismiss: + isBillingFailure(failure) && typedComposerPrompt(entry).trim() + ? () => onReturnToComposer({ local: false }) + : onDismiss, + onSeePlans: () => { + // Once paid, the plans dialog closes and retries this create. + requestOrcaCloudAfterCheckout({ kind: 'retry', creationId }) + openPlansPage('sandbox') + }, + onCreateLocally: () => onReturnToComposer({ local: true }), + onOpenBilling: () => { + const store = useAppStore.getState() + store.openSettingsTarget({ + pane: 'cloud-billing', + repoId: null, + // "Turn on overage" / "Raise spend cap" land on the overage card itself; the + // payment notice is at the top of the section already. + ...(failure?.kind === 'payment' + ? {} + : { sectionId: ORCA_BILLING_OVERAGE_SECTION_ID }) + }) + store.openSettingsPage() + }, + onSignIn: signIn, + // Your workspaces on Home, where you can put one to sleep or delete it. + onShowWorkspaces: () => openCloudWorkspacesHome({ running: true }), + onContactSupport: () => openAppHttpLink(SUPPORT_URL), + onConnectGitHub: connectGitHub, + onPushToGitHub: () => openAppHttpLink(PUSH_TO_GITHUB_URL) + }} + /> +
+ )} {building ? : null} - {cloud && !gated ? ( + {cloud && !gated && !billingBlock ? (