DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(shell): 连接进度弹窗可取消连接——中止引擎在飞尝试
Menghuan19184aee9ba2bef0
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 6a5eca69..646329b6 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -382,6 +382,7 @@"remote.connect.working": "Connecting in progress; you may close this dialog and it continues in background.","remote.connect.failed_title": "Connection failed","remote.connect.retry": "Retry",+ "remote.connect.cancel": "Cancel","remote.form.host": "Host","remote.form.name": "Name","remote.form.id": "ID",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex ad613fa2..9805afc8 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -382,6 +382,7 @@"remote.connect.working": "连接进行中,可关闭此窗口,连接会在后台继续。","remote.connect.failed_title": "连接失败","remote.connect.retry": "重试",+ "remote.connect.cancel": "取消连接","remote.form.host": "主机","remote.form.name": "名称","remote.form.id": "ID",diff --git a/src/layout/components/connect-dialog.test.tsx b/src/layout/components/connect-dialog.test.tsxindex 6478a18b..0e7a698f 100644--- a/src/layout/components/connect-dialog.test.tsx+++ b/src/layout/components/connect-dialog.test.tsx@@ -62,6 +62,28 @@ describe('connectDialog 连接进度弹窗', () => {await waitFor(() => expect(connectSpy).toHaveBeenCalledWith('m1'))})+ it('取消连接(进行中):中止引擎尝试并关闭弹窗,无失败定格', async () => {+ const disconnectSpy = vi.fn(async () => undefined)+ bindSshApiForTests({+ listMachines: vi.fn(async () => []),+ connect: vi.fn(async () => ({ tunnelBaseUrl: 'http://127.0.0.1:1' })),+ disconnect: disconnectSpy,+ })+ remote.machines = [{ id: 'm1', name: 'alpha', state: 'connecting' }]+ remote.pendingId = 'm1'+ remote.connectTrail = ['handshake']+ remote.connectLog = ['[handshake] ssh ok']+ render(<ConnectDialog />)+ await waitFor(() => expect(screen.getByRole('dialog')).toBeTruthy())+ fireEvent.click(screen.getByTestId('connect-cancel'))+ // 取消:断开下发、挂起与跟踪清空、弹窗关闭,且无失败定格+ await waitFor(() => expect(disconnectSpy).toHaveBeenCalledWith('m1'))+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())+ expect(remote.pendingId).toBeNull()+ expect(remote.connectFailed).toBeNull()+ expect(remote.connectLog).toEqual([])+ })+it('关闭(进行中):弹窗关闭、跟踪态清理,pending 语义不撤销', async () => {remote.machines = [{ id: 'm1', name: 'alpha', state: 'connecting' }]remote.pendingId = 'm1'diff --git a/src/layout/components/connect-dialog.tsx b/src/layout/components/connect-dialog.tsxindex 08903053..6213cf1e 100644--- a/src/layout/components/connect-dialog.tsx+++ b/src/layout/components/connect-dialog.tsx@@ -80,16 +80,29 @@ export function ConnectDialog() {</Description></If></Modal.Body>- <If cond={failed}>- <Modal.Footer>+ <Modal.Footer>+ <If cond={failed}><Button className="rounded-md" variant="tertiary" onPress={() => store.remote.dismissConnect()}>{t('buttons.close')}</Button><Button className="rounded-md" variant="primary" onPress={handleRetry}>{t('remote.connect.retry')}</Button>- </Modal.Footer>- </If>+ </If>+ <If cond={!failed}>+ <Button className="rounded-md" variant="tertiary" onPress={() => store.remote.dismissConnect()}>+ {t('buttons.close')}+ </Button>+ <Button+ className="rounded-md"+ variant="secondary"+ data-testid="connect-cancel"+ onPress={() => pendingId !== null && store.remote.cancelConnect(pendingId)}+ >+ {t('remote.connect.cancel')}+ </Button>+ </If>+ </Modal.Footer></Modal.Dialog></Modal.Container></Modal.Backdrop>diff --git a/src/store/modules/remote/store.test.ts b/src/store/modules/remote/store.test.tsindex 9c1f824c..dea8a134 100644--- a/src/store/modules/remote/store.test.ts+++ b/src/store/modules/remote/store.test.ts@@ -263,4 +263,32 @@ describe('remote store 切换语义', () => {expect(remote.connectFailed).toBeNull()expect(remote.connectLog).toEqual([])})++ describe('cancelConnect(取消连接)', () => {+ it('取消进行中的连接:在飞 connect 以取消错误落定时静默,不定格失败', async () => {+ let releaseConnect: (err: Error) => void = () => {}+ const engine = bindEngine({+ list: [[machineOf({ id: 'm1', state: 'disconnected' })]],+ connect: vi.fn(() => new Promise<{ tunnelBaseUrl: string }>((_resolve, reject) => {+ releaseConnect = reject+ })),+ })+ const disconnectSpy = vi.fn(async () => undefined)+ bindSshApiForTests({ listMachines: engine.listMachines, connect: engine.connect, disconnect: disconnectSpy })++ await remote.refresh()+ remote.switchTo('m1')+ expect(engine.connect).toHaveBeenCalledWith('m1')+ expect(remote.pendingId).toBe('m1')++ remote.cancelConnect('m1')+ expect(remote.pendingId).toBeNull()+ await vi.waitFor(() => expect(disconnectSpy).toHaveBeenCalledWith('m1'))++ // 引擎侧在飞 connect 以 "cancelled by disconnect" 拒绝:静默收场(不定格失败)+ releaseConnect(new Error('connect failed: connection cancelled by disconnect'))+ await vi.waitFor(() => expect(disconnectSpy).toHaveBeenCalledTimes(1))+ expect(remote.connectFailed).toBeNull()+ })+ })})diff --git a/src/store/modules/remote/store.ts b/src/store/modules/remote/store.tsindex a629e23c..706c4db1 100644--- a/src/store/modules/remote/store.ts+++ b/src/store/modules/remote/store.ts@@ -23,6 +23,9 @@ const POLL_INTERVAL_MS = 2000/** machine.events 增量游标(模块级,不属于 UI 状态)。 */let eventSeq = 0+/** 连接尝试代次:取消/新尝试作废旧 connectAndSwitch 的落定(成功与失败都静默)。 */+let connectEpoch = 0+/** 引擎/网络错误的可读摘要(与 ssh-ui 的 messageOf 同语义)。 */function messageOf(error: unknown): string {return error instanceof Error ? error.message : String(error)@@ -152,6 +155,23 @@ export const remote = defineStore({this.connectDismissed = true},+ /**+ * 取消进行中的连接:抬代次(在飞的 connectAndSwitch 落定静默)+ 中止+ * 引擎侧尝试(manager 的 disconnect 会取消在飞 connect)。弹窗随+ * pendingId 清空关闭;无失败定格。+ */+ cancelConnect(machineId: string) {+ if (this.pendingId !== machineId)+ return+ connectEpoch += 1+ this.pendingId = null+ this.dismissConnect()+ this.connectDismissed = false+ void api.disconnect(machineId)+ .catch(err => console.warn('[remote] cancel disconnect failed:', err))+ .finally(() => void this.refresh())+ },+/*** 切换视图:已连接直接切换;进行中(连接/重连)挂起等待;否则发起* 连接(阻塞到隧道就绪,见 S1 契约——不会指向空端口)。@@ -181,6 +201,7 @@ export const remote = defineStore({/** 开始跟踪一台机器的连接:复位日志/阶段/游标并挂起。 */beginTracking(machineId: string) {+ connectEpoch += 1this.pendingId = machineIdthis.connectFailed = nullthis.connectDismissed = false@@ -191,8 +212,12 @@ export const remote = defineStore({/** 连接一台机器并在就绪后切换;失败定格原因(进度弹窗呈现重试入口)。 */async connectAndSwitch(machineId: string) {+ const epoch = connectEpochtry {const link = await api.connect(machineId)+ // 已被取消或被新尝试取代:静默(不动 activeId/失败定格)+ if (epoch !== connectEpoch)+ returnawait this.refresh()const machine = this.machines.find(item => item.id === machineId)if (machine !== undefined && machine.state === 'connected') {@@ -205,6 +230,9 @@ export const remote = defineStore({}}catch (err) {+ // 用户取消(或新尝试取代):引擎报 "cancelled by disconnect",不定格失败+ if (epoch !== connectEpoch)+ returnconsole.warn('[remote] connect failed:', err)this.pendingId = nullthis.connectFailed = { id: machineId, error: messageOf(err) }@@ -259,4 +287,5 @@ export function disposeRemoteForTests(): void {remote.connectFailed = nullremote.connectDismissed = falseeventSeq = 0+ connectEpoch = 0}