Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(ssh): 远端插件同步清理悬空托管链接并等端口释放再重启

Menghuan19180cfa8381b1b4
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.ts
index 3724f858..31fad6fe 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
@@ -1,8 +1,9 @@
-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { execFileSync } from 'node:child_process'
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
-import { buildPluginsBundle, findBundledPluginsTree, pluginSyncApplyCommand, pluginSyncMarkerCommand } from './plugins-sync'
+import { buildPluginsBundle, findBundledPluginsTree, pluginSyncApplyCommand, pluginSyncMarkerCommand, WIRE_SCRIPT } from './plugins-sync'
describe('findBundledPluginsTree', () => {
it('locates the deployed tree from the repo dev layout (packages/ → src-tauri/resources/node_modules)', () => {
@@ -13,9 +14,10 @@ describe('findBundledPluginsTree', () => {
expect(tree!.root).toContain('src-tauri/resources/node_modules')
expect(tree!.pluginNames).toContain('dsh-tauri-ssh')
expect(tree!.pluginNames).toContain('dsh-tauri-ui')
- // 第三方依赖不挂 dsh 字段,不得混入插件清单
+ // 第三方依赖不挂 dsh 字段,不得混入插件清单;上游 panel 包并入 core 后为 11 个
expect(tree!.pluginNames).not.toContain('ssh2')
- expect(tree!.pluginNames.length).toBeGreaterThanOrEqual(12)
+ expect(tree!.pluginNames).not.toContain('dsh-tauri-panel')
+ expect(tree!.pluginNames.length).toBeGreaterThanOrEqual(11)
})
})
@@ -66,9 +68,44 @@ describe('plugin sync commands', () => {
expect(command).toContain('_wire.js')
expect(command).toContain('.dsh/profiles/web/package.json')
expect(command).toContain('dsh-tauri dsh-tauri-ssh')
- // 实例在跑则按 pidfile 重启(ensure 探测落空后按新 profile 拉起)
+ // 实例在跑则按 pidfile 重启(ensure 探测落空后按新 profile 拉起);
+ // pidfile 之外按安装路径精确清场,并等 3080 释放避免新实例 EADDRINUSE
expect(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')
expect(command).toContain('PLUGINS_SYNCED')
})
+
+ it('wire script prunes stale managed links absent from the current tree', async () => {
+ const staging = mkdtempSync(join(tmpdir(), 'wire-prune-'))
+ try {
+ const base = join(staging, 'plugins', 'node_modules')
+ mkdirSync(join(base, 'dsh-tauri'), { recursive: true })
+ writeFileSync(join(base, 'dsh-tauri', 'package.json'), '{"name":"dsh-tauri"}')
+ const profile = join(staging, 'profiles', 'web')
+ mkdirSync(join(profile, 'node_modules'), { recursive: true })
+ const pkg = join(profile, 'package.json')
+ writeFileSync(pkg, JSON.stringify({
+ dependencies: {
+ 'dsh-tauri': `link:${join(base, 'dsh-tauri')}`,
+ 'dsh-tauri-panel': `link:${join(base, 'dsh-tauri-panel')}`,
+ 'dshmarket': '^1.31.1',
+ },
+ dsh: { profile: { bundles: ['dsh-tauri', 'dsh-tauri-panel', 'dshmarket'] } },
+ }))
+ mkdirSync(join(profile, 'node_modules', 'dsh-tauri-panel'), { recursive: true })
+ const wire = join(staging, '_wire.js')
+ writeFileSync(wire, WIRE_SCRIPT)
+ execFileSync(process.execPath, [wire, pkg, base, 'dsh-tauri'])
+ const doc = JSON.parse(readFileSync(pkg, 'utf8'))
+ expect(Object.keys(doc.dependencies).sort()).toEqual(['dsh-tauri', 'dshmarket'])
+ expect(doc.dsh.profile.bundles).toEqual(['dsh-tauri', 'dshmarket'])
+ expect(existsSync(join(profile, 'node_modules', 'dsh-tauri-panel'))).toBe(false)
+ expect(existsSync(join(profile, 'node_modules', 'dsh-tauri'))).toBe(true)
+ }
+ finally {
+ rmSync(staging, { recursive: true, force: true })
+ }
+ })
})
diff --git a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts
index 8f0a503c..ee55eca8 100644
--- a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts
@@ -45,7 +45,7 @@ const REMOTE_PIDFILE = '.dsh/dsh-remote.pid'
const REMOTE_PROFILE = '.dsh/profiles/web'
/** The wiring helper uploaded alongside the tree (keeps shell quoting trivial). */
-const WIRE_SCRIPT = `const fs = require('fs')
+export const WIRE_SCRIPT = `const fs = require('fs')
const path = require('path')
const [profilePkg, base, ...names] = process.argv.slice(2)
const doc = JSON.parse(fs.readFileSync(profilePkg, 'utf8'))
@@ -55,6 +55,7 @@ doc.dsh.profile = doc.dsh.profile || {}
doc.dsh.profile.bundles = Array.isArray(doc.dsh.profile.bundles) ? doc.dsh.profile.bundles : []
const profileModules = path.join(path.dirname(profilePkg), 'node_modules')
fs.mkdirSync(profileModules, { recursive: true })
+const managedPrefix = path.resolve(base) + path.sep
for (const name of names) {
doc.dependencies[name] = 'link:' + path.join(base, name)
if (!doc.dsh.profile.bundles.includes(name)) doc.dsh.profile.bundles.push(name)
@@ -62,6 +63,16 @@ for (const name of names) {
fs.rmSync(link, { recursive: true, force: true })
fs.symlinkSync(path.join(base, name), link, 'dir')
}
+for (const name of Object.keys(doc.dependencies)) {
+ if (names.includes(name)) continue
+ const spec = doc.dependencies[name]
+ if (typeof spec !== 'string' || !spec.startsWith('link:')) continue
+ const target = path.resolve(path.dirname(profilePkg), spec.slice(5))
+ if (!target.startsWith(managedPrefix)) continue
+ delete doc.dependencies[name]
+ doc.dsh.profile.bundles = doc.dsh.profile.bundles.filter(b => b !== name)
+ fs.rmSync(path.join(profileModules, name), { recursive: true, force: true })
+}
fs.writeFileSync(profilePkg, JSON.stringify(doc, null, 2) + '\\n')
console.log('wired ' + names.length + ' bundled plugins')
`
@@ -179,8 +190,11 @@ export function pluginSyncApplyCommand(tree: BundledPluginsTree, hash: string):
`rm -rf "$BASE.old"`,
`echo "${hash}" > "$HOME/${SYNC_MARKER}"`,
`"$HOME/${REMOTE_ROOT}/runtime/bin/node" "$BASE/node_modules/_wire.js" "$HOME/${REMOTE_PROFILE}/package.json" "$BASE/node_modules" ${names}`,
- // 实例在跑则重启:ensure 流程探测不到就绪会按新 profile 重新拉起
+ // 实例在跑则重启:pidfile 之外还按安装路径精确清场(pidfile 可能因上次崩溃
+ // 指向已死进程),并等 3080 释放后再交还 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',
'echo PLUGINS_SYNCED',
].join('\n')
}