fix(test): P1-02 browser chat — add SaaS auth fixture for non-Tauri mode
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Root cause: Playwright external Chromium is not a Tauri runtime, so isTauriRuntime() returns false. The app needs SaaS session to route chat through relay, but tests never logged in. Fix: Auto-detect non-Tauri mode and pre-login via SaaS API, injecting session into localStorage before tests run.
This commit is contained in:
@@ -6,12 +6,53 @@
|
||||
*
|
||||
* 前提条件:
|
||||
* - Desktop App 运行在 http://localhost:1420 (pnpm tauri dev)
|
||||
* - SaaS Server 运行在 http://localhost:8080 (浏览器模式需要)
|
||||
* - 后端服务可用 (SaaS 或 Kernel)
|
||||
*
|
||||
* 运行: cd desktop && npx playwright test smoke_chat
|
||||
*/
|
||||
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
import { test as base, expect, type Page } from '@playwright/test';
|
||||
|
||||
const SaaS_BASE = 'http://localhost:8080/api/v1';
|
||||
const ADMIN_USER = 'admin';
|
||||
const ADMIN_PASS = 'admin123';
|
||||
|
||||
// Extend test with SaaS login fixture for browser-mode tests
|
||||
const test = base.extend<{
|
||||
saasAuthenticated: void;
|
||||
}>({
|
||||
saasAuthenticated: [async ({ page }, use) => {
|
||||
// Check if running in Tauri — if so, no SaaS login needed
|
||||
const isTauri = await page.evaluate(() => !!(window as any).__TAURI_INTERNALS__).catch(() => false);
|
||||
|
||||
if (!isTauri) {
|
||||
// Browser mode: need SaaS session before chat can work
|
||||
// Login via SaaS API and store session in localStorage
|
||||
try {
|
||||
const loginRes = await page.request.post(`${SaaS_BASE}/auth/login`, {
|
||||
data: { username: ADMIN_USER, password: ADMIN_PASS },
|
||||
});
|
||||
if (loginRes.ok()) {
|
||||
const loginJson = await loginRes.json();
|
||||
// Inject SaaS session into localStorage so the app can connect
|
||||
await page.evaluate((session) => {
|
||||
localStorage.setItem('zclaw-saas-session', JSON.stringify({
|
||||
saasUrl: 'http://localhost:8080',
|
||||
token: session.token,
|
||||
account: session.account,
|
||||
}));
|
||||
}, loginJson);
|
||||
} else {
|
||||
console.log(`SaaS login failed (${loginRes.status()}), browser chat may not work`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('SaaS server not reachable, browser chat will not work:', (e as Error).message);
|
||||
}
|
||||
}
|
||||
await use();
|
||||
}, { auto: true }],
|
||||
});
|
||||
|
||||
test.setTimeout(120000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user