mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
feat: support multiple workspace roots (#584)
This commit is contained in:
@@ -62,12 +62,12 @@ describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
|
||||
it('rejects cwd outside the workspace root with the standard error shape', async () => {
|
||||
const machine = makeMachine('machine-1')
|
||||
const client = new ApiMachineClient('cli-token', machine, workspaceRoot)
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot])
|
||||
|
||||
const outsideCwd = mkdtempSync(join(tmpdir(), 'hapi-outside-'))
|
||||
try {
|
||||
const result = await callListOpencodeModels(client, machine.id, outsideCwd)
|
||||
expect(result).toEqual({ success: false, error: 'Path is outside workspace root' })
|
||||
expect(result).toEqual({ success: false, error: 'Path is outside workspace roots' })
|
||||
expect(listOpencodeModelsForCwdMock).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
rmSync(outsideCwd, { recursive: true, force: true })
|
||||
@@ -77,7 +77,7 @@ describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
|
||||
it('rejects empty cwd with cwd-required error', async () => {
|
||||
const machine = makeMachine('machine-2')
|
||||
const client = new ApiMachineClient('cli-token', machine, workspaceRoot)
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot])
|
||||
|
||||
try {
|
||||
const result = await callListOpencodeModels(client, machine.id, '')
|
||||
@@ -90,7 +90,7 @@ describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
|
||||
it('forwards a workspace-internal cwd to listOpencodeModelsForCwd', async () => {
|
||||
const machine = makeMachine('machine-3')
|
||||
const client = new ApiMachineClient('cli-token', machine, workspaceRoot)
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot])
|
||||
|
||||
const innerDir = join(workspaceRoot, 'inner-project')
|
||||
mkdirSync(innerDir)
|
||||
@@ -115,4 +115,29 @@ describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
client.shutdown()
|
||||
}
|
||||
})
|
||||
|
||||
it('accepts cwd inside any configured workspace root', async () => {
|
||||
const machine = makeMachine('machine-4')
|
||||
const secondWorkspaceRoot = mkdtempSync(join(tmpdir(), 'hapi-machine-ws-2-'))
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot, secondWorkspaceRoot])
|
||||
|
||||
listOpencodeModelsForCwdMock.mockResolvedValueOnce({
|
||||
success: true,
|
||||
availableModels: [{ modelId: 'x/y' }],
|
||||
currentModelId: 'x/y'
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await callListOpencodeModels(client, machine.id, secondWorkspaceRoot)
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
availableModels: [{ modelId: 'x/y' }],
|
||||
currentModelId: 'x/y'
|
||||
})
|
||||
expect(listOpencodeModelsForCwdMock).toHaveBeenCalledWith(secondWorkspaceRoot)
|
||||
} finally {
|
||||
rmSync(secondWorkspaceRoot, { recursive: true, force: true })
|
||||
client.shutdown()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user