mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-26 15:27:55 +00:00
os.homedir() reads USERPROFILE on Windows and never HOME, so the isolation setup and every test that moved home were still resolving the developer's real home directory. Fixtures came back empty, real sessions leaked into counts, and the code under test wrote plans, receipts and a sync ledger into the real ~/.config/codeburn during a run. USERPROFILE now joins the redirected variables and a shared setHome() helper moves HOME and USERPROFILE together; every spawn env carries both. The remaining Windows-only failures were POSIX-shaped fixtures: chmod tricks that only toggle a read-only attribute on NTFS, pid 1 as an always-alive lock holder, splitting paths on '/', bare tar, mode-bit expectations, and per-file timeouts too short for the cost of a tsx spawn. Each gets a platform-aware equivalent so nothing is skipped on Windows and the POSIX branches stay byte-for-byte what they were. Full run on Windows: 267 files passed, 2 skipped, 3592 tests passed.
184 lines
5.7 KiB
TypeScript
184 lines
5.7 KiB
TypeScript
import { mkdtemp, rm } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
|
|
import { clearPlan, readPlan, readPlans, saveConfig, savePlan } from '../src/config.js'
|
|
import { getPresetPlan, isPlanId, isPlanProvider } from '../src/plans.js'
|
|
import { setHome } from './setup/home.js'
|
|
|
|
describe('plan presets', () => {
|
|
it('resolves builtin presets', () => {
|
|
expect(getPresetPlan('claude-pro')).toMatchObject({ id: 'claude-pro', monthlyUsd: 20, provider: 'claude' })
|
|
expect(getPresetPlan('claude-max')).toMatchObject({ id: 'claude-max', monthlyUsd: 200, provider: 'claude' })
|
|
expect(getPresetPlan('cursor-pro')).toMatchObject({ id: 'cursor-pro', monthlyUsd: 20, provider: 'cursor' })
|
|
expect(getPresetPlan('copilot-pro')).toMatchObject({ id: 'copilot-pro', monthlyCredits: 1500, monthlyUsd: 15, provider: 'copilot' })
|
|
expect(getPresetPlan('copilot-pro-plus')).toMatchObject({ id: 'copilot-pro-plus', monthlyCredits: 7000, monthlyUsd: 70, provider: 'copilot' })
|
|
expect(getPresetPlan('copilot-max')).toMatchObject({ id: 'copilot-max', monthlyCredits: 20000, monthlyUsd: 200, provider: 'copilot' })
|
|
expect(getPresetPlan('custom')).toBeNull()
|
|
})
|
|
|
|
it('validates ids and providers', () => {
|
|
expect(isPlanId('claude-pro')).toBe(true)
|
|
expect(isPlanId('none')).toBe(true)
|
|
expect(isPlanId('bad-plan')).toBe(false)
|
|
|
|
expect(isPlanProvider('all')).toBe(true)
|
|
expect(isPlanProvider('claude')).toBe(true)
|
|
expect(isPlanProvider('copilot')).toBe(true)
|
|
expect(isPlanProvider('invalid')).toBe(false)
|
|
expect(isPlanId('copilot-pro')).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('plan config persistence', () => {
|
|
it('round-trips per-provider plans and clears one provider at a time', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'codeburn-plan-test-'))
|
|
setHome(dir)
|
|
|
|
try {
|
|
await savePlan({
|
|
id: 'claude-max',
|
|
monthlyUsd: 200,
|
|
provider: 'claude',
|
|
resetDay: 12,
|
|
setAt: '2026-04-17T12:00:00.000Z',
|
|
})
|
|
await savePlan({
|
|
id: 'custom',
|
|
monthlyUsd: 200,
|
|
provider: 'codex',
|
|
resetDay: 1,
|
|
setAt: '2026-04-18T12:00:00.000Z',
|
|
})
|
|
|
|
const plans = await readPlans()
|
|
expect(plans.claude).toMatchObject({
|
|
id: 'claude-max',
|
|
monthlyUsd: 200,
|
|
provider: 'claude',
|
|
resetDay: 12,
|
|
})
|
|
expect(plans.codex).toMatchObject({
|
|
id: 'custom',
|
|
monthlyUsd: 200,
|
|
provider: 'codex',
|
|
resetDay: 1,
|
|
})
|
|
expect(await readPlan()).toMatchObject({ id: 'claude-max', provider: 'claude' })
|
|
|
|
await clearPlan('codex')
|
|
expect((await readPlans()).codex).toBeUndefined()
|
|
expect((await readPlans()).claude).toMatchObject({ id: 'claude-max' })
|
|
|
|
await clearPlan('all')
|
|
expect((await readPlans()).claude).toMatchObject({ id: 'claude-max' })
|
|
|
|
await clearPlan()
|
|
expect(await readPlan()).toBeUndefined()
|
|
expect(await readPlans()).toEqual({})
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('reads legacy single-plan config as a provider-keyed plan map', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'codeburn-plan-test-'))
|
|
setHome(dir)
|
|
|
|
try {
|
|
await saveConfig({
|
|
plan: {
|
|
id: 'cursor-pro',
|
|
monthlyUsd: 20,
|
|
provider: 'cursor',
|
|
resetDay: 3,
|
|
setAt: '2026-04-17T12:00:00.000Z',
|
|
},
|
|
})
|
|
|
|
const plans = await readPlans()
|
|
expect(plans.cursor).toMatchObject({
|
|
id: 'cursor-pro',
|
|
monthlyUsd: 20,
|
|
provider: 'cursor',
|
|
resetDay: 3,
|
|
})
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('drops a hand-edited all plan when provider-specific plans are present', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'codeburn-plan-test-'))
|
|
setHome(dir)
|
|
|
|
try {
|
|
await saveConfig({
|
|
plans: {
|
|
all: {
|
|
id: 'custom',
|
|
monthlyUsd: 300,
|
|
resetDay: 1,
|
|
setAt: '2026-04-17T12:00:00.000Z',
|
|
},
|
|
claude: {
|
|
id: 'claude-max',
|
|
monthlyUsd: 200,
|
|
resetDay: 1,
|
|
setAt: '2026-04-18T12:00:00.000Z',
|
|
},
|
|
},
|
|
})
|
|
|
|
const plans = await readPlans()
|
|
expect(plans.all).toBeUndefined()
|
|
expect(plans.claude).toMatchObject({ id: 'claude-max', provider: 'claude' })
|
|
expect(await readPlan()).toMatchObject({ id: 'claude-max', provider: 'claude' })
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('does not allow an all-provider plan to overlap provider-specific plans', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'codeburn-plan-test-'))
|
|
setHome(dir)
|
|
|
|
try {
|
|
await savePlan({
|
|
id: 'custom',
|
|
monthlyUsd: 100,
|
|
provider: 'all',
|
|
resetDay: 1,
|
|
setAt: '2026-04-17T12:00:00.000Z',
|
|
})
|
|
await savePlan({
|
|
id: 'claude-max',
|
|
monthlyUsd: 200,
|
|
provider: 'claude',
|
|
resetDay: 1,
|
|
setAt: '2026-04-18T12:00:00.000Z',
|
|
})
|
|
|
|
expect(await readPlans()).toMatchObject({
|
|
claude: { id: 'claude-max' },
|
|
})
|
|
expect((await readPlans()).all).toBeUndefined()
|
|
|
|
await savePlan({
|
|
id: 'custom',
|
|
monthlyUsd: 300,
|
|
provider: 'all',
|
|
resetDay: 1,
|
|
setAt: '2026-04-19T12:00:00.000Z',
|
|
})
|
|
expect(await readPlans()).toMatchObject({
|
|
all: { id: 'custom', monthlyUsd: 300 },
|
|
})
|
|
expect((await readPlans()).claude).toBeUndefined()
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|