|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * The package page's Install result says when the install door admitted the |
| 5 | + * package WITHOUT checking its platform protocol range: the answer's |
| 6 | + * `data.protocolCheckSkipped` (objectstack#30326), drawn under the success |
| 7 | + * sentence. Managed (loaded now, loaded at restart) and unmanaged answers all |
| 8 | + * carry it. |
| 9 | + * |
| 10 | + * `marketplaceApi` is NOT mocked: one stubbed `fetch` answers by path, so the |
| 11 | + * notice the page draws is the one that crossed the wire. `t` echoes the KEY |
| 12 | + * and the notice's facts. |
| 13 | + */ |
| 14 | + |
| 15 | +import '@testing-library/jest-dom/vitest'; |
| 16 | +import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 17 | +import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'; |
| 18 | + |
| 19 | +vi.mock('react-router-dom', () => ({ |
| 20 | + useNavigate: () => vi.fn(), |
| 21 | + useParams: () => ({ packageId: 'pkg_psa' }), |
| 22 | +})); |
| 23 | + |
| 24 | +vi.mock('@object-ui/auth', async (importOriginal) => ({ |
| 25 | + ...(await importOriginal<Record<string, unknown>>()), |
| 26 | + useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }), |
| 27 | +})); |
| 28 | + |
| 29 | +vi.mock('@object-ui/i18n', async (importOriginal) => ({ |
| 30 | + ...(await importOriginal<Record<string, unknown>>()), |
| 31 | + useObjectTranslation: () => ({ |
| 32 | + t: (key: string, o?: Record<string, unknown>) => { |
| 33 | + const facts = ['packageId', 'protocolVersion', 'requiredRange'].filter((k) => o?.[k] !== undefined).map((k) => `${k}=${String(o?.[k])}`); |
| 34 | + return facts.length > 0 ? `«${key}|${facts.join('|')}»` : `«${key}»`; |
| 35 | + }, |
| 36 | + language: 'en', |
| 37 | + }), |
| 38 | +})); |
| 39 | + |
| 40 | +vi.mock('../../../assistant/assistantBus', () => ({ emitMetadataRefresh: () => {} })); |
| 41 | +vi.mock('../../../providers/MetadataProvider', () => ({ useMetadata: () => ({ refresh: async () => {} }) })); |
| 42 | +vi.mock('../../../components/SuggestedBindingsPanel', () => ({ |
| 43 | + SuggestedBindingsPanel: () => <div data-testid="suggested-bindings" />, |
| 44 | +})); |
| 45 | +vi.mock('../ConnectorCredentialsStep', () => ({ |
| 46 | + ConnectorCredentialsStep: () => <div data-testid="credential-step" />, |
| 47 | +})); |
| 48 | + |
| 49 | +import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../../runtime-config'; |
| 50 | +import { MarketplacePackagePage } from '../MarketplacePackagePage'; |
| 51 | + |
| 52 | +const INSTALL_PATH = '/api/v1/marketplace/install-local'; |
| 53 | +const MANIFEST_PATH = '/api/v1/marketplace/packages/pkg_psa/versions/latest/manifest'; |
| 54 | +const CATALOG_PACKAGE = { |
| 55 | + package: { id: 'pkg_psa', manifest_id: 'com.acme.psa', display_name: 'PSA', latest_version: { id: 'ver_1', version: '1.0.0' } }, |
| 56 | + versions: [{ id: 'ver_1', version: '1.0.0' }], |
| 57 | +}; |
| 58 | +const SERVER_MESSAGE = 'SERVER-ENGLISH sentinel: installed without a compatibility check.'; |
| 59 | +const NO_RANGE = { reason: 'no-range', packageId: 'com.acme.psa', protocolVersion: '18.1.0', message: SERVER_MESSAGE }; |
| 60 | + |
| 61 | +const answer = (status: number, body: unknown) => ({ |
| 62 | + ok: status >= 200 && status < 300, |
| 63 | + status, |
| 64 | + statusText: '', |
| 65 | + headers: new Headers({ 'content-type': 'application/json' }), |
| 66 | + json: async () => body, |
| 67 | + text: async () => JSON.stringify(body), |
| 68 | +}); |
| 69 | + |
| 70 | +async function boot(installData: Record<string, unknown>, installModes?: string[]) { |
| 71 | + resetRuntimeConfigForTesting(); |
| 72 | + vi.stubGlobal('fetch', vi.fn(async (input: unknown, init?: { method?: string }) => { |
| 73 | + const path = new URL(String(input), 'http://console.test').pathname; |
| 74 | + const method = (init?.method ?? 'GET').toUpperCase(); |
| 75 | + if (path === '/api/v1/runtime/config') { |
| 76 | + return answer(200, { |
| 77 | + cloudUrl: '', singleEnvironment: true, |
| 78 | + features: { installLocal: true, marketplace: true, aiStudio: true, autoPublishAiBuilds: true }, |
| 79 | + branding: { productName: 'ObjectOS', productShortName: 'ObjectOS' }, |
| 80 | + }); |
| 81 | + } |
| 82 | + if (path === INSTALL_PATH && method === 'GET') return answer(200, { success: true, data: { items: [], total: 0 } }); |
| 83 | + if (path === INSTALL_PATH && method === 'POST') return answer(200, { success: true, data: installData }); |
| 84 | + if (path === MANIFEST_PATH) { |
| 85 | + return answer(200, { |
| 86 | + success: true, |
| 87 | + data: { manifest: { id: 'com.acme.psa', version: '1.0.0', type: 'app', ...(installModes ? { installModes } : {}) }, version: '1.0.0', version_id: 'ver_1' }, |
| 88 | + }); |
| 89 | + } |
| 90 | + if (path === '/api/v1/marketplace/packages/pkg_psa') return answer(200, { success: true, data: CATALOG_PACKAGE }); |
| 91 | + return answer(404, { success: false, error: { code: 'NOT_FOUND', message: `no route ${method} ${path}` } }); |
| 92 | + })); |
| 93 | + await initRuntimeConfig(); |
| 94 | +} |
| 95 | + |
| 96 | +async function install() { |
| 97 | + render(<MarketplacePackagePage />); |
| 98 | + const button = await screen.findByRole('button', { name: '«marketplace.action.install»' }); |
| 99 | + await act(async () => {}); |
| 100 | + fireEvent.click(button); |
| 101 | +} |
| 102 | + |
| 103 | +const MANAGED = { manifestId: 'com.acme.psa', version: '1.0.0', versionId: 'ver_1', installedAt: '2026-11-05T00:00:00Z', upgradedFrom: null }; |
| 104 | + |
| 105 | +afterEach(() => { |
| 106 | + cleanup(); |
| 107 | + vi.unstubAllGlobals(); |
| 108 | + resetRuntimeConfigForTesting(); |
| 109 | +}); |
| 110 | + |
| 111 | +describe('the package page\'s Install result draws protocolCheckSkipped (objectstack#30326)', () => { |
| 112 | + it('a managed install the kernel loaded: the success sentence, then the unchecked-protocol line', async () => { |
| 113 | + await boot({ ...MANAGED, hotLoaded: true, protocolCheckSkipped: NO_RANGE }); |
| 114 | + await install(); |
| 115 | + |
| 116 | + expect(await screen.findByText('«marketplace.install.localSuccess»')).toBeInTheDocument(); |
| 117 | + expect(screen.getByTestId('protocol-check-skipped')).toHaveTextContent( |
| 118 | + '«marketplace.install.protocolCheckSkipped.noRange|packageId=com.acme.psa|protocolVersion=18.1.0|requiredRange=»', |
| 119 | + ); |
| 120 | + expect(screen.queryByText(SERVER_MESSAGE)).not.toBeInTheDocument(); |
| 121 | + }); |
| 122 | + |
| 123 | + it('a managed install loaded at restart carries it too', async () => { |
| 124 | + await boot({ ...MANAGED, hotLoaded: false, protocolCheckSkipped: NO_RANGE }); |
| 125 | + await install(); |
| 126 | + |
| 127 | + expect(await screen.findByText('«marketplace.install.localLoadsAtRestart»')).toBeInTheDocument(); |
| 128 | + expect(screen.getByTestId('protocol-check-skipped')).toHaveTextContent('marketplace.install.protocolCheckSkipped.noRange'); |
| 129 | + }); |
| 130 | + |
| 131 | + it('an unmanaged copy with an unreadable range: the range it declared', async () => { |
| 132 | + await boot({ |
| 133 | + installMode: 'unmanaged', manifestId: 'com.acme.psa', version: '1.0.0', versionId: 'ver_1', installedAt: '2026-11-05T00:00:00Z', |
| 134 | + installedFrom: { packageId: 'com.acme.psa' }, targetPackageId: 'com.acme.psa_copy', namespace: 'psa', copiedCount: 0, copied: [], strippedLocks: [], |
| 135 | + protocolCheckSkipped: { |
| 136 | + reason: 'unparsed-range', packageId: 'com.acme.psa', protocolVersion: '18.1.0', |
| 137 | + requiredRange: 'latest', rangeSource: 'engines.protocol', message: SERVER_MESSAGE, |
| 138 | + }, |
| 139 | + }, ['unmanaged']); |
| 140 | + await install(); |
| 141 | + |
| 142 | + expect(await screen.findByText('«marketplace.install.unmanagedSuccess»')).toBeInTheDocument(); |
| 143 | + expect(screen.getByTestId('protocol-check-skipped')).toHaveTextContent( |
| 144 | + '«marketplace.install.protocolCheckSkipped.unparsedRange|packageId=com.acme.psa|protocolVersion=18.1.0|requiredRange=latest»', |
| 145 | + ); |
| 146 | + }); |
| 147 | + |
| 148 | + it('CONTROL: an install whose range was checked draws no such line', async () => { |
| 149 | + await boot({ ...MANAGED, hotLoaded: true }); |
| 150 | + await install(); |
| 151 | + |
| 152 | + expect(await screen.findByText('«marketplace.install.localSuccess»')).toBeInTheDocument(); |
| 153 | + expect(screen.queryByTestId('protocol-check-skipped')).not.toBeInTheDocument(); |
| 154 | + }); |
| 155 | +}); |
0 commit comments