Skip to content

Commit abd13a3

Browse files
Cover workspace registry behavior
1 parent c98120f commit abd13a3

1 file changed

Lines changed: 114 additions & 2 deletions

File tree

apps/codex-claw/src/server/codex-cli.test.ts

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { mkdtempSync, rmSync } from 'node:fs'
2+
import os from 'node:os'
3+
import path from 'node:path'
4+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
25

3-
import { mergeAssistantText, processCodexJsonLine } from './codex-cli'
6+
import {
7+
createCodexWorkspace,
8+
deleteCodexWorkspace,
9+
getCodexPaths,
10+
listCodexWorkspaces,
11+
mergeAssistantText,
12+
patchCodexWorkspace,
13+
processCodexJsonLine,
14+
resetCodexServerStateForTests,
15+
} from './codex-cli'
416

517
describe('processCodexJsonLine', function () {
618
it('parses assistant deltas before the final completed item', function () {
@@ -61,3 +73,103 @@ describe('mergeAssistantText', function () {
6173
expect(repeated).toBe('Hello')
6274
})
6375
})
76+
77+
describe('codex workspace registry', function () {
78+
const originalStateDir = process.env.CODEX_CLAW_STATE_DIR
79+
const originalCommand = process.env.CODEX_CLI_COMMAND
80+
const originalWorkdir = process.env.CODEX_CLI_WORKDIR
81+
const originalSandbox = process.env.CODEX_CLI_SANDBOX
82+
let tempDir = ''
83+
84+
beforeEach(function () {
85+
tempDir = mkdtempSync(path.join(os.tmpdir(), 'codex-claw-test-'))
86+
process.env.CODEX_CLAW_STATE_DIR = path.join(tempDir, 'state')
87+
process.env.CODEX_CLI_COMMAND = 'codex-test'
88+
process.env.CODEX_CLI_WORKDIR = tempDir
89+
process.env.CODEX_CLI_SANDBOX = 'read-only'
90+
resetCodexServerStateForTests()
91+
})
92+
93+
afterEach(function () {
94+
if (originalStateDir === undefined) {
95+
delete process.env.CODEX_CLAW_STATE_DIR
96+
} else {
97+
process.env.CODEX_CLAW_STATE_DIR = originalStateDir
98+
}
99+
if (originalCommand === undefined) {
100+
delete process.env.CODEX_CLI_COMMAND
101+
} else {
102+
process.env.CODEX_CLI_COMMAND = originalCommand
103+
}
104+
if (originalWorkdir === undefined) {
105+
delete process.env.CODEX_CLI_WORKDIR
106+
} else {
107+
process.env.CODEX_CLI_WORKDIR = originalWorkdir
108+
}
109+
if (originalSandbox === undefined) {
110+
delete process.env.CODEX_CLI_SANDBOX
111+
} else {
112+
process.env.CODEX_CLI_SANDBOX = originalSandbox
113+
}
114+
resetCodexServerStateForTests()
115+
rmSync(tempDir, { recursive: true, force: true })
116+
})
117+
118+
it('stores independent active workspace configuration', function () {
119+
expect(getCodexPaths().workspace).toMatchObject({
120+
id: 'default',
121+
codexCommand: 'codex-test',
122+
codexWorkdir: tempDir,
123+
stateDir: path.join(tempDir, 'state'),
124+
})
125+
126+
createCodexWorkspace({
127+
name: 'Docs repo',
128+
codexCommand: 'codex-next',
129+
codexSandbox: 'workspace-write',
130+
codexWorkdir: path.join(tempDir, 'docs'),
131+
stateDir: path.join(tempDir, 'docs-state'),
132+
active: true,
133+
})
134+
135+
expect(getCodexPaths()).toMatchObject({
136+
stateDir: path.join(tempDir, 'docs-state'),
137+
workspace: {
138+
id: 'docs-repo',
139+
name: 'Docs repo',
140+
codexCommand: 'codex-next',
141+
codexSandbox: 'workspace-write',
142+
codexWorkdir: path.join(tempDir, 'docs'),
143+
},
144+
})
145+
})
146+
147+
it('renames and removes non-default workspaces', function () {
148+
createCodexWorkspace({
149+
name: 'Feature repo',
150+
codexWorkdir: path.join(tempDir, 'feature'),
151+
stateDir: path.join(tempDir, 'feature-state'),
152+
active: true,
153+
})
154+
patchCodexWorkspace({
155+
id: 'feature-repo',
156+
name: 'Feature branch repo',
157+
})
158+
159+
expect(listCodexWorkspaces().workspaces).toEqual(
160+
expect.arrayContaining([
161+
expect.objectContaining({
162+
id: 'feature-repo',
163+
name: 'Feature branch repo',
164+
}),
165+
]),
166+
)
167+
168+
deleteCodexWorkspace('feature-repo')
169+
170+
expect(listCodexWorkspaces()).toMatchObject({
171+
activeWorkspaceId: 'default',
172+
workspaces: [expect.objectContaining({ id: 'default' })],
173+
})
174+
})
175+
})

0 commit comments

Comments
 (0)