✅ test(vscode): 更新 spawnClaude 断言以匹配绝对路径解析
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { EventEmitter } from 'node:events'
|
import { EventEmitter } from 'node:events'
|
||||||
|
import { delimiter } from 'node:path'
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
const execFile = vi.fn()
|
const execFile = vi.fn()
|
||||||
@@ -50,6 +51,12 @@ vi.mock('node:child_process', () => ({
|
|||||||
spawn,
|
spawn,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// spawnClaude 用解析出的绝对路径起进程并把 bin 目录前插 PATH(9255b55);
|
||||||
|
// 固定住解析结果,断言不再依赖本机 claude 的安装位置。
|
||||||
|
vi.mock('../../src/cc/claudeBin', () => ({
|
||||||
|
resolveClaudeBin: () => '/fake/claude-bin/claude',
|
||||||
|
}))
|
||||||
|
|
||||||
const listIssueComments = vi.fn()
|
const listIssueComments = vi.fn()
|
||||||
const postIssueComment = vi.fn()
|
const postIssueComment = vi.fn()
|
||||||
|
|
||||||
@@ -195,7 +202,7 @@ describe('spawnClaude', () => {
|
|||||||
})
|
})
|
||||||
expect(execFile).not.toHaveBeenCalled()
|
expect(execFile).not.toHaveBeenCalled()
|
||||||
expect(spawn).toHaveBeenCalledOnce()
|
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({
|
expect(spawn.mock.calls[0][2]).toMatchObject({
|
||||||
cwd: '/repo',
|
cwd: '/repo',
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
@@ -266,7 +273,7 @@ describe('spawnClaude', () => {
|
|||||||
expect(env).not.toHaveProperty('CLAUDE_CODE_ENTRYPOINT')
|
expect(env).not.toHaveProperty('CLAUDE_CODE_ENTRYPOINT')
|
||||||
expect(env).not.toHaveProperty('CLAUDE_CODE_SESSION_ID')
|
expect(env).not.toHaveProperty('CLAUDE_CODE_SESSION_ID')
|
||||||
expect(env).not.toHaveProperty('CLAUDE_CODE_SESSION')
|
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 {
|
finally {
|
||||||
for (const [key, value] of Object.entries(saved)) {
|
for (const [key, value] of Object.entries(saved)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user