From 5adc128a835a3651668597b6b05ac44f402b521a Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Mon, 30 Nov 2026 00:01:32 +0100 Subject: [PATCH 1/3] test(apps): verify remote rendering in Chromium over the real frame transport Slice 6 of #626, first part. A React app built with @rentnerproxy/app-ui 1.8.0 runs in the real sandboxed frame with the real asset policy, and the platform draws its tree with its own components. Chromium checks: - the frame is opaque, hidden and out of the focus order, and the tree appears in the platform page; - a press reaches the app, which updates its badge and asks for a toast; - tabs switch in the platform and the held form draft is saved by the app; - keyboard focus moves through the drawn controls and never enters the frame; - a batch the catalog rejects, sent past the SDK's checks, retires the frame; - a new frame document connects with a new session and draws again. The frame session moves from AppUiFrame into AppFrameView, which takes the theme, operations, dialogs and the end of the session as props, so the fixture and the planned dev host use the same component. A frame that renders remotely is hidden with the hidden attribute, which works without a stylesheet. The check runs as a job of App Runtime Reference whenever web inputs change. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/app-runtime-reference.yml | 58 +++++ web/src/features/AppUi/AppUiFrame.tsx | 148 +++-------- .../AppUi/Components/AppFrameView.tsx | 126 ++++++++++ .../AppUi/Types/app-frame-view.types.ts | 31 +++ .../features/AppUi/app-ui-frame.test.tsx | 4 +- .../fixtures/remote-ui-browser/app/app.mts | 90 +++++++ .../fixtures/remote-ui-browser/app/index.html | 9 + .../fixtures/remote-ui-browser/browser.mts | 234 ++++++++++++++++++ .../tests/fixtures/remote-ui-browser/bun.lock | 40 +++ .../fixtures/remote-ui-browser/package.json | 11 + .../tests/fixtures/remote-ui-host/fixture.ts | 2 + .../tests/fixtures/remote-ui-host/host.tsx | 90 +++++++ 12 files changed, 723 insertions(+), 120 deletions(-) create mode 100644 web/src/features/AppUi/Components/AppFrameView.tsx create mode 100644 web/src/features/AppUi/Types/app-frame-view.types.ts create mode 100644 web/src/tests/fixtures/remote-ui-browser/app/app.mts create mode 100644 web/src/tests/fixtures/remote-ui-browser/app/index.html create mode 100644 web/src/tests/fixtures/remote-ui-browser/browser.mts create mode 100644 web/src/tests/fixtures/remote-ui-browser/bun.lock create mode 100644 web/src/tests/fixtures/remote-ui-browser/package.json create mode 100644 web/src/tests/fixtures/remote-ui-host/fixture.ts create mode 100644 web/src/tests/fixtures/remote-ui-host/host.tsx diff --git a/.github/workflows/app-runtime-reference.yml b/.github/workflows/app-runtime-reference.yml index ab89b9483..50346957c 100644 --- a/.github/workflows/app-runtime-reference.yml +++ b/.github/workflows/app-runtime-reference.yml @@ -220,3 +220,61 @@ jobs: ${{ runner.temp }}/app-runtime-reference/greeting-grants.json ${{ runner.temp }}/app-runtime-reference/greeting-recovery.json ${{ runner.temp }}/app-runtime-reference/greeting-offline-restore.json + + remote-ui: + name: Remote UI browser fixture + needs: changes + if: ${{ !cancelled() }} + runs-on: ubuntu-24.04 + timeout-minutes: 20 + env: + # The platform's renderer, its shared components and the fixture are web inputs. + RUN_CHECK: ${{ needs.changes.outputs.web != 'false' }} + steps: + - name: Require successful change detection + env: + CHANGE_RESULT: ${{ needs.changes.result }} + run: test "$CHANGE_RESULT" = success + + - name: Report unaffected check + if: env.RUN_CHECK != 'true' + run: echo 'No web input changed; this check does not need to run.' + + - name: Check out exact tested commit + if: env.RUN_CHECK == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ github.sha }} + + - name: Set up Bun + if: env.RUN_CHECK == 'true' + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + with: + bun-version: 1.4.5 + + - name: Install locked platform and fixture dependencies and Chromium + if: env.RUN_CHECK == 'true' + shell: bash + run: | + bun install --no-env-file --frozen-lockfile --ignore-scripts + cd web/src/tests/fixtures/remote-ui-browser + bun install --no-env-file --frozen-lockfile + node node_modules/@playwright/test/cli.js install --only-shell chromium + shell=$(find "$HOME/.cache/ms-playwright" -type f \( -name chrome-headless-shell -o -name headless_shell \) -print -quit) + if [ -z "$shell" ] || ldd "$shell" | grep -q 'not found'; then + node node_modules/@playwright/test/cli.js install-deps chromium + fi + + - name: Verify remote rendering over the real frame transport + if: env.RUN_CHECK == 'true' + run: bun --no-env-file web/src/tests/fixtures/remote-ui-browser/browser.mts "$RUNNER_TEMP/remote-ui-browser.json" + + - name: Upload browser evidence + if: env.RUN_CHECK == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: remote-ui-browser-${{ github.run_attempt }} + if-no-files-found: error + retention-days: 14 + path: ${{ runner.temp }}/remote-ui-browser.json diff --git a/web/src/features/AppUi/AppUiFrame.tsx b/web/src/features/AppUi/AppUiFrame.tsx index 787845169..412232bf8 100644 --- a/web/src/features/AppUi/AppUiFrame.tsx +++ b/web/src/features/AppUi/AppUiFrame.tsx @@ -1,27 +1,16 @@ -import { toast } from '@rentnerkev/toasts' -import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react' +import { useEffect, useEffectEvent, useState } from 'react' -import { - appUiDefaultRoute, - type AppUiDialogRequest, - type AppUiRendering, - type AppUiToast, -} from '@/lib/AppUi/bridge.ts' +import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts' import type { AppUiSlot, AppUiSummary } from '@/lib/AppUi/contract.ts' import { APP_UI_PREFIX } from '@/lib/AppUi/paths.ts' -import { createRemoteUiStore, type RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts' -import { - bindAppUiFrame, - supportsRemoteRendering, - type AppUiRemoteEventDetail, - type AppUiRevocation, -} from '@/lib/AppUi/session.ts' +import type { AppUiRevocation } from '@/lib/AppUi/session.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' import { useAppUi } from './AppUiProvider.tsx' import { callAppUi } from '@/lib/AppUi/client.ts' import { openAppUiHandler } from './middleware.ts' -import RemoteAppView from './Components/RemoteAppView/index.tsx' +import AppFrameView from './Components/AppFrameView.tsx' +import type { AppFrameSource as OpenedSource } from './Types/app-frame-view.types.ts' type FrameProps = { app: AppUiSummary @@ -33,12 +22,7 @@ type FrameProps = { fill?: boolean | undefined } -type AppFrameSource = { nonce: string; url: string; frameToken: string } - -/** A toast an app asked for, always titled with the app's name so it never looks like the platform's. */ -function showAppToast(appName: string, { tone, heading, text }: AppUiToast) { - toast[tone](text, { title: heading ? `${appName} · ${heading}` : appName }) -} +type AppFrameSource = OpenedSource & { frameToken: string } export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill }: FrameProps) { const sessionId = useAppUi()?.sessionId @@ -182,57 +166,18 @@ function OpenedAppFrame({ onDisconnect: (reason: Exclude) => void }) { const ui = useAppUi() - const { t, locale } = useTranslationStore() - const theme = ui?.theme ?? 'light' - const iframe = useRef(null) - const bridge = useRef | null>(null) - // An app that may draw remotely shows nothing until its handshake says how it renders. - const [rendering, setRendering] = useState(() => - supportsRemoteRendering(app) ? 'pending' : 'frame', - ) - const [remoteTree] = useState(createRemoteUiStore) - const currentContext = useEffectEvent(() => ({ - theme, - locale, - route, - permissionKeys: app.permissionKeys, - })) - // Keys match the manifest pattern, so the joined list changes exactly when the keys do. - const permissionScope = app.permissionKeys.join(' ') - const navigate = useEffectEvent(onNavigate) - const dialog = useEffectEvent( - (request: AppUiDialogRequest, settle: (outcome: 'confirmed' | 'cancelled') => void) => { - ui?.openDialog({ - appName: app.name, - dialogId: request.dialogId, - mount: source.nonce, - settle, - }) - }, - ) - const revoke = useEffectEvent((reason: AppUiRevocation) => { - ui?.cancelDialog(source.nonce) - if (reason !== 'unmounted') onDisconnect(reason) - }) - - const onRemoteEvent = useCallback( - (node: string, event: RemoteUiEvent, detail: AppUiRemoteEventDetail) => - bridge.current?.sendRemoteEvent(node, event, detail), - [], - ) - - const bind = useEffectEvent((element: HTMLIFrameElement) => - bindAppUiFrame(element, source.nonce, app, { - onConnected: (mode) => { - setRendering(mode) - return currentContext() - }, - onRemoteMutate: (records) => remoteTree.apply(records), - onToast: (message) => showAppToast(app.name, message), - onNavigate: (target) => navigate(target), - onDialog: (request, settle) => dialog(request, settle), - onRevoked: (reason) => revoke(reason), - onApiRequest: ({ requestId, operationId, idempotencyKey, payload }, signal) => + // Operations go through the gateway with this frame's token; dialogs open in the platform. + return ( + callAppUi({ data: { installationId: app.installationId, @@ -244,50 +189,17 @@ function OpenedAppFrame({ payload, }, signal, - }), - }), - ) - - useLayoutEffect(() => { - const element = iframe.current - if (!element) return - const session = bind(element) - bridge.current = session - return () => { - bridge.current = null - session.close() - } - }, []) - - // The inventory poll updates the user's keys while the frame stays open. - useEffect(() => { - const permissionKeys = permissionScope === '' ? [] : permissionScope.split(' ') - bridge.current?.sendContext({ theme, locale, route, permissionKeys }) - }, [locale, permissionScope, route, theme]) - - // A remotely drawn app keeps running in its hidden frame, which never takes focus. - return ( - <> -