DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): swallow the child stdin error that broke the Linux CI run
hairyf6d558acc760b
diff --git a/packages/dsh-tauri-turnrewind/src/host/service/git.test.ts b/packages/dsh-tauri-turnrewind/src/host/service/git.test.tsnew file mode 100644index 00000000..8a158d27--- /dev/null+++ b/packages/dsh-tauri-turnrewind/src/host/service/git.test.ts@@ -0,0 +1,56 @@+import { execFile } from 'node:child_process'+import { mkdtemp, rm } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import { promisify } from 'node:util'+import { join } from 'pathe'+import { afterEach, describe, expect, it } from 'vitest'+import { gitInRepo } from './git'++const run = promisify(execFile)++const temporaryDirectories: string[] = []++async function tempRepo(): Promise<string> {+ const root = await mkdtemp(join(tmpdir(), 'dsh-turnrewind-git-'))+ temporaryDirectories.push(root)+ await run('git', ['-c', 'init.defaultBranch=main', 'init', '--quiet', root], { windowsHide: true })+ return root+}++afterEach(async () => {+ await Promise.all(temporaryDirectories.splice(0).map(path => rm(path, { recursive: true, force: true })))+})++describe('gitInRepo', () => {+ it('把 git 失败收敛成结果对象,而不是抛异常', async () => {+ const root = await tempRepo()+ expect((await gitInRepo(root, ['rev-parse', '--show-toplevel'])).ok).toBe(true)+ const failure = await gitInRepo(root, ['rev-parse', '--verify', '--quiet', 'refs/heads/does-not-exist'])+ expect(failure.ok).toBe(false)+ })++ it('短命命令也不会冒出未处理的 stdin 错误(Linux CI 上曾表现为 EPIPE)', async () => {+ // 回归背景:execFile 默认给 stdin 开管道,而 git 命令往往在写入前就退出;+ // 空写那次失败在 Linux 上是未处理的 'error' 事件,会以 uncaughtException 冒泡+ // (CI 里报 "Error: write EPIPE"),Windows 因管道语义不同不触发。+ const root = await tempRepo()+ const uncaught: unknown[] = []+ const onUncaught = (error: unknown): void => {+ uncaught.push(error)+ }+ process.on('uncaughtException', onUncaught)+ process.on('unhandledRejection', onUncaught)+ try {+ // 连续多次极短命令:把「子进程先退出、stdin 后写」的竞态窗口放到最大。+ for (let index = 0; index < 12; index += 1)+ expect((await gitInRepo(root, ['rev-parse', '--show-toplevel'])).ok).toBe(true)+ // 排空事件循环,让潜在的异步 stdin 错误有机会浮出来。+ await new Promise(resolve => setTimeout(resolve, 50))+ }+ finally {+ process.off('uncaughtException', onUncaught)+ process.off('unhandledRejection', onUncaught)+ }+ expect(uncaught).toEqual([])+ })+})diff --git a/packages/dsh-tauri-turnrewind/src/host/service/git.ts b/packages/dsh-tauri-turnrewind/src/host/service/git.tsindex c0c38487..3dabbd52 100644--- a/packages/dsh-tauri-turnrewind/src/host/service/git.ts+++ b/packages/dsh-tauri-turnrewind/src/host/service/git.ts@@ -17,8 +17,6 @@ import { GIT_TIMEOUT_MS } from '../constants'/** 单次 git 调用的可选项。 */export interface GitRunOptions {- /** 写入 stdin 的内容(`--stdin` 类命令)。 */- input?: string/** 追加/覆盖的环境变量。 */env?: Record<string, string>/** 墙钟超时;缺省 5 分钟。 */@@ -55,8 +53,12 @@ function execGit(cwd: string, args: string[], options: GitRunOptions): Promise<Gresolve({ ok: true, out: String(stdout ?? '') })},)- // execFile 的 stdin 是管道:不给输入时必须显式结束,否则等待 stdin 的命令会挂到超时。- child.stdin?.end(options.input ?? '')+ // execFile 默认给 stdin 开管道,而子进程往往在写入前就已退出:Linux 上那次写入会+ // 以 **未处理的 EPIPE** 冒泡(CI 稳定复现;Windows 管道语义不同未触发)。+ // 这里显式吞掉 stdin 的错误事件——真正的失败仍然由上面的回调统一上报。+ child.stdin?.on('error', () => {})+ // 本插件的 git 命令都不读 stdin(参数全部走 argv),但仍显式结束,避免子进程挂在等 stdin 上。+ child.stdin?.end()})}