Skip to content

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

6.7 KB
Raw Blame
import { expect, type Page, test } from '@playwright/test';

import {
  bootAuthenticatedPage,
  callCoreRpc,
  dismissWalkthroughIfPresent,
} from '../helpers/core-rpc';

async function emulateTauriRuntime(page: Page): Promise<void> {
  await page.evaluate(() => {
    const win = window as typeof window & {
      isTauri?: boolean;
      __TAURI_INTERNALS__?: { invoke?: (cmd: string, args?: unknown) => Promise<unknown> };
    };
    win.isTauri = true;
    win.__TAURI_INTERNALS__ = win.__TAURI_INTERNALS__ ?? {};
    win.__TAURI_INTERNALS__.invoke = win.__TAURI_INTERNALS__.invoke ?? (async () => null);
  });
}

async function waitForAdvancedRouteReady(page: Page): Promise<void> {
  await page.waitForSelector('#root', { state: 'attached' });
  await expect
    .poll(async () => {
      const text = await page
        .locator('#root')
        .innerText()
        .catch(() => '');
      return text.trim().length;
    })
    .toBeGreaterThan(20);
  await expect(page.getByText(/Select a Runtime|Connect to Your Runtime/)).toHaveCount(0);
}

async function gotoSettingsRoute(page: Page, hash: string): Promise<void> {
  await page.goto(`/#${hash}`);
  await waitForAdvancedRouteReady(page);
  await dismissWalkthroughIfPresent(page);
}

test.describe('Settings - Advanced Config', () => {
  test.beforeEach(async ({ page }) => {
    await bootAuthenticatedPage(page, 'pw-settings-advanced-user');
    await emulateTauriRuntime(page);
  });

  test('renders the developer options route and its advanced entries', async ({ page }) => {
    await gotoSettingsRoute(page, '/settings/developer-options');

    // Per-feature diagnostics moved into the settings sidebar; Restart Tour is
    // the stable action specific to the slim Developer Options panel.
    await expect(page.getByRole('button', { name: 'Restart Tour' })).toBeVisible();
  });

  test('persists composio trigger triage settings', async ({ page }) => {
    await gotoSettingsRoute(page, '/settings/composio-triggers');

    await expect(page.getByLabel('Disable AI triage for all triggers')).toBeVisible();
    await page.locator('#disabled-toolkits').fill('gmail, slack');
    await page
      .locator('#disabled-toolkits')
      .locator('xpath=ancestor::div[.//button[normalize-space()="Save"]][1]')
      .getByRole('button', { name: 'Save' })
      .click();
    await expect(page.getByText('Settings saved')).toBeVisible();

    await expect
      .poll(async () => {
        const after = await callCoreRpc<{ result?: { triage_disabled_toolkits?: string[] } }>(
          'openhuman.config_get_composio_trigger_settings',
          {}
        );
        const disabled = after.result?.triage_disabled_toolkits ?? [];
        return disabled.includes('gmail') && disabled.includes('slack');
      })
      .toBe(true);
  });

  test('persists autonomy max_actions_per_hour through core RPC', async ({ page }) => {
    const before = await callCoreRpc<{ result?: { max_actions_per_hour?: number } }>(
      'openhuman.config_get_autonomy_settings',
      {}
    );
    const current = before.result?.max_actions_per_hour ?? 20;
    const target = current === 250 ? 251 : 250;

    // /settings/autonomy redirects to Agent access, which hosts the autonomy
    // rate-limit section (Max actions per hour).
    await gotoSettingsRoute(page, '/settings/autonomy');

    await expect(page.getByRole('heading', { name: 'Max actions per hour' })).toBeVisible();
    await page.locator('#autonomy-max-actions').fill(String(target));
    await page
      .locator('#autonomy-max-actions')
      .locator('xpath=ancestor::div[.//button[normalize-space()="Save"]][1]')
      .getByRole('button', { name: 'Save' })
      .click();
    await expect(page.getByText('Saved.')).toBeVisible();

    await expect
      .poll(async () => {
        const after = await callCoreRpc<{ result?: { max_actions_per_hour?: number } }>(
          'openhuman.config_get_autonomy_settings',
          {}
        );
        return after.result?.max_actions_per_hour;
      })
      .toBe(target);
  });

  test('switches composio routing mode to direct and can return to backend mode', async ({
    page,
  }) => {
    await gotoSettingsRoute(page, '/settings/composio-routing');

    await expect(page.getByText('Routing mode')).toBeVisible();
    await page.getByLabel(/Direct/).check();
    await page.locator('#composio-api-key').fill('ck_live_e2e_composio_key');
    await page
      .locator('#composio-api-key')
      .locator('xpath=ancestor::div[.//button[normalize-space()="Save"]][1]')
      .getByRole('button', { name: 'Save' })
      .first()
      .click();

    const confirm = page.getByRole('button', { name: 'I understand, switch to Direct' });
    if (await confirm.isVisible().catch(() => false)) {
      await confirm.click();
    }

    await expect
      .poll(async () => {
        const mode = await callCoreRpc<{ result?: { mode?: string; api_key_set?: boolean } }>(
          'openhuman.composio_get_mode',
          {}
        );
        return { mode: mode.result?.mode ?? null, apiKeySet: Boolean(mode.result?.api_key_set) };
      })
      .toEqual({ mode: 'direct', apiKeySet: true });

    await callCoreRpc('openhuman.composio_clear_api_key', {});
    const backend = await callCoreRpc<{ result?: { mode?: string; api_key_set?: boolean } }>(
      'openhuman.composio_get_mode',
      {}
    );
    expect(backend.result?.mode).toBe('backend');
    expect(backend.result?.api_key_set).toBe(false);
  });

  test('mounts the remaining advanced settings routes', async ({ page }) => {
    await gotoSettingsRoute(page, '/settings/local-model-debug');
    await expect
      .poll(async () => page.evaluate(() => window.location.hash))
      .toContain('/connections');
    await expect(page.getByText('LLM Providers')).toBeVisible();

    await gotoSettingsRoute(page, '/settings/agent-chat');
    await expect
      .poll(async () => page.evaluate(() => window.location.hash))
      .toContain('/connections?tab=llm');
    await expect(page.getByText('LLM Providers')).toBeVisible();
    await expect(page.getByText('Runtime Status')).toHaveCount(0);

    await gotoSettingsRoute(page, '/settings/about');
    // The About description copy also contains "software updates"; match the
    // section label exactly to avoid a strict-mode violation.
    await expect(page.getByText('Resources', { exact: true })).toBeVisible();
    await expect(page.getByTestId('about-check-updates')).toBeVisible();

    // /settings/llm now redirects to the Connections page (LLM moved there).
    await gotoSettingsRoute(page, '/settings/llm');
    await expect
      .poll(async () => page.evaluate(() => window.location.hash))
      .toContain('/connections');
    await expect(page.getByText(/Reasoning|Cloud providers|OpenHuman/).first()).toBeVisible();
  });
});