feat: Pro 买断门禁、SFTP 精简与批量多机改造

新增 entitlement/license IPC 与 Waffo 一次性结账服务骨架,挂载 AI/转发/代理/串口/广播/批量导入导出门禁;批量执行改为结果矩阵并复用连接池,SFTP 工具栏图标化并去掉已连接条,同时完善跨平台本地终端与窗口配置。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Logan.LiandCursor committed 2026-08-07 11:38:30 +08:00
1 parent 101d2164b4
commit fea6d8db04
72 files changed
+3307 -396

No files matched your search

+24 -1
View File
@@ -5,10 +5,12 @@ import TerminalWorkspace from '../../src/components/terminal/TerminalWorkspace'
import { useAiProviderStore } from '../../src/stores/aiProviderStore'
import { useSettingsStore } from '../../src/stores/settingsStore'
import { useTabStore } from '../../src/stores/tabStore'
import { unlockProForTests } from '../helpers/entitlement'
describe('AI entry points', () => {
beforeEach(() => {
vi.clearAllMocks()
unlockProForTests()
useSettingsStore.setState({ isLoaded: true })
useAiProviderStore.setState({
providers: [],
@@ -32,7 +34,7 @@ describe('AI entry points', () => {
expect(screen.getByRole('button', { name: '添加' })).toBeVisible()
})
it('keeps a prominent AI assistant control wired into every terminal workspace', () => {
it('keeps a prominent AI assistant control on SSH terminal workspaces', () => {
useTabStore.setState({
tabs: [
{
@@ -56,4 +58,25 @@ describe('AI entry points', () => {
fireEvent.click(entry)
expect(entry).toHaveAttribute('aria-label', '关闭终端 AI 助手')
})
it('hides the AI assistant control on local shell workspaces', () => {
useTabStore.setState({
tabs: [
{
id: 'local-ai-test',
title: 'Local',
type: 'terminal',
isActive: false,
isLocal: true,
localShellKind: 'zsh',
localShellPath: '/bin/zsh',
},
],
activeTabId: null,
})
render(<TerminalWorkspace tabId="local-ai-test" isActive={false} />)
expect(screen.queryByTestId('terminal-ai-button')).toBeNull()
})
})
+8
View File
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import App from '../../src/app/App'
import { useSessionStore } from '../../src/stores/sessionStore'
import { mockDesktopApi } from '../setup'
import { unlockProForTests } from '../helpers/entitlement'
describe('App foundation acceptance', () => {
afterEach(() => {
@@ -60,6 +61,13 @@ describe('App foundation acceptance', () => {
it('writes exported sessions to the selected JSON file', async () => {
vi.clearAllMocks()
unlockProForTests()
vi.mocked(mockDesktopApi.licenseGet).mockResolvedValue({
plan: 'pro',
deviceId: 'test-device',
activated: true,
features: ['*'],
})
window.opsxApi = mockDesktopApi
useSessionStore.setState({
sessions: [
@@ -7,6 +7,7 @@ import SerialConnectDialog from '../../src/components/serial/SerialConnectDialog
import { useSessionStore } from '../../src/stores/sessionStore'
import { useTabStore } from '../../src/stores/tabStore'
import { mockDesktopApi } from '../setup'
import { unlockProForTests } from '../helpers/entitlement'
const serialMocks = vi.hoisted(() => ({
listSerialPorts: vi.fn(),
@@ -19,6 +20,7 @@ vi.mock('../../src/platform/serial', () => ({
describe('Quick launcher and serial acceptance', () => {
beforeEach(() => {
vi.clearAllMocks()
unlockProForTests()
window.opsxApi = mockDesktopApi
serialMocks.listSerialPorts.mockResolvedValue([
{ path: '/dev/tty.debug-console', portType: 'Serial' },
@@ -96,12 +98,12 @@ describe('Quick launcher and serial acceptance', () => {
})
})
it('keeps the documented manual serial path when enumeration returns no devices', async () => {
it('keeps the platform default serial path when enumeration returns no devices', async () => {
serialMocks.listSerialPorts.mockResolvedValue([])
render(<SerialConnectDialog isOpen onClose={vi.fn()} onConnect={vi.fn()} />)
await waitFor(() => expect(serialMocks.listSerialPorts).toHaveBeenCalled())
expect(screen.getByLabelText('设备')).toHaveValue('/dev/tty.debug-console')
expect(screen.getByText(/\/dev\/tty\.Bluetooth-Incoming-Port/)).toBeVisible()
expect(screen.getByLabelText('设备')).toHaveValue('/dev/tty.usbserial')
expect(screen.queryByRole('button', { name: /Bluetooth-Incoming-Port/ })).toBeNull()
})
})
@@ -70,7 +70,7 @@ describe('SFTP basic transfer acceptance', () => {
})
render(<SFTPView tabId="sftp-tab" sessionId={session.id} />)
await screen.findByText('已连接')
await screen.findByRole('button', { name: '上传' })
await user.click(screen.getByRole('button', { name: '上传' }))
await waitFor(() => {
@@ -86,7 +86,7 @@ describe('SFTP basic transfer acceptance', () => {
const user = userEvent.setup()
render(<SFTPView tabId="sftp-tab" sessionId={session.id} />)
await screen.findByText('已连接')
await screen.findByRole('button', { name: '上传' })
await user.click(await screen.findByText('remote.txt'))
await user.click(screen.getByRole('button', { name: '下载' }))
@@ -115,7 +115,7 @@ describe('SFTP basic transfer acceptance', () => {
})
render(<SFTPView tabId="sftp-tab" sessionId={session.id} />)
await screen.findByText('已连接')
await screen.findByRole('button', { name: '上传' })
await user.click(screen.getByRole('button', { name: '上传' }))
expect(await screen.findByText(/Permission denied/)).toBeVisible()
@@ -127,7 +127,7 @@ describe('SFTP basic transfer acceptance', () => {
files: [{ name: 'local.txt', path: '/Users/test/local.txt', type: 'file', size: 8, modified: 1_700_000_000 }],
})
render(<SFTPView tabId="sftp-tab" sessionId={session.id} />)
await screen.findByText('已连接')
await screen.findByRole('button', { name: '上传' })
const transfer = createDataTransfer()
fireEvent.dragStart(await screen.findByText('local.txt'), { dataTransfer: transfer })
@@ -144,7 +144,7 @@ describe('SFTP basic transfer acceptance', () => {
it('downloads by dragging a remote row onto the local panel', async () => {
render(<SFTPView tabId="sftp-tab" sessionId={session.id} />)
await screen.findByText('已连接')
await screen.findByRole('button', { name: '上传' })
const transfer = createDataTransfer()
fireEvent.dragStart(await screen.findByText('remote.txt'), { dataTransfer: transfer })
@@ -6,10 +6,12 @@ import QuickConnectDialog from '../../src/components/sessions/QuickConnectDialog
import { useSessionStore } from '../../src/stores/sessionStore'
import { useTabStore } from '../../src/stores/tabStore'
import { mockDesktopApi } from '../setup'
import { unlockProForTests } from '../helpers/entitlement'
describe('Session workflow acceptance', () => {
beforeEach(() => {
vi.clearAllMocks()
unlockProForTests()
window.opsxApi = mockDesktopApi
useSessionStore.setState({ sessions: [] })
useTabStore.setState({
+24
View File
@@ -0,0 +1,24 @@
import { useEntitlementStore } from '../../src/stores/entitlementStore'
/** Enable Pro features for acceptance tests that exercise gated flows. */
export function unlockProForTests(): void {
useEntitlementStore.setState({
plan: 'pro',
deviceId: 'test-device',
expiresAt: null,
features: ['*'],
loaded: true,
wall: { open: false },
})
}
export function resetEntitlementForTests(): void {
useEntitlementStore.setState({
plan: 'free',
deviceId: 'test-device',
expiresAt: null,
features: [],
loaded: true,
wall: { open: false },
})
}
+20
View File
@@ -63,6 +63,25 @@ export const mockDesktopApi: DesktopApiContract = {
// Settings
settingsGet: vi.fn().mockResolvedValue({ success: true, value: undefined }),
settingsSet: vi.fn().mockResolvedValue({ success: true }),
licenseGet: vi.fn().mockResolvedValue({
plan: 'free',
deviceId: 'test-device',
activated: false,
features: [],
}),
licenseActivate: vi.fn().mockResolvedValue({
plan: 'pro',
deviceId: 'test-device',
activated: true,
features: ['*'],
}),
licenseClear: vi.fn().mockResolvedValue({
plan: 'free',
deviceId: 'test-device',
activated: false,
features: [],
}),
licenseDeviceId: vi.fn().mockResolvedValue('test-device'),
aiProviderSaveKey: vi.fn().mockResolvedValue({ success: true }),
aiProviderHasKey: vi.fn().mockResolvedValue(false),
aiProviderDeleteKey: vi.fn().mockResolvedValue({ success: true }),
@@ -126,6 +145,7 @@ export const mockDesktopApi: DesktopApiContract = {
onMenuExportSessions: vi.fn(),
onMenuOpenSettings: vi.fn(),
onSshLinkAvailable: vi.fn(),
onProLink: vi.fn(),
respondHostKeyPrompt: vi.fn(),
knownHostsList: vi.fn().mockResolvedValue({ success: true, entries: [] }),
knownHostsRemove: vi.fn().mockResolvedValue({ success: true }),
+53
View File
@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest'
import { connectionReuseFingerprint } from '../../src/utils/connectionFingerprint'
import type { SSHConnectionConfig } from '../../shared/types/session.types'
const base = (): SSHConnectionConfig => ({
host: 'example.com',
port: 22,
username: 'root',
authType: 'password',
password: 'secret',
})
describe('connectionReuseFingerprint', () => {
it('matches identical configs', () => {
expect(connectionReuseFingerprint(base())).toBe(connectionReuseFingerprint(base()))
})
it('differs when password presence changes', () => {
const a = base()
const b = { ...base(), password: undefined, authType: 'agent' as const }
expect(connectionReuseFingerprint(a)).not.toBe(connectionReuseFingerprint(b))
})
it('differs when private key path differs', () => {
const a = { ...base(), authType: 'key' as const, password: undefined, privateKey: '/a' }
const b = { ...base(), authType: 'key' as const, password: undefined, privateKey: '/b' }
expect(connectionReuseFingerprint(a)).not.toBe(connectionReuseFingerprint(b))
})
it('differs when proxy differs', () => {
const a = {
...base(),
proxy: { type: 'socks5' as const, host: '127.0.0.1', port: 1080 },
}
const b = {
...base(),
proxy: { type: 'http' as const, host: '127.0.0.1', port: 8080 },
}
expect(connectionReuseFingerprint(a)).not.toBe(connectionReuseFingerprint(b))
})
it('differs when jump host differs', () => {
const a = {
...base(),
jumpHost: { host: 'bastion', username: 'jump', authType: 'password' as const, password: 'x' },
}
const b = {
...base(),
jumpHost: { host: 'other', username: 'jump', authType: 'password' as const, password: 'x' },
}
expect(connectionReuseFingerprint(a)).not.toBe(connectionReuseFingerprint(b))
})
})
+54
View File
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest'
import { isWindowsLocalPath, joinLocalPath, parentPath, splitPathSegments } from '../../src/utils/localPath'
import { fallbackLocalShells, localShellEnterKey } from '../../src/utils/platformShells'
describe('localPath', () => {
it('detects windows paths', () => {
expect(isWindowsLocalPath('C:\\Users\\a')).toBe(true)
expect(isWindowsLocalPath('D:/tmp')).toBe(true)
expect(isWindowsLocalPath('/home/a')).toBe(false)
})
it('computes windows parents without collapsing to /', () => {
expect(parentPath('C:\\Users\\logan\\docs', true)).toBe('C:\\Users\\logan')
expect(parentPath('C:\\Users', true)).toBe('C:\\')
expect(parentPath('C:\\', true)).toBe('C:\\')
})
it('splits windows breadcrumbs with drive root', () => {
const segments = splitPathSegments('C:\\Users\\logan', true)
expect(segments.root).toBe('C:\\')
expect(segments.parts).toEqual(['Users', 'logan'])
expect(segments.join(['Users'])).toBe('C:\\Users')
})
it('keeps posix remote parents', () => {
expect(parentPath('/var/log', false)).toBe('/var')
expect(parentPath('/', false)).toBe('/')
})
it('joins local paths with platform separators', () => {
expect(joinLocalPath('C:\\Users', 'a.txt')).toBe('C:\\Users\\a.txt')
expect(joinLocalPath('/home/a', 'b.txt')).toBe('/home/a/b.txt')
})
})
describe('platformShells', () => {
it('returns windows shells for windows platform', () => {
const shells = fallbackLocalShells('windows')
expect(shells.some((shell) => shell.kind === 'cmd')).toBe(true)
expect(shells.some((shell) => shell.kind === 'pwsh')).toBe(true)
})
it('defaults linux to bash', () => {
const shells = fallbackLocalShells('linux')
expect(shells[0]?.kind).toBe('bash')
expect(shells[0]?.isDefault).toBe(true)
})
it('uses CRLF enter for windows shells', () => {
expect(localShellEnterKey('cmd')).toBe('\r\n')
expect(localShellEnterKey('pwsh')).toBe('\r\n')
expect(localShellEnterKey('bash')).toBe('\n')
})
})