Archon/archon-ui-main/vite.config.ts
Wirasm 1a78a8e287
feat: TanStack Query Migration Phase 2 - Cleanup and Test Reorganization (#588)
* refactor: migrate layouts to TanStack Query and Radix UI patterns

- Created new modern layout components in src/components/layout/
- Migrated from old MainLayout/SideNavigation to new system
- Added BackendStatus component with proper separation of concerns
- Fixed horizontal scrollbar issues in project list
- Renamed old layouts folder to agent-chat for unused chat panel
- Added layout directory to Biome configuration
- Fixed all linting and TypeScript issues in new layout code
- Uses TanStack Query for backend health monitoring
- Temporarily imports old settings/credentials until full migration

* test: reorganize test infrastructure with colocated tests in subdirectories

- Move tests into dedicated tests/ subdirectories within each feature
- Create centralized test utilities in src/features/testing/
- Update all import paths to match new structure
- Configure tsconfig.prod.json to exclude test files
- Remove legacy test files from old test/ directory
- All 32 tests passing with proper provider wrapping

* fix: use error boundary wrapper for ProjectPage

- Export ProjectsViewWithBoundary from projects feature module
- Update ProjectPage to use boundary-wrapped version
- Provides proper error containment and recovery with TanStack Query integration

* cleanup: remove unused MCP client components

- Remove ToolTestingPanel, ClientCard, and MCPClients components
- These were part of an unimplemented MCP clients feature
- Clean up commented import in MCPPage
- Preparing for proper MCP feature migration to features directory

* cleanup: remove unused mcpService.ts

- Remove duplicate/unused mcpService.ts (579 lines)
- Keep mcpServerService.ts which is actively used by MCPPage and useMCPQueries
- mcpService was never imported or used anywhere in the codebase

* cleanup: remove unused mcpClientService and update deprecation comments

- Remove mcpClientService.ts (445 lines) - no longer used after removing MCP client components
- Update deprecation comments in mcpServerService to remove references to deleted service
- This completes the MCP service cleanup

* fix: correct test directory exclusion in coverage config

Update coverage exclusion from 'test/' to 'tests/' to match actual
project structure and ensure proper test file exclusion from coverage.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: fix ArchonChatPanel import path in agent-chat.mdx

Update import from deprecated layouts to agent-chat directory.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: improve backend health hook and types

- Use existing ETag infrastructure in useBackendHealth for 70% bandwidth reduction
- Honor React Query cancellation signals with proper timeout handling
- Remove duplicate HealthResponse interface, import from shared types
- Add React type import to fix potential strict TypeScript issues

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: remove .d.ts exclusion from production TypeScript config

Removing **/*.d.ts exclusion to fix import.meta.env type errors in
production builds. The exclusion was preventing src/env.d.ts from
being included, breaking ImportMetaEnv interface definitions.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: implement modern MCP feature architecture

- Add new /features/mcp with TanStack Query integration
- Components: McpClientList, McpStatusBar, McpConfigSection
- Services: mcpApi with ETag caching
- Hooks: useMcpStatus, useMcpConfig, useMcpClients, useMcpSessionInfo
- Views: McpView with error boundary wrapper
- Full TypeScript types for MCP protocol

Part of TanStack Query migration phase 2.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: complete MCP modernization and cleanup

- Remove deprecated mcpServerService.ts (237 lines)
- Remove unused useMCPQueries.ts hooks (77 lines)
- Simplify MCPPage.tsx to use new feature architecture
- Export useSmartPolling from ui/hooks for MCP feature
- Add Python MCP API routes for backend integration

This completes the MCP migration to TanStack Query with:
- ETag caching for 70% bandwidth reduction
- Smart polling with visibility awareness
- Vertical slice architecture
- Full TypeScript type safety

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: correct MCP transport mode display and complete cleanup

- Fix backend API to return correct "streamable-http" transport mode
- Update frontend to dynamically display transport type from config
- Remove unused MCP functions (startMCPServer, stopMCPServer, getMCPServerStatus)
- Clean up unused MCPServerResponse interface
- Update log messages to show accurate transport mode
- Complete aggressive MCP cleanup with 75% code reduction (617 lines removed)

Backend changes:
- python/src/server/api_routes/mcp_api.py: Fix transport and logs
- Reduced from 818 to 201 lines while preserving all functionality

Frontend changes:
- McpStatusBar: Dynamic transport display based on config
- McpView: Pass config to status bar component
- api.ts: Remove unused MCP management functions

All MCP tools tested and verified working after cleanup.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* simplify MCP API to status-only endpoints

- Remove Docker container management functionality
- Remove start/stop/restart endpoints
- Simplify to status and config endpoints only
- Container is now managed entirely via docker-compose

* feat: complete MCP feature migration to TanStack Query

- Add MCP feature with TanStack Query hooks and services
- Create useMcpQueries hook with smart polling for status/config
- Implement mcpApi service with streamable-http transport
- Add MCP page component with real-time updates
- Export MCP hooks from features/ui for global access
- Fix logging bug in mcp_api.py (invalid error kwarg)
- Update docker command to v2 syntax (docker compose)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: clean up unused CSS and unify Tron-themed scrollbars

- Remove 200+ lines of unused CSS classes (62% file size reduction)
- Delete unused: glass classes, neon-dividers, card animations, screensaver animations
- Remove unused knowledge-item-card and hide-scrollbar styles
- Remove unused flip-card and card expansion animations
- Update scrollbar-thin to match Tron theme with blue glow effects
- Add gradient and glow effects to thin scrollbars for consistency
- Keep only actively used styles: neon-grid, scrollbars, animation delays

File reduced from 11.2KB to 4.3KB with no visual regressions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: address CodeRabbit CSS review feedback

- Fix neon-grid Tailwind @apply with arbitrary values (breaking build)
- Convert hardcoded RGBA colors to HSL tokens using --blue-accent
- Add prefers-reduced-motion accessibility support
- Add Firefox dark mode scrollbar-color support
- Optimize transitions to specific properties instead of 'all'

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: properly close Docker client to prevent resource leak

- Add finally block to ensure Docker client is closed
- Prevents resource leak in get_container_status function
- Fix linting issues (whitespace and newline)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-06 13:43:53 +03:00

356 lines
14 KiB
TypeScript

/// <reference types="vitest" />
import path from "path";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import { exec } from 'child_process';
import { readFile } from 'fs/promises';
import { existsSync, mkdirSync } from 'fs';
import type { ConfigEnv, UserConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
// Load environment variables
const env = loadEnv(mode, process.cwd(), '');
// Get host and port from environment variables or use defaults
// For internal Docker communication, use the service name
// For external access, use the HOST from environment
const isDocker = process.env.DOCKER_ENV === 'true' || existsSync('/.dockerenv');
const internalHost = 'archon-server'; // Docker service name for internal communication
const externalHost = process.env.HOST || 'localhost'; // Host for external access
const host = isDocker ? internalHost : externalHost;
const port = process.env.ARCHON_SERVER_PORT || env.ARCHON_SERVER_PORT || '8181';
return {
plugins: [
react(),
// Custom plugin to add test endpoint
{
name: 'test-runner',
configureServer(server) {
// Serve coverage directory statically
server.middlewares.use(async (req, res, next) => {
if (req.url?.startsWith('/coverage/')) {
const filePath = path.join(process.cwd(), req.url);
console.log('[VITE] Serving coverage file:', filePath);
try {
const data = await readFile(filePath);
const contentType = req.url.endsWith('.json') ? 'application/json' :
req.url.endsWith('.html') ? 'text/html' : 'text/plain';
res.setHeader('Content-Type', contentType);
res.end(data);
} catch (err) {
console.log('[VITE] Coverage file not found:', filePath);
res.statusCode = 404;
res.end('Not found');
}
} else {
next();
}
});
// Test execution endpoint (basic tests)
server.middlewares.use('/api/run-tests', (req: any, res: any) => {
if (req.method !== 'POST') {
res.statusCode = 405;
res.end('Method not allowed');
return;
}
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
});
// Run vitest with proper configuration (includes JSON reporter)
const testProcess = exec('npm run test -- --run', {
cwd: process.cwd()
});
testProcess.stdout?.on('data', (data) => {
const text = data.toString();
// Split by newlines but preserve empty lines for better formatting
const lines = text.split('\n');
lines.forEach((line: string) => {
// Send all lines including empty ones for proper formatting
res.write(`data: ${JSON.stringify({ type: 'output', message: line, timestamp: new Date().toISOString() })}\n\n`);
});
// Flush the response to ensure immediate delivery
if (res.flushHeaders) {
res.flushHeaders();
}
});
testProcess.stderr?.on('data', (data) => {
const lines = data.toString().split('\n').filter((line: string) => line.trim());
lines.forEach((line: string) => {
// Strip ANSI escape codes
const cleanLine = line.replace(/\\x1b\[[0-9;]*m/g, '');
res.write(`data: ${JSON.stringify({ type: 'output', message: cleanLine, timestamp: new Date().toISOString() })}\n\n`);
});
});
testProcess.on('close', (code) => {
res.write(`data: ${JSON.stringify({
type: 'completed',
exit_code: code,
status: code === 0 ? 'completed' : 'failed',
message: code === 0 ? 'Tests completed and results generated!' : 'Tests failed',
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
testProcess.on('error', (error) => {
res.write(`data: ${JSON.stringify({
type: 'error',
message: error.message,
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
req.on('close', () => {
testProcess.kill();
});
});
// Test execution with coverage endpoint
server.middlewares.use('/api/run-tests-with-coverage', (req: any, res: any) => {
if (req.method !== 'POST') {
res.statusCode = 405;
res.end('Method not allowed');
return;
}
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
});
// Run vitest with coverage using the proper script (now includes both default and JSON reporters)
// Add CI=true to get cleaner output without HTML dumps
// Override the reporter to use verbose for better streaming output
// When running in Docker, we need to ensure the test results directory exists
const testResultsDir = path.join(process.cwd(), 'public', 'test-results');
if (!existsSync(testResultsDir)) {
mkdirSync(testResultsDir, { recursive: true });
}
const testProcess = exec('npm run test:coverage:stream', {
cwd: process.cwd(),
env: {
...process.env,
FORCE_COLOR: '1',
CI: 'true',
NODE_ENV: 'test'
} // Enable color output and CI mode for cleaner output
});
testProcess.stdout?.on('data', (data) => {
const text = data.toString();
// Split by newlines but preserve empty lines for better formatting
const lines = text.split('\n');
lines.forEach((line: string) => {
// Strip ANSI escape codes to get clean text
const cleanLine = line.replace(/\\x1b\[[0-9;]*m/g, '');
// Send all lines for verbose reporter output
res.write(`data: ${JSON.stringify({ type: 'output', message: cleanLine, timestamp: new Date().toISOString() })}\n\n`);
});
// Flush the response to ensure immediate delivery
if (res.flushHeaders) {
res.flushHeaders();
}
});
testProcess.stderr?.on('data', (data) => {
const lines = data.toString().split('\n').filter((line: string) => line.trim());
lines.forEach((line: string) => {
// Strip ANSI escape codes
const cleanLine = line.replace(/\\x1b\[[0-9;]*m/g, '');
res.write(`data: ${JSON.stringify({ type: 'output', message: cleanLine, timestamp: new Date().toISOString() })}\n\n`);
});
});
testProcess.on('close', (code) => {
res.write(`data: ${JSON.stringify({
type: 'completed',
exit_code: code,
status: code === 0 ? 'completed' : 'failed',
message: code === 0 ? 'Tests completed with coverage and results generated!' : 'Tests failed',
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
testProcess.on('error', (error) => {
res.write(`data: ${JSON.stringify({
type: 'error',
message: error.message,
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
req.on('close', () => {
testProcess.kill();
});
});
// Coverage generation endpoint
server.middlewares.use('/api/generate-coverage', (req: any, res: any) => {
if (req.method !== 'POST') {
res.statusCode = 405;
res.end('Method not allowed');
return;
}
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
});
res.write(`data: ${JSON.stringify({
type: 'status',
message: 'Starting coverage generation...',
timestamp: new Date().toISOString()
})}\n\n`);
// Run coverage generation
const coverageProcess = exec('npm run test:coverage', {
cwd: process.cwd()
});
coverageProcess.stdout?.on('data', (data) => {
const lines = data.toString().split('\n').filter((line: string) => line.trim());
lines.forEach((line: string) => {
res.write(`data: ${JSON.stringify({ type: 'output', message: line, timestamp: new Date().toISOString() })}\n\n`);
});
});
coverageProcess.stderr?.on('data', (data) => {
const lines = data.toString().split('\n').filter((line: string) => line.trim());
lines.forEach((line: string) => {
res.write(`data: ${JSON.stringify({ type: 'output', message: line, timestamp: new Date().toISOString() })}\n\n`);
});
});
coverageProcess.on('close', (code) => {
res.write(`data: ${JSON.stringify({
type: 'completed',
exit_code: code,
status: code === 0 ? 'completed' : 'failed',
message: code === 0 ? 'Coverage report generated successfully!' : 'Coverage generation failed',
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
coverageProcess.on('error', (error) => {
res.write(`data: ${JSON.stringify({
type: 'error',
message: error.message,
timestamp: new Date().toISOString()
})}\n\n`);
res.end();
});
req.on('close', () => {
coverageProcess.kill();
});
});
}
}
],
server: {
host: '0.0.0.0', // Listen on all network interfaces with explicit IP
port: parseInt(process.env.ARCHON_UI_PORT || env.ARCHON_UI_PORT || '3737'), // Use configurable port
strictPort: true, // Exit if port is in use
allowedHosts: (() => {
const defaultHosts = ['localhost', '127.0.0.1', '::1'];
const customHosts = env.VITE_ALLOWED_HOSTS?.trim()
? env.VITE_ALLOWED_HOSTS.split(',').map(h => h.trim()).filter(Boolean)
: [];
const hostFromEnv = (process.env.HOST ?? env.HOST) && (process.env.HOST ?? env.HOST) !== 'localhost'
? [process.env.HOST ?? env.HOST]
: [];
return [...new Set([...defaultHosts, ...hostFromEnv, ...customHosts])];
})(),
proxy: {
'/api': {
target: `http://${host}:${port}`,
changeOrigin: true,
secure: false,
configure: (proxy, options) => {
proxy.on('error', (err, req, res) => {
console.log('🚨 [VITE PROXY ERROR]:', err.message);
console.log('🚨 [VITE PROXY ERROR] Target:', `http://${host}:${port}`);
console.log('🚨 [VITE PROXY ERROR] Request:', req.url);
});
proxy.on('proxyReq', (proxyReq, req, res) => {
console.log('🔄 [VITE PROXY] Forwarding:', req.method, req.url, 'to', `http://${host}:${port}${req.url}`);
});
}
}
},
},
define: {
'import.meta.env.VITE_HOST': JSON.stringify(host),
'import.meta.env.VITE_PORT': JSON.stringify(port),
'import.meta.env.PROD': env.PROD === 'true',
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './tests/setup.ts',
css: true,
include: [
'src/**/*.{test,spec}.{ts,tsx}', // Tests colocated in features
'tests/**/*.{test,spec}.{ts,tsx}' // Tests in tests directory
],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
],
env: {
VITE_HOST: host,
VITE_PORT: port,
},
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'tests/',
'**/*.d.ts',
'**/*.config.*',
'**/mockData.ts',
'**/*.test.{ts,tsx}',
],
}
}
};
});