This commit is contained in:
2026-06-16 06:18:42 +02:00
parent 3f5078841d
commit 66248c4736
39 changed files with 6699 additions and 94 deletions

54
test/config.test.ts Normal file
View File

@@ -0,0 +1,54 @@
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { DEFAULTS, getConfig, getThemeCss, resolveConfig } from '../src/main/config'
let dir = ''
afterEach(async () => { if (dir) await rm(dir, { recursive: true, force: true }) })
describe('resolveConfig', () => {
it('creates config.default.json + theme.css and yields defaults for a fresh project', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-cfg-'))
await resolveConfig(dir)
const def = JSON.parse(await readFile(join(dir, '.helder/config.default.json'), 'utf8'))
expect(def).toEqual(DEFAULTS)
const theme = await readFile(join(dir, '.helder/theme.css'), 'utf8')
expect(theme).toContain('--code-font')
expect(getConfig().ai.command).toBe('claude')
expect(getThemeCss()).toContain('Helder theme')
})
it('deep-merges a sparse config.json over defaults', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-cfg-'))
await resolveConfig(dir)
await writeFile(join(dir, '.helder/config.json'),
JSON.stringify({ ai: { command: 'claude --model opus' }, editor: { tabSize: 2 } }))
await resolveConfig(dir)
const c = getConfig()
expect(c.ai.command).toBe('claude --model opus') // overridden
expect(c.ai.autoLaunch).toBe(true) // default kept
expect(c.editor.tabSize).toBe(2) // overridden
expect(c.editor.autoSave).toBe(false) // default kept
expect(c.git.confirmDiscard).toBe(true) // default kept
})
it('always regenerates config.default.json with full built-in defaults', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-cfg-'))
await resolveConfig(dir)
await writeFile(join(dir, '.helder/config.json'), JSON.stringify({ ai: { command: 'x' } }))
await resolveConfig(dir)
const def = JSON.parse(await readFile(join(dir, '.helder/config.default.json'), 'utf8'))
expect(def.ai.command).toBe('claude')
})
it('does not overwrite an existing theme.css', async () => {
dir = await mkdtemp(join(tmpdir(), 'helder-cfg-'))
await resolveConfig(dir)
await writeFile(join(dir, '.helder/theme.css'), ':root{--accent:#ff0000}')
await resolveConfig(dir)
expect(getThemeCss()).toContain('#ff0000')
})
})