release(v0.2.0): streaming, MCP protocol, Browser Hand, security enhancements
## Major Features ### Streaming Response System - Implement LlmDriver trait with `stream()` method returning async Stream - Add SSE parsing for Anthropic and OpenAI API streaming - Integrate Tauri event system for frontend streaming (`stream:chunk` events) - Add StreamChunk types: Delta, ToolStart, ToolEnd, Complete, Error ### MCP Protocol Implementation - Add MCP JSON-RPC 2.0 types (mcp_types.rs) - Implement stdio-based MCP transport (mcp_transport.rs) - Support tool discovery, execution, and resource operations ### Browser Hand Implementation - Complete browser automation with Playwright-style actions - Support Navigate, Click, Type, Scrape, Screenshot, Wait actions - Add educational Hands: Whiteboard, Slideshow, Speech, Quiz ### Security Enhancements - Implement command whitelist/blacklist for shell_exec tool - Add SSRF protection with private IP blocking - Create security.toml configuration file ## Test Improvements - Fix test import paths (security-utils, setup) - Fix vi.mock hoisting issues with vi.hoisted() - Update test expectations for validateUrl and sanitizeFilename - Add getUnsupportedLocalGatewayStatus mock ## Documentation Updates - Update architecture documentation - Improve configuration reference - Add quick-start guide updates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
125
desktop/tests/e2e/playwright.tauri-cdp.config.ts
Normal file
125
desktop/tests/e2e/playwright.tauri-cdp.config.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* ZCLAW Tauri E2E 测试配置 - CDP 连接版本
|
||||
*
|
||||
* 通过 Chrome DevTools Protocol (CDP) 连接到 Tauri WebView
|
||||
* 参考: https://www.aidoczh.com/playwright/dotnet/docs/webview2.html
|
||||
*/
|
||||
|
||||
import { defineConfig, devices, chromium, Browser, BrowserContext } from '@playwright/test';
|
||||
|
||||
const TAURI_DEV_PORT = 1420;
|
||||
|
||||
/**
|
||||
* 通过 CDP 连接到运行中的 Tauri 应用
|
||||
*/
|
||||
async function connectToTauriWebView(): Promise<{ browser: Browser; context: BrowserContext }> {
|
||||
console.log('[Tauri CDP] Attempting to connect to Tauri WebView via CDP...');
|
||||
|
||||
// 启动 Chromium,连接到 Tauri WebView 的 CDP 端点
|
||||
// Tauri WebView2 默认调试端口是 9222 (Windows)
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
channel: 'chromium',
|
||||
});
|
||||
|
||||
// 尝试通过 WebView2 CDP 连接
|
||||
// Tauri 在 Windows 上使用 WebView2,可以通过 CDP 调试
|
||||
try {
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
// 连接到本地 Tauri 应用
|
||||
await page.goto(`http://localhost:${TAURI_DEV_PORT}`, {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 30000,
|
||||
});
|
||||
|
||||
console.log('[Tauri CDP] Connected to Tauri WebView');
|
||||
|
||||
return { browser, context };
|
||||
} catch (error) {
|
||||
console.error('[Tauri CDP] Failed to connect:', error);
|
||||
await browser.close();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待 Tauri 应用就绪
|
||||
*/
|
||||
async function waitForTauriReady(): Promise<void> {
|
||||
const maxWait = 60000;
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < maxWait) {
|
||||
try {
|
||||
const response = await fetch(`http://localhost:${TAURI_DEV_PORT}`, {
|
||||
method: 'HEAD',
|
||||
});
|
||||
if (response.ok) {
|
||||
console.log('[Tauri Ready] Application is ready!');
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// 还没准备好
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
}
|
||||
|
||||
throw new Error('Tauri app failed to start within timeout');
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './specs',
|
||||
|
||||
timeout: 120000,
|
||||
expect: {
|
||||
timeout: 15000,
|
||||
},
|
||||
|
||||
fullyParallel: false,
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: 0,
|
||||
|
||||
reporter: [
|
||||
['html', { outputFolder: 'test-results/tauri-cdp-report' }],
|
||||
['json', { outputFile: 'test-results/tauri-cdp-results.json' }],
|
||||
['list'],
|
||||
],
|
||||
|
||||
use: {
|
||||
baseURL: `http://localhost:${TAURI_DEV_PORT}`,
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
actionTimeout: 15000,
|
||||
navigationTimeout: 60000,
|
||||
},
|
||||
|
||||
projects: [
|
||||
{
|
||||
name: 'tauri-cdp',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
viewport: { width: 1280, height: 800 },
|
||||
launchOptions: {
|
||||
args: [
|
||||
'--disable-web-security',
|
||||
'--allow-insecure-localhost',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
webServer: {
|
||||
command: 'pnpm tauri dev',
|
||||
url: `http://localhost:${TAURI_DEV_PORT}`,
|
||||
reuseExistingServer: true,
|
||||
timeout: 180000,
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
},
|
||||
|
||||
outputDir: 'test-results/tauri-cdp-artifacts',
|
||||
});
|
||||
Reference in New Issue
Block a user