chore: 保存工作副本——客户端授权新契约(双端点/验签/令牌/周检)与桌面会话可靠性改进
This commit is contained in:
1 parent
f71eef0eba
commit
ae6093c9b3
163 files changed
+4911
-2494
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
BUG_REPORT_ISSUE_URL,
|
||||
buildBugReportUrl,
|
||||
formatRuntimeSystem,
|
||||
githubBugPlatform,
|
||||
} from '../../src/utils/bugReport'
|
||||
|
||||
describe('bugReport', () => {
|
||||
it('maps rust OS names onto the GitHub form dropdown', () => {
|
||||
expect(githubBugPlatform('macos')).toBe('macOS')
|
||||
expect(githubBugPlatform('windows')).toBe('Windows')
|
||||
expect(githubBugPlatform('linux')).toBe('Linux')
|
||||
expect(githubBugPlatform('freebsd')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('formats the About system line for people, not rust consts', () => {
|
||||
expect(formatRuntimeSystem('macos', 'aarch64')).toBe('macOS · aarch64')
|
||||
expect(formatRuntimeSystem('windows', 'x86_64')).toBe('Windows · x86_64')
|
||||
})
|
||||
|
||||
it('pre-fills the issue form the way Settings → About should', () => {
|
||||
const url = buildBugReportUrl({
|
||||
appVersion: '2.1.1',
|
||||
os: 'macos',
|
||||
arch: 'aarch64',
|
||||
logPath: '/tmp/opsxshell.log',
|
||||
userAgent: 'Mozilla/5.0 Test',
|
||||
})
|
||||
|
||||
const parsed = new URL(url)
|
||||
expect(`${parsed.origin}${parsed.pathname}`).toBe(BUG_REPORT_ISSUE_URL)
|
||||
expect(parsed.searchParams.get('template')).toBe('bug_report.yml')
|
||||
expect(parsed.searchParams.get('title')).toBe('[Bug] ')
|
||||
expect(parsed.searchParams.get('platform')).toBe('macOS')
|
||||
expect(parsed.searchParams.get('version')).toBe('2.1.1')
|
||||
expect(parsed.searchParams.get('install_source')).toBeNull()
|
||||
expect(parsed.searchParams.get('logs')).toContain('Reported from OpsXShell Settings (opsxshell 2.1.1).')
|
||||
expect(parsed.searchParams.get('logs')).toContain('OS: macos aarch64')
|
||||
expect(parsed.searchParams.get('logs')).toContain('Log file: /tmp/opsxshell.log')
|
||||
expect(parsed.searchParams.get('logs')).not.toContain('Tauri')
|
||||
expect(parsed.searchParams.get('logs')).not.toContain('libssh2')
|
||||
expect(parsed.searchParams.get('logs')).not.toContain('password')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { desktopCanvasDisplaySize, resolutionFromPane } from '../../src/utils/desktopResolution'
|
||||
|
||||
describe('desktopCanvasDisplaySize', () => {
|
||||
it('lets RDP fill a taller pane instead of letterboxing 1280×800', () => {
|
||||
expect(desktopCanvasDisplaySize('rdp', 1100, 980, 1280, 800)).toEqual({
|
||||
width: 1100,
|
||||
height: 980,
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps VNC aspect ratio so the framebuffer is not stretched', () => {
|
||||
expect(desktopCanvasDisplaySize('vnc', 1100, 980, 1280, 800)).toEqual({
|
||||
width: 1100,
|
||||
height: 687,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolutionFromPane', () => {
|
||||
it('uses the pane when it is large enough for a desktop session', () => {
|
||||
expect(resolutionFromPane(1420, 900, { width: 1280, height: 800 })).toEqual({
|
||||
width: 1420,
|
||||
height: 900,
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back when the pane is still collapsing or hidden', () => {
|
||||
expect(resolutionFromPane(0, 0, { width: 1280, height: 800 })).toEqual({
|
||||
width: 1280,
|
||||
height: 800,
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
classifyDisconnectReason,
|
||||
reconnectDelayMs,
|
||||
shouldAutoReconnect,
|
||||
shouldForgetNativeConnection,
|
||||
} from '../../src/utils/disconnectReason'
|
||||
|
||||
describe('classifyDisconnectReason', () => {
|
||||
it('treats keepalive failure as a link drop that should reconnect', () => {
|
||||
expect(classifyDisconnectReason('keepalive failed')).toBe('keepalive')
|
||||
expect(shouldAutoReconnect('keepalive')).toBe(true)
|
||||
})
|
||||
|
||||
it('does not treat the legacy native default as a user click', () => {
|
||||
expect(classifyDisconnectReason('closed by user')).toBe('unexpected')
|
||||
expect(classifyDisconnectReason('connection closed')).toBe('unexpected')
|
||||
expect(shouldAutoReconnect('unexpected')).toBe(true)
|
||||
})
|
||||
|
||||
it('skips auto-reconnect for local policy and teardown', () => {
|
||||
expect(classifyDisconnectReason('idle suspend')).toBe('idle-suspend')
|
||||
expect(shouldAutoReconnect('idle-suspend')).toBe(false)
|
||||
expect(shouldForgetNativeConnection('idle-suspend')).toBe(false)
|
||||
|
||||
expect(classifyDisconnectReason('manual')).toBe('user')
|
||||
expect(classifyDisconnectReason('no refs')).toBe('user')
|
||||
expect(classifyDisconnectReason('auto reconnect cleanup')).toBe('cleanup')
|
||||
expect(shouldAutoReconnect('user')).toBe(false)
|
||||
expect(shouldAutoReconnect('cleanup')).toBe(false)
|
||||
})
|
||||
|
||||
it('backs off reconnect delay', () => {
|
||||
expect(reconnectDelayMs(1, 1000)).toBe(1000)
|
||||
expect(reconnectDelayMs(2, 1000)).toBe(1600)
|
||||
expect(reconnectDelayMs(20, 1000, 5000)).toBe(5000)
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,9 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
panesAfterConnectionStateChange,
|
||||
resolveTerminalInputTargets,
|
||||
shouldBroadcastTerminalInput,
|
||||
shouldCollapseTerminalSplitForOverlay,
|
||||
} from '../../src/utils/terminalPanes'
|
||||
|
||||
const panes = [
|
||||
@@ -16,10 +18,7 @@ describe('terminal pane input routing', () => {
|
||||
})
|
||||
|
||||
it('routes broadcast input to every ready shell in pane order', () => {
|
||||
expect(resolveTerminalInputTargets(panes, 'left', true)).toEqual([
|
||||
'shell-1',
|
||||
'shell-3',
|
||||
])
|
||||
expect(resolveTerminalInputTargets(panes, 'left', true)).toEqual(['shell-1', 'shell-3'])
|
||||
})
|
||||
|
||||
it('does not write when the source pane has no ready shell', () => {
|
||||
@@ -34,3 +33,48 @@ describe('terminal pane input routing', () => {
|
||||
expect(shouldBroadcastTerminalInput(false, false, 'ssh-connection')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('panesAfterConnectionStateChange', () => {
|
||||
const split = [
|
||||
{ id: 'pane-a', shellId: 'shell-old', closed: { reason: 'stale' } },
|
||||
{ id: 'pane-b', shellId: 'shell-2' },
|
||||
{ id: 'pane-c', shellId: 'shell-3' },
|
||||
]
|
||||
|
||||
it('clears every split shell when the pooled session drops', () => {
|
||||
const next = panesAfterConnectionStateChange(split, 'reconnecting', 'shell-new')
|
||||
expect(next.map((pane) => pane.shellId)).toEqual([null, null, null])
|
||||
expect(next.every((pane) => pane.closed == null)).toBe(true)
|
||||
expect(next.map((pane) => pane.id)).toEqual(['pane-a', 'pane-b', 'pane-c'])
|
||||
})
|
||||
|
||||
it('rebinds the primary pane to the new shell after reconnect', () => {
|
||||
const cleared = panesAfterConnectionStateChange(split, 'disconnected', null)
|
||||
const next = panesAfterConnectionStateChange(cleared, 'connected', 'shell-new')
|
||||
expect(next[0].shellId).toBe('shell-new')
|
||||
expect(next[1].shellId).toBeNull()
|
||||
expect(next[2].shellId).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps the split layout in memory while collapsing the overlay visually', () => {
|
||||
expect(
|
||||
shouldCollapseTerminalSplitForOverlay({
|
||||
connectionState: 'disconnected',
|
||||
needsReconnect: true,
|
||||
showSuspendedOverlay: false,
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
shouldCollapseTerminalSplitForOverlay({
|
||||
connectionState: 'connected',
|
||||
needsReconnect: false,
|
||||
showSuspendedOverlay: false,
|
||||
})
|
||||
).toBe(false)
|
||||
expect(panesAfterConnectionStateChange(split, 'disconnected', null).map((pane) => pane.id)).toEqual([
|
||||
'pane-a',
|
||||
'pane-b',
|
||||
'pane-c',
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user