DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(04): 复制诊断日志 — copy-logs button on Setup error page (#244)
CoderStory3efc4917d8c9
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 173079bf..e865f6e4 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -116,6 +116,7 @@"ui.install_log": "Installation log","buttons.save": "Save","buttons.copy": "Copy",+ "buttons.copy_logs": "Copy Logs","messages.copy_success": "URL copied to clipboard","messages.log_copied": "Logs copied to clipboard","messages.copy_failed": "Failed to copy URL",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 789c1c2b..5981ba49 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -116,6 +116,7 @@"ui.install_log": "安装日志","buttons.save": "保存","buttons.copy": "复制",+ "buttons.copy_logs": "复制日志","messages.copy_success": "地址已复制到剪贴板","messages.log_copied": "日志已复制到剪贴板","messages.copy_failed": "复制地址失败",diff --git a/src/layout/components/setup.tsx b/src/layout/components/setup.tsxindex 30662195..03e6b0f0 100644--- a/src/layout/components/setup.tsx+++ b/src/layout/components/setup.tsx@@ -1,9 +1,14 @@import type { IconComponent } from './loadable'import type { SetupStatus } from '@/store/modules/harness'-import { ArrowDownToLine, CircleCheck, CircleExclamation, CircleInfo, Magnifier, Rocket } from '@gravity-ui/icons'+import { ArrowDownToLine, CircleCheck, CircleExclamation, CircleInfo, Copy, Magnifier, Rocket } from '@gravity-ui/icons'+import { invoke } from '@tauri-apps/api/core'import { useTranslation } from 'react-i18next'+import { If, Then } from 'react-if-lite'import { useStore } from 'valtio-define'+import { button } from '@/components/primitives'import { store } from '@/store'+import { writeClipboardText } from '@/utils/clipboard'+import { toast } from '@/utils/toast'import { Loadable } from './loadable'// 各阶段对应不同图标,保持与 logo 一致的黑白中性色调@@ -16,6 +21,18 @@ const STATUS_ICONS: Record<SetupStatus, IconComponent> = {error: CircleExclamation,}+async function copyLogsHandler(t: (key: string) => string) {+ try {+ const logs = await invoke<string>('read_run_logs')+ await writeClipboardText(logs)+ toast(t('messages.logs_copied'), {})+ }+ catch (err) {+ console.error('[Setup] failed to copy logs:', err)+ toast(t('messages.logs_copy_failed'), { variant: 'danger' })+ }+}+/*** 安装/更新页:基于通用 Loadable 组件渲染,* 视觉与官方 web shell 的 boot 加载页(AppRoot)一致。@@ -56,6 +73,17 @@ export function Setup() {{hint && (<p className="m-0 text-xs leading-[18px] break-all text-load-muted">{hint}</p>)}+ <If cond={error}>+ <Then>+ <button+ className={button({ tone: 'ghost', size: 'sm' })}+ onClick={() => copyLogsHandler(t)}+ >+ <Copy className="size-4" />+ {t('buttons.copy_logs')}+ </button>+ </Then>+ </If></Loadable>)}diff --git a/test/clipboard.test.ts b/test/clipboard.test.tsindex f044c63d..74ea391c 100644--- a/test/clipboard.test.ts+++ b/test/clipboard.test.ts@@ -11,6 +11,7 @@ const CLIPBOARD_CALL_SITES = ['../src/components/config-debug.tsx','../src/layout/components/navbar.tsx','../src/layout/components/preinstall-setup.tsx',+ '../src/layout/components/setup.tsx',]describe('clipboard integration', () => {diff --git a/test/setup-copy-logs.test.ts b/test/setup-copy-logs.test.tsnew file mode 100644index 00000000..538dfddd--- /dev/null+++ b/test/setup-copy-logs.test.ts@@ -0,0 +1,43 @@+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++describe('setup error page copy-logs contract (SYST-04)', () => {+ it('exposes a copyLogsHandler that fetches run logs via the Tauri command', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('copyLogsHandler')+ expect(source).toContain(`invoke<string>('read_run_logs')`)+ })++ it('routes the logs through the native clipboard helper, never navigator.clipboard', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ expect(source).not.toContain('navigator.clipboard.writeText')+ expect(source).toContain('writeClipboardText(')+ })++ it('surfaces copy success with the shared logs_copied toast', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('messages.logs_copied')+ })++ it('surfaces copy failure with the danger logs_copy_failed toast', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ const nativeWrite = source.indexOf('writeClipboardText(')+ expect(nativeWrite).toBeGreaterThan(-1)+ const failurePath = source.slice(nativeWrite, nativeWrite + 500)+ expect(failurePath).toContain('catch (err)')+ expect(failurePath).toContain('messages.logs_copy_failed')+ expect(failurePath).toContain('variant: \'danger\'')+ })++ it('renders a ghost button labelled with the copy_logs i18n key', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('button({ tone: \'ghost\'')+ expect(source).toContain('buttons.copy_logs')+ })++ it('decorates the button with the Copy icon from the project icon set', () => {+ const source = readFileSync(new URL('../src/layout/components/setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('Copy')+ expect(source).toContain('@gravity-ui/icons')+ })+})