From 0c542e83755ecb20f2edbf06c4207b15d9df14d4 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 02:41:14 -0800 Subject: [PATCH 1/3] copy(billing): overage reads '{{rate}} per sandbox hour' with the rate from the plan (glossary); formatRateCents always shows cents --- .../src/components/billing/PlanBillingUsage.tsx | 16 ++++++++-------- .../components/billing/plans/TeamPlanCard.tsx | 15 ++++++++++----- .../billing/plans/plans-pricing.test.ts | 6 ++++++ .../components/billing/plans/plans-pricing.ts | 10 ++++++++++ src/renderer/src/i18n/locales/en.json | 6 +++--- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/components/billing/PlanBillingUsage.tsx b/src/renderer/src/components/billing/PlanBillingUsage.tsx index 8f306414235..b56af82d4cd 100644 --- a/src/renderer/src/components/billing/PlanBillingUsage.tsx +++ b/src/renderer/src/components/billing/PlanBillingUsage.tsx @@ -11,7 +11,7 @@ import type { OrcaBillingOverageArgs } from '../../../../shared/orca-billing' import { formatHours, includedUsagePercent } from './plan-billing-format' -import { formatCents } from './plans/plans-pricing' +import { formatCents, formatRateCents } from './plans/plans-pricing' import { ORCA_BILLING_OVERAGE_SECTION_ID } from '../new-workspace/orca-cloud-run-target-access' /** "Resets and renews Dec 2" when both land the same day (monthly); separate parts otherwise. */ @@ -162,17 +162,17 @@ export function OverageControls({ const changed = capValid && capDollars.trim() !== savedDollars const paymentFailed = entitlement.payment.pastDueSince !== null const description = t( - 'auto.components.billing.overageDescription5', - 'Optional overage at {{value0}}/hour, up to a monthly spend cap you set ({{value1}} by default).', + 'auto.components.billing.overageDescription6', + 'Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set ({{cap}} by default).', { - value0: formatCents(overage.centsPerHour, locale), - value1: formatCents(entitlement.offers?.team.defaultSpendCapCents ?? 2500, locale) + rate: formatRateCents(overage.centsPerHour, locale), + cap: formatCents(entitlement.offers?.team.defaultSpendCapCents ?? 2500, locale) } ) const descriptionOn = t( - 'auto.components.billing.overageDescriptionOn2', - 'Optional overage at {{value0}}/hour, up to a monthly spend cap you set.', - { value0: formatCents(overage.centsPerHour, locale) } + 'auto.components.billing.overageDescriptionOn3', + 'Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set.', + { rate: formatRateCents(overage.centsPerHour, locale) } ) const capPercent = overage.spendCapCents > 0 diff --git a/src/renderer/src/components/billing/plans/TeamPlanCard.tsx b/src/renderer/src/components/billing/plans/TeamPlanCard.tsx index 1ab9d0ecbf8..34e4e84771c 100644 --- a/src/renderer/src/components/billing/plans/TeamPlanCard.tsx +++ b/src/renderer/src/components/billing/plans/TeamPlanCard.tsx @@ -7,7 +7,12 @@ import { LoadingSpinner } from '@/components/LoadingSpinner' import { useIntlLocale, useTranslate } from '@/i18n/use-translate' import type { OrcaBillingInterval, OrcaBillingOffers } from '../../../../../shared/orca-billing' import { PlanCardShell } from './PlanCardShell' -import { formatCents, perSeatMonthlyCents, periodTotalCents } from './plans-pricing' +import { + formatCents, + formatRateCents, + perSeatMonthlyCents, + periodTotalCents +} from './plans-pricing' import { ORCA_CLOUD_SANDBOX_SPEC } from '../../../../../shared/hosted-sandbox/hosted-sandbox-wire' export type TeamPlanCardMode = 'choose' | 'current' | 'locked' @@ -65,11 +70,11 @@ export function TeamPlanCard({ ), t('auto.components.billing.plans.featureReady', 'Ready in seconds, nothing to set up or host'), t( - 'auto.components.billing.plans.featureOverage5', - 'Optional overage at {{value0}}/hour, up to a monthly spend cap you set ({{value1}} by default)', + 'auto.components.billing.plans.featureOverage6', + 'Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set ({{cap}} by default)', { - value0: formatCents(team.overageCentsPerHour, locale), - value1: formatCents(team.defaultSpendCapCents, locale) + rate: formatRateCents(team.overageCentsPerHour, locale), + cap: formatCents(team.defaultSpendCapCents, locale) } ) ] diff --git a/src/renderer/src/components/billing/plans/plans-pricing.test.ts b/src/renderer/src/components/billing/plans/plans-pricing.test.ts index 19dd7bb2c5b..047e7075978 100644 --- a/src/renderer/src/components/billing/plans/plans-pricing.test.ts +++ b/src/renderer/src/components/billing/plans/plans-pricing.test.ts @@ -4,6 +4,7 @@ import { annualSavingsPercent, clampSeats, formatCents, + formatRateCents, perSeatMonthlyCents, periodTotalCents } from './plans-pricing' @@ -38,6 +39,11 @@ describe('plans pricing', () => { expect(formatCents(144000, 'en-US')).toBe('$1,440') }) + it('always shows cents on a per-hour rate', () => { + expect(formatRateCents(100, 'en-US')).toBe('$1.00') + expect(formatRateCents(75, 'en-US')).toBe('$0.75') + }) + it('clamps seats to 1..max', () => { expect(clampSeats(0, 500)).toBe(1) expect(clampSeats(Number.NaN, 500)).toBe(1) diff --git a/src/renderer/src/components/billing/plans/plans-pricing.ts b/src/renderer/src/components/billing/plans/plans-pricing.ts index 5e94f0aac1b..1d83adea42b 100644 --- a/src/renderer/src/components/billing/plans/plans-pricing.ts +++ b/src/renderer/src/components/billing/plans/plans-pricing.ts @@ -46,6 +46,16 @@ export function formatCents(cents: number, locale: string): string { }).format(cents / 100) } +/** A per-hour rate always shows cents ("$1.00", "$0.75"), unlike whole-dollar prices. */ +export function formatRateCents(cents: number, locale: string): string { + return new Intl.NumberFormat(locale, { + style: 'currency', + currency: 'USD', + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }).format(cents / 100) +} + export const MIN_SEATS = 1 export function clampSeats(value: number, max: number): number { diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index b9bcc9b9409..fa9eb939091 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -20624,7 +20624,7 @@ "was": "Was", "featureHours4": "{{value0}} sandbox hours per seat each month, pooled across your team", "featureSpec": "Every sandbox gets {{value0}} vCPU · {{value1}} GB", - "featureOverage5": "Optional overage at {{value0}}/hour, up to a monthly spend cap you set ({{value1}} by default)", + "featureOverage6": "Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set ({{cap}} by default)", "footTerms4": "Prices in USD, before tax. Overage is off until an owner or admin turns it on. Cancel anytime; your plan runs to the end of the billing period.", "lockedBody2": "Only an owner or admin of your team can choose a plan. Ask one of them to open Plan & billing in Orca.", "vpSecretsBody4": "API keys you add to Orca are never written to the sandbox. Agents and terminals get them as environment variables.", @@ -20699,7 +20699,7 @@ "enterpriseContactSales": "Contact sales", "openForbidden2": "Only an owner or admin can manage billing.", "openSignedOut2": "Sign in to Orca again to manage your team.", - "overageDescription5": "Optional overage at {{value0}}/hour, up to a monthly spend cap you set ({{value1}} by default).", + "overageDescription6": "Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set ({{cap}} by default).", "overageHoursOnly": "{{value0}} overage hours this month", "overageMemberHint": "Owners and admins can change overage.", "overageOffRead": "Off", @@ -20719,7 +20719,7 @@ "sandboxHoursUsedMonth": "{{value0}} of {{value1}} sandbox hours used this month", "warn100b": "All of this month’s sandbox hours are used.", "warnPercent2": "You’ve used {{value0}}% of this month’s sandbox hours.", - "overageDescriptionOn2": "Optional overage at {{value0}}/hour, up to a monthly spend cap you set.", + "overageDescriptionOn3": "Optional overage at {{rate}} per sandbox hour, up to a monthly spend cap you set.", "reasonCapMember3": "Spend cap reached. Ask an owner or admin to raise the spend cap. Your files are safe.", "reasonGraceExpired3": "Payment failed. New sandboxes can’t start and running sandboxes are asleep. Update your payment method. Your files are safe.", "reasonGraceExpiredMember2": "Payment failed. New sandboxes can’t start and running sandboxes are asleep. Ask an owner or admin to update the payment method. Your files are safe.", From 9a4bd94b66c559e1685a61a10e44cb4621068cfb Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 02:44:23 -0800 Subject: [PATCH 2/3] feat(billing): member billing walls and back-to-work after checkout (DS-15, DS-16) DS-15: no-plan access carries canManageBilling. Members see 'Ask an owner or admin' instead of Upgrade, and the hint says 'Ask an owner or admin to choose one.'; at the cap they're told to raise the spend cap. Every billing failure on the build card offers 'Create on this computer instead' (same prompt, Local), and Dismiss hands the typed prompt back to the composer. DS-16: choosing a plan from an Orca Cloud wall leaves an intent. Once paid, the plans dialog returns to the open composer with Orca Cloud picked, or retries the refused create. The no-plan card adds Try again, and the Team page's create action opens on Orca Cloud. --- .../billing/checkout/checkout-return.ts | 49 +++++++++++ .../billing/plans/PlansDialogHost.tsx | 15 ++-- .../billing/team/TeamDialogHost.tsx | 7 +- .../CloudAgentSetup.fixture.tsx | 1 + ...orkspaceComposerProjectSection.fixture.tsx | 59 ++++++++++++- .../new-workspace/OrcaCloudSelectionHint.tsx | 30 +++++-- .../RunTargetCombobox.fixture.tsx | 42 +++++++++- .../new-workspace/RunTargetCombobox.test.tsx | 13 ++- .../new-workspace/RunTargetOrcaCloudRow.tsx | 30 ++++--- .../orca-cloud-run-target-access.test.ts | 62 ++++++++++++++ .../orca-cloud-run-target-access.ts | 24 ++++-- .../use-run-target-orca-cloud.ts | 14 +++- .../VmBuildFailureActions.tsx | 46 ++++++++--- .../VmBuildFailureCard.test.tsx | 34 +++++++- .../worktree-creation/VmBuildSheet.tsx | 18 +++- .../VmBuildSheetCloudFailures.fixture.tsx | 38 +++++++-- .../WorktreeCreationPanel.tsx | 10 +++ .../vm-build-composer-return.test.ts | 49 +++++++++++ .../vm-build-composer-return.ts | 33 ++++++++ .../vm-build-sheet-fixture-support.tsx | 9 +- .../src/hooks/useEphemeralVmRecipeOptions.ts | 4 + src/renderer/src/i18n/locales/en.json | 7 +- .../src/lib/orca-cloud-after-checkout.test.ts | 62 ++++++++++++++ .../src/lib/orca-cloud-after-checkout.ts | 82 +++++++++++++++++++ 24 files changed, 670 insertions(+), 68 deletions(-) create mode 100644 src/renderer/src/components/billing/checkout/checkout-return.ts create mode 100644 src/renderer/src/components/new-workspace/orca-cloud-run-target-access.test.ts create mode 100644 src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts create mode 100644 src/renderer/src/components/worktree-creation/vm-build-composer-return.ts create mode 100644 src/renderer/src/lib/orca-cloud-after-checkout.test.ts create mode 100644 src/renderer/src/lib/orca-cloud-after-checkout.ts diff --git a/src/renderer/src/components/billing/checkout/checkout-return.ts b/src/renderer/src/components/billing/checkout/checkout-return.ts new file mode 100644 index 00000000000..e600549131a --- /dev/null +++ b/src/renderer/src/components/billing/checkout/checkout-return.ts @@ -0,0 +1,49 @@ +import { useAppStore } from '@/store/index' +import { + takeOrcaCloudCheckoutReturn, + emitOrcaCloudCheckoutReturn +} from '@/lib/orca-cloud-after-checkout' +import { requestOrcaCloudSelectionAfterSignIn } from '@/lib/orca-cloud-select-after-sign-in' +import { invalidateOrcaCloudBilling } from '@/components/new-workspace/orca-cloud-billing-cache' +import { ORCA_CLOUD_RECIPE_ID } from '../../../../../shared/hosted-sandbox/orca-cloud-recipe-id' +import { closePlansPage } from '../plans/plans-page-store' +import { closeTeamPage, openTeamPage } from '../team/team-page-store' + +/** + * A paid Checkout closes the plans page and goes back to the work that hit the wall: the open + * composer with Orca Cloud picked, or the refused create, retried. Without an intent it lands on + * the Team page's "You're on Team" confirmation. + */ +export function returnAfterPaidCheckout(paidSeats: number): void { + closePlansPage() + const store = useAppStore.getState() + const target = takeOrcaCloudCheckoutReturn({ + composerOpen: store.activeModal === 'new-workspace-composer', + hasCreation: (creationId) => Boolean(store.pendingWorktreeCreations[creationId]) + }) + if (target.kind === 'team-page') { + openTeamPage({ kind: 'checkout-success', seats: paidSeats }) + return + } + closeTeamPage() + // The Run-on row cached "no plan"; read the new entitlement now so it shows hours, not Upgrade. + invalidateOrcaCloudBilling() + switch (target.kind) { + case 'retry': + // Lazy: the creation flow's import graph is heavy and billing never needs it otherwise. + void import('@/lib/workspace/creation/worktree-creation-flow').then( + ({ retryBackgroundWorktreeCreation }) => retryBackgroundWorktreeCreation(target.creationId) + ) + return + case 'select-in-composer': + // The composer's recipe list reloads and consumes this, as it does after signing in. + requestOrcaCloudSelectionAfterSignIn() + emitOrcaCloudCheckoutReturn() + return + case 'open-composer': + store.openModal('new-workspace-composer', { + initialEphemeralVmRecipeId: ORCA_CLOUD_RECIPE_ID, + telemetrySource: 'unknown' + }) + } +} diff --git a/src/renderer/src/components/billing/plans/PlansDialogHost.tsx b/src/renderer/src/components/billing/plans/PlansDialogHost.tsx index a18897ec431..33fd15573a7 100644 --- a/src/renderer/src/components/billing/plans/PlansDialogHost.tsx +++ b/src/renderer/src/components/billing/plans/PlansDialogHost.tsx @@ -1,4 +1,4 @@ -import { useCallback, useState } from 'react' +import { useState } from 'react' import { Dialog } from '@/components/ui/dialog' import { useTranslate } from '@/i18n/use-translate' import { useAppStore } from '@/store/index' @@ -7,7 +7,8 @@ import { CheckoutPanel } from '../checkout/CheckoutPanel' import { useCheckoutFlow } from '../checkout/use-checkout-flow' import { openFailureCopy } from '../plan-billing-copy' import type { PlanBillingNotice } from '../PlanBillingSection' -import { openTeamPage } from '../team/team-page-store' +import { returnAfterPaidCheckout } from '../checkout/checkout-return' +import { cancelOrcaCloudAfterCheckout } from '@/lib/orca-cloud-after-checkout' import { useOrcaBillingStatus } from '../use-orca-billing-status' import { PlansDialogContent } from './PlansDialogContent' import { closePlansPage, usePlansPageState } from './plans-page-store' @@ -17,7 +18,7 @@ import { useOrgSeatCount } from './use-org-seat-count' * The plans page. A dialog because choosing a plan is a decision step in front of Checkout; * it reads the billing service's offers, so prices and limits are never hardcoded here. * Checkout itself runs on Stripe's hosted page in the browser; this dialog follows it and, - * once paid, hands over to the Team page. + * once paid, returns to the Orca Cloud wall that opened it, or hands over to the Team page. */ export function PlansDialogHost(): React.JSX.Element { const t = useTranslate() @@ -29,11 +30,7 @@ export function PlansDialogHost(): React.JSX.Element { const [notice, setNotice] = useState(null) const [orderedAt, setOrderedAt] = useState(0) - const onPaid = useCallback((paidSeats: number) => { - closePlansPage() - openTeamPage({ kind: 'checkout-success', seats: paidSeats }) - }, []) - const checkout = useCheckoutFlow({ onPaid }) + const checkout = useCheckoutFlow({ onPaid: returnAfterPaidCheckout }) const openPortal = async (): Promise => { setBusy(true) @@ -69,6 +66,8 @@ export function PlansDialogHost(): React.JSX.Element { // Closing ends the watch: polling stops and the next open starts from the plans. checkout.reset() closePlansPage() + // Leaving without paying: nothing to return to Orca Cloud for. + cancelOrcaCloudAfterCheckout() setNotice(null) } }} diff --git a/src/renderer/src/components/billing/team/TeamDialogHost.tsx b/src/renderer/src/components/billing/team/TeamDialogHost.tsx index 5485dadf76d..dbce53b536d 100644 --- a/src/renderer/src/components/billing/team/TeamDialogHost.tsx +++ b/src/renderer/src/components/billing/team/TeamDialogHost.tsx @@ -14,6 +14,7 @@ import { createTeamFailureCopy, mutationFailureCopy } from './team-copy' import { clearTeamPageArrival, closeTeamPage, useTeamPageState } from './team-page-store' import { useOrgRoster } from './use-org-roster' import { useTeamActions } from './use-team-actions' +import { ORCA_CLOUD_RECIPE_ID } from '../../../../../shared/hosted-sandbox/orca-cloud-recipe-id' function TeamPageBody({ arrival }: { arrival: ReturnType['arrival'] }) { const t = useTranslate() @@ -199,7 +200,11 @@ function TeamPageBody({ arrival }: { arrival: ReturnType { closeTeamPage() - openModal('new-workspace-composer', { telemetrySource: 'unknown' }) + // The plan is for Orca Cloud, so the composer opens on it rather than this computer. + openModal('new-workspace-composer', { + initialEphemeralVmRecipeId: ORCA_CLOUD_RECIPE_ID, + telemetrySource: 'unknown' + }) }} onDismissArrival={clearTeamPageArrival} onContactSales={(url) => void window.api.shell.openUrl(url)} diff --git a/src/renderer/src/components/cloud-agent-setup/CloudAgentSetup.fixture.tsx b/src/renderer/src/components/cloud-agent-setup/CloudAgentSetup.fixture.tsx index 045af8c6965..d87e93644ac 100644 --- a/src/renderer/src/components/cloud-agent-setup/CloudAgentSetup.fixture.tsx +++ b/src/renderer/src/components/cloud-agent-setup/CloudAgentSetup.fixture.tsx @@ -55,6 +55,7 @@ function sheet( onCancel={noop} onRetry={noop} onDismiss={noop} + onReturnToComposer={noop} onEditRecipe={noop} cloudAgentStep={ diff --git a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.fixture.tsx b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.fixture.tsx index 25256cbdac5..7248037b064 100644 --- a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.fixture.tsx +++ b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.fixture.tsx @@ -142,7 +142,16 @@ function ProjectAndHostPreview({ ) } -export const closed = defineFixture({ width: 560, render: () => }) +export const closed = defineFixture({ + width: 560, + // The browser preload answers agent keys and Cloud secrets with stubs the Orca Cloud agent hint + // can't read; without them the hint shows nothing, as it does before they load. + setup: () => { + window.api.agentApiKeys = undefined + window.api.cloudSecrets = undefined + }, + render: () => +}) export const narrow = defineFixture({ width: 360, render: () => }) export const folderOnly = defineFixture({ width: 560, @@ -186,7 +195,11 @@ export const hostMenuOrcaCloud = defineFixture({ }) export const hostMenuOrcaCloudLocked = defineFixture({ ...hostMenu, - render: () => + render: () => ( + + ) }) export const orcaCloudSelected = defineFixture({ ...closed, @@ -196,7 +209,10 @@ export const orcaCloudSelected = defineFixture({ export const orcaCloudSelectedNoPlan = defineFixture({ ...closed, render: () => ( - + ) }) export const orcaCloudSelectedOutOfHoursMember = defineFixture({ @@ -217,3 +233,40 @@ export const orcaCloudSelectedPaymentAdmin = defineFixture({ /> ) }) +// DS-15: a member can't choose a plan or raise the cap, so the hint says who can and offers no fix. +export const orcaCloudSelectedNoPlanMember = defineFixture({ + ...closed, + render: () => ( + + ) +}) +export const orcaCloudSelectedCapMember = defineFixture({ + ...closed, + render: () => ( + + ) +}) +export const hostMenuOrcaCloudNoPlanMember = defineFixture({ + ...hostMenu, + render: () => ( + + ) +}) +// DS-16: back from a paid Checkout, the composer is open again with Orca Cloud picked and its hours. +export const orcaCloudAfterCheckout = defineFixture({ + ...closed, + render: () => ( + + ) +}) diff --git a/src/renderer/src/components/new-workspace/OrcaCloudSelectionHint.tsx b/src/renderer/src/components/new-workspace/OrcaCloudSelectionHint.tsx index f353144eea6..34767afbc05 100644 --- a/src/renderer/src/components/new-workspace/OrcaCloudSelectionHint.tsx +++ b/src/renderer/src/components/new-workspace/OrcaCloudSelectionHint.tsx @@ -28,11 +28,20 @@ function useBlockCopy(access: OrcaCloudRunTargetAccess): BlockCopy | null { 'auto.components.new.workspace.RunTargetCombobox.orcaCloudNeedsTeamPlan', 'Orca Cloud needs a Team plan.' ), - detail: '', + detail: access.canManageBilling + ? '' + : t( + 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskChoosePlan', + 'Ask an owner or admin to choose one.' + ), tone: 'neutral', - action: access.lapsed - ? t('auto.components.new.workspace.RunTargetCombobox.orcaCloudRenew', 'Renew') - : t('auto.components.new.workspace.RunTargetCombobox.orcaCloudUpgrade', 'Upgrade') + ...(access.canManageBilling + ? { + action: access.lapsed + ? t('auto.components.new.workspace.RunTargetCombobox.orcaCloudRenew', 'Renew') + : t('auto.components.new.workspace.RunTargetCombobox.orcaCloudUpgrade', 'Upgrade') + } + : {}) } case 'out-of-hours': { const cap = access.cause === 'cap' @@ -49,10 +58,15 @@ function useBlockCopy(access: OrcaCloudRunTargetAccess): BlockCopy | null { ), detail: access.canManageBilling ? '' - : t( - 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskAddHoursOnly', - 'Ask an owner or admin to add hours.' - ), + : cap + ? t( + 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskRaiseSpendCap', + 'Ask an owner or admin to raise the spend cap.' + ) + : t( + 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskAddHoursOnly', + 'Ask an owner or admin to add hours.' + ), tone: 'neutral', ...(access.canManageBilling ? { diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx index 92e6c1dbcc4..0037f139367 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.fixture.tsx @@ -121,7 +121,12 @@ export const orcaCloudEntitled = defineFixture({ }) export const orcaCloudNotEntitled = defineFixture({ width: 420, - render: () => , + render: () => ( + + ), interact: open }) export const orcaCloudOutOfHours = defineFixture({ @@ -153,7 +158,12 @@ export const orcaCloudPaymentIssue = defineFixture({ }) export const orcaCloudLapsed = defineFixture({ width: 420, - render: () => , + render: () => ( + + ), interact: open }) export const orcaCloudSelectedClosed = defineFixture({ @@ -188,7 +198,12 @@ export const orcaCloudSignedOut = defineFixture({ }) export const orcaCloudNoCapability = defineFixture({ width: 420, - render: () => , + render: () => ( + + ), interact: open }) export const orcaCloudCapReached = defineFixture({ @@ -233,3 +248,24 @@ export const needsSetupArmed = defineFixture({ render: () => , interact: pressKeys('ArrowDown', 'ArrowDown') }) +// DS-15: members see who can fix it, not Upgrade, and the row can't be picked. +export const orcaCloudNoPlanMember = defineFixture({ + width: 420, + render: () => ( + + ), + interact: open +}) +export const orcaCloudCapReachedMember = defineFixture({ + width: 420, + render: () => ( + + ), + interact: open +}) diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.test.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.test.tsx index 96eaf67974a..28c12a4b7c3 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.test.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.test.tsx @@ -137,13 +137,24 @@ describe('RunTargetCombobox', () => { it('opens the plans page instead of building when there is no plan', () => { const onRecipeChange = vi.fn() - render({ state: 'no-plan', lapsed: false }, onRecipeChange) + render({ state: 'no-plan', lapsed: false, canManageBilling: true }, onRecipeChange) press('ArrowDown') press('Enter') expect(openPlansPage).toHaveBeenCalledWith('sandbox') expect(onRecipeChange).not.toHaveBeenCalled() }) + it('tells a member without a plan to ask an owner or admin instead of opening plans', () => { + const onRecipeChange = vi.fn() + render({ state: 'no-plan', lapsed: false, canManageBilling: false }, onRecipeChange) + expect(container.textContent).toContain('Ask an owner or admin') + expect(container.textContent).not.toContain('Upgrade') + press('ArrowDown') + press('Enter') + expect(openPlansPage).not.toHaveBeenCalled() + expect(onRecipeChange).not.toHaveBeenCalled() + }) + it('moves keyboard focus into the recipe submenu and commits a recipe with Enter', () => { const onRecipeChange = vi.fn() render({ state: 'entitled', remainingSeconds: 3600 }, onRecipeChange) diff --git a/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx b/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx index b4beb0ceb9b..3b005030eb3 100644 --- a/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetOrcaCloudRow.tsx @@ -148,6 +148,19 @@ function OrcaCloudDetail({ access }: { access: OrcaCloudRunTargetAccess }): Reac } } +/** Members can't fix billing; say who can rather than offer a pick that does nothing. */ +function AskOwnerOrAdmin(): React.JSX.Element { + const t = useTranslate() + return ( + + {t( + 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskOwnerOrAdmin', + 'Ask an owner or admin' + )} + + ) +} + function OrcaCloudMeta({ access, onAction @@ -187,6 +200,9 @@ function OrcaCloudMeta({ /> ) case 'no-plan': + if (!access.canManageBilling) { + return + } return ( - {t( - 'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskOwnerOrAdmin', - 'Ask an owner or admin' - )} - - ) + return } return ( ({ + openPlansPage: (source: string) => openPlansPage(source) +})) +const requestOrcaCloudAfterCheckout = vi.fn() +vi.mock('@/lib/orca-cloud-after-checkout', () => ({ + requestOrcaCloudAfterCheckout: (intent: unknown) => requestOrcaCloudAfterCheckout(intent) +})) + +function denied( + reason: OrcaBillingEntitlement['reason'], + canManageBilling: boolean +): Parameters[0] { + return { + status: 'ok', + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: access reads only these fields. + entitlement: { + canStartSandbox: false, + remainingIncludedSeconds: 0, + reason, + canManageBilling + } as OrcaBillingEntitlement + } +} + +describe('Orca Cloud run-target access by role', () => { + beforeEach(() => { + openPlansPage.mockReset() + requestOrcaCloudAfterCheckout.mockReset() + }) + + it('carries the role on no plan, so members are not sent to plans they cannot buy', () => { + const owner = toOrcaCloudRunTargetAccess(denied('no_subscription', true)) + const member = toOrcaCloudRunTargetAccess(denied('subscription_inactive', false)) + expect(owner).toEqual({ state: 'no-plan', lapsed: false, canManageBilling: true }) + expect(member).toEqual({ state: 'no-plan', lapsed: true, canManageBilling: false }) + expect(getOrcaCloudPick(member)).toEqual({ kind: 'blocked' }) + expect(openPlansPage).not.toHaveBeenCalled() + }) + + it('sends an owner or admin to plans and leaves a return-to-composer intent', () => { + const pick = getOrcaCloudPick(toOrcaCloudRunTargetAccess(denied('no_subscription', true))) + expect(pick.kind).toBe('act') + if (pick.kind === 'act') { + pick.run() + } + expect(requestOrcaCloudAfterCheckout).toHaveBeenCalledWith({ kind: 'composer' }) + expect(openPlansPage).toHaveBeenCalledWith('sandbox') + }) + + it('blocks members at the spend cap and lets owners act', () => { + const member = toOrcaCloudRunTargetAccess(denied('overage_cap_reached', false)) + expect(member).toEqual({ state: 'out-of-hours', cause: 'cap', canManageBilling: false }) + expect(getOrcaCloudPick(member)).toEqual({ kind: 'blocked' }) + const owner = toOrcaCloudRunTargetAccess(denied('overage_cap_reached', true)) + expect(getOrcaCloudPick(owner).kind).toBe('act') + }) +}) diff --git a/src/renderer/src/components/new-workspace/orca-cloud-run-target-access.ts b/src/renderer/src/components/new-workspace/orca-cloud-run-target-access.ts index 53d7af107cf..fb12e2f3e50 100644 --- a/src/renderer/src/components/new-workspace/orca-cloud-run-target-access.ts +++ b/src/renderer/src/components/new-workspace/orca-cloud-run-target-access.ts @@ -5,6 +5,7 @@ import { cancelOrcaCloudSelectionAfterSignIn, requestOrcaCloudSelectionAfterSignIn } from '@/lib/orca-cloud-select-after-sign-in' +import { requestOrcaCloudAfterCheckout } from '@/lib/orca-cloud-after-checkout' import { classifyEntitlementDenial } from '../../../../shared/orca-billing' /** Signing in from the row selects Orca Cloud once main offers it (the recipe list reloads). */ @@ -21,23 +22,30 @@ function signInThenSelectOrcaCloud(): void { .catch(() => cancelOrcaCloudSelectionAfterSignIn(token)) } +/** Paying from the row returns to this composer with Orca Cloud picked (see PlansDialogHost). */ +function choosePlanThenSelectOrcaCloud(): void { + requestOrcaCloudAfterCheckout({ kind: 'composer' }) + openPlansPage('sandbox') +} + /** * What the Run-on picker knows about the account's Orca Cloud access. * - `loading`: the first billing read is in flight; picking waits briefly for it. * - `unknown`: billing unreachable or not signed in to billing; picking proceeds and the build reports. * - `signed-out`: the build offers Orca Cloud but nobody is signed in; picking starts sign-in. * - `entitled`: can start a sandbox; `remainingSeconds` is the included time left this window. - * - `no-plan`: no active Team subscription (`lapsed` when one existed); routes to the plans page. + * - `no-plan`: no active Team subscription (`lapsed` when one existed); routes owners/admins to the + * plans page and, once paid, back to the composer with Orca Cloud picked. * - `out-of-hours`: included hours are spent (`cause: 'hours'`) or the overage cap is (`'cap'`). * - `payment-issue`: a failed payment blocks new starts. - * Out-of-hours and payment issues are actionable only by owners/admins (`canManageBilling`). + * No plan, out-of-hours and payment issues are actionable only by owners/admins (`canManageBilling`). */ export type OrcaCloudRunTargetAccess = | { state: 'loading' } | { state: 'unknown' } | { state: 'signed-out' } | { state: 'entitled'; remainingSeconds: number } - | { state: 'no-plan'; lapsed: boolean } + | { state: 'no-plan'; lapsed: boolean; canManageBilling: boolean } | { state: 'out-of-hours'; cause: 'hours' | 'cap'; canManageBilling: boolean } | { state: 'payment-issue'; canManageBilling: boolean } @@ -69,7 +77,11 @@ export function toOrcaCloudRunTargetAccess( case 'memberLimit': case 'machineSize': case 'other': - return { state: 'no-plan', lapsed: entitlement.reason === 'subscription_inactive' } + return { + state: 'no-plan', + lapsed: entitlement.reason === 'subscription_inactive', + canManageBilling + } } } @@ -89,7 +101,9 @@ export function getOrcaCloudPick(access: OrcaCloudRunTargetAccess): OrcaCloudPic case 'signed-out': return { kind: 'act', run: signInThenSelectOrcaCloud } case 'no-plan': - return { kind: 'act', run: () => openPlansPage('sandbox') } + return access.canManageBilling + ? { kind: 'act', run: choosePlanThenSelectOrcaCloud } + : { kind: 'blocked' } case 'out-of-hours': return access.canManageBilling ? { kind: 'act', run: openOverageSettings } 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 bacb45b0041..040b4594d03 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 @@ -28,7 +28,8 @@ export function getRunTargetOrcaCloudOffer({ case 'needs-sign-in': return override ?? { state: 'signed-out' } case 'needs-capability': - return override ?? { state: 'no-plan', lapsed: false } + // No billing read without the capability; unknown roles get the owner's way forward. + return override ?? { state: 'no-plan', lapsed: false, canManageBilling: true } case 'offered': case 'unavailable': return null @@ -65,8 +66,15 @@ export function useRunTargetOrcaCloud({ runBlockedAction: () => void select: (recipe: EphemeralVmRecipeOption | null) => void } { - const fetched = useOrcaCloudRunTargetAccess(!override && recipes.some(isOrcaCloudRecipe)) - const access = offer ?? override ?? fetched + const fetched = useOrcaCloudRunTargetAccess( + !override && (recipes.some(isOrcaCloudRecipe) || offer?.state === 'no-plan') + ) + // Without the capability the offer can't know the role; billing's answer can, so members are + // told to ask an owner or admin instead of being sent to plans they can't buy. + const access = + !override && offer?.state === 'no-plan' && fetched.state === 'no-plan' + ? fetched + : (offer ?? override ?? fetched) const [pending, setPending] = useState(false) const pickToken = useRef(0) const openRef = useRef(open) diff --git a/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx b/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx index 49ce22447c9..870c7d5c2ec 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx @@ -7,6 +7,7 @@ import { Loader2, LifeBuoy, LogIn, + Monitor, PanelLeft, Pencil, RotateCcw, @@ -31,6 +32,8 @@ export type VmBuildFailureActions = { onDismiss: () => void onSeePlans: () => void onOpenBilling: () => void + /** Billing refusals: reopen the composer with the same prompt, on this computer. */ + onCreateLocally: () => void onSignIn: () => void onShowWorkspaces: () => void onContactSupport: () => void @@ -46,6 +49,8 @@ type Action = { disabled?: boolean /** In progress: stays focusable (aria-disabled + aria-busy) so keyboard focus isn't dropped. */ pending?: boolean + /** Outline even when first: a way around the problem, not its fix. */ + secondary?: boolean } /** At most two visible actions; the rest sit in a More menu so the way forward stays obvious. */ @@ -78,18 +83,34 @@ function failureActions( icon: , onClick: actions.onEditRecipe } + // Every billing refusal can still run the same prompt here instead of waiting on billing. + const createLocally: Action = { + key: 'local', + label: t( + 'auto.components.worktree.creation.VmBuildFailureCard.createOnThisComputer', + 'Create on this computer instead' + ), + icon: , + onClick: actions.onCreateLocally, + secondary: true + } switch (failure.kind) { case 'plan': - return { - primary: [ - { - key: 'plans', - label: t('auto.lib.orcaCloudSession.seePlans', 'See plans'), - onClick: actions.onSeePlans + // Members can't choose a plan; their card tells them who can. + return canManageBilling + ? { + primary: [ + { + key: 'plans', + label: t('auto.lib.orcaCloudSession.seePlans', 'See plans'), + onClick: actions.onSeePlans + }, + // Paying elsewhere (another device, the portal) is picked up by trying again. + tryAgain + ], + more: [createLocally] } - ], - more: [] - } + : { primary: [createLocally], more: [] } case 'hoursUsed': case 'spendCap': case 'payment': @@ -116,9 +137,10 @@ function failureActions( ), icon: , onClick: actions.onOpenBilling - } + }, + createLocally ] - : [], + : [createLocally], more: [] } case 'signIn': @@ -288,7 +310,7 @@ export function FailureActionRow({ key={action.key} type="button" size="xs" - variant={index === 0 ? 'default' : 'outline'} + variant={index === 0 && !action.secondary ? 'default' : 'outline'} onClick={action.pending ? undefined : action.onClick} disabled={action.disabled} aria-disabled={action.pending || undefined} diff --git a/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx b/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx index 80c51125f67..c50f250e083 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx @@ -15,6 +15,7 @@ const actions = (): VmBuildFailureActions => ({ onDismiss: vi.fn(), onSeePlans: vi.fn(), onOpenBilling: vi.fn(), + onCreateLocally: vi.fn(), onSignIn: vi.fn(), onShowWorkspaces: vi.fn(), onContactSupport: vi.fn(), @@ -25,10 +26,12 @@ const actions = (): VmBuildFailureActions => ({ function Sheet({ failure, connectingGitHub = false, + canManageBilling = true, handlers }: { failure: VmBuildFailure | null connectingGitHub?: boolean + canManageBilling?: boolean handlers: VmBuildFailureActions }) { return ( @@ -42,7 +45,7 @@ function Sheet({ vmKept={false} firstErrorLine={null} canFixWithAgent={false} - canManageBilling + canManageBilling={canManageBilling} signingIn={false} connectingGitHub={connectingGitHub} repoName="acme/web" @@ -80,3 +83,32 @@ it('keeps a pending Connect GitHub focusable and ignores repeat clicks', () => { expect(handlers.onConnectGitHub).not.toHaveBeenCalled() expect(document.activeElement).toBe(button) }) + +it('offers an owner See plans then Try again on no plan', () => { + const handlers = actions() + render() + const buttons = screen.getAllByRole('button').map((button) => button.textContent?.trim()) + expect(buttons.slice(0, 2)).toEqual(['See plans', 'Try again']) + fireEvent.click(screen.getByRole('button', { name: /Try again/ })) + expect(handlers.onRetry).toHaveBeenCalledOnce() +}) + +it.each(['plan', 'hoursUsed', 'spendCap', 'payment'] as const)( + 'gives a member running into %s a way to create on this computer, not a billing fix', + (kind) => { + const handlers = actions() + render() + expect( + screen.queryByRole('button', { name: /See plans|Raise spend cap|Turn on overage/ }) + ).toBeNull() + fireEvent.click(screen.getByRole('button', { name: /Create on this computer instead/ })) + expect(handlers.onCreateLocally).toHaveBeenCalledOnce() + } +) + +it("keeps Create on this computer instead beside an owner's billing fix", () => { + const handlers = actions() + render() + const buttons = screen.getAllByRole('button').map((button) => button.textContent?.trim()) + expect(buttons.slice(0, 2)).toEqual(['Raise spend cap', 'Create on this computer instead']) +}) diff --git a/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx b/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx index 343674b9ebc..e2f3bf70f8c 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildSheet.tsx @@ -28,6 +28,8 @@ import { import { deriveVmBuildSteps, isOrcaCloudBuild, type VmBuildStep } from './vm-build-steps' import { useMinimumRunningSteps } from './use-minimum-running-steps' import { useRetryAfterCloudSignIn } from './use-retry-after-cloud-sign-in' +import { typedComposerPrompt } from './vm-build-composer-return' +import { requestOrcaCloudAfterCheckout } from '@/lib/orca-cloud-after-checkout' import { connectOrcaCloudGitHub, orcaCloudRepoName, @@ -84,6 +86,7 @@ export function VmBuildSheet({ onCancel, onRetry, onDismiss, + onReturnToComposer, onEditRecipe, agentSignInRow, cloudAgentStep, @@ -98,6 +101,8 @@ export function VmBuildSheet({ onRetry: () => void /** Leaves the build; when a VM is still up the caller confirms before it is deleted. */ onDismiss: () => void + /** Leaves a refused build for the composer with its prompt; `local` runs it on this computer. */ + onReturnToComposer: (options: { local: boolean }) => void onEditRecipe: () => void /** Fixtures only: a fixed sign-in row in place of the live one. */ agentSignInRow?: React.ReactNode @@ -269,8 +274,17 @@ export function VmBuildSheet({ : onRetry, onEditRecipe, onOpenAnyway: () => resolveVmEnvironmentCheckDecision(creationId, 'open-anyway'), - onDismiss, - onSeePlans: () => openPlansPage('sandbox'), + // 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: 'orca-account', repoId: null }) diff --git a/src/renderer/src/components/worktree-creation/VmBuildSheetCloudFailures.fixture.tsx b/src/renderer/src/components/worktree-creation/VmBuildSheetCloudFailures.fixture.tsx index fec59dc74aa..fc3505df430 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildSheetCloudFailures.fixture.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildSheetCloudFailures.fixture.tsx @@ -13,12 +13,29 @@ import { // Orca Cloud refusals and failures, one card each. +function stubBillingRole(canManageBilling: boolean): void { + window.api.orcaProfiles.billingStatus = () => + Promise.resolve({ + status: 'ok', + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the card reads only canManageBilling. + entitlement: { canManageBilling } as never + }) +} + +// An owner unless stated: the card's billing fix depends on the role billing reports. function cloudFailure(errorCode: string | undefined, error: string, log = CLOUD_LOG) { - return frame( + const fixture = frame( entry({ status: 'error', errorCode, provisioningLog: log, errorAt: T0 + 2_000 }, CLOUD_RECIPE), error, T0 + 2_000 ) + return defineFixture({ + ...fixture, + setup: () => { + seedFixtureRepo() + stubBillingRole(true) + } + }) } export const cloudPlanRequired = cloudFailure( @@ -63,12 +80,7 @@ function asMember(fixture: ReturnType) { ...fixture, setup: () => { seedFixtureRepo() - window.api.orcaProfiles.billingStatus = () => - Promise.resolve({ - status: 'ok', - // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the card reads only canManageBilling. - entitlement: { canManageBilling: false } as never - }) + stubBillingRole(false) } }) } @@ -160,3 +172,15 @@ export const cloudPaymentDue = cloudFailure( ) export const cloudNetwork = cloudFailure(undefined, 'fetch failed', CLOUD_LOG) + +// An owner without a plan gets See plans and Try again; More holds "Create on this computer +// instead", which every billing card offers. +export const cloudPlanRequiredMore = defineFixture({ + ...cloudPlanRequired, + interact: async (frameElement) => { + Array.from(frameElement.querySelectorAll('button')) + .find((button) => button.textContent?.trim() === 'More') + ?.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 })) + await new Promise((resolve) => setTimeout(resolve, 300)) + } +}) diff --git a/src/renderer/src/components/worktree-creation/WorktreeCreationPanel.tsx b/src/renderer/src/components/worktree-creation/WorktreeCreationPanel.tsx index 54dfb17f755..d7aca945fb2 100644 --- a/src/renderer/src/components/worktree-creation/WorktreeCreationPanel.tsx +++ b/src/renderer/src/components/worktree-creation/WorktreeCreationPanel.tsx @@ -16,6 +16,7 @@ import { } from './worktree-creation-clock' import { VmBuildSheet } from './VmBuildSheet' import { VmDeleteConfirmDialog } from './VmDeleteConfirmDialog' +import { composerDataFromRefusedCreate } from './vm-build-composer-return' /** Debounced in-frame creation placeholder: tab strip names the workspace while body shows status, enabling same-frame handoff without duplicating labels. */ export default function WorktreeCreationPanel({ @@ -91,6 +92,15 @@ export default function WorktreeCreationPanel({ onCancel={dismiss} onRetry={() => retryBackgroundWorktreeCreation(creationId)} onDismiss={leave} + onReturnToComposer={({ local }) => { + const data = composerDataFromRefusedCreate(entry, { local }) + dismiss() + const store = useAppStore.getState() + // Never replace a dialog the user opened meanwhile. + if (store.activeModal === 'none') { + store.openModal('new-workspace-composer', data) + } + }} onEditRecipe={() => { const state = useAppStore.getState() state.openSettingsTarget({ diff --git a/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts b/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts new file mode 100644 index 00000000000..bd377bf9d55 --- /dev/null +++ b/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it } from 'vitest' +import type { WorktreeCreationRequest } from '@/lib/workspace/creation/pending-worktree-creation' +import { composerDataFromRefusedCreate, typedComposerPrompt } from './vm-build-composer-return' + +// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: only the fields read here. +const request = { + repoId: 'repo-1', + name: 'otter', + displayName: 'Fix login', + displayNameKind: 'user', + baseBranch: 'main', + agent: 'claude', + note: 'Fix the login redirect', + telemetrySource: 'sidebar', + ephemeralVmRecipe: { + sourceRepoId: 'repo-1', + recipeId: 'cloud', + projectId: 'p', + provider: 'orca-cloud' + } +} as unknown as WorktreeCreationRequest + +describe('composer data for a create billing refused', () => { + it('restores the typed prompt and keeps Orca Cloud on Dismiss', () => { + expect(composerDataFromRefusedCreate({ request }, { local: false })).toEqual({ + initialRepoId: 'repo-1', + initialEphemeralVmRecipeId: 'cloud', + prefilledName: 'Fix login', + initialBaseBranch: 'main', + recovery: { note: 'Fix the login redirect', agent: 'claude' }, + telemetrySource: 'sidebar' + }) + }) + + it('drops the sandbox for Create on this computer instead', () => { + const data = composerDataFromRefusedCreate({ request }, { local: true }) + expect(data.initialEphemeralVmRecipeId).toBeUndefined() + expect(data.recovery?.note).toBe('Fix the login redirect') + }) + + it('prefers a prompt queued during the build and never restores a generated name', () => { + const entry = { + heldChatMessage: 'Queued instead', + request: { ...request, displayNameKind: 'generated' as const } + } + expect(typedComposerPrompt(entry)).toBe('Queued instead') + expect(composerDataFromRefusedCreate(entry, { local: true }).prefilledName).toBeUndefined() + }) +}) diff --git a/src/renderer/src/components/worktree-creation/vm-build-composer-return.ts b/src/renderer/src/components/worktree-creation/vm-build-composer-return.ts new file mode 100644 index 00000000000..1db89f80ec2 --- /dev/null +++ b/src/renderer/src/components/worktree-creation/vm-build-composer-return.ts @@ -0,0 +1,33 @@ +import type { ComposerModalData } from '@/components/new-workspace/composer-modal-data' +import type { PendingWorktreeCreation } from '@/lib/workspace/creation/pending-worktree-creation' + +type ReturnSource = Pick + +/** What the user typed for the agent: a prompt queued during the build, else the composer's. */ +export function typedComposerPrompt(entry: ReturnSource): string { + return entry.heldChatMessage ?? entry.request.note +} + +/** + * The composer as it was submitted, for a create billing refused before anything started: same + * project, name, base, agent and prompt. `local` drops the sandbox so it runs on this computer; + * otherwise the same Run-on target is kept. + */ +export function composerDataFromRefusedCreate( + entry: ReturnSource, + { local }: { local: boolean } +): ComposerModalData { + const { request } = entry + const recipe = request.ephemeralVmRecipe + return { + initialRepoId: recipe?.sourceRepoId ?? request.repoId, + ...(!local && recipe ? { initialEphemeralVmRecipeId: recipe.recipeId } : {}), + // A generated name is regenerated; only a name the user typed comes back. + ...(request.displayNameKind === 'user' && request.displayName + ? { prefilledName: request.displayName } + : {}), + ...(request.baseBranch ? { initialBaseBranch: request.baseBranch } : {}), + recovery: { note: typedComposerPrompt(entry), agent: request.agent }, + telemetrySource: request.telemetrySource ?? 'unknown' + } +} diff --git a/src/renderer/src/components/worktree-creation/vm-build-sheet-fixture-support.tsx b/src/renderer/src/components/worktree-creation/vm-build-sheet-fixture-support.tsx index 26f66cb9b16..c9a136dd578 100644 --- a/src/renderer/src/components/worktree-creation/vm-build-sheet-fixture-support.tsx +++ b/src/renderer/src/components/worktree-creation/vm-build-sheet-fixture-support.tsx @@ -41,8 +41,12 @@ export function entry( provisioningLog: log, provisioningLogStamps: stampsFor(log === '' ? 0 : log.split('\n').length), phaseLog: [{ phase: 'provisioning-vm', at: T0 }], - // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the sheet reads only name and ephemeralVmRecipe from the request. - request: { name: 'fix-login', ephemeralVmRecipe: recipe } as PendingWorktreeCreation['request'], + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the sheet reads only name, note and ephemeralVmRecipe from the request. + request: { + name: 'fix-login', + note: 'Fix the login redirect', + ephemeralVmRecipe: recipe + } as PendingWorktreeCreation['request'], ...patch } } @@ -64,6 +68,7 @@ export function sheet( onCancel={() => {}} onRetry={() => {}} onDismiss={() => {}} + onReturnToComposer={() => {}} onEditRecipe={() => {}} agentSignInRow={agentSignInRow} stepTimings={FIXTURE_STEP_TIMINGS} diff --git a/src/renderer/src/hooks/useEphemeralVmRecipeOptions.ts b/src/renderer/src/hooks/useEphemeralVmRecipeOptions.ts index 9737ba987c3..4c12ae15ea6 100644 --- a/src/renderer/src/hooks/useEphemeralVmRecipeOptions.ts +++ b/src/renderer/src/hooks/useEphemeralVmRecipeOptions.ts @@ -6,6 +6,7 @@ import type { EphemeralVmFailure } from '../../../shared/ephemeral-vm-failure-co import { ephemeralVmErrorText } from '@/lib/ephemeral-vm-error-copy' import { useUiLanguageRevision } from '@/i18n/use-ui-language-revision' import { takeOrcaCloudSelectionAfterSignIn } from '@/lib/orca-cloud-select-after-sign-in' +import { onOrcaCloudCheckoutReturn } from '@/lib/orca-cloud-after-checkout' type EphemeralVmRecipeOptionsArgs = { enabled: boolean @@ -143,6 +144,9 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs): load(false) }, [authKey, load]) + // A paid Checkout from the Run-on row: reload so the left selection intent picks Orca Cloud. + useEffect(() => onOrcaCloudCheckoutReturn(() => load(false)), [load]) + useEffect(() => { if (!window.api.plugins?.onChanged) { return diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index b9bcc9b9409..e40ed058260 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -4217,7 +4217,8 @@ "connectGitHubFailed": "Couldn’t open GitHub. Try again in a moment.", "noGithubRemoteBody2": "Orca Cloud clones your code from GitHub, and this repository has no GitHub remote. Push it to GitHub, then try again. Nothing was created, and you weren’t charged.", "howToPushToGitHub": "How to push to GitHub", - "spendCapReachedBodyMember2": "Your team has reached this month’s spend cap. Ask an owner or admin to raise the spend cap. Nothing was created, and you weren’t charged." + "spendCapReachedBodyMember2": "Your team has reached this month’s spend cap. Ask an owner or admin to raise the spend cap. Nothing was created, and you weren’t charged.", + "createOnThisComputer": "Create on this computer instead" }, "VmBuildLog": { "jumpToError": "Jump to first error", @@ -16616,7 +16617,9 @@ "orcaCloudAskPayment": "Ask an owner or admin to update the payment method.", "orcaCloudIdleSleep_one": "Sleeps after {{count}} minute idle", "orcaCloudIdleSleep_other": "Sleeps after {{count}} minutes idle", - "orcaCloudAskAddHoursOnly": "Ask an owner or admin to add hours." + "orcaCloudAskAddHoursOnly": "Ask an owner or admin to add hours.", + "orcaCloudAskChoosePlan": "Ask an owner or admin to choose one.", + "orcaCloudAskRaiseSpendCap": "Ask an owner or admin to raise the spend cap." }, "projectCombobox": { "recentHeading": "Recent", diff --git a/src/renderer/src/lib/orca-cloud-after-checkout.test.ts b/src/renderer/src/lib/orca-cloud-after-checkout.test.ts new file mode 100644 index 00000000000..ec6e6d4d060 --- /dev/null +++ b/src/renderer/src/lib/orca-cloud-after-checkout.test.ts @@ -0,0 +1,62 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { + cancelOrcaCloudAfterCheckout, + emitOrcaCloudCheckoutReturn, + onOrcaCloudCheckoutReturn, + requestOrcaCloudAfterCheckout, + resetOrcaCloudAfterCheckout, + takeOrcaCloudCheckoutReturn +} from './orca-cloud-after-checkout' + +const composerOpen = { composerOpen: true, hasCreation: () => true } +const composerClosed = { composerOpen: false, hasCreation: () => true } + +describe('select Orca Cloud after checkout', () => { + afterEach(() => resetOrcaCloudAfterCheckout()) + + it('lands on the Team page when no wall asked', () => { + expect(takeOrcaCloudCheckoutReturn(composerOpen)).toEqual({ kind: 'team-page' }) + }) + + it('returns to the open composer once, then the intent is consumed', () => { + requestOrcaCloudAfterCheckout({ kind: 'composer' }, 1_000) + expect(takeOrcaCloudCheckoutReturn(composerOpen, 2_000)).toEqual({ + kind: 'select-in-composer' + }) + expect(takeOrcaCloudCheckoutReturn(composerOpen, 3_000)).toEqual({ kind: 'team-page' }) + }) + + it('reopens the composer on Orca Cloud when it closed while paying', () => { + requestOrcaCloudAfterCheckout({ kind: 'composer' }, 1_000) + expect(takeOrcaCloudCheckoutReturn(composerClosed, 2_000)).toEqual({ kind: 'open-composer' }) + }) + + it('retries the refused creation, or falls back to the composer when it was dismissed', () => { + requestOrcaCloudAfterCheckout({ kind: 'retry', creationId: 'c1' }, 1_000) + expect(takeOrcaCloudCheckoutReturn(composerClosed, 2_000)).toEqual({ + kind: 'retry', + creationId: 'c1' + }) + requestOrcaCloudAfterCheckout({ kind: 'retry', creationId: 'gone' }, 1_000) + expect( + takeOrcaCloudCheckoutReturn({ composerOpen: false, hasCreation: () => false }, 2_000) + ).toEqual({ kind: 'open-composer' }) + }) + + it('drops a cancelled or abandoned intent', () => { + requestOrcaCloudAfterCheckout({ kind: 'composer' }, 1_000) + cancelOrcaCloudAfterCheckout() + expect(takeOrcaCloudCheckoutReturn(composerOpen, 2_000)).toEqual({ kind: 'team-page' }) + requestOrcaCloudAfterCheckout({ kind: 'composer' }, 0) + expect(takeOrcaCloudCheckoutReturn(composerOpen, 31 * 60_000)).toEqual({ kind: 'team-page' }) + }) + + it('notifies listening composers until they unsubscribe', () => { + const listener = vi.fn() + const off = onOrcaCloudCheckoutReturn(listener) + emitOrcaCloudCheckoutReturn() + off() + emitOrcaCloudCheckoutReturn() + expect(listener).toHaveBeenCalledTimes(1) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud-after-checkout.ts b/src/renderer/src/lib/orca-cloud-after-checkout.ts new file mode 100644 index 00000000000..3ac5247b793 --- /dev/null +++ b/src/renderer/src/lib/orca-cloud-after-checkout.ts @@ -0,0 +1,82 @@ +// Choosing a plan from an Orca Cloud wall should land back on the work, not on the Team page: +// the Run-on picker returns to its open composer with Orca Cloud picked, and a build card that +// was refused for no plan retries that create. Like signInThenSelectOrcaCloud, the wall leaves +// an intent that the plans dialog consumes once Checkout reports paid. + +/** An intent older than this belongs to an abandoned Checkout and is ignored. */ +const INTENT_TTL_MS = 30 * 60_000 + +export type OrcaCloudCheckoutIntent = + /** From the Run-on picker: select Orca Cloud in the composer. */ + | { kind: 'composer' } + /** From a build card refused for no plan: retry that pending creation. */ + | { kind: 'retry'; creationId: string } + +/** Where a paid Checkout lands. */ +export type OrcaCloudCheckoutReturn = + /** No intent: the Team page's one-time "You're on Team" confirmation. */ + | { kind: 'team-page' } + /** The composer that asked is still open: pick Orca Cloud in it. */ + | { kind: 'select-in-composer' } + /** The composer closed meanwhile: reopen it on Orca Cloud. */ + | { kind: 'open-composer' } + | { kind: 'retry'; creationId: string } + +let pending: { intent: OrcaCloudCheckoutIntent; requestedAt: number } | null = null + +export function requestOrcaCloudAfterCheckout( + intent: OrcaCloudCheckoutIntent, + now = Date.now() +): void { + pending = { intent, requestedAt: now } +} + +/** Closing the plans page without paying drops the intent. */ +export function cancelOrcaCloudAfterCheckout(): void { + pending = null +} + +/** Consumes the intent and says where a paid Checkout should land. */ +export function takeOrcaCloudCheckoutReturn( + context: { + /** The new-workspace composer is the active modal. */ + composerOpen: boolean + /** The creation still exists (not dismissed while paying). */ + hasCreation: (creationId: string) => boolean + }, + now = Date.now() +): OrcaCloudCheckoutReturn { + const taken = pending + pending = null + if (!taken || now - taken.requestedAt > INTENT_TTL_MS) { + return { kind: 'team-page' } + } + const { intent } = taken + if (intent.kind === 'retry' && context.hasCreation(intent.creationId)) { + return { kind: 'retry', creationId: intent.creationId } + } + return context.composerOpen ? { kind: 'select-in-composer' } : { kind: 'open-composer' } +} + +type Listener = () => void +const listeners = new Set() + +/** The open composer's recipe list listens so a paid Checkout can pick Orca Cloud in it. */ +export function onOrcaCloudCheckoutReturn(listener: Listener): () => void { + listeners.add(listener) + return () => { + listeners.delete(listener) + } +} + +export function emitOrcaCloudCheckoutReturn(): void { + for (const listener of listeners) { + listener() + } +} + +/** Test seam. */ +export function resetOrcaCloudAfterCheckout(): void { + pending = null + listeners.clear() +} From 548e1549ae133deff42f6e8d593e11a7b03e7795 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 02:51:58 -0800 Subject: [PATCH 3/3] fix(billing): 'Use this computer instead' and glossary error order on member cards Design-squad sign-off tweaks for DS-15: the action reopens the composer rather than creating, so it says so; member billing bodies put 'Nothing was created, and you weren't charged.' before who to ask. --- .../worktree-creation/VmBuildFailureActions.tsx | 4 ++-- .../VmBuildFailureCard.test.tsx | 6 +++--- .../vm-build-composer-return.test.ts | 2 +- .../worktree-creation/vm-build-failure-copy.ts | 16 ++++++++-------- src/renderer/src/i18n/locales/en.json | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx b/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx index 870c7d5c2ec..63d8101f5ac 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildFailureActions.tsx @@ -87,8 +87,8 @@ function failureActions( const createLocally: Action = { key: 'local', label: t( - 'auto.components.worktree.creation.VmBuildFailureCard.createOnThisComputer', - 'Create on this computer instead' + 'auto.components.worktree.creation.VmBuildFailureCard.useThisComputer', + 'Use this computer instead' ), icon: , onClick: actions.onCreateLocally, diff --git a/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx b/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx index c50f250e083..6ad77b291a4 100644 --- a/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx +++ b/src/renderer/src/components/worktree-creation/VmBuildFailureCard.test.tsx @@ -101,14 +101,14 @@ it.each(['plan', 'hoursUsed', 'spendCap', 'payment'] as const)( expect( screen.queryByRole('button', { name: /See plans|Raise spend cap|Turn on overage/ }) ).toBeNull() - fireEvent.click(screen.getByRole('button', { name: /Create on this computer instead/ })) + fireEvent.click(screen.getByRole('button', { name: /Use this computer instead/ })) expect(handlers.onCreateLocally).toHaveBeenCalledOnce() } ) -it("keeps Create on this computer instead beside an owner's billing fix", () => { +it("keeps Use this computer instead beside an owner's billing fix", () => { const handlers = actions() render() const buttons = screen.getAllByRole('button').map((button) => button.textContent?.trim()) - expect(buttons.slice(0, 2)).toEqual(['Raise spend cap', 'Create on this computer instead']) + expect(buttons.slice(0, 2)).toEqual(['Raise spend cap', 'Use this computer instead']) }) diff --git a/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts b/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts index bd377bf9d55..ab74de0f3ee 100644 --- a/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts +++ b/src/renderer/src/components/worktree-creation/vm-build-composer-return.test.ts @@ -32,7 +32,7 @@ describe('composer data for a create billing refused', () => { }) }) - it('drops the sandbox for Create on this computer instead', () => { + it('drops the sandbox for Use this computer instead', () => { const data = composerDataFromRefusedCreate({ request }, { local: true }) expect(data.initialEphemeralVmRecipeId).toBeUndefined() expect(data.recovery?.note).toBe('Fix the login redirect') diff --git a/src/renderer/src/components/worktree-creation/vm-build-failure-copy.ts b/src/renderer/src/components/worktree-creation/vm-build-failure-copy.ts index dd9d63528d3..8a55cc84ea8 100644 --- a/src/renderer/src/components/worktree-creation/vm-build-failure-copy.ts +++ b/src/renderer/src/components/worktree-creation/vm-build-failure-copy.ts @@ -80,8 +80,8 @@ export function vmBuildFailureCopy( 'Cloud workspaces are part of the Team plan. Nothing was created, and you weren’t charged.' ) : t( - 'auto.components.worktree.creation.VmBuildFailureCard.planBodyMember2', - 'Ask an owner or admin to choose a Team plan. Nothing was created, and you weren’t charged.' + 'auto.components.worktree.creation.VmBuildFailureCard.planBodyMember3', + 'Nothing was created, and you weren’t charged. Ask an owner or admin to choose a Team plan.' ) } case 'hoursUsed': @@ -96,8 +96,8 @@ export function vmBuildFailureCopy( 'Your team has used this month’s sandbox hours. Turn on overage to keep starting sandboxes. Nothing was created, and you weren’t charged.' ) : t( - 'auto.components.worktree.creation.VmBuildFailureCard.outOfHoursBodyMember', - 'Your team has used this month’s sandbox hours. Ask an owner or admin to add hours. Nothing was created, and you weren’t charged.' + 'auto.components.worktree.creation.VmBuildFailureCard.outOfHoursBodyMember2', + 'Your team has used this month’s sandbox hours. Nothing was created, and you weren’t charged. Ask an owner or admin to add hours.' ) } case 'spendCap': @@ -112,8 +112,8 @@ export function vmBuildFailureCopy( 'Your team has reached this month’s spend cap. Raise it to keep starting sandboxes. Nothing was created, and you weren’t charged.' ) : t( - 'auto.components.worktree.creation.VmBuildFailureCard.spendCapReachedBodyMember2', - 'Your team has reached this month’s spend cap. Ask an owner or admin to raise the spend cap. Nothing was created, and you weren’t charged.' + 'auto.components.worktree.creation.VmBuildFailureCard.spendCapReachedBodyMember3', + 'Your team has reached this month’s spend cap. Nothing was created, and you weren’t charged. Ask an owner or admin to raise the spend cap.' ) } case 'payment': @@ -128,8 +128,8 @@ export function vmBuildFailureCopy( 'New sandboxes can’t start until the payment goes through. Nothing was created, and you weren’t charged.' ) : t( - 'auto.components.worktree.creation.VmBuildFailureCard.paymentFailedBodyMember', - 'New sandboxes can’t start until the payment goes through. Ask an owner or admin to update the payment method. Nothing was created, and you weren’t charged.' + 'auto.components.worktree.creation.VmBuildFailureCard.paymentFailedBodyMember2', + 'New sandboxes can’t start until the payment goes through. Nothing was created, and you weren’t charged. Ask an owner or admin to update the payment method.' ) } case 'concurrency': diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index e40ed058260..752bc1899ae 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -4193,15 +4193,12 @@ "openingGitHub": "Opening GitHub…", "connectGitHub": "Connect GitHub", "planBody2": "Cloud workspaces are part of the Team plan. Nothing was created, and you weren’t charged.", - "planBodyMember2": "Ask an owner or admin to choose a Team plan. Nothing was created, and you weren’t charged.", "outOfHoursTitle": "Out of sandbox hours", "outOfHoursBody": "Your team has used this month’s sandbox hours. Turn on overage to keep starting sandboxes. Nothing was created, and you weren’t charged.", - "outOfHoursBodyMember": "Your team has used this month’s sandbox hours. Ask an owner or admin to add hours. Nothing was created, and you weren’t charged.", "spendCapReachedTitle": "Spend cap reached", "spendCapReachedBody": "Your team has reached this month’s spend cap. Raise it to keep starting sandboxes. Nothing was created, and you weren’t charged.", "paymentFailedTitle": "Payment failed", "paymentFailedBody": "New sandboxes can’t start until the payment goes through. Nothing was created, and you weren’t charged.", - "paymentFailedBodyMember": "New sandboxes can’t start until the payment goes through. Ask an owner or admin to update the payment method. Nothing was created, and you weren’t charged.", "teamLimitTitle": "You’re at your team’s limit of running sandboxes", "limitBody": "Put one to sleep or delete it, then try again. Nothing was created, and you weren’t charged.", "teamLimitBody": "Your team can run {{value0}} sandboxes at once ({{value1}} per seat). Put one to sleep or delete it, then try again. Nothing was created, and you weren’t charged.", @@ -4217,8 +4214,11 @@ "connectGitHubFailed": "Couldn’t open GitHub. Try again in a moment.", "noGithubRemoteBody2": "Orca Cloud clones your code from GitHub, and this repository has no GitHub remote. Push it to GitHub, then try again. Nothing was created, and you weren’t charged.", "howToPushToGitHub": "How to push to GitHub", - "spendCapReachedBodyMember2": "Your team has reached this month’s spend cap. Ask an owner or admin to raise the spend cap. Nothing was created, and you weren’t charged.", - "createOnThisComputer": "Create on this computer instead" + "useThisComputer": "Use this computer instead", + "planBodyMember3": "Nothing was created, and you weren’t charged. Ask an owner or admin to choose a Team plan.", + "outOfHoursBodyMember2": "Your team has used this month’s sandbox hours. Nothing was created, and you weren’t charged. Ask an owner or admin to add hours.", + "spendCapReachedBodyMember3": "Your team has reached this month’s spend cap. Nothing was created, and you weren’t charged. Ask an owner or admin to raise the spend cap.", + "paymentFailedBodyMember2": "New sandboxes can’t start until the payment goes through. Nothing was created, and you weren’t charged. Ask an owner or admin to update the payment method." }, "VmBuildLog": { "jumpToError": "Jump to first error",