mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Merge remote-tracking branch 'private/cloud/integration' into cloud/sleeping-read-snapshot
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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<PlanBillingNotice | null>(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<void> => {
|
||||
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)
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
)
|
||||
]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<typeof useTeamPageState>['arrival'] }) {
|
||||
const t = useTranslate()
|
||||
@@ -199,7 +200,11 @@ function TeamPageBody({ arrival }: { arrival: ReturnType<typeof useTeamPageState
|
||||
onManageBilling={openPortal}
|
||||
onCreateWorkspace={() => {
|
||||
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)}
|
||||
|
||||
@@ -55,6 +55,7 @@ function sheet(
|
||||
onCancel={noop}
|
||||
onRetry={noop}
|
||||
onDismiss={noop}
|
||||
onReturnToComposer={noop}
|
||||
onEditRecipe={noop}
|
||||
cloudAgentStep={
|
||||
<VmBuildCloudAgentStepView model={model} actions={actions} initialMode={initialMode} />
|
||||
|
||||
+56
-3
@@ -142,7 +142,16 @@ function ProjectAndHostPreview({
|
||||
)
|
||||
}
|
||||
|
||||
export const closed = defineFixture({ width: 560, render: () => <ProjectAndHostPreview /> })
|
||||
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: () => <ProjectAndHostPreview />
|
||||
})
|
||||
export const narrow = defineFixture({ width: 360, render: () => <ProjectAndHostPreview /> })
|
||||
export const folderOnly = defineFixture({
|
||||
width: 560,
|
||||
@@ -186,7 +195,11 @@ export const hostMenuOrcaCloud = defineFixture({
|
||||
})
|
||||
export const hostMenuOrcaCloudLocked = defineFixture({
|
||||
...hostMenu,
|
||||
render: () => <ProjectAndHostPreview orcaCloud={{ state: 'no-plan', lapsed: false }} />
|
||||
render: () => (
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'no-plan', lapsed: false, canManageBilling: true }}
|
||||
/>
|
||||
)
|
||||
})
|
||||
export const orcaCloudSelected = defineFixture({
|
||||
...closed,
|
||||
@@ -196,7 +209,10 @@ export const orcaCloudSelected = defineFixture({
|
||||
export const orcaCloudSelectedNoPlan = defineFixture({
|
||||
...closed,
|
||||
render: () => (
|
||||
<ProjectAndHostPreview orcaCloud={{ state: 'no-plan', lapsed: false }} cloudSelected />
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'no-plan', lapsed: false, canManageBilling: true }}
|
||||
cloudSelected
|
||||
/>
|
||||
)
|
||||
})
|
||||
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: () => (
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'no-plan', lapsed: false, canManageBilling: false }}
|
||||
cloudSelected
|
||||
/>
|
||||
)
|
||||
})
|
||||
export const orcaCloudSelectedCapMember = defineFixture({
|
||||
...closed,
|
||||
render: () => (
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'out-of-hours', cause: 'cap', canManageBilling: false }}
|
||||
cloudSelected
|
||||
/>
|
||||
)
|
||||
})
|
||||
export const hostMenuOrcaCloudNoPlanMember = defineFixture({
|
||||
...hostMenu,
|
||||
render: () => (
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'no-plan', lapsed: false, canManageBilling: false }}
|
||||
/>
|
||||
)
|
||||
})
|
||||
// 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: () => (
|
||||
<ProjectAndHostPreview
|
||||
orcaCloud={{ state: 'entitled', remainingSeconds: 300 * 3600 }}
|
||||
cloudSelected
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -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
|
||||
? {
|
||||
|
||||
@@ -121,7 +121,12 @@ export const orcaCloudEntitled = defineFixture({
|
||||
})
|
||||
export const orcaCloudNotEntitled = defineFixture({
|
||||
width: 420,
|
||||
render: () => <Preview recipes={withCloud} access={{ state: 'no-plan', lapsed: false }} />,
|
||||
render: () => (
|
||||
<Preview
|
||||
recipes={withCloud}
|
||||
access={{ state: 'no-plan', lapsed: false, canManageBilling: true }}
|
||||
/>
|
||||
),
|
||||
interact: open
|
||||
})
|
||||
export const orcaCloudOutOfHours = defineFixture({
|
||||
@@ -153,7 +158,12 @@ export const orcaCloudPaymentIssue = defineFixture({
|
||||
})
|
||||
export const orcaCloudLapsed = defineFixture({
|
||||
width: 420,
|
||||
render: () => <Preview recipes={withCloud} access={{ state: 'no-plan', lapsed: true }} />,
|
||||
render: () => (
|
||||
<Preview
|
||||
recipes={withCloud}
|
||||
access={{ state: 'no-plan', lapsed: true, canManageBilling: true }}
|
||||
/>
|
||||
),
|
||||
interact: open
|
||||
})
|
||||
export const orcaCloudSelectedClosed = defineFixture({
|
||||
@@ -188,7 +198,12 @@ export const orcaCloudSignedOut = defineFixture({
|
||||
})
|
||||
export const orcaCloudNoCapability = defineFixture({
|
||||
width: 420,
|
||||
render: () => <Preview recipes={[devboxRecipe]} access={{ state: 'no-plan', lapsed: false }} />,
|
||||
render: () => (
|
||||
<Preview
|
||||
recipes={[devboxRecipe]}
|
||||
access={{ state: 'no-plan', lapsed: false, canManageBilling: true }}
|
||||
/>
|
||||
),
|
||||
interact: open
|
||||
})
|
||||
export const orcaCloudCapReached = defineFixture({
|
||||
@@ -233,3 +248,24 @@ export const needsSetupArmed = defineFixture({
|
||||
render: () => <Preview />,
|
||||
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: () => (
|
||||
<Preview
|
||||
recipes={withCloud}
|
||||
access={{ state: 'no-plan', lapsed: false, canManageBilling: false }}
|
||||
/>
|
||||
),
|
||||
interact: open
|
||||
})
|
||||
export const orcaCloudCapReachedMember = defineFixture({
|
||||
width: 420,
|
||||
render: () => (
|
||||
<Preview
|
||||
recipes={withCloud}
|
||||
access={{ state: 'out-of-hours', cause: 'cap', canManageBilling: false }}
|
||||
/>
|
||||
),
|
||||
interact: open
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 (
|
||||
<span className="ml-2 shrink-0 self-center text-xs text-muted-foreground">
|
||||
{t(
|
||||
'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskOwnerOrAdmin',
|
||||
'Ask an owner or admin'
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function OrcaCloudMeta({
|
||||
access,
|
||||
onAction
|
||||
@@ -187,6 +200,9 @@ function OrcaCloudMeta({
|
||||
/>
|
||||
)
|
||||
case 'no-plan':
|
||||
if (!access.canManageBilling) {
|
||||
return <AskOwnerOrAdmin />
|
||||
}
|
||||
return (
|
||||
<RowAction
|
||||
label={
|
||||
@@ -200,15 +216,7 @@ function OrcaCloudMeta({
|
||||
case 'out-of-hours':
|
||||
case 'payment-issue':
|
||||
if (!access.canManageBilling) {
|
||||
// Members can't fix it; say who can rather than offer a pick that does nothing.
|
||||
return (
|
||||
<span className="ml-2 shrink-0 self-center text-xs text-muted-foreground">
|
||||
{t(
|
||||
'auto.components.new.workspace.RunTargetCombobox.orcaCloudAskOwnerOrAdmin',
|
||||
'Ask an owner or admin'
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
return <AskOwnerOrAdmin />
|
||||
}
|
||||
return (
|
||||
<RowAction
|
||||
@@ -276,7 +284,9 @@ export function RunTargetOrcaCloudRow({
|
||||
armed={armed}
|
||||
current={current}
|
||||
disabled={
|
||||
(access.state === 'out-of-hours' || access.state === 'payment-issue') &&
|
||||
(access.state === 'no-plan' ||
|
||||
access.state === 'out-of-hours' ||
|
||||
access.state === 'payment-issue') &&
|
||||
!access.canManageBilling
|
||||
}
|
||||
optionId={optionId}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { OrcaBillingEntitlement } from '../../../../shared/orca-billing'
|
||||
import { getOrcaCloudPick, toOrcaCloudRunTargetAccess } from './orca-cloud-run-target-access'
|
||||
|
||||
const openPlansPage = vi.fn()
|
||||
vi.mock('@/components/billing/plans/plans-page-store', () => ({
|
||||
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<typeof toOrcaCloudRunTargetAccess>[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')
|
||||
})
|
||||
})
|
||||
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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: <Pencil />,
|
||||
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.useThisComputer',
|
||||
'Use this computer instead'
|
||||
),
|
||||
icon: <Monitor />,
|
||||
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: <CreditCard />,
|
||||
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}
|
||||
|
||||
@@ -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(<Sheet failure={{ kind: 'plan' }} handlers={handlers} />)
|
||||
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(<Sheet failure={{ kind }} canManageBilling={false} handlers={handlers} />)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /See plans|Raise spend cap|Turn on overage/ })
|
||||
).toBeNull()
|
||||
fireEvent.click(screen.getByRole('button', { name: /Use this computer instead/ }))
|
||||
expect(handlers.onCreateLocally).toHaveBeenCalledOnce()
|
||||
}
|
||||
)
|
||||
|
||||
it("keeps Use this computer instead beside an owner's billing fix", () => {
|
||||
const handlers = actions()
|
||||
render(<Sheet failure={{ kind: 'spendCap' }} handlers={handlers} />)
|
||||
const buttons = screen.getAllByRole('button').map((button) => button.textContent?.trim())
|
||||
expect(buttons.slice(0, 2)).toEqual(['Raise spend cap', 'Use this computer instead'])
|
||||
})
|
||||
|
||||
@@ -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 })
|
||||
|
||||
+31
-7
@@ -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<typeof cloudFailure>) {
|
||||
...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))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 Use 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()
|
||||
})
|
||||
})
|
||||
@@ -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<PendingWorktreeCreation, 'heldChatMessage' | 'request'>
|
||||
|
||||
/** 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'
|
||||
}
|
||||
}
|
||||
@@ -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':
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,7 +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."
|
||||
"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",
|
||||
@@ -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",
|
||||
@@ -20624,7 +20627,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 +20702,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 +20722,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.",
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -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<Listener>()
|
||||
|
||||
/** 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()
|
||||
}
|
||||
Reference in New Issue
Block a user