From 0d98db4be393bfea0f29fa5a6b84645b33bca03b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:37:19 +0000 Subject: [PATCH 1/3] fix(app-shell): upgrade links open the runtime's declared upgradeUrl The console now reads the top-level `upgradeUrl` that /api/v1/runtime/config already serves (verbatim, absent stays absent) and exposes getUpgradeUrl(). The storage-full banner, the AI usage indicator's call to action and the AI chat quota CTA open it when declared; absent, each keeps today's cloudConsoleUrl() target and its show/hide rule. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa --- .../app-shell/src/console/ai/AiChatPage.tsx | 14 ++++---- .../app-shell/src/layout/AiUsageIndicator.tsx | 11 ++++--- .../src/layout/StorageUsageBanner.tsx | 12 ++++--- ui/packages/app-shell/src/runtime-config.ts | 33 +++++++++++++++++++ 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/ui/packages/app-shell/src/console/ai/AiChatPage.tsx b/ui/packages/app-shell/src/console/ai/AiChatPage.tsx index 2969ba231c6..c6d947c1d9d 100644 --- a/ui/packages/app-shell/src/console/ai/AiChatPage.tsx +++ b/ui/packages/app-shell/src/console/ai/AiChatPage.tsx @@ -137,7 +137,7 @@ import { publishPlanApprovalPending, subscribeMetadataRefresh, } from '../../assistant/assistantBus.js'; -import { getRuntimeConfig, isAiStudioEnabled } from '../../runtime-config.js'; +import { getRuntimeConfig, getUpgradeUrl, isAiStudioEnabled } from '../../runtime-config.js'; import { makerConvergedOnBuild, makerVisibleAgents } from '../../hooks/surfaceAgent.js'; import { useCanAuthorMetadata } from '../../hooks/useCanAuthorMetadata.js'; import { useHomePath } from '../../hooks/useHomePath.js'; @@ -2935,13 +2935,13 @@ export function ChatPane({ > window.open(cloudConsoleUrl(), '_blank', 'noopener,noreferrer') + (getUpgradeUrl() ?? cloudConsoleUrl()) + ? () => window.open(getUpgradeUrl() ?? cloudConsoleUrl(), '_blank', 'noopener,noreferrer') : undefined } onOpenBuilder={openBuilder} diff --git a/ui/packages/app-shell/src/layout/AiUsageIndicator.tsx b/ui/packages/app-shell/src/layout/AiUsageIndicator.tsx index 5be7a819e2c..eae301c31ba 100644 --- a/ui/packages/app-shell/src/layout/AiUsageIndicator.tsx +++ b/ui/packages/app-shell/src/layout/AiUsageIndicator.tsx @@ -40,6 +40,7 @@ import { formatNumber, useObjectTranslation } from '@object-ui/i18n'; import { useAgents } from '@object-ui/plugin-chatbot/core'; import { useAiUsage, type AiMeterUsage } from '../hooks/useAiUsage.js'; import { cloudConsoleUrl } from '../console/marketplace/marketplaceApi.js'; +import { getUpgradeUrl } from '../runtime-config.js'; /** Fraction at/above which the pool is "running low" (amber + CTA). */ export const NEAR_FULL = 0.8; @@ -214,9 +215,11 @@ export function AiUsageIndicator({ apiBase, enabled = true, className }: AiUsage return null; }; - // No upstream cloud named by the runtime ⇒ no control plane to send anyone - // to, so no CTA (objectui#7253). - const showCta = tone !== 'ok' && (pool.upgrade || pool.topUp) && !!cloudConsoleUrl(); + // The control plane's declared upgrade entry when served (objectstack#34622), + // else its origin. Neither ⇒ no control plane to send anyone to, so no CTA + // (objectui#7253). + const ctaUrl = getUpgradeUrl() ?? cloudConsoleUrl(); + const showCta = tone !== 'ok' && (pool.upgrade || pool.topUp) && !!ctaUrl; const reset = resetLabel(pool); return ( @@ -258,7 +261,7 @@ export function AiUsageIndicator({ apiBase, enabled = true, className }: AiUsage size="sm" className="mt-1 h-auto p-0 text-xs" data-testid="ai-usage-cta" - onClick={() => window.open(cloudConsoleUrl(), '_blank', 'noopener,noreferrer')} + onClick={() => window.open(ctaUrl, '_blank', 'noopener,noreferrer')} > {pool.upgrade ? t('console.ai.usage.ctaUpgrade', { defaultValue: 'Upgrade to keep going' }) diff --git a/ui/packages/app-shell/src/layout/StorageUsageBanner.tsx b/ui/packages/app-shell/src/layout/StorageUsageBanner.tsx index 48b27f2375a..c4f71854181 100644 --- a/ui/packages/app-shell/src/layout/StorageUsageBanner.tsx +++ b/ui/packages/app-shell/src/layout/StorageUsageBanner.tsx @@ -23,8 +23,10 @@ * Only the full banner carries it, as the adjudication orders. It is not gated * on a plan: the guardrail's refusal envelope for the same verdict declares its * upgrade flag as the literal `true`, and a plan with no limit never reaches - * `blocked`. It links to {@link cloudConsoleUrl} — the control plane's origin, - * the most specific destination a tenant runtime is told about — and is left + * `blocked`. It links to the control plane's declared upgrade entry + * ({@link getUpgradeUrl}, objectstack#34622) when this runtime serves one: a + * deep address the Cloud console root's landing never redirects. Otherwise it + * links to {@link cloudConsoleUrl} — the control plane's origin — and is left * out when this runtime names no upstream cloud, the rule the AI usage * indicator's call to action already follows. * @@ -48,7 +50,7 @@ import { useWorkspaceAdminStatus } from '@object-ui/auth'; import { useObjectTranslation, useDisplayLocale, formatDisplayNumber } from '@object-ui/i18n'; import { useStorageUsageReading, classifyStorageUsage } from '../hooks/useStorageUsageReading.js'; import { cloudConsoleUrl } from '../console/marketplace/marketplaceApi.js'; -import { isStorageUsageServed } from '../runtime-config.js'; +import { getUpgradeUrl, isStorageUsageServed } from '../runtime-config.js'; export interface StorageUsageBannerProps { /** Override the resolved tenant runtime base (e.g. `/api/v1`). */ @@ -72,7 +74,9 @@ export function StorageUsageBanner({ apiBase, className }: StorageUsageBannerPro const blocked = view.case === 'blocked'; const used = formatDisplayNumber(view.usedMb, { locale, maximumFractionDigits: 1 }); const limit = formatDisplayNumber(view.limitMb, { locale, maximumFractionDigits: 1 }); - const upgradeUrl = blocked ? cloudConsoleUrl() : ''; + // The declared upgrade entry when served; absent, today's origin link and + // its no-upstream rule (objectstack#34622). + const upgradeUrl = blocked ? (getUpgradeUrl() ?? cloudConsoleUrl()) : ''; const title = blocked ? t('console.storageUsage.blockedTitle', { diff --git a/ui/packages/app-shell/src/runtime-config.ts b/ui/packages/app-shell/src/runtime-config.ts index c669671e8dc..a0be844f3ef 100644 --- a/ui/packages/app-shell/src/runtime-config.ts +++ b/ui/packages/app-shell/src/runtime-config.ts @@ -340,6 +340,20 @@ export interface AppShellRuntimeConfig { * absolute `https:` URL, so nothing is re-validated here. */ mapStyleUrl?: string; + /** + * The control plane's upgrade / billing entry (objectstack#34622): the + * absolute URL `RuntimeConfigPlugin` serves as the top-level `upgradeUrl` + * when the host declares one (objectstack#14514, maintainer ruling cloud#1850 + * option A), absent otherwise. A deep address, so the Cloud console root's + * landing never redirects it back into this environment. + * + * Taken VERBATIM: the producer already refuses a value that is not an + * absolute http(s) URL, and nothing here composes, trims or defaults one. + * Re-derived from each payload in full, like `mapStyleUrl`: absent, empty + * and non-string all leave it absent, and a later payload without the key + * withdraws it. Read it through {@link getUpgradeUrl}. + */ + upgradeUrl?: string; } const defaults: AppShellRuntimeConfig = { @@ -468,6 +482,11 @@ export async function initRuntimeConfig(baseUrl: string = ''): Promise { typeof body.mapStyleUrl === 'string' && body.mapStyleUrl.trim() ? body.mapStyleUrl.trim() : undefined, + // objectstack#34622 — the declared upgrade entry, verbatim, or none. + upgradeUrl: + typeof body.upgradeUrl === 'string' && body.upgradeUrl.trim() + ? body.upgradeUrl + : undefined, defaultOrgId: body.defaultOrgId ?? current.defaultOrgId ?? null, defaultEnvironmentId: body.defaultEnvironmentId ?? current.defaultEnvironmentId ?? null, features: body.features @@ -620,6 +639,20 @@ export function getCloudBase(): string { return current.cloudUrl ?? ''; } +/** + * The control plane's declared upgrade / billing entry, or `undefined` when + * this runtime declares none (objectstack#34622, + * {@link AppShellRuntimeConfig.upgradeUrl}). + * + * The upgrade links (storage-full banner, AI quota call to action) open this + * when it is present and keep their `cloudConsoleUrl()` target, with its + * show/hide rule, when it is absent. ⛔ Never compose a substitute from + * {@link getCloudBase}: the path below the origin belongs to the control plane. + */ +export function getUpgradeUrl(): string | undefined { + return current.upgradeUrl; +} + /** * Is a marketplace catalog reachable from this runtime? (objectui#5504) * From c42d2ed7b4941f49268ebdda10d6537744d66834 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:38:58 +0000 Subject: [PATCH 2/3] test(app-shell): pin the declared upgradeUrl on the three upgrade links Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa --- .../AiChatPage.upgradeUrl-34622.test.tsx | 169 ++++++++++++++++++ .../__tests__/AiUsageIndicator.test.tsx | 80 ++++++++- .../__tests__/StorageUsageBanner.test.tsx | 81 ++++++++- .../app-shell/src/runtime-config.test.ts | 46 ++++- 4 files changed, 373 insertions(+), 3 deletions(-) create mode 100644 ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.upgradeUrl-34622.test.tsx diff --git a/ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.upgradeUrl-34622.test.tsx b/ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.upgradeUrl-34622.test.tsx new file mode 100644 index 00000000000..d11be0fcf80 --- /dev/null +++ b/ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.upgradeUrl-34622.test.tsx @@ -0,0 +1,169 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#34622 — the AI chat's quota exit (`onUpgrade`, the paywall + * button `ChatbotEnhanced` draws) opens the control plane's declared + * `upgradeUrl` when this runtime serves one: a deep address, which the Cloud + * console root's landing never redirects back into the environment. + * + * Absent, it is today's exit unchanged: the Cloud origin from + * `cloudConsoleUrl()`, and NO button (`onUpgrade` undefined) on a runtime that + * names no upstream cloud (objectui#7253). + * + * The pane is rendered for real with `ChatbotEnhanced` replaced by a prop + * recorder, because the `onUpgrade` prop ChatPane hands down is the contract + * under assertion. The runtime config is the REAL reader, fed one payload + * through a replaced `fetch`. + */ + +import '@testing-library/jest-dom/vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, render } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import React from 'react'; + +/** Props of the last `ChatbotEnhanced` render. */ +let captured: Record = {}; + +vi.mock('@object-ui/plugin-chatbot', async (importOriginal) => { + const actual = await importOriginal>(); + return { + ...actual, + ChatbotEnhanced: (props: Record) => { + captured = props; + return null; + }, + useObjectChat: () => ({ + messages: [], + isLoading: false, + error: undefined, + sendMessage: vi.fn(), + stop: vi.fn(), + reload: vi.fn(), + clear: vi.fn(), + setMessages: vi.fn(), + }), + useAiModels: () => ({ models: [], defaultModelId: undefined }), + }; +}); + +vi.mock('../../../providers/MetadataProvider', async (importOriginal) => { + const actual = await importOriginal>(); + return { ...actual, useMetadata: () => ({ apps: [] }) }; +}); +vi.mock('../../../providers/AdapterProvider', async (importOriginal) => { + const actual = await importOriginal>(); + return { ...actual, useAdapter: () => null }; +}); +vi.mock('../../marketplace/marketplaceApi', async (importOriginal) => ({ + ...(await importOriginal>()), + cloudConsoleUrl: vi.fn(), +})); + +import { I18nProvider } from '@object-ui/i18n'; +import type { AgentDescriptor } from '@object-ui/plugin-chatbot'; +import { ChatPane } from '../AiChatPage'; +import { cloudConsoleUrl } from '../../marketplace/marketplaceApi'; +import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../../runtime-config'; + +window.matchMedia = ((query: string) => ({ + matches: false, + media: query, + onchange: null, + addEventListener: () => {}, + removeEventListener: () => {}, + addListener: () => {}, + removeListener: () => {}, + dispatchEvent: () => false, +})) as unknown as typeof window.matchMedia; + +const CLOUD = 'https://cloud.example.test'; +const UPGRADE = 'https://cloud.example.test/_console/billing?org=acme'; +const cloudMock = cloudConsoleUrl as unknown as ReturnType; +const openMock = vi.fn(); + +async function serveRuntimeConfig(payload: Record) { + const realFetch = globalThis.fetch; + globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => payload })) as unknown as typeof fetch; + try { + await initRuntimeConfig(); + } finally { + globalThis.fetch = realFetch; + } +} + +/** Render the pane and hand back the `onUpgrade` prop it gave the chatbot. */ +function renderOnUpgrade(): (() => void) | undefined { + cleanup(); + captured = {}; + render( + + + + + , + ); + expect('onUpgrade' in captured).toBe(true); + return captured.onUpgrade as (() => void) | undefined; +} + +beforeEach(() => { + window.localStorage.clear(); + vi.clearAllMocks(); + vi.stubGlobal('open', openMock); + resetRuntimeConfigForTesting(); + cloudMock.mockReturnValue(CLOUD); +}); +afterEach(() => { + cleanup(); + resetRuntimeConfigForTesting(); + vi.unstubAllGlobals(); +}); + +describe('AI chat quota exit — declared upgradeUrl (objectstack#34622)', () => { + it('declared: the exit opens the declared address, not the Cloud origin', async () => { + await serveRuntimeConfig({ cloudUrl: CLOUD, upgradeUrl: UPGRADE }); + const onUpgrade = renderOnUpgrade(); + expect(onUpgrade).toBeTypeOf('function'); + onUpgrade!(); + expect(openMock).toHaveBeenCalledTimes(1); + expect(openMock).toHaveBeenCalledWith(UPGRADE, '_blank', 'noopener,noreferrer'); + }); + + it('declared on a runtime that names no upstream cloud: the exit is wired, to the declared address', async () => { + cloudMock.mockReturnValue(''); + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + const onUpgrade = renderOnUpgrade(); + expect(onUpgrade).toBeTypeOf('function'); + onUpgrade!(); + expect(openMock).toHaveBeenCalledWith(UPGRADE, '_blank', 'noopener,noreferrer'); + }); + + // CONTROL — absent, today's exit: the Cloud origin, or no button at all. + it('absent: the exit opens the Cloud origin, as before', async () => { + await serveRuntimeConfig({ cloudUrl: CLOUD }); + const onUpgrade = renderOnUpgrade(); + expect(onUpgrade).toBeTypeOf('function'); + onUpgrade!(); + expect(openMock).toHaveBeenCalledWith(CLOUD, '_blank', 'noopener,noreferrer'); + }); + + it('absent on a runtime that names no upstream cloud: no exit (no upgrade button), as before', async () => { + cloudMock.mockReturnValue(''); + await serveRuntimeConfig({ singleEnvironment: true }); + expect(renderOnUpgrade()).toBeUndefined(); + expect(openMock).not.toHaveBeenCalled(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/AiUsageIndicator.test.tsx b/ui/packages/app-shell/src/layout/__tests__/AiUsageIndicator.test.tsx index 6b370b5d741..9806665dafa 100644 --- a/ui/packages/app-shell/src/layout/__tests__/AiUsageIndicator.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/AiUsageIndicator.test.tsx @@ -28,7 +28,7 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({ })); const openMock = vi.fn(); vi.mock('../../console/marketplace/marketplaceApi', () => ({ - cloudConsoleUrl: () => 'https://cloud.example', + cloudConsoleUrl: vi.fn(() => 'https://cloud.example'), })); vi.mock('../../hooks/useAiUsage', () => ({ useAiUsage: vi.fn() })); // objectui#11799 — the indicator reads usage only while the agent catalog lists @@ -41,6 +41,8 @@ vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({ import { useAiUsage } from '../../hooks/useAiUsage'; import { AiUsageIndicator } from '../AiUsageIndicator'; +import { cloudConsoleUrl } from '../../console/marketplace/marketplaceApi'; +import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../runtime-config'; // The REAL hook, for the cases that drive a wire payload through the parser // into the component. Loaded at module scope so its import cost is paid in the @@ -308,3 +310,79 @@ describe('AiUsageIndicator', () => { }); }); }); + +// objectstack#34622 — the call to action opens the control plane's declared +// `upgradeUrl` (served by /api/v1/runtime/config) when the runtime serves one, +// and is unchanged — target and show/hide rule — when it does not. Driven +// through the REAL runtime-config reader: only `fetch` is replaced, for the one +// config request. +describe('AiUsageIndicator — declared upgradeUrl (objectstack#34622)', () => { + const UPGRADE = 'https://cloud.example/_console/billing?org=acme'; + const cloudMock = cloudConsoleUrl as unknown as ReturnType; + + async function serveRuntimeConfig(payload: Record) { + const realFetch = globalThis.fetch; + globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => payload })) as unknown as typeof fetch; + try { + await initRuntimeConfig(); + } finally { + globalThis.fetch = realFetch; + } + } + + function openCta() { + render(); + fireEvent.click(screen.getByTestId('ai-usage-indicator')); + return screen.queryByTestId('ai-usage-cta'); + } + + beforeEach(() => { + vi.clearAllMocks(); + vi.stubGlobal('open', openMock); + resetRuntimeConfigForTesting(); + }); + afterEach(() => { + resetRuntimeConfigForTesting(); + cloudMock.mockImplementation(() => 'https://cloud.example'); + }); + + it.each([ + ['upgrade', { upgrade: true, topUp: false }], + ['top-up', { upgrade: false, topUp: true }], + ])('declared: the %s CTA opens the declared address, not the Cloud origin', async (_label, flags) => { + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setUsage({ pool: pool({ fraction: 0.95, ...flags }) }); + fireEvent.click(openCta()!); + expect(openMock).toHaveBeenCalledTimes(1); + expect(openMock).toHaveBeenCalledWith(UPGRADE, '_blank', 'noopener,noreferrer'); + }); + + it('declared on a runtime that names no upstream cloud: the CTA is drawn, to the declared address', async () => { + cloudMock.mockReturnValue(''); + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setUsage({ pool: pool({ fraction: 0.95, upgrade: true }) }); + fireEvent.click(openCta()!); + expect(openMock).toHaveBeenCalledWith(UPGRADE, '_blank', 'noopener,noreferrer'); + }); + + it('declared: a pool with headroom still shows no CTA', async () => { + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setUsage({ pool: pool({ fraction: 0.2, upgrade: true }) }); + expect(openCta()).toBeNull(); + }); + + // CONTROL — absent, today's target and today's show/hide rule. + it('absent: the CTA opens the Cloud origin, as before', async () => { + await serveRuntimeConfig({ cloudUrl: 'https://cloud.example' }); + setUsage({ pool: pool({ fraction: 0.95, upgrade: true }) }); + fireEvent.click(openCta()!); + expect(openMock).toHaveBeenCalledWith('https://cloud.example', '_blank', 'noopener,noreferrer'); + }); + + it('absent on a runtime that names no upstream cloud: no CTA, as before', async () => { + cloudMock.mockReturnValue(''); + await serveRuntimeConfig({ singleEnvironment: true }); + setUsage({ pool: pool({ fraction: 0.95, upgrade: true }) }); + expect(openCta()).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/StorageUsageBanner.test.tsx b/ui/packages/app-shell/src/layout/__tests__/StorageUsageBanner.test.tsx index 29801ee78c5..89fcabf7bb6 100644 --- a/ui/packages/app-shell/src/layout/__tests__/StorageUsageBanner.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/StorageUsageBanner.test.tsx @@ -10,7 +10,7 @@ * these cases exercise the same classifier the component ships with. */ import '@testing-library/jest-dom/vitest'; -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { render, screen } from '@testing-library/react'; import type { StorageUsageSnapshot } from '../../hooks/useStorageUsageReading'; @@ -43,6 +43,7 @@ import { useWorkspaceAdminStatus } from '@object-ui/auth'; import { useStorageUsageReading } from '../../hooks/useStorageUsageReading'; import { cloudConsoleUrl } from '../../console/marketplace/marketplaceApi'; import { StorageUsageBanner } from '../StorageUsageBanner'; +import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../runtime-config'; const asMock = (fn: unknown) => fn as unknown as ReturnType; @@ -136,3 +137,81 @@ describe('StorageUsageBanner', () => { ); }); }); + +// objectstack#34622 — the full banner's upgrade entry opens the control plane's +// declared `upgradeUrl` (served by /api/v1/runtime/config) when the runtime +// serves one, and is unchanged when it does not. Driven through the REAL +// runtime-config reader: only `fetch` is replaced, for the one config request. +describe('StorageUsageBanner — declared upgradeUrl (objectstack#34622)', () => { + const UPGRADE = 'https://cloud.example.test/_console/billing?org=acme'; + + async function serveRuntimeConfig(payload: Record) { + const realFetch = globalThis.fetch; + globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => payload })) as unknown as typeof fetch; + try { + await initRuntimeConfig(); + } finally { + globalThis.fetch = realFetch; + } + } + + beforeEach(() => { + vi.clearAllMocks(); + resetRuntimeConfigForTesting(); + setAdmin(true); + asMock(cloudConsoleUrl).mockReturnValue(CLOUD); + }); + afterEach(() => resetRuntimeConfigForTesting()); + + it('declared: the upgrade entry links the declared address, not the Cloud origin', async () => { + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setSnapshot(BLOCKED); + render(); + + const upgrade = screen.getByTestId('storage-usage-upgrade'); + expect(upgrade).toHaveAttribute('href', UPGRADE); + expect(upgrade).toHaveAttribute('target', '_blank'); + expect(upgrade).toHaveAttribute('rel', 'noopener noreferrer'); + }); + + it('declared on a runtime that names no upstream cloud: the entry is still drawn, to the declared address', async () => { + asMock(cloudConsoleUrl).mockReturnValue(''); + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setSnapshot(BLOCKED); + render(); + + expect(screen.getByTestId('storage-usage-upgrade')).toHaveAttribute('href', UPGRADE); + }); + + it('declared: the `warn` banner still carries no upgrade entry', async () => { + await serveRuntimeConfig({ upgradeUrl: UPGRADE }); + setSnapshot(WARNING); + render(); + + expect(screen.getByTestId('storage-usage-banner')).toHaveAttribute('data-storage-usage-case', 'warning'); + expect(screen.queryByTestId('storage-usage-upgrade')).toBeNull(); + }); + + // CONTROL — absent, the banner is byte for byte today's. + it('absent: a served config without the key renders the same markup as no config — the Cloud origin link', async () => { + setSnapshot(BLOCKED); + const before = render(); + const untouched = before.container.innerHTML; + before.unmount(); + + await serveRuntimeConfig({ cloudUrl: CLOUD }); + const after = render(); + expect(after.container.innerHTML).toBe(untouched); + expect(screen.getByTestId('storage-usage-upgrade')).toHaveAttribute('href', CLOUD); + }); + + it('absent on a runtime that names no upstream cloud: no upgrade entry, as before', async () => { + asMock(cloudConsoleUrl).mockReturnValue(''); + await serveRuntimeConfig({ singleEnvironment: true }); + setSnapshot(BLOCKED); + render(); + + expect(screen.getByTestId('storage-usage-banner')).toHaveAttribute('data-storage-usage-case', 'blocked'); + expect(screen.queryByTestId('storage-usage-upgrade')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/runtime-config.test.ts b/ui/packages/app-shell/src/runtime-config.test.ts index 046f08dacc9..2ee652468c9 100644 --- a/ui/packages/app-shell/src/runtime-config.test.ts +++ b/ui/packages/app-shell/src/runtime-config.test.ts @@ -9,7 +9,7 @@ */ import { describe, it, expect, afterEach, vi } from 'vitest'; -import { initRuntimeConfig, getRuntimeConfig, getPlatformStage, getProductName, isDefaultProductName, isAiStudioEnabled, isMarketplaceEnabled, isStorageUsageServed, isSingleAppSwitcherHidden, getClientErrorReporting, resetRuntimeConfigForTesting } from './runtime-config.js'; +import { initRuntimeConfig, getRuntimeConfig, getPlatformStage, getProductName, isDefaultProductName, isAiStudioEnabled, isMarketplaceEnabled, isStorageUsageServed, isSingleAppSwitcherHidden, getClientErrorReporting, getUpgradeUrl, resetRuntimeConfigForTesting } from './runtime-config.js'; function mockConfig(features: Record) { vi.stubGlobal('fetch', vi.fn(async () => ({ @@ -317,6 +317,50 @@ describe('runtime-config mapStyleUrl (objectstack#26163)', () => { }); }); +// objectstack#34622 — the top-level `upgradeUrl` RuntimeConfigPlugin serves +// when the host declares one (objectstack#14514, ruling cloud#1850 option A). +describe('runtime-config upgradeUrl (objectstack#34622)', () => { + // A deep address with a query and a trailing slash: verbatim means neither + // is trimmed nor rewritten. + const UPGRADE = 'https://cloud.example.test/_console/billing/plan/?org=acme'; + + it('is absent before init', () => { + resetRuntimeConfigForTesting(); + expect(getUpgradeUrl()).toBeUndefined(); + expect('upgradeUrl' in getRuntimeConfig()).toBe(false); + }); + + it('takes the served upgradeUrl verbatim', async () => { + mockPayload({ cloudUrl: 'https://cloud.example.test/', upgradeUrl: UPGRADE }); + await initRuntimeConfig(); + expect(getUpgradeUrl()).toBe(UPGRADE); + expect(getRuntimeConfig().upgradeUrl).toBe(UPGRADE); + }); + + it.each([ + ['absent (the host declared none)', { cloudUrl: 'https://cloud.example.test' }], + ['empty', { upgradeUrl: '' }], + ['whitespace', { upgradeUrl: ' ' }], + ['not a string', { upgradeUrl: 42 }], + ['an object', { upgradeUrl: { href: UPGRADE } }], + ['nested under features, where it is not read', { features: { upgradeUrl: UPGRADE } }], + ])('is absent when the key is %s — never a default composed from cloudUrl', async (_label, payload) => { + mockPayload(payload); + await initRuntimeConfig(); + expect(getUpgradeUrl()).toBeUndefined(); + }); + + it('withdraws it when a later fetch no longer serves it', async () => { + mockPayload({ upgradeUrl: UPGRADE }); + await initRuntimeConfig(); + expect(getUpgradeUrl()).toBe(UPGRADE); + + mockPayload({ singleEnvironment: false }); + await initRuntimeConfig(); + expect(getUpgradeUrl()).toBeUndefined(); + }); +}); + describe('runtime-config platform stage', () => { it('defaults to preview before init (badge shows out of the box)', () => { resetRuntimeConfigForTesting(); From 4a23edddb51ae9f3b00a403d886382873fb05d64 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 13:47:27 +0000 Subject: [PATCH 3/3] chore: changeset for the declared upgradeUrl links Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa --- .changeset/34622-upgrade-links-declared-url.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .changeset/34622-upgrade-links-declared-url.md diff --git a/.changeset/34622-upgrade-links-declared-url.md b/.changeset/34622-upgrade-links-declared-url.md new file mode 100644 index 00000000000..73268808d69 --- /dev/null +++ b/.changeset/34622-upgrade-links-declared-url.md @@ -0,0 +1,18 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): the upgrade links open the runtime's declared `upgradeUrl` + +Clause-②: no +Metadata-protocol: none + +`GET /api/v1/runtime/config` already serves a top-level `upgradeUrl` when the host declares one: the absolute address of the control plane's upgrade or billing page. The Console never read it, so three upgrade links opened the Cloud origin instead. On Cloud, the origin redirects to the console root, and a manager whose only organization has a running environment lands back in that environment, so the link never reaches billing. + +The Console now reads `upgradeUrl` as served (an absent, empty or non-string value stays absent; nothing is composed in its place) and exposes it as `getUpgradeUrl()`. These links open it when it is declared: + +- the storage-full banner's "Upgrade to continue"; +- the AI usage indicator's call to action; +- the AI chat's quota upgrade button. + +When the runtime declares no `upgradeUrl`, each link behaves as before: it opens `cloudConsoleUrl()`, and it is not drawn on a runtime that names no upstream cloud.