forked from getagentseal/codeburn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-plan.test.ts
More file actions
150 lines (125 loc) · 6.16 KB
/
Copy pathcli-plan.test.ts
File metadata and controls
150 lines (125 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { mkdtemp, readFile, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { spawnSync } from 'node:child_process'
import { describe, it, expect } from 'vitest'
const CLI_PLAN_TIMEOUT_MS = 10_000
function runCli(args: string[], home: string) {
return spawnSync(process.execPath, ['--import', 'tsx', 'src/cli.ts', ...args], {
cwd: process.cwd(),
env: {
...process.env,
HOME: home,
USERPROFILE: home, // os.homedir() uses USERPROFILE on Windows
HOMEPATH: home,
HOMEDRIVE: '',
},
encoding: 'utf-8',
})
}
describe('codeburn plan command', () => {
it('persists provider-keyed plans and clears on reset', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
const setResult = runCli(['plan', 'set', 'claude-max'], home)
expect(setResult.status).toBe(0)
const setCodexResult = runCli(['plan', 'set', 'custom', '--monthly-usd', '200', '--provider', 'codex'], home)
expect(setCodexResult.status).toBe(0)
const configPath = join(home, '.config', 'codeburn', 'config.json')
const configRaw = await readFile(configPath, 'utf-8')
const config = JSON.parse(configRaw) as { plans?: { claude?: { id?: string; monthlyUsd?: number }; codex?: { id?: string; monthlyUsd?: number } } }
expect(config.plans?.claude?.id).toBe('claude-max')
expect(config.plans?.claude?.monthlyUsd).toBe(200)
expect(config.plans?.codex?.id).toBe('custom')
expect(config.plans?.codex?.monthlyUsd).toBe(200)
const resetResult = runCli(['plan', 'reset'], home)
expect(resetResult.status).toBe(0)
const afterResetRaw = await readFile(configPath, 'utf-8')
const afterReset = JSON.parse(afterResetRaw) as { plan?: unknown; plans?: unknown }
expect(afterReset.plan).toBeUndefined()
expect(afterReset.plans).toBeUndefined()
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('resets one provider without removing other plans', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
expect(runCli(['plan', 'set', 'claude-max'], home).status).toBe(0)
expect(runCli(['plan', 'set', 'custom', '--monthly-usd', '200', '--provider', 'codex'], home).status).toBe(0)
expect(runCli(['plan', 'reset', '--provider', 'codex'], home).status).toBe(0)
const configPath = join(home, '.config', 'codeburn', 'config.json')
const configRaw = await readFile(configPath, 'utf-8')
const config = JSON.parse(configRaw) as { plans?: { claude?: { id?: string }; codex?: unknown } }
expect(config.plans?.claude?.id).toBe('claude-max')
expect(config.plans?.codex).toBeUndefined()
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('resets the all-provider plan without removing provider-specific plans', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
expect(runCli(['plan', 'set', 'claude-max'], home).status).toBe(0)
expect(runCli(['plan', 'reset', '--provider', 'all'], home).status).toBe(0)
const configPath = join(home, '.config', 'codeburn', 'config.json')
const configRaw = await readFile(configPath, 'utf-8')
const config = JSON.parse(configRaw) as { plans?: { claude?: { id?: string }; all?: unknown } }
expect(config.plans?.claude?.id).toBe('claude-max')
expect(config.plans?.all).toBeUndefined()
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('shows all configured plans as json', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
expect(runCli(['plan', 'set', 'claude-max'], home).status).toBe(0)
expect(runCli(['plan', 'set', 'custom', '--monthly-usd', '200', '--provider', 'codex'], home).status).toBe(0)
const result = runCli(['plan', '--format', 'json'], home)
expect(result.status).toBe(0)
const payload = JSON.parse(result.stdout) as { id?: string; provider?: string; plans?: { claude?: { id?: string }; codex?: { id?: string } } }
expect(payload.id).toBe('claude-max')
expect(payload.provider).toBe('claude')
expect(payload.plans?.claude?.id).toBe('claude-max')
expect(payload.plans?.codex?.id).toBe('custom')
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('filters shown plans by provider', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
expect(runCli(['plan', 'set', 'claude-max'], home).status).toBe(0)
expect(runCli(['plan', 'set', 'custom', '--monthly-usd', '200', '--provider', 'codex'], home).status).toBe(0)
const result = runCli(['plan', '--format', 'json', '--provider', 'codex'], home)
expect(result.status).toBe(0)
const payload = JSON.parse(result.stdout) as { id?: string; provider?: string; plans?: unknown }
expect(payload.id).toBe('custom')
expect(payload.provider).toBe('codex')
expect(payload.plans).toMatchObject({ codex: { id: 'custom' } })
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('rejects all-provider scope for preset plans', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
const result = runCli(['plan', 'set', 'claude-max', '--provider', 'all'], home)
expect(result.status).toBe(1)
expect(result.stderr).toContain('omit --provider or use --provider claude')
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
it('shows invalid reset-day value in error output', async () => {
const home = await mkdtemp(join(tmpdir(), 'codeburn-cli-plan-'))
try {
const result = runCli(['plan', 'set', 'claude-max', '--reset-day', '99'], home)
expect(result.status).toBe(1)
expect(result.stderr).toContain('--reset-day must be an integer from 1 to 28; got 99.')
} finally {
await rm(home, { recursive: true, force: true })
}
}, CLI_PLAN_TIMEOUT_MS)
})