核心修复:
- ssh-service.ts: 新增 resolvePrivateKey(),将私钥文件路径(~/.ssh/id_rsa)解析为内容后传给 ssh2,
解决 'Cannot parse privateKey: Unsupported key format' 错误
- useTerminalConnection.ts + sessionHelper.ts: 根据 authType 过滤字段,password/agent 认证不再传 privateKey
- sessionStore.ts: addSession() 现在先调用 sessionCreate() 持久化到 SQLite,解决恢复标签'无可用连接信息'问题
- database-service.ts: updateSession() 补充 private_key_path 字段持久化
- SessionDialog.tsx: 默认 username='root'、privateKey='~/.ssh/id_rsa'
UI/UX:
- 语义化主题系统(app-theme.ts),强制深色模式,全局无边框设计
- macOS 标题栏支持双击最大化(window:toggleMaximize IPC)
- macOS 菜单栏('OpsXShell' 应用菜单 + Settings Cmd+,)
- WelcomeView 4卡片布局,移除 Settings 按钮
- TabBar/TabItem 背景色统一(bg-dark-800/900),消除白色边框线
架构优化:
- SFTP 生命周期修复(useSFTP.ts useRef + autoConnectAttempted guard)
- 连接池竞态修复,支持快速多标签连接
- IPC 接口规范化,安全错误处理
- Vite 代码分割优化
质量: lint零错误 | tsc零错误 | build成功 | 49 tests pass
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
/**
|
|
* ConnectionPool Store Tests - 连接池状态管理测试
|
|
*
|
|
* 注意: 这些测试验证 store 接口存在且可用
|
|
* 实际的连接功能需要集成测试环境
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
import { useConnectionPool, useConnectionStore, getConnectionStore } from '../../src/stores/connection'
|
|
|
|
describe('ConnectionPool Store', () => {
|
|
describe('store 初始化', () => {
|
|
it('useConnectionStore hook 应该存在', () => {
|
|
expect(typeof useConnectionStore).toBe('function')
|
|
})
|
|
|
|
it('useConnectionPool hook 应该存在 (向后兼容别名)', () => {
|
|
expect(typeof useConnectionPool).toBe('function')
|
|
})
|
|
|
|
it('getConnectionStore 函数应该存在', () => {
|
|
expect(typeof getConnectionStore).toBe('function')
|
|
})
|
|
|
|
it('getConnectionStore 应该返回正确的接口', () => {
|
|
const store = getConnectionStore()
|
|
expect(store).toHaveProperty('createConnection')
|
|
expect(store).toHaveProperty('getConnection')
|
|
expect(store).toHaveProperty('releaseConnection')
|
|
expect(store).toHaveProperty('disconnectConnection')
|
|
expect(store).toHaveProperty('getStats')
|
|
})
|
|
})
|
|
|
|
describe('store 方法签名', () => {
|
|
it('createConnection 应该是异步函数', () => {
|
|
const store = getConnectionStore()
|
|
expect(store.createConnection).toBeInstanceOf(Function)
|
|
// 验证是 async function (通过返回 Promise)
|
|
const result = store.createConnection('test-tab', {
|
|
host: 'localhost',
|
|
port: 22,
|
|
username: 'test',
|
|
})
|
|
expect(result).toBeInstanceOf(Promise)
|
|
})
|
|
|
|
it('getStats 应该返回连接统计', () => {
|
|
const store = getConnectionStore()
|
|
const stats = store.getStats()
|
|
expect(stats).toHaveProperty('total')
|
|
expect(stats).toHaveProperty('connected')
|
|
expect(stats).toHaveProperty('background')
|
|
expect(stats).toHaveProperty('suspended')
|
|
})
|
|
})
|
|
|
|
describe('配置', () => {
|
|
it('应该有默认最大连接数配置', () => {
|
|
const store = getConnectionStore()
|
|
expect(store.config).toBeDefined()
|
|
expect(store.config.maxConnections).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('应该有默认后台连接配置', () => {
|
|
const store = getConnectionStore()
|
|
expect(store.config.maxBackgroundConnections).toBeGreaterThan(0)
|
|
})
|
|
})
|
|
})
|