-
Notifications
You must be signed in to change notification settings - Fork 38
fix(code-reviews): disable interactive tools #3272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22fc2e2
fix(code-reviews): disable interactive tools
alex-alecu c6213fc
fix(review): sync platform metadata
alex-alecu c990161
refactor(review): share status check
alex-alecu 675a23b
fix(review): count filtered events
alex-alecu 6489a8d
fix(review): keep snapshot read-only
alex-alecu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
services/cloud-agent-next/src/execution/orchestrator.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { Env, SandboxInstance } from '../types.js'; | ||
| import type { ExecutionPlan } from './types.js'; | ||
|
|
||
| const { ensureWrapperMock, promptMock, resumeMock, initiateMock, getOrCreateSessionMock } = | ||
| vi.hoisted(() => ({ | ||
| ensureWrapperMock: vi.fn(), | ||
| promptMock: vi.fn(), | ||
| resumeMock: vi.fn(), | ||
| initiateMock: vi.fn(), | ||
| getOrCreateSessionMock: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('../session-service.js', () => ({ | ||
| SessionService: class SessionService { | ||
| resume = resumeMock; | ||
| initiateWithRetry = initiateMock; | ||
| getOrCreateSession = getOrCreateSessionMock; | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('../kilo/wrapper-client.js', () => ({ | ||
| WrapperClient: { | ||
| ensureWrapper: ensureWrapperMock, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('./image-prompt-parts.js', () => ({ | ||
| buildImagePromptParts: vi.fn(), | ||
| downloadImagePromptParts: vi.fn().mockResolvedValue([]), | ||
| })); | ||
|
|
||
| import { ExecutionOrchestrator } from './orchestrator.js'; | ||
|
|
||
| const preparedSession = { | ||
| session: { exec: vi.fn() }, | ||
| context: { | ||
| workspacePath: '/workspace/test', | ||
| upstreamBranch: 'main', | ||
| }, | ||
| }; | ||
|
|
||
| const basePlan = { | ||
| executionId: 'exc_test', | ||
| sessionId: 'agent_test', | ||
| userId: 'user_test', | ||
| prompt: 'Review this change', | ||
| mode: 'code', | ||
| workspace: { | ||
| shouldPrepare: false, | ||
| sandboxId: 'sandbox_test', | ||
| resumeContext: { | ||
| kiloSessionId: 'kilo_existing', | ||
| workspacePath: '/workspace/test', | ||
| kilocodeToken: 'kilo_token', | ||
| branchName: 'session/agent_test', | ||
| }, | ||
| }, | ||
| wrapper: { | ||
| kiloSessionId: 'kilo_existing', | ||
| model: { providerID: 'kilocode', modelID: 'test-model' }, | ||
| }, | ||
| } satisfies ExecutionPlan; | ||
|
|
||
| function createOrchestrator() { | ||
| const sandbox = {} as SandboxInstance; | ||
| const recordKiloServerActivity = vi.fn().mockResolvedValue(undefined); | ||
|
|
||
| const orchestrator = new ExecutionOrchestrator({ | ||
| getSandbox: vi.fn().mockResolvedValue(sandbox), | ||
| getSessionStub: vi.fn().mockReturnValue({ recordKiloServerActivity }), | ||
| getIngestUrl: vi.fn().mockReturnValue('wss://ingest.example.com/ingest'), | ||
| env: {} as Env, | ||
| }); | ||
|
|
||
| return orchestrator; | ||
| } | ||
|
|
||
| describe('ExecutionOrchestrator tool overrides', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| promptMock.mockResolvedValue({ messageId: 'msg_test' }); | ||
| ensureWrapperMock.mockResolvedValue({ | ||
| client: { prompt: promptMock }, | ||
| sessionId: 'kilo_existing', | ||
| }); | ||
| resumeMock.mockResolvedValue(preparedSession); | ||
| initiateMock.mockResolvedValue(preparedSession); | ||
| getOrCreateSessionMock.mockResolvedValue(preparedSession.session); | ||
| }); | ||
|
|
||
| it('disables interactive tools for code-review resume executions', async () => { | ||
| const orchestrator = createOrchestrator(); | ||
| const plan = { | ||
| ...basePlan, | ||
| workspace: { | ||
| ...basePlan.workspace, | ||
| resumeContext: { | ||
| ...basePlan.workspace.resumeContext, | ||
| createdOnPlatform: 'code-review', | ||
| }, | ||
| }, | ||
| } satisfies ExecutionPlan; | ||
|
|
||
| await orchestrator.execute(plan); | ||
|
|
||
| expect(promptMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| tools: { | ||
| question: false, | ||
| plan_enter: false, | ||
| plan_exit: false, | ||
| }, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('does not send tool overrides for non-code-review executions', async () => { | ||
| const orchestrator = createOrchestrator(); | ||
|
|
||
| await orchestrator.execute(basePlan); | ||
|
|
||
| expect(promptMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| tools: undefined, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('uses existing metadata to detect code-review fast-path executions', async () => { | ||
| const orchestrator = createOrchestrator(); | ||
| const plan = { | ||
| ...basePlan, | ||
| workspace: { | ||
| shouldPrepare: true, | ||
| sandboxId: 'sandbox_test', | ||
| initContext: { | ||
| kilocodeToken: 'kilo_token', | ||
| isPreparedSession: true, | ||
| }, | ||
| existingMetadata: { | ||
| workspacePath: '/workspace/test', | ||
| kiloSessionId: 'kilo_existing', | ||
| sandboxId: 'sandbox_test', | ||
| sessionHome: '/home/agent_test', | ||
| branchName: 'session/agent_test', | ||
| createdOnPlatform: 'code-review', | ||
| }, | ||
| }, | ||
| } satisfies ExecutionPlan; | ||
|
|
||
| await orchestrator.execute(plan); | ||
|
|
||
| expect(promptMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| tools: { | ||
| question: false, | ||
| plan_enter: false, | ||
| plan_exit: false, | ||
| }, | ||
| }) | ||
| ); | ||
| expect(getOrCreateSessionMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| createdOnPlatform: 'code-review', | ||
| }) | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.