Skip to content

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

fix(ssh): 同步失败先报真因,完整输出按需展开

Menghuan1918a9770d4e6fad
diff --git a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.test.tsx b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.test.tsx
index c2966797..a7127b3a 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.test.tsx
+++ b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.test.tsx
@@ -162,6 +162,31 @@ describe('syncPanel', () => {
})
})
+ it('keeps the failure headline cause-first and shows the raw output on demand', async () => {
+ const store = connectedStore(routeFetch({}))
+ store.store.update((state) => {
+ state.sync.results = [{
+ kind: 'plugin',
+ name: 'dsh-better-sidebar',
+ ok: false,
+ error: 'exit 1: make: *** [pty.target.mk:119] Error 127 | gyp ERR! stack Error: `make` failed with exit code: 2',
+ log: 'Progress: resolved 584\nmake: *** [pty.target.mk:119] Error 127\n[ERR_PNPM_PREPARE_PACKAGE] failed',
+ }]
+ })
+ render(<SyncPanel store={store} t={t} />)
+ await waitFor(() => expect(screen.getByTestId('sync-results')).toBeTruthy())
+ const row = screen.getByTestId('sync-result-dsh-better-sidebar')
+ expect(row.textContent).toContain('Error 127')
+ expect(row.textContent).not.toContain('Progress: resolved')
+ // 完整输出默认收起,点开才显示(长日志不糊在行内)
+ const toggle = screen.getByTestId('sync-log-toggle-dsh-better-sidebar')
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
+ expect(screen.queryByTestId('sync-log')).toBeNull()
+ fireEvent.click(toggle)
+ expect(screen.getByTestId('sync-log-toggle-dsh-better-sidebar').getAttribute('aria-expanded')).toBe('true')
+ expect(screen.getByTestId('sync-log').textContent).toContain('ERR_PNPM_PREPARE_PACKAGE')
+ })
+
it('renders a complete failure with every reason visible', async () => {
const store = connectedStore(routeFetch({}))
store.store.update((state) => {
diff --git a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx
index de9f6b43..6e95e054 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx
+++ b/packages/dsh-tauri-ssh-ui/src/client/components/sync-panel.tsx
@@ -313,6 +313,7 @@ function SyncResults({ results, applying, t, onRetry }: {
}): ReactNode {
const okCount = results.filter(item => item.ok).length
const failed = results.length - okCount
+ const [openLogOf, setOpenLogOf] = useState<string | null>(null)
return (
<div className={cls.syncResults} data-testid="sync-results">
<p className={cls.syncSummary}>
@@ -334,10 +335,25 @@ function SyncResults({ results, applying, t, onRetry }: {
{item.ok
? <span className={cls.syncOk}>{t('sync.itemOk')}</span>
: (
- <span className={cls.statusError} role="alert">
- {t('sync.itemFailed')}
- {item.error === undefined ? '' : `:${item.error}`}
- </span>
+ <>
+ <span className={cls.statusError} role="alert">
+ {t('sync.itemFailed')}
+ {item.error === undefined ? '' : `:${item.error}`}
+ </span>
+ {item.log === undefined
+ ? null
+ : (
+ <button
+ type="button"
+ className={cls.syncLogToggle}
+ aria-expanded={openLogOf === syncKeyOf(item)}
+ data-testid={`sync-log-toggle-${item.name}`}
+ onClick={() => setOpenLogOf(current => current === syncKeyOf(item) ? null : syncKeyOf(item))}
+ >
+ {openLogOf === syncKeyOf(item) ? t('sync.hideOutput') : t('sync.showOutput')}
+ </button>
+ )}
+ </>
)}
</li>
))}
@@ -349,6 +365,13 @@ function SyncResults({ results, applying, t, onRetry }: {
</Button>
)
: null}
+ {openLogOf === null
+ ? null
+ : (
+ <pre className={cls.logStream} data-testid="sync-log">
+ {results.find(item => syncKeyOf(item) === openLogOf)?.log ?? ''}
+ </pre>
+ )}
</div>
)
}
diff --git a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts b/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
index bd80a479..c7fc9a29 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
@@ -85,6 +85,8 @@ export const zh = {
'sync.retryFailed': '重试失败项({count})',
'sync.itemOk': '已同步',
'sync.itemFailed': '失败',
+ 'sync.showOutput': '查看输出',
+ 'sync.hideOutput': '收起输出',
'progress.syncing': '正在同步第 {attempt}/{total} 项…',
'progress.handshake': '正在建立 SSH 连接…',
'progress.starting': '正在启动远端实例…',
@@ -201,6 +203,8 @@ export const en = {
'sync.retryFailed': 'Retry failed items ({count})',
'sync.itemOk': 'synced',
'sync.itemFailed': 'failed',
+ 'sync.showOutput': 'Show output',
+ 'sync.hideOutput': 'Hide output',
'progress.syncing': 'Syncing item {attempt}/{total}…',
'progress.handshake': 'Connecting over SSH…',
'progress.starting': 'Starting the remote instance…',
diff --git a/packages/dsh-tauri-ssh-ui/src/client/store/index.ts b/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
index fc1580a1..d55b5002 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
@@ -248,6 +248,7 @@ export function syncApplyResultOf(value: unknown): SyncApplyResult | null {
...typeof item.root === 'string' ? { root: item.root } : {},
ok: item.ok,
...typeof item.error === 'string' ? { error: item.error } : {},
+ ...typeof item.log === 'string' ? { log: item.log } : {},
})
}
return { items: out }
diff --git a/packages/dsh-tauri-ssh-ui/src/client/styles/index.cssr.ts b/packages/dsh-tauri-ssh-ui/src/client/styles/index.cssr.ts
index 6279b6b5..f77e9c95 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/styles/index.cssr.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/styles/index.cssr.ts
@@ -717,6 +717,17 @@ export default c([
color: 'var(--dsw-alias-label-primary)',
}),
+ /* 「查看输出」开关:行内小按钮,展开后是卡片同款的滚动日志块 */
+ c('.dshp-ssh-sync-log-toggle', {
+ padding: '0',
+ border: 0,
+ background: 'transparent',
+ color: 'var(--dsw-alias-state-business-primary)',
+ fontSize: '12px',
+ lineHeight: '18px',
+ cursor: 'pointer',
+ }),
+
c('.dshp-ssh-sync-ok', {
fontSize: '12px',
lineHeight: '18px',
diff --git a/packages/dsh-tauri-ssh-ui/src/client/styles/index.ts b/packages/dsh-tauri-ssh-ui/src/client/styles/index.ts
index 798c6d4e..9b5e36c3 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/styles/index.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/styles/index.ts
@@ -94,4 +94,5 @@ export const cls = {
syncResult: 'dshp-ssh-sync-result',
syncResultName: 'dshp-ssh-sync-result-name',
syncOk: 'dshp-ssh-sync-ok',
+ syncLogToggle: 'dshp-ssh-sync-log-toggle',
} as const
diff --git a/packages/dsh-tauri-ssh-ui/src/client/types/sync.ts b/packages/dsh-tauri-ssh-ui/src/client/types/sync.ts
index 789d3a33..07bdb947 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/types/sync.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/types/sync.ts
@@ -74,7 +74,10 @@ export interface SyncItemResult {
name: string
root?: string
ok: boolean
+ /** Operator-facing failure: cause first, tail as context. */
error?: string
+ /** The remote command's own output (trimmed), shown on demand. */
+ log?: string
}
/** The `sync.apply` value. */
diff --git a/packages/dsh-tauri-ssh/src/host/service/sync.test.ts b/packages/dsh-tauri-ssh/src/host/service/sync.test.ts
index 10e83d40..25cd373d 100644
--- a/packages/dsh-tauri-ssh/src/host/service/sync.test.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/sync.test.ts
@@ -239,6 +239,69 @@ describe('syncEngine.apply', () => {
expect(deduped.items).toHaveLength(2)
})
+ it('leads the failure with the cause and keeps the whole output for display', async () => {
+ // 真机输出(ops 上 dsh-better-sidebar 的 node-pty 构建失败):真正的原因在
+ // 长长的安装日志中间,末尾反而是 pnpm/dsh 的通用指引——只取末几行会把
+ // 操作者引到错误的结论上。
+ const stdout = [
+ '... pnpm-install: Progress: resolved 584, downloaded 584, added 584, done',
+ '... pnpm-install: .../[email protected]/node_modules/node-pty install: gyp info it worked if it ends with ok',
+ '... pnpm-install: .../node-pty install: make: *** [pty.target.mk:119: Release/obj.target/pty/src/unix/pty.o] Error 127',
+ '... pnpm-install: .../node-pty install: gyp ERR! stack Error: `make` failed with exit code: 2',
+ '... pnpm-install: [ELIFECYCLE] Command failed with exit code 1.',
+ '[ERR_PNPM_PREPARE_PACKAGE] Failed to prepare git-hosted package fetched from "https://codeload.github.com/omdsh-dev/DSH-better-sidebar/tar.gz/1fcf43cc": [email protected] pnpm-install: `pnpm install`',
+ 'Exit status 1',
+ 'This error happened while installing a direct dependency of /root/.dsh/profiles/remote',
+ ].join('\n')
+ const stderr = [
+ 'dsh: pnpm failed in profile directory /root/.dsh/profiles/remote',
+ 'dsh: git-hosted plugins build on install via their prepare script, which pnpm blocks until allowed — add the exact key pnpm printed above',
+ ].join('\n')
+ const session = fakeSession(command => command.includes('printf') ? ok('/dsh\n') : { code: 1, stdout, stderr })
+ const sync = new SyncEngine({
+ profileDependencies: () => ({}),
+ scanSkills: () => [],
+ packSkills: async () => Buffer.alloc(0),
+ openSession: async () => session,
+ })
+ const result = await sync.apply(machine, [{ name: 'dsh-better-sidebar', spec: 'github:a/b' }], [], { profileName: 'remote' })
+ const item = result.items[0]!
+ expect(item.ok).toBe(false)
+ // 头一条是真正的原因(缺 make/g++ 的编译失败),且不掺末尾那句会误导人的通用指引
+ expect(item.error).toContain('gyp ERR! stack Error: `make` failed with exit code: 2')
+ expect(item.error).toContain('Error 127')
+ expect(item.error?.startsWith('exit 1: ')).toBe(true)
+ expect(item.error).not.toContain('add the exact key pnpm printed above')
+ expect(item.error).not.toContain('This error happened while installing')
+ // 完整输出随条目返回(供「查看输出」展开)
+ expect(item.log).toContain('ERR_PNPM_PREPARE_PACKAGE')
+ expect(item.log).toContain('make: ***')
+ expect(item.log?.split('\n').length).toBe(10)
+ })
+
+ it('caps the carried output and skips it on success', async () => {
+ const huge = Array.from({ length: 200 }, (_, index) => `line ${index}`).join('\n')
+ const session = fakeSession(command => command.includes('printf') ? ok('/dsh\n') : { code: 1, stdout: huge, stderr: '' })
+ const sync = new SyncEngine({
+ profileDependencies: () => ({}),
+ scanSkills: () => [],
+ packSkills: async () => Buffer.alloc(0),
+ openSession: async () => session,
+ })
+ const failed = await sync.apply(machine, [{ name: 'p', spec: 'github:a/b' }], [], { profileName: 'remote' })
+ expect(failed.items[0]?.log?.split('\n').length).toBe(60)
+ expect(failed.items[0]?.log).toContain('line 199')
+
+ const healthy = fakeSession(() => ok('/dsh\n'))
+ const fine = await new SyncEngine({
+ profileDependencies: () => ({}),
+ scanSkills: () => [],
+ packSkills: async () => Buffer.alloc(0),
+ openSession: async () => healthy,
+ }).apply(machine, [{ name: 'p', spec: 'github:a/b' }], [], { profileName: 'remote' })
+ expect(fine.items[0]?.log).toBeUndefined()
+ })
+
it('grants the build keys pnpm asked for and retries the install once', async () => {
const guidance = `allowBuilds:\n ${'p@https://example.com/p.tar.gz/abc'}: true\n`
let installs = 0
diff --git a/packages/dsh-tauri-ssh/src/host/service/sync.ts b/packages/dsh-tauri-ssh/src/host/service/sync.ts
index 127177b9..a94e4702 100644
--- a/packages/dsh-tauri-ssh/src/host/service/sync.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/sync.ts
@@ -31,6 +31,16 @@ export const REMOTE_PLUGIN_PROFILE = DEFAULT_REMOTE_PROFILE
/** How many output lines an item failure carries (the operator-facing tail). */
const FAILURE_TAIL_LINES = 5
+/** How many cause lines the headline carries: the earliest ones are the root cause. */
+const FAILURE_CAUSE_LINES = 2
+
+/** The lines a cause is picked from: every real error signature pnpm/node-gyp emit. */
+const FAILURE_CAUSE = /ERR_PNPM_|gyp ERR!|error:|Error:|Error \d|not ok|not found|No such file|Permission denied|exit code|Command failed|ELIFECYCLE/u
+
+/** The full output an item carries for on-demand display (lines, then bytes). */
+const FAILURE_LOG_LINES = 60
+const FAILURE_LOG_BYTES = 8000
+
/**
* The desktop's own bundled plugins (`dsh-tauri*`). They ride the connect-time
* bundle sync automatically, so the manual sync list must not offer them:
@@ -118,16 +128,47 @@ export function skillExtractCommand(): string {
return `mkdir -p "$HOME/.dsh/skills" && tar -xf - -C "$HOME/.dsh/skills"`
}
-/** The last few non-empty lines of a command's output, joined for an error message. */
-function tailOf(text: string): string {
- const lines = text.split('\n').map(line => line.trim()).filter(line => line !== '')
- return lines.slice(-FAILURE_TAIL_LINES).join(' | ')
+/**
+ * The lines of one command's output, trimmed, blanks dropped.
+ * @param stdout - captured stdout.
+ * @param stderr - captured stderr.
+ * @returns stdout lines first, then stderr lines.
+ */
+function outputLines(stdout: string, stderr: string): string[] {
+ return `${stdout}\n${stderr}`.split('\n').map(line => line.trim()).filter(line => line !== '')
}
-/** One operator-facing failure for a finished remote command. */
+/**
+ * One operator-facing failure for a finished remote command.
+ *
+ * The headline names the *cause* first: a multi-minute install buries the real
+ * error (`gyp ERR! stack Error: make failed…`, `ERR_PNPM_PREPARE_PACKAGE`) well
+ * above the last few lines, and the sweeping guidance pnpm/dsh print last is
+ * generic — reading only the tail tells the operator the wrong story. The tail
+ * still rides along as context, and the full output travels in the item's
+ * `log` for on-demand display.
+ * @param code - the command's exit code.
+ * @param stdout - captured stdout.
+ * @param stderr - captured stderr.
+ * @returns the operator-facing message.
+ */
function describeFailure(code: number | null, stdout: string, stderr: string): string {
- const tail = [tailOf(stdout), tailOf(stderr)].filter(part => part !== '').join(' | ')
- return `exit ${code ?? '?'}${tail === '' ? '' : `: ${tail}`}`
+ const lines = outputLines(stdout, stderr)
+ // 有原因行就只报原因(最早的几条=根因),不再掺末尾的通用指引——那句往往
+ // 与真实原因无关(真机案例:构建门禁已放行,末尾仍在讲门禁,真因是缺 g++)。
+ const causes = lines.filter(line => FAILURE_CAUSE.test(line)).slice(0, FAILURE_CAUSE_LINES)
+ const picked = causes.length > 0 ? causes : lines.slice(-FAILURE_TAIL_LINES)
+ const parts = picked.map(line => (line.length > 300 ? `${line.slice(0, 300)}…` : line))
+ return `exit ${code ?? '?'}${parts.length === 0 ? '' : `: ${parts.join(' | ')}`}`
+}
+
+/** The trimmed full output an item keeps for on-demand display (newest kept). */
+function failureLogOf(stdout: string, stderr: string): string | undefined {
+ const lines = outputLines(stdout, stderr)
+ if (lines.length === 0)
+ return undefined
+ const kept = lines.slice(-FAILURE_LOG_LINES).join('\n')
+ return kept.length > FAILURE_LOG_BYTES ? `${kept.slice(kept.length - FAILURE_LOG_BYTES)}` : kept
}
/** Engine seams — the fs/ssh touchpoints, injectable for tests. */
@@ -249,11 +290,19 @@ export class SyncEngine {
if (granted.length > 0)
result = await session.exec(command, deadline)
}
- items.push(
- result.code === 0
- ? { kind: 'plugin', name: plugin.name, ok: true }
- : { kind: 'plugin', name: plugin.name, ok: false, error: describeFailure(result.code, result.stdout, result.stderr) },
- )
+ if (result.code === 0) {
+ items.push({ kind: 'plugin', name: plugin.name, ok: true })
+ }
+ else {
+ const log = failureLogOf(result.stdout, result.stderr)
+ items.push({
+ kind: 'plugin',
+ name: plugin.name,
+ ok: false,
+ error: describeFailure(result.code, result.stdout, result.stderr),
+ ...log === undefined ? {} : { log },
+ })
+ }
progress.settled += 1
}
}
@@ -332,11 +381,19 @@ export class SyncEngine {
stdinData: tar,
...this.deps.commandTimeoutMs === undefined ? {} : { timeoutMs: this.deps.commandTimeoutMs },
})
+ const log = result.code === 0 ? undefined : failureLogOf(result.stdout, result.stderr)
for (const skill of transferable) {
items.push(
result.code === 0
? { kind: 'skill', name: skill.name, root, ok: true }
- : { kind: 'skill', name: skill.name, root, ok: false, error: describeFailure(result.code, result.stdout, result.stderr) },
+ : {
+ kind: 'skill',
+ name: skill.name,
+ root,
+ ok: false,
+ error: describeFailure(result.code, result.stdout, result.stderr),
+ ...log === undefined ? {} : { log },
+ },
)
}
progress.settled += transferable.length
diff --git a/packages/dsh-tauri-ssh/src/host/types/index.ts b/packages/dsh-tauri-ssh/src/host/types/index.ts
index 2f453779..a976fe5f 100644
--- a/packages/dsh-tauri-ssh/src/host/types/index.ts
+++ b/packages/dsh-tauri-ssh/src/host/types/index.ts
@@ -309,8 +309,17 @@ export interface SyncItemResult {
/** Skill root; plugins carry none. */
root?: SyncSkillRoot
ok: boolean
- /** Operator-facing failure description; absent on success. */
+ /**
+ * Operator-facing failure description; absent on success. It leads with the
+ * cause line(s) and keeps the tail as context — a long install log buries
+ * the real error well above the end.
+ */
error?: string
+ /**
+ * The command's own output (trimmed, newest kept) for on-demand display;
+ * absent on success and when the command printed nothing.
+ */
+ log?: string
}
/** The `sync.apply` value: every requested item, success and failure alike. */