mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 00:07:01 +08:00
Merge pull request #356 from xqliu/revert-pr-229-ut-infrastructure
Revert PR #229: Remove UT infrastructure
This commit is contained in:
54
.github/workflows/test.yml
vendored
54
.github/workflows/test.yml
vendored
@@ -1,54 +0,0 @@
|
|||||||
name: Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main, dev]
|
|
||||||
pull_request:
|
|
||||||
branches: [main, dev]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
backend-tests:
|
|
||||||
name: Backend Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true # Don't block PRs
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.23'
|
|
||||||
|
|
||||||
- name: Download dependencies
|
|
||||||
run: go mod download
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: go test -v ./...
|
|
||||||
|
|
||||||
- name: Generate coverage
|
|
||||||
run: go test -coverprofile=coverage.out ./...
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true # Don't block PRs
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
cache: 'npm'
|
|
||||||
cache-dependency-path: web/package-lock.json
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: cd web && npm ci
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: cd web && npm run test
|
|
||||||
153
Makefile
153
Makefile
@@ -1,153 +0,0 @@
|
|||||||
# NOFX Makefile for testing and development
|
|
||||||
|
|
||||||
.PHONY: help test test-backend test-frontend test-coverage clean
|
|
||||||
|
|
||||||
# Default target
|
|
||||||
help:
|
|
||||||
@echo "NOFX Testing & Development Commands"
|
|
||||||
@echo ""
|
|
||||||
@echo "Testing:"
|
|
||||||
@echo " make test - Run all tests (backend + frontend)"
|
|
||||||
@echo " make test-backend - Run backend tests only"
|
|
||||||
@echo " make test-frontend - Run frontend tests only"
|
|
||||||
@echo " make test-coverage - Generate backend coverage report"
|
|
||||||
@echo ""
|
|
||||||
@echo "Build:"
|
|
||||||
@echo " make build - Build backend binary"
|
|
||||||
@echo " make build-frontend - Build frontend"
|
|
||||||
@echo ""
|
|
||||||
@echo "Clean:"
|
|
||||||
@echo " make clean - Clean build artifacts and test cache"
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Testing
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Run all tests
|
|
||||||
test:
|
|
||||||
@echo "🧪 Running backend tests..."
|
|
||||||
go test -v ./...
|
|
||||||
@echo ""
|
|
||||||
@echo "🧪 Running frontend tests..."
|
|
||||||
cd web && npm run test
|
|
||||||
@echo "✅ All tests completed"
|
|
||||||
|
|
||||||
# Backend tests only
|
|
||||||
test-backend:
|
|
||||||
@echo "🧪 Running backend tests..."
|
|
||||||
go test -v ./...
|
|
||||||
|
|
||||||
# Frontend tests only
|
|
||||||
test-frontend:
|
|
||||||
@echo "🧪 Running frontend tests..."
|
|
||||||
cd web && npm run test
|
|
||||||
|
|
||||||
# Coverage report
|
|
||||||
test-coverage:
|
|
||||||
@echo "📊 Generating coverage..."
|
|
||||||
go test -coverprofile=coverage.out ./...
|
|
||||||
go tool cover -html=coverage.out -o coverage.html
|
|
||||||
@echo "✅ Backend coverage: coverage.html"
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Build
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Build backend binary
|
|
||||||
build:
|
|
||||||
@echo "🔨 Building backend..."
|
|
||||||
go build -o nofx
|
|
||||||
@echo "✅ Backend built: ./nofx"
|
|
||||||
|
|
||||||
# Build frontend
|
|
||||||
build-frontend:
|
|
||||||
@echo "🔨 Building frontend..."
|
|
||||||
cd web && npm run build
|
|
||||||
@echo "✅ Frontend built: ./web/dist"
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Development
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Run backend in development mode
|
|
||||||
run:
|
|
||||||
@echo "🚀 Starting backend..."
|
|
||||||
go run main.go
|
|
||||||
|
|
||||||
# Run frontend in development mode
|
|
||||||
run-frontend:
|
|
||||||
@echo "🚀 Starting frontend dev server..."
|
|
||||||
cd web && npm run dev
|
|
||||||
|
|
||||||
# Format Go code
|
|
||||||
fmt:
|
|
||||||
@echo "🎨 Formatting Go code..."
|
|
||||||
go fmt ./...
|
|
||||||
@echo "✅ Code formatted"
|
|
||||||
|
|
||||||
# Lint Go code (requires golangci-lint)
|
|
||||||
lint:
|
|
||||||
@echo "🔍 Linting Go code..."
|
|
||||||
golangci-lint run
|
|
||||||
@echo "✅ Linting completed"
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Clean
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@echo "🧹 Cleaning..."
|
|
||||||
rm -f nofx
|
|
||||||
rm -f coverage.out coverage.html
|
|
||||||
rm -rf web/dist
|
|
||||||
go clean -testcache
|
|
||||||
@echo "✅ Cleaned"
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Docker
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Build Docker images
|
|
||||||
docker-build:
|
|
||||||
@echo "🐳 Building Docker images..."
|
|
||||||
docker compose build
|
|
||||||
@echo "✅ Docker images built"
|
|
||||||
|
|
||||||
# Run Docker containers
|
|
||||||
docker-up:
|
|
||||||
@echo "🐳 Starting Docker containers..."
|
|
||||||
docker compose up -d
|
|
||||||
@echo "✅ Docker containers started"
|
|
||||||
|
|
||||||
# Stop Docker containers
|
|
||||||
docker-down:
|
|
||||||
@echo "🐳 Stopping Docker containers..."
|
|
||||||
docker compose down
|
|
||||||
@echo "✅ Docker containers stopped"
|
|
||||||
|
|
||||||
# View Docker logs
|
|
||||||
docker-logs:
|
|
||||||
docker compose logs -f
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Dependencies
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Download Go dependencies
|
|
||||||
deps:
|
|
||||||
@echo "📦 Downloading Go dependencies..."
|
|
||||||
go mod download
|
|
||||||
@echo "✅ Dependencies downloaded"
|
|
||||||
|
|
||||||
# Update Go dependencies
|
|
||||||
deps-update:
|
|
||||||
@echo "📦 Updating Go dependencies..."
|
|
||||||
go get -u ./...
|
|
||||||
go mod tidy
|
|
||||||
@echo "✅ Dependencies updated"
|
|
||||||
|
|
||||||
# Install frontend dependencies
|
|
||||||
deps-frontend:
|
|
||||||
@echo "📦 Installing frontend dependencies..."
|
|
||||||
cd web && npm install
|
|
||||||
@echo "✅ Frontend dependencies installed"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestExample(t *testing.T) {
|
|
||||||
if 1+1 != 2 {
|
|
||||||
t.Error("Math is broken")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -257,9 +257,9 @@ func (at *AutoTrader) Stop() {
|
|||||||
func (at *AutoTrader) runCycle() error {
|
func (at *AutoTrader) runCycle() error {
|
||||||
at.callCount++
|
at.callCount++
|
||||||
|
|
||||||
log.Print("\n" + strings.Repeat("=", 70))
|
log.Printf("\n" + strings.Repeat("=", 70))
|
||||||
log.Printf("⏰ %s - AI决策周期 #%d", time.Now().Format("2006-01-02 15:04:05"), at.callCount)
|
log.Printf("⏰ %s - AI决策周期 #%d", time.Now().Format("2006-01-02 15:04:05"), at.callCount)
|
||||||
log.Print(strings.Repeat("=", 70))
|
log.Printf(strings.Repeat("=", 70))
|
||||||
|
|
||||||
// 创建决策记录
|
// 创建决策记录
|
||||||
record := &logger.DecisionRecord{
|
record := &logger.DecisionRecord{
|
||||||
@@ -346,19 +346,19 @@ func (at *AutoTrader) runCycle() error {
|
|||||||
// 打印系统提示词和AI思维链(即使有错误,也要输出以便调试)
|
// 打印系统提示词和AI思维链(即使有错误,也要输出以便调试)
|
||||||
if decision != nil {
|
if decision != nil {
|
||||||
if decision.SystemPrompt != "" {
|
if decision.SystemPrompt != "" {
|
||||||
log.Print("\n" + strings.Repeat("=", 70))
|
log.Printf("\n" + strings.Repeat("=", 70))
|
||||||
log.Printf("📋 系统提示词 [模板: %s] (错误情况)", at.systemPromptTemplate)
|
log.Printf("📋 系统提示词 [模板: %s] (错误情况)", at.systemPromptTemplate)
|
||||||
log.Println(strings.Repeat("=", 70))
|
log.Println(strings.Repeat("=", 70))
|
||||||
log.Println(decision.SystemPrompt)
|
log.Println(decision.SystemPrompt)
|
||||||
log.Print(strings.Repeat("=", 70) + "\n")
|
log.Printf(strings.Repeat("=", 70) + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if decision.CoTTrace != "" {
|
if decision.CoTTrace != "" {
|
||||||
log.Print("\n" + strings.Repeat("-", 70))
|
log.Printf("\n" + strings.Repeat("-", 70))
|
||||||
log.Println("💭 AI思维链分析(错误情况):")
|
log.Println("💭 AI思维链分析(错误情况):")
|
||||||
log.Println(strings.Repeat("-", 70))
|
log.Println(strings.Repeat("-", 70))
|
||||||
log.Println(decision.CoTTrace)
|
log.Println(decision.CoTTrace)
|
||||||
log.Print(strings.Repeat("-", 70) + "\n")
|
log.Printf(strings.Repeat("-", 70) + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3280
web/package-lock.json
generated
3280
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview"
|
||||||
"test": "vitest run"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-slot": "^1.2.3",
|
"@radix-ui/react-slot": "^1.2.3",
|
||||||
@@ -23,16 +22,13 @@
|
|||||||
"zustand": "^5.0.2"
|
"zustand": "^5.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/react": "^16.1.0",
|
|
||||||
"@types/react": "^18.3.17",
|
"@types/react": "^18.3.17",
|
||||||
"@types/react-dom": "^18.3.5",
|
"@types/react-dom": "^18.3.5",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"jsdom": "^25.0.1",
|
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"vite": "^6.0.7",
|
"vite": "^6.0.7"
|
||||||
"vitest": "^2.1.8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest'
|
|
||||||
|
|
||||||
describe('Example Test', () => {
|
|
||||||
it('should pass', () => {
|
|
||||||
expect(1 + 1).toBe(2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
||||||
import { render, waitFor } from '../test/test-utils'
|
|
||||||
import { AITradersPage } from './AITradersPage'
|
|
||||||
import { api } from '../lib/api'
|
|
||||||
import type { AIModel, Exchange } from '../types'
|
|
||||||
|
|
||||||
// Mock the API module
|
|
||||||
vi.mock('../lib/api', () => ({
|
|
||||||
api: {
|
|
||||||
getTraders: vi.fn(),
|
|
||||||
getModelConfigs: vi.fn(),
|
|
||||||
getExchangeConfigs: vi.fn(),
|
|
||||||
getSupportedModels: vi.fn(),
|
|
||||||
getSupportedExchanges: vi.fn(),
|
|
||||||
getUserSignalSource: vi.fn(),
|
|
||||||
getTraderConfig: vi.fn(),
|
|
||||||
updateTrader: vi.fn(),
|
|
||||||
createTrader: vi.fn(),
|
|
||||||
deleteTrader: vi.fn(),
|
|
||||||
startTrader: vi.fn(),
|
|
||||||
stopTrader: vi.fn(),
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Mock Language Context
|
|
||||||
vi.mock('../contexts/LanguageContext', () => ({
|
|
||||||
useLanguage: () => ({ language: 'zh' }),
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Mock SWR
|
|
||||||
vi.mock('swr', () => ({
|
|
||||||
default: (key: string) => {
|
|
||||||
if (key === 'traders') {
|
|
||||||
return { data: [], mutate: vi.fn() }
|
|
||||||
}
|
|
||||||
return { data: undefined, mutate: vi.fn() }
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe('AITradersPage - Issue #227 Fix', () => {
|
|
||||||
const mockDisabledModel: AIModel = {
|
|
||||||
id: 'deepseek_chat',
|
|
||||||
name: 'DeepSeek Chat',
|
|
||||||
provider: 'deepseek',
|
|
||||||
enabled: false, // 模型未启用
|
|
||||||
apiKey: 'test-api-key',
|
|
||||||
customApiUrl: '',
|
|
||||||
customModelName: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockDisabledExchange: Exchange = {
|
|
||||||
id: 'binance',
|
|
||||||
name: 'Binance',
|
|
||||||
type: 'cex',
|
|
||||||
enabled: false, // 交易所未启用
|
|
||||||
apiKey: 'test-api-key',
|
|
||||||
secretKey: 'test-secret-key',
|
|
||||||
testnet: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockEnabledModel: AIModel = {
|
|
||||||
id: 'qwen_chat',
|
|
||||||
name: 'Qwen Chat',
|
|
||||||
provider: 'qwen',
|
|
||||||
enabled: true,
|
|
||||||
apiKey: 'test-api-key-qwen',
|
|
||||||
customApiUrl: '',
|
|
||||||
customModelName: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockEnabledExchange: Exchange = {
|
|
||||||
id: 'hyperliquid',
|
|
||||||
name: 'Hyperliquid',
|
|
||||||
type: 'dex',
|
|
||||||
enabled: true,
|
|
||||||
apiKey: 'test-private-key',
|
|
||||||
secretKey: '',
|
|
||||||
testnet: false,
|
|
||||||
hyperliquidWalletAddr: '0xtest',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks()
|
|
||||||
|
|
||||||
// Setup default mock responses
|
|
||||||
vi.mocked(api.getModelConfigs).mockResolvedValue([mockDisabledModel, mockEnabledModel])
|
|
||||||
vi.mocked(api.getExchangeConfigs).mockResolvedValue([mockDisabledExchange, mockEnabledExchange])
|
|
||||||
vi.mocked(api.getSupportedModels).mockResolvedValue([mockDisabledModel, mockEnabledModel])
|
|
||||||
vi.mocked(api.getSupportedExchanges).mockResolvedValue([mockDisabledExchange, mockEnabledExchange])
|
|
||||||
vi.mocked(api.getUserSignalSource).mockRejectedValue(new Error('Not configured'))
|
|
||||||
vi.mocked(api.getTraderConfig).mockResolvedValue({
|
|
||||||
trader_id: 'trader-001',
|
|
||||||
trader_name: 'Test Trader',
|
|
||||||
ai_model: 'deepseek_chat',
|
|
||||||
exchange_id: 'binance',
|
|
||||||
btc_eth_leverage: 5,
|
|
||||||
altcoin_leverage: 3,
|
|
||||||
trading_symbols: 'BTCUSDT,ETHUSDT',
|
|
||||||
custom_prompt: '',
|
|
||||||
override_base_prompt: false,
|
|
||||||
system_prompt_template: 'default',
|
|
||||||
is_cross_margin: true,
|
|
||||||
use_coin_pool: false,
|
|
||||||
use_oi_top: false,
|
|
||||||
initial_balance: 1000,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should allow editing initial balance for a trader with disabled model/exchange', async () => {
|
|
||||||
// This test verifies the fix for issue #227
|
|
||||||
// Previously, editing a trader with a disabled model/exchange would fail
|
|
||||||
// because the code used enabledModels/enabledExchanges for validation
|
|
||||||
// Now it uses allModels/allExchanges, allowing edits even when the config is disabled
|
|
||||||
|
|
||||||
const onTraderSelect = vi.fn()
|
|
||||||
|
|
||||||
render(<AITradersPage onTraderSelect={onTraderSelect} />)
|
|
||||||
|
|
||||||
// Wait for the component to load configs
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(api.getModelConfigs).toHaveBeenCalled()
|
|
||||||
expect(api.getExchangeConfigs).toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Verify that the fix allows finding disabled models and exchanges
|
|
||||||
// The component should have loaded both enabled and disabled configs
|
|
||||||
expect(api.getModelConfigs).toHaveBeenCalled()
|
|
||||||
expect(api.getExchangeConfigs).toHaveBeenCalled()
|
|
||||||
|
|
||||||
// The key insight of this test:
|
|
||||||
// - mockDisabledModel has enabled: false
|
|
||||||
// - mockDisabledExchange has enabled: false
|
|
||||||
// - The trader uses these disabled configs
|
|
||||||
// - Before the fix: handleSaveEditTrader would fail to find them in enabledModels/enabledExchanges
|
|
||||||
// - After the fix: handleSaveEditTrader finds them in allModels/allExchanges
|
|
||||||
|
|
||||||
// We verify the fix works by checking that both configs are loaded
|
|
||||||
const modelConfigs = await api.getModelConfigs()
|
|
||||||
const exchangeConfigs = await api.getExchangeConfigs()
|
|
||||||
|
|
||||||
expect(modelConfigs).toContainEqual(mockDisabledModel)
|
|
||||||
expect(modelConfigs).toContainEqual(mockEnabledModel)
|
|
||||||
expect(exchangeConfigs).toContainEqual(mockDisabledExchange)
|
|
||||||
expect(exchangeConfigs).toContainEqual(mockEnabledExchange)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should use allModels instead of enabledModels for edit validation', async () => {
|
|
||||||
// Direct validation that the fix is in place
|
|
||||||
// The component should be able to validate traders against all configured models
|
|
||||||
// not just enabled ones
|
|
||||||
|
|
||||||
render(<AITradersPage />)
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(api.getModelConfigs).toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
const allModels = await api.getModelConfigs()
|
|
||||||
|
|
||||||
// Verify we have both enabled and disabled models in allModels
|
|
||||||
const disabledModel = allModels.find(m => m.id === 'deepseek_chat' && !m.enabled)
|
|
||||||
const enabledModel = allModels.find(m => m.id === 'qwen_chat' && m.enabled)
|
|
||||||
|
|
||||||
expect(disabledModel).toBeDefined()
|
|
||||||
expect(enabledModel).toBeDefined()
|
|
||||||
|
|
||||||
// This ensures the fix allows editing traders with disabled configs
|
|
||||||
// because allModels contains both enabled and disabled models
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should use allExchanges instead of enabledExchanges for edit validation', async () => {
|
|
||||||
// Direct validation that the fix is in place for exchanges
|
|
||||||
// The component should be able to validate traders against all configured exchanges
|
|
||||||
// not just enabled ones
|
|
||||||
|
|
||||||
render(<AITradersPage />)
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(api.getExchangeConfigs).toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
const allExchanges = await api.getExchangeConfigs()
|
|
||||||
|
|
||||||
// Verify we have both enabled and disabled exchanges in allExchanges
|
|
||||||
const disabledExchange = allExchanges.find(e => e.id === 'binance' && !e.enabled)
|
|
||||||
const enabledExchange = allExchanges.find(e => e.id === 'hyperliquid' && e.enabled)
|
|
||||||
|
|
||||||
expect(disabledExchange).toBeDefined()
|
|
||||||
expect(enabledExchange).toBeDefined()
|
|
||||||
|
|
||||||
// This ensures the fix allows editing traders with disabled configs
|
|
||||||
// because allExchanges contains both enabled and disabled exchanges
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should still only allow creating traders with enabled configs', async () => {
|
|
||||||
// Verify that the create flow still uses enabledModels/enabledExchanges
|
|
||||||
// This ensures we don't allow creating new traders with disabled configs
|
|
||||||
|
|
||||||
render(<AITradersPage />)
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(api.getModelConfigs).toHaveBeenCalled()
|
|
||||||
expect(api.getExchangeConfigs).toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
// The create modal should only show enabled configs
|
|
||||||
// This behavior should not change with our fix
|
|
||||||
const allModels = await api.getModelConfigs()
|
|
||||||
const allExchanges = await api.getExchangeConfigs()
|
|
||||||
|
|
||||||
const enabledModelsCount = allModels.filter(m => m.enabled && m.apiKey).length
|
|
||||||
const enabledExchangesCount = allExchanges.filter(e => {
|
|
||||||
if (!e.enabled) return false
|
|
||||||
if (e.id === 'hyperliquid') {
|
|
||||||
return e.apiKey && e.hyperliquidWalletAddr
|
|
||||||
}
|
|
||||||
return e.apiKey && e.secretKey
|
|
||||||
}).length
|
|
||||||
|
|
||||||
expect(enabledModelsCount).toBe(1) // Only qwen_chat
|
|
||||||
expect(enabledExchangesCount).toBe(1) // Only hyperliquid
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -182,8 +182,8 @@ export function AITradersPage({ onTraderSelect }: AITradersPageProps) {
|
|||||||
if (!editingTrader) return;
|
if (!editingTrader) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const model = allModels?.find(m => m.id === data.ai_model_id);
|
const model = enabledModels?.find(m => m.id === data.ai_model_id);
|
||||||
const exchange = allExchanges?.find(e => e.id === data.exchange_id);
|
const exchange = enabledExchanges?.find(e => e.id === data.exchange_id);
|
||||||
|
|
||||||
if (!model) {
|
if (!model) {
|
||||||
alert(t('modelConfigNotExist', language));
|
alert(t('modelConfigNotExist', language));
|
||||||
@@ -782,8 +782,8 @@ export function AITradersPage({ onTraderSelect }: AITradersPageProps) {
|
|||||||
isOpen={showEditModal}
|
isOpen={showEditModal}
|
||||||
isEditMode={true}
|
isEditMode={true}
|
||||||
traderData={editingTrader}
|
traderData={editingTrader}
|
||||||
availableModels={allModels}
|
availableModels={enabledModels}
|
||||||
availableExchanges={allExchanges}
|
availableExchanges={enabledExchanges}
|
||||||
onSave={handleSaveEditTrader}
|
onSave={handleSaveEditTrader}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setShowEditModal(false);
|
setShowEditModal(false);
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import { ReactElement } from 'react'
|
|
||||||
import { render, RenderOptions } from '@testing-library/react'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom render function that wraps components with common providers
|
|
||||||
*/
|
|
||||||
export function renderWithProviders(
|
|
||||||
ui: ReactElement,
|
|
||||||
options?: Omit<RenderOptions, 'wrapper'>
|
|
||||||
) {
|
|
||||||
return render(ui, { ...options })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-export everything from @testing-library/react
|
|
||||||
export * from '@testing-library/react'
|
|
||||||
|
|
||||||
// Override render with our custom version
|
|
||||||
export { renderWithProviders as render }
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { defineConfig } from 'vitest/config'
|
|
||||||
import react from '@vitejs/plugin-react'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [react()],
|
|
||||||
test: {
|
|
||||||
environment: 'jsdom',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user