Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(e2e): trim connectivity spec to device-offline coverage

Steven Enamakelc1133f093bd9
diff --git a/app/test/e2e/specs/connectivity-state-differentiation.spec.ts b/app/test/e2e/specs/connectivity-state-differentiation.spec.ts
index 437e5a8a66..6522a21f90 100644
--- a/app/test/e2e/specs/connectivity-state-differentiation.spec.ts
+++ b/app/test/e2e/specs/connectivity-state-differentiation.spec.ts
@@ -1,255 +1,54 @@
/**
- * E2E: Differentiate device offline, backend unreachable, socket disconnected,
- * and core offline states (issue #1527).
- *
- * Verifies that the UI shows distinct status copy and actions for each
- * connectivity failure mode, and that recovery transitions work without
- * requiring a reinstall or data reset.
- *
- * ## Driver notes
- * - Backend-unreachable: requires `httpFaultRules` mock behavior (array of
- * fault-rule objects). The old `forceHttpStatus` key is not implemented in
- * the mock server — scenarios that depend on it are skipped with a gap note.
- * - Socket-disconnected: POST to `/__admin/socket/disconnect` closes all
- * active Socket.IO sessions server-side. The client reconnect loop then
- * surfaces `backend-only` copy.
- * - Internet-offline: simulated via `window.dispatchEvent(new Event('offline'))`
- * in the WebView. Triggers the `internet-offline` branch in connectivitySlice.
- * - Core-offline: the embedded core runs in-process inside the Tauri host and
- * cannot be stopped without killing the entire app process. There is a
- * `restart_core_process` Tauri command, but no Tauri command to *stop* the
- * core without immediately restarting it, and no way to invoke Tauri commands
- * from outside the WebView renderer during E2E. Scenario is skipped with a
- * TODO; see product gap note below.
- *
- * ## Product gap — forceHttpStatus not implemented
- * The mock server (`scripts/mock-api/server.mjs`) applies HTTP faults via the
- * `httpFaultRules` behavior key (an array of rule objects), not a bare
- * `forceHttpStatus` string. Scenarios 1 and 4 that previously called
- * `setMockBehavior('forceHttpStatus', '503')` are skipped until the spec is
- * updated to use `httpFaultRules` fault injection. Tracked in issue #1527.
- *
- * ## Product gap — core-offline Tauri command
- * There is no Tauri IPC command accessible from the E2E harness that stops the
- * core without immediately restarting it. `restart_core_process` bounces the
- * core but only returns after it is healthy again, so there is no observable
- * window where the UI can show the `core-unreachable` state.
- *
- * Product gap: expose a `stop_core_process` Tauri command (debug-build-only
- * is acceptable) so the test harness can drive the `core-unreachable` branch.
- * Tracked in issue #1527.
+ * E2E coverage for device-offline feedback in the signed-in home surface.
+ * Socket recovery and local-core health selection have focused store and
+ * service tests; this suite exercises the user-visible browser event path.
*/
import { waitForApp, waitForAppReady } from '../helpers/app-helpers';
-import { textExists as _textExists, waitForText as _waitForText } from '../helpers/element-helpers';
+import { textExists } from '../helpers/element-helpers';
import { resetApp } from '../helpers/reset-app';
-import {
- getMockServerPort,
- resetMockBehavior,
- startMockServer,
- stopMockServer,
-} from '../mock-server';
+import { navigateViaHash } from '../helpers/shared-flows';
+import { resetMockBehavior, startMockServer, stopMockServer } from '../mock-server';
const USER_ID = 'e2e-connectivity-state-differentiation';
-/**
- * Stable text fragments rendered by the app for each blocking state.
- *
- * These are substrings of the i18n values in en.ts — waitForText uses
- * XPath contains(text(), …) so a unique prefix is sufficient.
- *
- * home.statusBackendOnly → "Reconnecting to backend… your agent will be available again shortly."
- * home.statusInternetOffline → "Your device is offline right now. Check your network…"
- * app.connectionIndicator.reconnecting → "Reconnecting…"
- * app.connectionIndicator.coreOffline → "Core offline"
- * app.connectionIndicator.offline → "Offline"
- */
-const _STATUS_TEXT = {
- internetOffline: 'Your device is offline right now',
- coreUnreachable: "The OpenHuman core isn't responding",
- // Full value ends with "… your agent will be available again shortly."
- backendOnly: 'Reconnecting to backend',
- // The indicator renders "Reconnecting…" (with Unicode ellipsis U+2026)
- reconnecting: 'Reconnecting…',
- coreOffline: 'Core offline',
- offline: 'Offline',
-} as const;
-
-/** Timeout for connectivity state changes to propagate to the UI. */
-const _CONNECTIVITY_SETTLE_MS = 12_000;
-
-function stepLog(message: string): void {
- console.log(`[ConnectivityDiffE2E][${new Date().toISOString()}] ${message}`);
-}
-
-/**
- * Call the mock admin endpoint directly from Node (outside the WebView) to
- * disconnect all Socket.IO clients. Returns the number of sessions
- * disconnected, or -1 on failure.
- */
-async function _adminDisconnectSockets(): Promise<number> {
- const port = getMockServerPort();
- stepLog(`Posting to /__admin/socket/disconnect on mock port ${String(port)}`);
- try {
- const res = await fetch(`http://127.0.0.1:${String(port)}/__admin/socket/disconnect`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({}),
- });
- const json = (await res.json()) as { success?: boolean; data?: { disconnected?: number } };
- const count = json.data?.disconnected ?? 0;
- stepLog(`adminDisconnectSockets: disconnected=${count}`);
- return count;
- } catch (err) {
- stepLog(`adminDisconnectSockets failed: ${String(err)}`);
- return -1;
- }
-}
-
-/**
- * Simulate device-offline inside the WebView by dispatching the native
- * 'offline' DOM event. The connectivity slice listens on window.
- */
-async function _simulateDeviceOffline(): Promise<void> {
- await browser.execute(() => {
- window.dispatchEvent(new Event('offline'));
- });
+async function setDeviceOffline(offline: boolean): Promise<void> {
+ await browser.execute((value: boolean) => {
+ Object.defineProperty(navigator, 'onLine', { configurable: true, value: !value });
+ window.dispatchEvent(new Event(value ? 'offline' : 'online'));
+ }, offline);
}
-/**
- * Restore device-online inside the WebView by dispatching the native
- * 'online' DOM event.
- */
-async function simulateDeviceOnline(): Promise<void> {
- await browser.execute(() => {
- window.dispatchEvent(new Event('online'));
- });
-}
-
-describe('Connectivity state differentiation (issue #1527)', () => {
+describe('Connectivity state differentiation', () => {
before(async function beforeSuite() {
this.timeout(120_000);
- stepLog('Starting mock server');
await startMockServer();
- stepLog('Waiting for app');
await waitForApp();
- stepLog('Resetting app state');
await resetApp(USER_ID);
- stepLog('Suite setup complete');
});
afterEach(async () => {
- // Always restore clean mock behavior and online state after each test so
- // subsequent scenarios start from a known baseline.
resetMockBehavior();
try {
- await simulateDeviceOnline();
+ await setDeviceOffline(false);
} catch {
- // Non-fatal — if the WebView is in a bad state the next reset will fix it.
+ // A failed WebView will be reset by the next test setup.
}
});
after(async () => {
- stepLog('Stopping mock server');
await stopMockServer();
});
- // ---------------------------------------------------------------------------
- // Scenario 1: Internet available, backend unreachable
- //
- // SKIPPED: The mock server does not support the `forceHttpStatus` behavior
- // key. HTTP fault injection uses the `httpFaultRules` array format instead.
- // The spec needs to be updated to use `setMockBehavior('httpFaultRules', …)`
- // with a rule object that sets status=503 for all non-admin routes before
- // this scenario can be enabled. Tracked in issue #1527.
- // ---------------------------------------------------------------------------
- it.skip('shows backend-reconnecting status when backend is unreachable but internet is up', async function () {
- this.timeout(60_000);
- // TODO(issue #1527): replace forceHttpStatus with httpFaultRules injection:
- // setMockBehavior('httpFaultRules',
- // JSON.stringify([{ status: 503, error: 'Mock backend down' }]));
- // Then assert STATUS_TEXT.backendOnly appears and clears after resetMockBehavior().
- stepLog('SKIPPED — forceHttpStatus not implemented in mock server');
- });
-
- // ---------------------------------------------------------------------------
- // Scenario 2: Socket disconnected (backend reachable, socket layer dropped)
- //
- // SKIPPED: The mock backend is local (same process as the test runner), so
- // the Socket.IO client reconnects within milliseconds of being dropped.
- // The "Reconnecting…" indicator in ConnectionIndicator only renders when
- // `blocking === 'backend-only'` AND `legacyStatus === 'connecting'` — a
- // window so narrow that it is consistently missed in the e2e harness before
- // the auto-reconnect fires and transitions the socket back to 'connected'.
- // Additionally, `/__admin/socket/disconnect` may not be wired in all
- // mock-server configurations. Tracked in issue #1527.
- // GAP: ConnectionIndicator "Reconnecting…" state is too transient to observe
- // reliably in docker e2e; needs either a delayed-reconnect mock option
- // or a deterministic reconnect-pause before the assertion can pass.
- // ---------------------------------------------------------------------------
- it.skip('shows reconnecting status after socket is force-disconnected server-side', async function () {
- this.timeout(60_000);
- stepLog('SKIPPED — Reconnecting… window too transient in local mock; see issue #1527');
- });
-
- // ---------------------------------------------------------------------------
- // Scenario 3: True device offline
- //
- // SKIPPED: The "Your device is offline right now" status copy is rendered
- // only inside Home.tsx (the /home route). The test dispatches window.offline
- // without first navigating to /home, so waitForText never finds the copy in
- // the DOM regardless of whether the connectivitySlice updates correctly.
- // Even with a prior navigateViaHash('/home'), the auth guard may redirect
- // away from /home before the offline event propagates, and the copy is
- // conditionally rendered only when `blocking === 'internet-offline'`.
- // Fixing this requires synchronised navigation + offline dispatch that is
- // too fragile without a dedicated test-mode hook. Tracked in issue #1527.
- // GAP: Device-offline UI copy is only surfaced on /home; test needs explicit
- // /home navigation + connectivity-slice propagation guard before the
- // assertion can reliably pass in docker e2e.
- // ---------------------------------------------------------------------------
- it.skip('shows device-offline copy (not backend-only) when window fires "offline" event', async function () {
+ it('shows device-offline copy when the browser fires offline', async function () {
this.timeout(30_000);
- stepLog('SKIPPED — statusInternetOffline copy only visible on /home; see issue #1527');
- });
-
- // ---------------------------------------------------------------------------
- // Scenario 4: Backend recovers after 503 — no reinstall/data-reset required
- //
- // SKIPPED: Same gap as Scenario 1 — depends on `forceHttpStatus` which is
- // not implemented in the mock server. Re-enable alongside Scenario 1 once
- // `httpFaultRules` injection is wired up. Tracked in issue #1527.
- // ---------------------------------------------------------------------------
- it.skip('status updates to healthy without reinstall after backend recovers from 503', async function () {
- this.timeout(60_000);
- // TODO(issue #1527): use httpFaultRules to inject 503, then assert banner
- // clears automatically after resetMockBehavior() without any user action.
- stepLog('SKIPPED — forceHttpStatus not implemented in mock server');
- });
-
- // ---------------------------------------------------------------------------
- // Scenario 5: Internet available + core offline → core-specific indicator
- //
- // SKIPPED: The embedded core runs in-process inside the Tauri host. There
- // is no Tauri IPC command accessible from the E2E harness that stops the
- // core without immediately restarting it. `restart_core_process` bounces
- // the core but only returns after it is healthy again, so there is no
- // observable window where the UI can show the `core-unreachable` state.
- //
- // Product gap: expose a `stop_core_process` Tauri command (debug-build-only
- // is acceptable) so the test harness can drive the `core-unreachable` branch
- // and assert that the UI shows "Core offline" rather than "Offline" (the
- // device-offline copy). Tracked in issue #1527.
- // ---------------------------------------------------------------------------
- it.skip('shows core-offline indicator (not device-offline) when internet is up but core is unreachable', async () => {
- // TODO(issue #1527): implement once a `stop_core_process` or equivalent
- // debug Tauri command exists. Steps:
- // 1. Invoke `stop_core_process` via browser.execute + window.__TAURI_INTERNALS__
- // (requires debug build with the command registered).
- // 2. Wait for the core health-monitor poll to fire and update connectivity.core.
- // 3. Assert `textExists('Core offline')` === true.
- // 4. Assert `textExists('Offline')` === false (not device-offline copy).
- // 5. Assert `textExists("The OpenHuman core isn't responding")` === true.
- // 6. Restart the core and assert the indicator recovers.
- await waitForAppReady(5_000);
+ await navigateViaHash('/home');
+ await waitForAppReady(10_000);
+ await setDeviceOffline(true);
+
+ await browser.waitUntil(async () => await textExists('Your device is offline right now'), {
+ timeout: 10_000,
+ interval: 250,
+ timeoutMsg: 'home did not render its device-offline message',
+ });
});
});
diff --git a/app/test/playwright/specs/connectivity-state-differentiation.spec.ts b/app/test/playwright/specs/connectivity-state-differentiation.spec.ts
index bc10efb023..a7dfde5162 100644
--- a/app/test/playwright/specs/connectivity-state-differentiation.spec.ts
+++ b/app/test/playwright/specs/connectivity-state-differentiation.spec.ts
@@ -9,7 +9,7 @@ async function setDeviceOffline(page: import('@playwright/test').Page, offline:
}, offline);
}
-test.describe('Connectivity state differentiation (issue #1527)', () => {
+test.describe('Connectivity state differentiation', () => {
test.beforeEach(async ({ page }, testInfo) => {
const testSlug = testInfo.title.toLowerCase().replace(/[^a-z0-9]+/g, '-');
await bootAuthenticatedPage(page, 'pw-connectivity-diff-' + testSlug, '/home');
@@ -19,11 +19,10 @@ test.describe('Connectivity state differentiation (issue #1527)', () => {
await setDeviceOffline(page, false);
});
- // `backend-only` is the browser's Socket.IO link to the local core. A 503
- // from the hosted backend does not drive this state; selector behavior has
- // focused store coverage.
-
- test.skip('shows reconnecting status after socket is force-disconnected server-side', async () => {}); // https://github.com/tinyhumansai/openhuman/issues/1527
+ // `backend-only` is the browser's Socket.IO link to the local core. The mock
+ // immediately accepts reconnects after a server-side disconnect, so the
+ // transient reconnect label cannot be asserted deterministically here;
+ // selector behavior has focused store coverage.
test('shows device-offline copy (not backend-only) when window fires offline', async ({ page }) => {
await setDeviceOffline(page, true);