## 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>
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import '@testing-library/jest-dom';
|
|
import { vi } from 'vitest';
|
|
import { webcrypto } from 'node:crypto';
|
|
|
|
// Polyfill Web Crypto API for Node.js test environment
|
|
Object.defineProperty(global, 'crypto', {
|
|
value: webcrypto,
|
|
configurable: true,
|
|
});
|
|
|
|
// Mock Tauri API
|
|
vi.mock('@tauri-apps/api/core', () => ({
|
|
invoke: vi.fn(),
|
|
}));
|
|
|
|
// Mock Tauri runtime check
|
|
vi.mock('../src/lib/tauri-gateway', () => ({
|
|
isTauriRuntime: () => false,
|
|
getGatewayClient: vi.fn(),
|
|
startLocalGateway: vi.fn(),
|
|
stopLocalGateway: vi.fn(),
|
|
getLocalGatewayStatus: vi.fn(),
|
|
getLocalGatewayAuth: vi.fn(),
|
|
prepareLocalGatewayForTauri: vi.fn(),
|
|
approveLocalGatewayDevicePairing: vi.fn(),
|
|
getOpenFangProcessList: vi.fn(),
|
|
getOpenFangProcessLogs: vi.fn(),
|
|
getUnsupportedLocalGatewayStatus: vi.fn(() => ({
|
|
supported: false,
|
|
cliAvailable: false,
|
|
runtimeSource: null,
|
|
runtimePath: null,
|
|
serviceLabel: null,
|
|
serviceLoaded: false,
|
|
serviceStatus: null,
|
|
configOk: false,
|
|
port: null,
|
|
portStatus: null,
|
|
probeUrl: null,
|
|
listenerPids: [],
|
|
error: null,
|
|
raw: {},
|
|
})),
|
|
}));
|
|
|
|
// Mock localStorage with export for test access
|
|
export const localStorageMock = (() => {
|
|
let store: Record<string, string> = {};
|
|
return {
|
|
getItem: (key: string) => store[key] || null,
|
|
setItem: (key: string, value: string) => {
|
|
store[key] = value;
|
|
},
|
|
removeItem: (key: string) => {
|
|
delete store[key];
|
|
},
|
|
clear: () => {
|
|
store = {};
|
|
},
|
|
get length() {
|
|
return Object.keys(store).length;
|
|
},
|
|
key: (index: number) => {
|
|
const keys = Object.keys(store);
|
|
return keys[index] || null;
|
|
},
|
|
};
|
|
})();
|
|
|
|
Object.defineProperty(global, 'localStorage', {
|
|
value: localStorageMock,
|
|
configurable: true,
|
|
});
|
|
|
|
// Note: We intentionally do NOT mock crypto.subtle here.
|
|
// Tests that need real crypto operations (like crypto-utils) will use the real Web Crypto API.
|
|
// Tests that need to mock crypto operations should do so in their own test files.
|
|
//
|
|
// If you need to mock crypto.subtle for specific tests, use:
|
|
// vi.spyOn(crypto.subtle, 'encrypt').mockImplementation(...)
|
|
// Or restore after mocking:
|
|
// afterAll(() => vi.restoreAllMocks())
|