Files
claude-code-haha/desktop/scripts/dev-launcher.test.ts
T
程序员阿江(Relakkes) 83b0242558 fix: resolve reproduced issue regressions and add Zed support
- Restore file-tree Add to chat and keyboard menu behavior (#1322).
- Preserve nested OpenAI cache hits beside zero-valued cache fields (#1327).
- Allow exact development renderer CORS preflights while retaining auth (#1335).
- Prevent stale transcripts from restoring explicitly cleared goals (#1339).
- Recover interrupted auto-dream attempts while preserving legacy stamps (#1349).
- Add Zed to the existing editor discovery and launch menu (#1346).

Refs #1322, #1327, #1335, #1339, #1349, #1346

Validation: local before/after reproductions, browser smoke, server 5537
and desktop 6086 tests passed; provider/chat/agent-flow/persistence checks
passed. Changed-line coverage is 98.23%. The full coverage gate remains
blocked by the unchanged IM slow-drip test; native signing/package
validation is incomplete.
2026-09-20 20:29:40 +08:00

69 lines
3.1 KiB
TypeScript

import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import { createElectronDevEnv, DEFAULT_RENDERER_URL, mergeNoProxy, resolveElectronExecutable } from './electron-dev'
// resolveElectronExecutable 依赖 node_modules/electron/dist 真实存在,
// 但 bun 默认不执行 electron 的 postinstall 下载,dist 在本机/CI 经常缺席。
// 测试用自带夹具 desktopRoot,不依赖环境安装状态。
function createDesktopRootFixture(withExecutables = true) {
const root = mkdtempSync(path.join(tmpdir(), 'cc-haha-dev-launcher-'))
if (!withExecutables) return root
const dist = path.join(root, 'node_modules', 'electron', 'dist')
mkdirSync(path.join(dist, 'Electron.app', 'Contents', 'MacOS'), { recursive: true })
writeFileSync(path.join(dist, 'electron.exe'), '')
writeFileSync(path.join(dist, 'electron'), '')
writeFileSync(path.join(dist, 'Electron.app', 'Contents', 'MacOS', 'Electron'), '')
return root
}
describe('desktop dev launcher environment', () => {
it('uses localhost and bypasses proxies for local renderer startup', () => {
const env = createElectronDevEnv({
HTTPS_PROXY: 'http://proxy.example',
NO_PROXY: 'example.com',
})
expect(env.ELECTRON_RENDERER_URL).toBe(DEFAULT_RENDERER_URL)
expect(env.CC_HAHA_TRUSTED_RENDERER_ORIGIN).toBe(DEFAULT_RENDERER_URL)
expect(env.NO_PROXY).toBe('example.com,localhost,127.0.0.1,::1')
expect(env.no_proxy).toBe(env.NO_PROXY)
})
it('preserves explicit renderer URL while adding missing local no_proxy entries', () => {
const env = createElectronDevEnv({
ELECTRON_RENDERER_URL: 'http://localhost:1777',
no_proxy: 'localhost',
})
expect(env.ELECTRON_RENDERER_URL).toBe('http://localhost:1777')
expect(env.NO_PROXY).toBe('localhost,127.0.0.1,::1')
expect(env.no_proxy).toBe(env.NO_PROXY)
})
it('derives the exact trusted origin from the validated renderer URL', () => {
const env = createElectronDevEnv({
ELECTRON_RENDERER_URL: ' http://localhost:1777/app?dev=1 ',
CC_HAHA_TRUSTED_RENDERER_ORIGIN: 'https://untrusted.example',
})
expect(env.CC_HAHA_TRUSTED_RENDERER_ORIGIN).toBe('http://localhost:1777')
expect(() => createElectronDevEnv({ ELECTRON_RENDERER_URL: 'https://untrusted.example' })).toThrow('Refusing non-local')
})
it('deduplicates no_proxy entries', () => {
expect(mergeNoProxy('localhost,127.0.0.1')).toBe('localhost,127.0.0.1,::1')
})
it.each([
['win32', /electron\.exe$/],
['darwin', /Electron\.app[\\/]Contents[\\/]MacOS[\\/]Electron$/],
['linux', /dist[\\/]electron$/],
] as const)('resolves the %s Electron executable directly instead of shelling through bunx', (platform, pattern) => {
expect(resolveElectronExecutable(createDesktopRootFixture(), platform)).toMatch(pattern)
})
it('throws an actionable error when the Electron executable is missing', () => {
expect(() => resolveElectronExecutable(createDesktopRootFixture(false), 'linux')).toThrow(/Electron executable not found/)
})
})