mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
feat: add Grok Build support (#1030)
* test: define Grok Build integration behavior * feat: add Grok Build agent integration * test: cover Grok permissions and resume paths * docs: add Grok Build setup guide * fix: scope Grok ACP discovery to session cwd * fix: align Grok permission UI semantics * docs: clarify Grok runner setup * test: require Grok create model and effort options * feat: add Grok create model and effort pickers * test: define Grok runtime parity behavior * feat: add Grok runtime ACP controls and discovery * fix: tighten Grok runtime controls * fix: suppress nonfatal Grok title quota errors * feat: support Grok Auto permission mode * feat: forward ACP native session titles for Grok * fix: guard Grok Windows shell arguments
This commit is contained in:
@@ -5,6 +5,7 @@ import { join } from 'node:path'
|
||||
|
||||
const ioMock = vi.hoisted(() => vi.fn())
|
||||
const listOpencodeModelsForCwdMock = vi.hoisted(() => vi.fn())
|
||||
const listGrokModelsForCwdMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('socket.io-client', () => ({
|
||||
io: ioMock
|
||||
@@ -18,6 +19,10 @@ vi.mock('../modules/common/opencodeModels', () => ({
|
||||
listOpencodeModelsForCwd: listOpencodeModelsForCwdMock
|
||||
}))
|
||||
|
||||
vi.mock('../modules/common/grokModels', () => ({
|
||||
listGrokModelsForCwd: listGrokModelsForCwdMock
|
||||
}))
|
||||
|
||||
import { ApiMachineClient, normalizeWindowsDriveRoot } from './apiMachine'
|
||||
import type { Machine } from './types'
|
||||
|
||||
@@ -60,12 +65,22 @@ async function callListOpencodeModels(client: ApiMachineClient, machineId: strin
|
||||
return JSON.parse(raw) as unknown
|
||||
}
|
||||
|
||||
async function callListGrokModels(client: ApiMachineClient, machineId: string, cwd: string): Promise<unknown> {
|
||||
const manager = (client as unknown as { rpcHandlerManager: { handleRequest: (req: { method: string; params: string }) => Promise<string> } }).rpcHandlerManager
|
||||
const raw = await manager.handleRequest({
|
||||
method: `${machineId}:listGrokModelsForCwd`,
|
||||
params: JSON.stringify({ cwd })
|
||||
})
|
||||
return JSON.parse(raw) as unknown
|
||||
}
|
||||
|
||||
describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
let workspaceRoot: string
|
||||
|
||||
beforeEach(() => {
|
||||
ioMock.mockReset()
|
||||
listOpencodeModelsForCwdMock.mockReset()
|
||||
listGrokModelsForCwdMock.mockReset()
|
||||
workspaceRoot = mkdtempSync(join(tmpdir(), 'hapi-machine-ws-'))
|
||||
})
|
||||
|
||||
@@ -157,6 +172,58 @@ describe('ApiMachineClient listOpencodeModelsForCwd handler', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ApiMachineClient listGrokModelsForCwd handler', () => {
|
||||
let workspaceRoot: string
|
||||
|
||||
beforeEach(() => {
|
||||
ioMock.mockReset()
|
||||
listGrokModelsForCwdMock.mockReset()
|
||||
workspaceRoot = mkdtempSync(join(tmpdir(), 'hapi-grok-machine-ws-'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(workspaceRoot, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('rejects cwd outside workspace roots before running grok models', async () => {
|
||||
const machine = makeMachine('grok-machine-1')
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot])
|
||||
const outsideCwd = mkdtempSync(join(tmpdir(), 'hapi-grok-outside-'))
|
||||
|
||||
try {
|
||||
expect(await callListGrokModels(client, machine.id, outsideCwd)).toEqual({
|
||||
success: false,
|
||||
error: 'Path is outside workspace roots'
|
||||
})
|
||||
expect(listGrokModelsForCwdMock).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
rmSync(outsideCwd, { recursive: true, force: true })
|
||||
client.shutdown()
|
||||
}
|
||||
})
|
||||
|
||||
it('forwards a workspace cwd to the Grok model probe', async () => {
|
||||
const machine = makeMachine('grok-machine-2')
|
||||
const client = new ApiMachineClient('cli-token', machine, [workspaceRoot])
|
||||
listGrokModelsForCwdMock.mockResolvedValueOnce({
|
||||
success: true,
|
||||
availableModels: [{ modelId: 'grok-4.5' }],
|
||||
currentModelId: 'grok-4.5'
|
||||
})
|
||||
|
||||
try {
|
||||
expect(await callListGrokModels(client, machine.id, workspaceRoot)).toEqual({
|
||||
success: true,
|
||||
availableModels: [{ modelId: 'grok-4.5' }],
|
||||
currentModelId: 'grok-4.5'
|
||||
})
|
||||
expect(listGrokModelsForCwdMock).toHaveBeenCalledWith(realpathSync.native(workspaceRoot))
|
||||
} finally {
|
||||
client.shutdown()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('ApiMachineClient keepAlive lifecycle', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
Reference in New Issue
Block a user