Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/src/hooks/useKeyringOperationApprovals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});
8 changes: 6 additions & 2 deletions app/src/hooks/useKeyringOperationApprovals.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -53,10 +53,13 @@ export function useKeyringOperationApprovals(): {
dismiss: (requestId: string) => void;
} {
const [requests, setRequests] = useState<KeyringOperationApprovalRequest[]>([]);
// 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<string>());

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
Expand Down Expand Up @@ -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));
}, []);

Expand Down
19 changes: 15 additions & 4 deletions app/src/services/__tests__/keyringApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
);
});
7 changes: 5 additions & 2 deletions app/src/services/keyringApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown[]> => {
const response = await callCoreRpc<{ result: unknown }>({
// The controller answers with the bare array; accept a `{ result }` envelope too.
const response = await callCoreRpc<unknown>({
method: 'openhuman.keyring_consent_list_pending_operations',
});
return Array.isArray(response.result) ? response.result : [];
if (Array.isArray(response)) return response;
Comment thread
M3gA-Mind marked this conversation as resolved.
Resolved
const wrapped = (response as { result?: unknown } | null)?.result;
return Array.isArray(wrapped) ? wrapped : [];
};
90 changes: 90 additions & 0 deletions app/test/playwright/specs/keyring-consent-before-sign-in.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { expect, test } from '@playwright/test';
Comment thread
M3gA-Mind marked this conversation as resolved.
Resolved

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)}`;
}
)
Comment thread
M3gA-Mind marked this conversation as resolved.
Resolved
.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(outcome).toBe('ok');
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);
});
});
4 changes: 2 additions & 2 deletions docs/gitbooks/en/developing/e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/__tests__/e2e-web-shards.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
);
Expand Down
Loading