Repository navigation
fix(byo): pick the runner before the install, not after (TASK-645 item 5) #3019
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
6 commits
Select commit
Hold shift + click to select a range
e402332
fix(byo): pick the runner before the install, not after (TASK-645 ite…
lilyshen0722 1cf09a7
test(byo): queue the second issue's responses in the card test (TASK-…
lilyshen0722 355f4bf
fix(byo): no runner picker on a card; way back from a card opens the …
lilyshen0722 763c98f
fix(byo): the card's name is the lookup base only on the card (TASK-6…
lilyshen0722 5f78d32
fix(byo): keep the ?name= prefill on plain links (TASK-645 item 5)
lilyshen0722 859a883
fix(byo): a runner switch clears the key prompt; picker locks while i…
lilyshen0722 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
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
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
106 changes: 106 additions & 0 deletions
106
frontend/src/v2/__tests__/V2AgentBYORunnerSwitchRekey.test.tsx
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,106 @@ | ||
| // @ts-nocheck | ||
| // Keep setup request assertions independent of funnel telemetry. | ||
| jest.mock('../utils/byoTelemetry', () => ({ recordByoStep: jest.fn() })); | ||
| // TASK-645 item 5, Vera's HOLD on #3019: the runner is the one choice that | ||
| // names the install, so a runner switch must not leave a key-replacement prompt | ||
| // for the other runner's name, and the picker must not move while an issue is in flight. | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import V2AgentBYO from '../components/V2AgentBYO'; | ||
| import { AuthContext } from '../../context/AuthContext'; | ||
|
|
||
| jest.mock('../components/V2NavRail', () => () => null); | ||
| jest.mock('../hooks/useV2PodAttention', () => ({ | ||
| ...jest.requireActual('../hooks/useV2PodAttention'), | ||
| useV2PodAttention: () => ({ items: [], count: null, countByPod: {}, refresh: async () => {} }), | ||
| })); | ||
| jest.mock('axios', () => { | ||
| const mock = { | ||
| get: jest.fn(), | ||
| post: jest.fn(), | ||
| patch: jest.fn(), | ||
| delete: jest.fn(), | ||
| defaults: { baseURL: '', headers: { common: {} } }, | ||
| interceptors: { | ||
| request: { use: jest.fn(), eject: jest.fn() }, | ||
| response: { use: jest.fn(), eject: jest.fn() }, | ||
| }, | ||
| }; | ||
| return { __esModule: true, default: mock, ...mock }; | ||
| }); | ||
|
|
||
| const axios = jest.requireMock('axios').default; | ||
|
|
||
| const authValue = { | ||
| currentUser: { _id: 'u1', username: 'sam' }, | ||
| user: { _id: 'u1', username: 'sam' }, | ||
| token: 'user-jwt', | ||
| loading: false, | ||
| error: null, | ||
| isAuthenticated: true, | ||
| register: jest.fn(), | ||
| login: jest.fn(), | ||
| logout: jest.fn(), | ||
| updateProfile: jest.fn(), | ||
| }; | ||
|
|
||
| const renderPage = () => render( | ||
| <AuthContext.Provider value={authValue}> | ||
| <MemoryRouter initialEntries={['/']}> | ||
| <V2AgentBYO /> | ||
| </MemoryRouter> | ||
| </AuthContext.Provider>, | ||
| ); | ||
|
|
||
| const tokenCalls = () => axios.post.mock.calls.filter(([url]) => /runtime-tokens/.test(url)); | ||
|
|
||
| // sam-claude already holds a key, so the first issue answers existing:true. | ||
| const mockAlreadyKeyed = (tokenReply) => { | ||
| axios.get.mockImplementation((url) => { | ||
| if (url === '/api/pods') return Promise.resolve({ data: [{ _id: 'p1', name: 'Workspace', type: 'chat' }] }); | ||
| if (url.startsWith('/api/registry/agents/next-free-name?')) return Promise.resolve({ data: { name: new URLSearchParams(url.split('?')[1]).get('base') } }); | ||
| return Promise.resolve({ data: {} }); | ||
| }); | ||
| axios.post.mockImplementation((url) => { | ||
| if (url === '/api/registry/install') return Promise.reject({ response: { data: { error: 'Agent already installed in this pod' } } }); | ||
| if (/runtime-tokens/.test(url)) return tokenReply(); | ||
| return Promise.resolve({ data: {} }); | ||
| }); | ||
| }; | ||
|
|
||
| describe('BYO runner switch and key replacement (TASK-645 item 5, #3019 HOLD)', () => { | ||
| beforeEach(() => jest.clearAllMocks()); | ||
|
|
||
| test('switching runner clears the replace-key prompt, so it cannot rotate the other runner’s key', async () => { | ||
| mockAlreadyKeyed(() => Promise.resolve({ data: { existing: true } })); | ||
| renderPage(); | ||
| await waitFor(() => expect(screen.getByRole('button', { name: /get my connect command/i })).toBeEnabled()); | ||
| fireEvent.click(screen.getByRole('button', { name: /get my connect command/i })); | ||
| await screen.findByTestId('byo-replace-key-confirmation'); | ||
| expect(screen.getByTestId('byo-replace-key-confirmation')).toHaveTextContent('sam-claude'); | ||
|
|
||
| fireEvent.click(screen.getByTestId('byo-runner-codex')); | ||
|
|
||
| expect(screen.queryByTestId('byo-replace-key-confirmation')).toBeNull(); | ||
| expect(screen.queryByRole('button', { name: /replace the running agent.s key/i })).toBeNull(); | ||
| // No force-rotation was sent for sam-claude. | ||
| expect(tokenCalls().some(([, body]) => body && body.force)).toBe(false); | ||
| }); | ||
|
|
||
| test('the runner picker is disabled while an issue is in flight', async () => { | ||
| let release; | ||
| mockAlreadyKeyed(() => new Promise((resolve) => { release = resolve; })); | ||
| renderPage(); | ||
| await waitFor(() => expect(screen.getByRole('button', { name: /get my connect command/i })).toBeEnabled()); | ||
| fireEvent.click(screen.getByRole('button', { name: /get my connect command/i })); | ||
| await waitFor(() => expect(tokenCalls()).toHaveLength(1)); | ||
|
|
||
| expect(screen.getByTestId('byo-runner-claude')).toBeDisabled(); | ||
| expect(screen.getByTestId('byo-runner-codex')).toBeDisabled(); | ||
|
|
||
| release({ data: { existing: true } }); | ||
| await screen.findByTestId('byo-replace-key-confirmation'); | ||
| expect(screen.getByTestId('byo-runner-codex')).toBeEnabled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.