From f7714f768c8c1ae0da95743c9a627a7b69c67210 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 12:11:36 +0530 Subject: [PATCH 1/3] fix(keyring): read the pending-operations poll from the bare array the core sends The signed-out renderer polls keyring_consent_list_pending_operations while no socket exists, but read .result off a value callCoreRpc had already unwrapped, so every poll yielded no prompts and a first sign-in's keyring write could never be approved. Return the array itself, still accept a { result } envelope, and mock the real wire shape in the test. Adds the TS-E2E S-06 Playwright spec, which runs on a core started with OPENHUMAN_TEST_KEYRING_CONSENT=off. --- app/src/services/__tests__/keyringApi.test.ts | 19 +++- app/src/services/keyringApi.ts | 7 +- .../keyring-consent-before-sign-in.spec.ts | 89 +++++++++++++++++++ 3 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts diff --git a/app/src/services/__tests__/keyringApi.test.ts b/app/src/services/__tests__/keyringApi.test.ts index fb541f00252..3c6299700f6 100644 --- a/app/src/services/__tests__/keyringApi.test.ts +++ b/app/src/services/__tests__/keyringApi.test.ts @@ -57,15 +57,26 @@ describe('keyringApi', () => { }); }); - it('lists pending keyring operations and tolerates a non-array result', async () => { + it('lists pending keyring operations from the bare array the core sends', async () => { const pending = [{ request_id: 'request-1' }]; - mockRpc.mockResolvedValueOnce({ result: pending }); + mockRpc.mockResolvedValueOnce(pending); await expect(listPendingKeyringOperations()).resolves.toEqual(pending); expect(mockRpc).toHaveBeenCalledWith({ method: 'openhuman.keyring_consent_list_pending_operations', }); + }); - mockRpc.mockResolvedValueOnce({ result: null }); - await expect(listPendingKeyringOperations()).resolves.toEqual([]); + it('accepts a { result } envelope around the pending operations', async () => { + const pending = [{ request_id: 'request-1' }]; + mockRpc.mockResolvedValueOnce({ result: pending }); + await expect(listPendingKeyringOperations()).resolves.toEqual(pending); }); + + it.each([null, undefined, {}, { result: null }, 'pending'])( + 'treats a malformed pending-operations answer (%j) as none', + async answer => { + mockRpc.mockResolvedValueOnce(answer); + await expect(listPendingKeyringOperations()).resolves.toEqual([]); + } + ); }); diff --git a/app/src/services/keyringApi.ts b/app/src/services/keyringApi.ts index d1e32156937..1c189a500e9 100644 --- a/app/src/services/keyringApi.ts +++ b/app/src/services/keyringApi.ts @@ -41,8 +41,11 @@ export const respondToKeyringOperation = async ( * no socket yet (before sign-in), so the approval prompt still reaches it. */ export const listPendingKeyringOperations = async (): Promise => { - const response = await callCoreRpc<{ result: unknown }>({ + // The controller answers with the bare array; accept a `{ result }` envelope too. + const response = await callCoreRpc({ method: 'openhuman.keyring_consent_list_pending_operations', }); - return Array.isArray(response.result) ? response.result : []; + if (Array.isArray(response)) return response; + const wrapped = (response as { result?: unknown } | null)?.result; + return Array.isArray(wrapped) ? wrapped : []; }; diff --git a/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts b/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts new file mode 100644 index 00000000000..8f8d4ec3acc --- /dev/null +++ b/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts @@ -0,0 +1,89 @@ +import { expect, test } from '@playwright/test'; + +import { bootRuntimeReadyGuestPage, callCoreRpc } from '../helpers/core-rpc'; + +// TS-E2E S-06: a signed-out renderer has no socket, so it must find the +// keyring prompt a first sign-in raises by polling +// `keyring_consent_list_pending_operations`, show it, and let the user allow +// it. The lane's test responder answers these prompts by default, so this +// spec runs only on a core started with OPENHUMAN_TEST_KEYRING_CONSENT=off. + +const USER_ID = 'ts-e2e-s06-user'; + +function sessionJwt(userId: string): string { + const payload = Buffer.from( + JSON.stringify({ sub: userId, userId, exp: Math.floor(Date.now() / 1000) + 3600 }) + ).toString('base64url'); + return `eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.${payload}.sig`; +} + +test.describe('keyring consent before sign-in', () => { + test.skip( + process.env.OPENHUMAN_TEST_KEYRING_CONSENT !== 'off', + 'TS-E2E S-06 needs the core test keyring responder off' + ); + + test('s_06 shows the sign-in keyring prompt without a socket and signs in once allowed', async ({ + page, + }) => { + test.setTimeout(180_000); + await bootRuntimeReadyGuestPage(page); + + const token = sessionJwt(USER_ID); + let settled = false; + let outcome = 'pending'; + const signIn = callCoreRpc('openhuman.auth_set_credential', { + token, + kind: 'session', + userId: USER_ID, + user: { _id: USER_ID, id: USER_ID, displayName: 'TS-E2E S-06' }, + }) + .then( + () => { + outcome = 'ok'; + }, + (error: unknown) => { + outcome = `error: ${String(error)}`; + } + ) + .finally(() => { + settled = true; + }); + + const dialog = page.getByTestId('keyring-operation-approval-dialog'); + await expect(dialog) + .toBeVisible({ timeout: 20_000 }) + .catch(async (error: unknown) => { + // Tell "the core raised no prompt" apart from "the renderer missed it". + const pending = await callCoreRpc('openhuman.keyring_consent_list_pending_operations', {}); + throw new Error( + `${String(error)}\nsign-in outcome: ${outcome}\ncore pending operations: ${JSON.stringify(pending)}` + ); + }); + await expect(dialog).toContainText('openhuman.credentials'); + await expect(dialog).not.toContainText(token); + + const deadline = Date.now() + 120_000; + let allowed = 0; + while (!settled && Date.now() < deadline) { + if (await dialog.isVisible()) { + // The next prompt can replace this one mid-click; a missed click retries. + const clicked = await dialog + .getByRole('button', { name: 'Allow once' }) + .click({ timeout: 2_000 }) + .then(() => true) + .catch(() => false); + if (clicked) allowed += 1; + } + await page.waitForTimeout(250); + } + + await signIn; + expect(allowed).toBeGreaterThan(0); + const state = await callCoreRpc<{ + isAuthenticated?: boolean; + result?: { isAuthenticated?: boolean }; + }>('openhuman.auth_get_state'); + expect(state.result?.isAuthenticated ?? state.isAuthenticated).toBe(true); + }); +}); From ad4dd897db1a55db280d3c33a594076287e71cf2 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 13:15:51 +0530 Subject: [PATCH 2/3] test(e2e-web): count the new keyring consent spec in the Playwright selection The selection test pins the discovered spec counts; the S-06 spec makes them 111 (all) and 110 (required). Update the e2e testing doc to match. --- docs/gitbooks/en/developing/e2e-testing.md | 4 ++-- scripts/__tests__/e2e-web-shards.test.mjs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/gitbooks/en/developing/e2e-testing.md b/docs/gitbooks/en/developing/e2e-testing.md index b27a88e3be0..721683ff638 100644 --- a/docs/gitbooks/en/developing/e2e-testing.md +++ b/docs/gitbooks/en/developing/e2e-testing.md @@ -183,7 +183,7 @@ desktop suite and Rust E2E: | Playwright web | `playwright-e2e` | Four required Linux jobs, 16 ordinary shards per job plus round-robin special cases | | Desktop | `e2e-desktop`, via `e2e-reusable.yml` | Four Linux suite groups | -Playwright builds its web bundle and standalone core once, then uploads the same artifact to all four required lanes. The required selection runs 109 of the 110 discovered specs: all 48 active browser owners from the consolidation inventory and their assertion recipients remain required, as do every other healthy browser spec. It schedules 64 ordinary shards and nine isolated cases (Connections aliases, Connections deep links, and seven Skills search/install cases), each with its own core and workspace: 73 required units total. A separate `playwright-legacy-diagnostic` job runs the unchanged `aui-tool-result-elements.spec.ts` as one file-atomic unit. Its component compatibility blocker is tracked in [issue #236](https://github.com/senamakel/openhuman/issues/236#issuecomment-6284472501). Only this diagnostic job is advisory; it is excluded from the final gate, while all four required lanes remain strict. The scheduler continues through assigned units to collect failures and exits nonzero if any required unit fails. CI Full therefore runs 74 fresh Playwright units across the required and diagnostic jobs, without claiming the legacy diagnostic passed. Manual Playwright selects all 110 specs strictly, using the same 64 shards and nine isolated cases (73 units); it has no advisory selection. +Playwright builds its web bundle and standalone core once, then uploads the same artifact to all four required lanes. The required selection runs 110 of the 111 discovered specs: all 48 active browser owners from the consolidation inventory and their assertion recipients remain required, as do every other healthy browser spec. It schedules 64 ordinary shards and nine isolated cases (Connections aliases, Connections deep links, and seven Skills search/install cases), each with its own core and workspace: 73 required units total. A separate `playwright-legacy-diagnostic` job runs the unchanged `aui-tool-result-elements.spec.ts` as one file-atomic unit. Its component compatibility blocker is tracked in [issue #236](https://github.com/senamakel/openhuman/issues/236#issuecomment-6284472501). Only this diagnostic job is advisory; it is excluded from the final gate, while all four required lanes remain strict. The scheduler continues through assigned units to collect failures and exits nonzero if any required unit fails. CI Full therefore runs 74 fresh Playwright units across the required and diagnostic jobs, without claiming the legacy diagnostic passed. Manual Playwright selects all 111 specs strictly, using the same 64 shards and nine isolated cases (73 units); it has no advisory selection. The desktop lane calls the reusable workflow with `run_linux: true`, `run_macos: false` and `run_windows: false`, so only the Linux harness runs. Linux uses four fresh WDIO sessions: `foundation` (`auth,navigation,system`), `chat` (`chat,skills,journeys`), `connections` (`providers,provider-web,connectors`), and `settings` (`settings,notifications`). Payments and webhooks have no native flows after their browser owners moved to Playwright, so they are absent from the native shard assignments. The consolidation reviewed 51 same-basename native/Playwright pairs; it retained only five narrowly split mixed cases and retired one obsolete offline-banner pair. The native suite also retains 24 preexisting native-only files outside that duplicate inventory, plus `tauri-commands.spec.ts`, whose browser bootstrap checks moved to the Playwright smoke owner while its native IPC checks remain. The 24 native-only files were not assessed for whether they require the desktop host. The reusable workflow applies the same group definitions to its macOS and Windows full-suite jobs, but those jobs are currently disabled. @@ -217,7 +217,7 @@ renamed files), and add it only to the owning suite. If host and browser cases cover distinct behavior, name and document both responsibilities explicitly; never keep a second full copy as extra confidence. -The current inventory has 30 native spec files and 110 Playwright spec files, +The current inventory has 30 native spec files and 111 Playwright spec files, with only the five mixed files above shared by basename. The 24 preexisting native-only files were outside the duplicate inventory and were not assessed for whether they need a desktop host; `tauri-commands.spec.ts` retains the diff --git a/scripts/__tests__/e2e-web-shards.test.mjs b/scripts/__tests__/e2e-web-shards.test.mjs index 61368782061..0f56d4b9ce1 100644 --- a/scripts/__tests__/e2e-web-shards.test.mjs +++ b/scripts/__tests__/e2e-web-shards.test.mjs @@ -159,8 +159,8 @@ test("selection discovery works in the CI image without ripgrep", () => { assert.deepEqual( selections.map((result) => [result.selection, result.files.length]), [ - ["all", 110], - ["required", 109], + ["all", 111], + ["required", 110], ["diagnostic", 1], ], ); From 81b2d9032012bf7c1e0c9d6bb3a696594367fc10 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 13:15:51 +0530 Subject: [PATCH 3/3] fix(keyring): never re-show a dismissed approval from a stale poll A poll in flight while the user answers can still list the answered request, which would reopen the dialog. Remember dismissed request ids and drop them. The S-06 spec now also asserts the sign-in RPC succeeded. --- app/src/hooks/useKeyringOperationApprovals.test.ts | 9 +++++++++ app/src/hooks/useKeyringOperationApprovals.ts | 8 ++++++-- .../specs/keyring-consent-before-sign-in.spec.ts | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/hooks/useKeyringOperationApprovals.test.ts b/app/src/hooks/useKeyringOperationApprovals.test.ts index 954a6310b74..aa6a594e9e2 100644 --- a/app/src/hooks/useKeyringOperationApprovals.test.ts +++ b/app/src/hooks/useKeyringOperationApprovals.test.ts @@ -126,4 +126,13 @@ describe('useKeyringOperationApprovals', () => { expect(listPending).not.toHaveBeenCalled(); }); + + it('does not show a dismissed request again when a stale poll lists it', () => { + const { result } = renderHook(() => useKeyringOperationApprovals()); + emit(REQUEST); + act(() => result.current.dismiss(REQUEST.request_id)); + emit(REQUEST); + + expect(result.current.requests).toEqual([]); + }); }); diff --git a/app/src/hooks/useKeyringOperationApprovals.ts b/app/src/hooks/useKeyringOperationApprovals.ts index 739803038b8..d0aef84c89f 100644 --- a/app/src/hooks/useKeyringOperationApprovals.ts +++ b/app/src/hooks/useKeyringOperationApprovals.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import { listPendingKeyringOperations } from '../services/keyringApi'; import { socketService } from '../services/socketService'; @@ -53,10 +53,13 @@ export function useKeyringOperationApprovals(): { dismiss: (requestId: string) => void; } { const [requests, setRequests] = useState([]); + // A poll that was in flight when the user answered can still list the + // answered request; never show a dismissed request again. + const dismissed = useRef(new Set()); const handleRequest = useCallback((payload: unknown) => { const request = parseRequest(payload); - if (!request) return; + if (!request || dismissed.current.has(request.request_id)) return; setRequests(current => current.some(existing => existing.request_id === request.request_id) ? current @@ -94,6 +97,7 @@ export function useKeyringOperationApprovals(): { }, [handleRequest]); const dismiss = useCallback((requestId: string) => { + dismissed.current.add(requestId); setRequests(current => current.filter(request => request.request_id !== requestId)); }, []); diff --git a/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts b/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts index 8f8d4ec3acc..3c72dfde1d7 100644 --- a/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts +++ b/app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts @@ -79,6 +79,7 @@ test.describe('keyring consent before sign-in', () => { } await signIn; + expect(outcome).toBe('ok'); expect(allowed).toBeGreaterThan(0); const state = await callCoreRpc<{ isAuthenticated?: boolean;