DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(ssh): 处理评审指出的 4 处严重问题
hairyf6481b6587a34
diff --git a/packages/dsh-tauri-ssh/src/host/apply.test.ts b/packages/dsh-tauri-ssh/src/host/apply.test.tsindex 4166fce2..602a6202 100644--- a/packages/dsh-tauri-ssh/src/host/apply.test.ts+++ b/packages/dsh-tauri-ssh/src/host/apply.test.ts@@ -312,6 +312,31 @@ describe('ssh-remote plugin', () => {})})+ it('stores the remote profile name on save and clears it when the row omits it', async () => {+ const settings = scriptedSettings()+ settings.set(String(MACHINES_NAMESPACE), { machines: { a: { ...machine('a'), profileName: 'alpha' } } })+ const { service } = boot({ settings })+ await service.save('a' as never, {+ name: 'alpha',+ host: '10.0.0.1',+ port: 22,+ user: 'root',+ remotePort: 3080,+ profileName: 'beta',+ })+ // 回归守护:save 必须搬运 row.profileName,否则每次编辑都会把远端 profile+ // 名清掉、静默退回默认 `remote` profile。+ expect(service.profileViews()[0]).toMatchObject({ profileName: 'beta' })+ await service.save('a' as never, {+ name: 'alpha',+ host: '10.0.0.1',+ port: 22,+ user: 'root',+ remotePort: 3080,+ })+ expect(service.profileViews()[0]).not.toHaveProperty('profileName')+ })+it('keeps whichever stored secrets exist and rewrites only typed ones', async () => {const settings = scriptedSettings()settings.set(String(MACHINES_NAMESPACE), {diff --git a/packages/dsh-tauri-ssh/src/host/apply.ts b/packages/dsh-tauri-ssh/src/host/apply.tsindex 95d6c948..243f7ccf 100644--- a/packages/dsh-tauri-ssh/src/host/apply.ts+++ b/packages/dsh-tauri-ssh/src/host/apply.ts@@ -260,6 +260,8 @@ export class SshRemoteService implements SshApiHost {}if (row.startCommand !== undefined && row.startCommand !== '')next.startCommand = row.startCommand+ if (row.profileName !== undefined && row.profileName !== '')+ next.profileName = row.profileNameif (row.color !== undefined && row.color !== '')next.color = row.colorif (row.tintBorder === true)diff --git a/packages/dsh-tauri-ssh/src/host/routes/index.ts b/packages/dsh-tauri-ssh/src/host/routes/index.tsindex 7a30f146..415cd013 100644--- a/packages/dsh-tauri-ssh/src/host/routes/index.ts+++ b/packages/dsh-tauri-ssh/src/host/routes/index.ts@@ -60,6 +60,8 @@ export interface SshMachineListItem extends MachineView {nextRetryAt?: number/** Which credential the live (or last successful) connection used. */authMethod?: SshMachineStatus['authMethod']+ /** Live progress of the in-flight operation. */+ progress?: SshMachineStatus['progress']}/** The manager face this API needs (the plugin's service). */diff --git a/packages/dsh-tauri-ssh/src/host/service/manager.test.ts b/packages/dsh-tauri-ssh/src/host/service/manager.test.tsindex 88562198..483ed9d5 100644--- a/packages/dsh-tauri-ssh/src/host/service/manager.test.ts+++ b/packages/dsh-tauri-ssh/src/host/service/manager.test.ts@@ -290,7 +290,7 @@ function boot(overrides: Partial<{config: typeof configplanInstall: () => Promise<RemoteInstallPlan>mintCookie: (authenticatedUrl: string) => Promise<string | undefined>- syncPlugins: (session: import('./transport').SshSession, profileName: string, hooks: { onEvent?: (stage: import('../types/index').SshMachineStage, line: string) => void }) => Promise<boolean>+ syncPlugins: (session: import('./transport').SshSession, profileName: string, remotePort: number, hooks: { onEvent?: (stage: import('../types/index').SshMachineStage, line: string) => void }) => Promise<boolean>localAllowlist: () => import('./allowlist').WorkspaceAllowlist}> = {}) {const transport = new FakeTransport(overrides.sessionFactory ?? (() => new FakeSession(() => true)))diff --git a/packages/dsh-tauri-ssh/src/host/service/manager.ts b/packages/dsh-tauri-ssh/src/host/service/manager.tsindex 0265ab56..c3847983 100644--- a/packages/dsh-tauri-ssh/src/host/service/manager.ts+++ b/packages/dsh-tauri-ssh/src/host/service/manager.ts@@ -99,7 +99,7 @@ export interface SshManagerDeps {* tarball pipeline; tests stub it to stay offline). Returns whether the* remote was modified (a running instance gets restarted by the sync).*/- syncPlugins?: (session: SshSession, profileName: string, hooks: { onEvent?: (stage: SshMachineStage, line: string) => void }) => Promise<boolean>+ syncPlugins?: (session: SshSession, profileName: string, remotePort: number, hooks: { onEvent?: (stage: SshMachineStage, line: string) => void }) => Promise<boolean>}/** The sentinel rethrown when an in-flight attempt loses to a disconnect. */@@ -452,7 +452,7 @@ export class SshManager {// 上传并重启实例,随后的 ensure 按新 profile 拉起。best-effort:同步// 失败降级为原生远端 UI,连接本身不受影响。try {- await (this.deps.syncPlugins ?? syncBundledPlugins)(session, safeProfileName(profile.profileName), {+ await (this.deps.syncPlugins ?? syncBundledPlugins)(session, safeProfileName(profile.profileName), profile.remotePort, {onEvent: (stage, line) => {if (generation === state.generation)this.deps.events.append(machineId, stage, line)diff --git a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.test.ts b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.test.tsindex b0685b3f..2829e23e 100644--- a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.test.ts+++ b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.test.ts@@ -58,7 +58,7 @@ describe('plugin sync commands', () => {})it('apply command: atomic swap + hash marker + profile wiring + instance restart', () => {- const command = pluginSyncApplyCommand(tree, 'abc123', 'remote')+ const command = pluginSyncApplyCommand(tree, 'abc123', 'remote', 3080)// 原子交换:staging → 正式位expect(command).toContain('$BASE.new')expect(command).toContain('mv "$BASE.new" "$BASE"')@@ -69,11 +69,13 @@ describe('plugin sync commands', () => {expect(command).toContain('.dsh/profiles/remote/package.json')expect(command).toContain('dsh-tauri dsh-tauri-ssh')// 实例在跑则按 pidfile 重启(ensure 探测落空后按新 profile 拉起);- // pidfile 之外按安装路径精确清场,并等 3080 释放避免新实例 EADDRINUSE+ // pidfile 之外按安装路径精确清场,并等远端实例端口释放避免新实例 EADDRINUSEexpect(command).toContain('.dsh/dsh-remote.pid')expect(command).toContain('kill')expect(command).toContain('pkill -f')expect(command).toContain('/dev/tcp/127.0.0.1/3080')+ // 等待循环探测的是该机器自己的 remotePort,不是硬编码的 3080+ expect(pluginSyncApplyCommand(tree, 'abc123', 'remote', 3082)).toContain('/dev/tcp/127.0.0.1/3082')expect(command).toContain('PLUGINS_SYNCED')})diff --git a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.tsindex 950d998b..44efea6d 100644--- a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts+++ b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts@@ -177,7 +177,7 @@ export function pluginSyncMarkerCommand(): string {* restart a running instance so the ensure-launch flow relaunches it onto* the new profile.*/-export function pluginSyncApplyCommand(tree: BundledPluginsTree, hash: string, profileName: string): string {+export function pluginSyncApplyCommand(tree: BundledPluginsTree, hash: string, profileName: string, remotePort: number): string {const names = tree.pluginNames.join(' ')const profile = `.dsh/profiles/${profileName}`return [@@ -193,10 +193,10 @@ export function pluginSyncApplyCommand(tree: BundledPluginsTree, hash: string, p`[ -f "$HOME/${profile}/package.json" ] || "$HOME/${REMOTE_ROOT}/runtime/bin/node" "$HOME/${REMOTE_ROOT}/dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js" --profile ${profileName} --from-default-profile web --help >/dev/null 2>&1`,`"$HOME/${REMOTE_ROOT}/runtime/bin/node" "$BASE/node_modules/_wire.js" "$HOME/${profile}/package.json" "$BASE/node_modules" ${names}`,// 实例在跑则重启:pidfile 之外还按安装路径精确清场(pidfile 可能因上次崩溃- // 指向已死进程),并等 3080 释放后再交还 ensure 拉起,避免新实例 EADDRINUSE+ // 指向已死进程),并等远端实例端口释放后再交还 ensure 拉起,避免新实例 EADDRINUSE`[ -f "$HOME/${REMOTE_PIDFILE}" ] && kill "$(cat "$HOME/${REMOTE_PIDFILE}")" 2>/dev/null || true`,`pkill -f "$HOME/${REMOTE_ROOT}/dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js web" 2>/dev/null || true`,- 'i=0; while [ $i -lt 50 ] && (exec 3<>/dev/tcp/127.0.0.1/3080) 2>/dev/null; do i=$((i+1)); sleep 0.2; done',+ `i=0; while [ $i -lt 50 ] && (exec 3<>/dev/tcp/127.0.0.1/${remotePort}) 2>/dev/null; do i=$((i+1)); sleep 0.2; done`,'echo PLUGINS_SYNCED',].join('\n')}@@ -208,6 +208,7 @@ export function pluginSyncApplyCommand(tree: BundledPluginsTree, hash: string, pexport async function syncBundledPlugins(session: SshSession,profileName: string,+ remotePort: number,hooks: { onEvent?: (stage: SshMachineStage, line: string) => void } = {},): Promise<boolean> {const tree = findBundledPluginsTree()@@ -221,7 +222,7 @@ export async function syncBundledPlugins(return falseconst sizeMb = (tar.length / 1024 / 1024).toFixed(1)hooks.onEvent?.('install', `同步桌面捆绑插件到远端(${tree.pluginNames.length} 个, ${sizeMb} MB)`)- const applied = await session.exec(pluginSyncApplyCommand(tree, hash, profileName), { stdinData: tar })+ const applied = await session.exec(pluginSyncApplyCommand(tree, hash, profileName, remotePort), { stdinData: tar })if (applied.code !== 0 || !applied.stdout.includes('PLUGINS_SYNCED'))throw new Error(`远端插件同步失败: ${applied.stderr.trim() || `exit ${applied.code}`}`)hooks.onEvent?.('install', `桌面捆绑插件已同步,远端实例按新 profile 重启`)diff --git a/packages/dsh-tauri-ssh/src/host/service/transport.ts b/packages/dsh-tauri-ssh/src/host/service/transport.tsindex f1040533..cc83855b 100644--- a/packages/dsh-tauri-ssh/src/host/service/transport.ts+++ b/packages/dsh-tauri-ssh/src/host/service/transport.ts@@ -674,9 +674,13 @@ function pipeChannelWithCookie(const buffered: Buffer[] = []let bufferedLength = 0let injected = false+ const writeToChannel = (data: Buffer): void => {+ if (!channel.write(data))+ socket.pause()+ }socket.on('data', (chunk: Buffer) => {if (injected) {- channel.write(chunk)+ writeToChannel(chunk)return}buffered.push(chunk)@@ -686,16 +690,17 @@ function pipeChannelWithCookie(if (headEnd === -1) {if (bufferedLength > TUNNEL_HEAD_CAP) {injected = true- channel.write(whole)+ writeToChannel(whole)}return}injected = trueconst head = whole.subarray(0, headEnd).toString('latin1')const rest = whole.subarray(headEnd)- channel.write(Buffer.concat([Buffer.from(injectCookieHead(head, cookie), 'latin1'), rest]))+ writeToChannel(Buffer.concat([Buffer.from(injectCookieHead(head, cookie), 'latin1'), rest]))})socket.on('end', () => channel.end())+ channel.on('drain', () => socket.resume())channel.on('end', () => socket.end())channel.pipe(socket)}