// @ts-nocheck
/**
 * Settings → AI & Skills (capability 13.3).
 *
 * Rewritten to follow the cron-jobs-flow reference: one `resetApp(...)` at
 * the top establishes a fresh-install baseline (auth + onboarding via
 * real UI), then each test navigates to a sub-route and asserts the panel
 * actually mounted. No more per-suite ad-hoc auth bootstrapping.
 *
 * Covers:
 *   - 13.3.1 LLM panel renders AI routing/provider controls
 *   - 13.3.2 Tools panel renders at least one tool toggle
 */
import { waitForApp } from '../helpers/app-helpers';
import { textExists, waitForText } from '../helpers/element-helpers';
import { resetApp } from '../helpers/reset-app';
import { navigateViaHash } from '../helpers/shared-flows';
import { startMockServer, stopMockServer } from '../mock-server';

const USER_ID = 'e2e-settings-ai-skills';

describe('Settings - AI & Skills', () => {
  before(async function beforeSuite() {
    this.timeout(90_000);
    await startMockServer();
    await waitForApp();
    await resetApp(USER_ID);
  });

  after(async () => {
    await stopMockServer();
  });

  it('mounts LLM panel and shows provider/routing controls (13.3.1)', async function () {
    this.timeout(90_000);
    await navigateViaHash('/settings/llm');

    await waitForText('AI', 15_000);
    const hasAiSurface =
      (await textExists('Cloud providers')) ||
      (await textExists('Primary cloud')) ||
      (await textExists('Reasoning'));
    expect(hasAiSurface).toBe(true);
  });

  it('mounts Tools panel and shows skill toggles (13.3.2)', async () => {
    await navigateViaHash('/settings/tools');

    await waitForText('Tools', 15_000);
    const toolVisible = (await textExists('Filesystem')) || (await textExists('Shell'));
    expect(toolVisible).toBe(true);
  });
});
