|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * objectui#7253 — the paywall exit's destination. |
| 5 | + * |
| 6 | + * The AI quota refusal's "Upgrade plan" CTA used to open |
| 7 | + * `${cloudBase}/apps/cloud-control/sys_environment`, a path this repo composed |
| 8 | + * from three guesses about the CONTROL PLANE's console — its mount (`/_console`, |
| 9 | + * injected by that host), its app slug (`cloud_control`, not `cloud-control`) |
| 10 | + * and its route. All three were wrong, so the button landed on the control |
| 11 | + * plane's API 404 — `{"success":false,"error":{"code":"ENDPOINT_NOT_FOUND"}}` — |
| 12 | + * measured on the local rig. |
| 13 | + * |
| 14 | + * The fix is negative and that is the point: the only thing the runtime tells a |
| 15 | + * tenant SPA about the control plane is its ORIGIN, so the origin is all we may |
| 16 | + * name. These assertions pin the absence of a composed path, not a particular |
| 17 | + * page — a future "improvement" that appends one is the bug coming back. |
| 18 | + */ |
| 19 | + |
| 20 | +import { describe, it, expect, vi } from 'vitest'; |
| 21 | + |
| 22 | +// `vi.hoisted`, not a plain const: `vi.mock` is hoisted above module-body |
| 23 | +// statements, so a bare const is still in TDZ when the factory runs. The |
| 24 | +// default is a CANARY, not '': a case that forgets to set a base then fails |
| 25 | +// loudly instead of agreeing with the "no cloud configured" assertion. |
| 26 | +const { cloudBase } = vi.hoisted(() => ({ cloudBase: vi.fn(() => 'MOCK_UNSET') })); |
| 27 | +vi.mock('../../../runtime-config', () => ({ |
| 28 | + getCloudBase: () => cloudBase(), |
| 29 | +})); |
| 30 | + |
| 31 | +/** |
| 32 | + * Import the helper FRESH under the mock. |
| 33 | + * |
| 34 | + * The `unit` project runs with `isolate: false` (one module graph per worker), |
| 35 | + * so a sibling file that imported `marketplaceApi` unmocked — `readApiError` |
| 36 | + * does — leaves a cached copy bound to the REAL `getCloudBase`, and a |
| 37 | + * top-of-file import here silently reads through to it. Measured: the same |
| 38 | + * assertions passed alone and returned `''` in a multi-file run. `resetModules` |
| 39 | + * + a dynamic import inside the test is the supported way to re-evaluate under |
| 40 | + * this file's own mock. |
| 41 | + */ |
| 42 | +async function urlFor(base: string): Promise<string> { |
| 43 | + cloudBase.mockReturnValue(base); |
| 44 | + vi.resetModules(); |
| 45 | + const { cloudConsoleUrl } = await import('../marketplaceApi'); |
| 46 | + return cloudConsoleUrl(); |
| 47 | +} |
| 48 | + |
| 49 | +describe('cloudConsoleUrl (objectui#7253)', () => { |
| 50 | + it('is the runtime-supplied cloud origin, verbatim', async () => { |
| 51 | + expect(await urlFor('https://cloud.objectos.app')).toBe('https://cloud.objectos.app'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('appends no control-plane path — not the app slug, not an object route', async () => { |
| 55 | + const url = await urlFor('https://cloud.objectos.app'); |
| 56 | + // The exact shape that produced the dead link. |
| 57 | + expect(url).not.toContain('/apps/'); |
| 58 | + expect(url).not.toContain('cloud-control'); |
| 59 | + expect(url).not.toContain('sys_environment'); |
| 60 | + expect(url).not.toContain('sys_package'); |
| 61 | + // …and nothing else either: path-free, so the console mount's own root |
| 62 | + // redirect (`/` → `/_console/`) decides where the user lands. |
| 63 | + expect(new URL(url).pathname).toBe('/'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('honours a base that already carries a prefix (reverse-proxied control plane)', async () => { |
| 67 | + expect(await urlFor('https://acme.example/cloud')).toBe('https://acme.example/cloud'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('is empty when the runtime named no upstream cloud — callers render no link', async () => { |
| 71 | + // NOT the former `|| 'https://cloud.objectos.app'` fallback: a self-hosted |
| 72 | + // or air-gapped runtime has no control plane, and sending its users to the |
| 73 | + // vendor's SaaS is worse than showing nothing. |
| 74 | + expect(await urlFor('')).toBe(''); |
| 75 | + }); |
| 76 | +}); |
0 commit comments