From c20bd863706c61079bb914a30d5b476655d5446a Mon Sep 17 00:00:00 2001 From: cruldra Date: Tue, 18 Aug 2026 23:57:21 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(vscode):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20spawnClaude=20=E6=96=AD=E8=A8=80=E4=BB=A5=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vscode/test/gitea/stateJson.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vscode/test/gitea/stateJson.test.ts b/vscode/test/gitea/stateJson.test.ts index 63074c9..7a2b806 100644 --- a/vscode/test/gitea/stateJson.test.ts +++ b/vscode/test/gitea/stateJson.test.ts @@ -1,4 +1,5 @@ import { EventEmitter } from 'node:events' +import { delimiter } from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' const execFile = vi.fn() @@ -50,6 +51,12 @@ vi.mock('node:child_process', () => ({ spawn, })) +// spawnClaude 用解析出的绝对路径起进程并把 bin 目录前插 PATH(9255b55); +// 固定住解析结果,断言不再依赖本机 claude 的安装位置。 +vi.mock('../../src/cc/claudeBin', () => ({ + resolveClaudeBin: () => '/fake/claude-bin/claude', +})) + const listIssueComments = vi.fn() const postIssueComment = vi.fn() @@ -195,7 +202,7 @@ describe('spawnClaude', () => { }) expect(execFile).not.toHaveBeenCalled() expect(spawn).toHaveBeenCalledOnce() - expect(spawn.mock.calls[0][0]).toBe('claude') + expect(spawn.mock.calls[0][0]).toBe('/fake/claude-bin/claude') expect(spawn.mock.calls[0][2]).toMatchObject({ cwd: '/repo', stdio: ['ignore', 'pipe', 'pipe'], @@ -266,7 +273,7 @@ describe('spawnClaude', () => { expect(env).not.toHaveProperty('CLAUDE_CODE_ENTRYPOINT') expect(env).not.toHaveProperty('CLAUDE_CODE_SESSION_ID') expect(env).not.toHaveProperty('CLAUDE_CODE_SESSION') - expect(env.PATH).toBe(process.env.PATH) + expect(env.PATH).toBe(`/fake/claude-bin${delimiter}${process.env.PATH}`) } finally { for (const [key, value] of Object.entries(saved)) {