Repository navigation
fix(byo): the daemon keeps an agent running; the run command is the quick try (TASK-645 items 3, 4) #3028
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
fix(byo): the daemon keeps an agent running; the run command is the quick try (TASK-645 items 3, 4) #3028
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a35651a
fix(byo): the daemon keeps an agent running; the run command is the q…
lilyshen0722 2ba691d
fix(byo): stop-on-close points to Add a computer, not daemon install;…
lilyshen0722 ce92b5a
test(byo): select Bring your own before the machine-guard assertion (…
lilyshen0722 504f4e2
fix(byo): fix stop-on-close route, gate quick-try and recommended off…
lilyshen0722 b7d4827
fix(byo): show the daemon block on the result page, keep stop-on-clos…
lilyshen0722 c40890e
fix(byo): stop-on-close line stops naming a computer already on file
lilyshen0722 3228a2a
fix(byo): computer-on-file line points at the start form, not the res…
lilyshen0722 59c9001
fix(byo): On my computer on the result page when a computer is on fil…
lilyshen0722 c18a253
fix(byo): offer no daemon block on Windows, on either page
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
170 changes: 170 additions & 0 deletions
170
frontend/src/v2/__tests__/V2AgentBYOConnectPaths.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,170 @@ | ||
| // @ts-nocheck | ||
| // Keep setup request assertions independent of funnel telemetry. | ||
| jest.mock('../utils/byoTelemetry', () => ({ recordByoStep: jest.fn() })); | ||
| // TASK-645 item 3 and 4: the two connect paths. The run command is the quick | ||
| // try and dies with its Terminal; the daemon is the one that keeps an agent | ||
| // running. Each state is pinned by its own copy, so a rewording can't drop it. | ||
| 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 MAC = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36'; | ||
| const WINDOWS = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36'; | ||
| const realUserAgent = window.navigator.userAgent; | ||
| const setUserAgent = (value) => Object.defineProperty(window.navigator, 'userAgent', { value, configurable: true }); | ||
|
|
||
| const mockPage = ({ machines = [] } = {}) => { | ||
| axios.get.mockImplementation((url) => { | ||
| if (url.startsWith('/api/hosted/availability')) return Promise.resolve({ data: { configured: false, caps: { agentsPerUser: 1, turnsPerDay: 200 } } }); | ||
| if (url === '/api/pods') return Promise.resolve({ data: [{ _id: 'p1', name: 'Workspace', type: 'chat' }] }); | ||
| if (url === '/api/machines') return Promise.resolve({ data: { machines, offlineAfterMs: 90000 } }); | ||
| 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 | ||
| .mockResolvedValueOnce({ data: { ok: true } }) | ||
| .mockResolvedValueOnce({ data: { token: 'cm_agent_test_token' } }); | ||
| }; | ||
|
|
||
| const renderPage = () => render( | ||
| <AuthContext.Provider value={authValue}> | ||
| <MemoryRouter> | ||
| <V2AgentBYO /> | ||
| </MemoryRouter> | ||
| </AuthContext.Provider>, | ||
| ); | ||
|
|
||
| const issueRun = async () => { | ||
| await waitFor(() => expect(screen.getByText('Workspace (chat)')).toBeInTheDocument()); | ||
| 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.findByText(/your connect command for/i); | ||
| }; | ||
|
|
||
| describe('BYO connect paths: run is the quick try, the daemon keeps it running (TASK-645 items 3 and 4)', () => { | ||
| afterEach(() => setUserAgent(realUserAgent)); | ||
| beforeEach(() => jest.clearAllMocks()); | ||
|
|
||
| test('run path on a Mac: the quick-try line names the daemon, and the command says it stops with its Terminal', async () => { | ||
| setUserAgent(MAC); | ||
| mockPage({ machines: [] }); | ||
| renderPage(); | ||
| expect(await screen.findByTestId('byo-quick-try')).toHaveTextContent(/stops when that window closes/); | ||
| expect(screen.getByTestId('byo-quick-try')).toHaveTextContent(/Other ways to connect/); | ||
|
|
||
| await issueRun(); | ||
| const stops = screen.getByTestId('byo-listen-stops-on-close'); | ||
| expect(stops).toHaveTextContent(/stops when this Terminal window closes/); | ||
| expect(stops).toHaveTextContent(/Other ways to connect/); | ||
| expect(stops).toHaveTextContent(/On my computer/); | ||
| expect(stops).not.toHaveTextContent(/daemon install/); | ||
| // The line points at a block that is actually on this page. | ||
| expect(screen.getByTestId('byo-result-more-ways')).toContainElement(screen.getByTestId('byo-add-computer')); | ||
| }); | ||
|
|
||
| test('result page with a computer on file: the add-computer block is not offered again', async () => { | ||
| setUserAgent(MAC); | ||
| mockPage({ machines: [{ machineId: 'm1', name: 'Sams-MacBook', status: 'online', lastSeenAt: new Date().toISOString() }] }); | ||
| renderPage(); | ||
| await waitFor(() => expect(axios.get).toHaveBeenCalledWith('/api/machines', expect.anything())); | ||
| fireEvent.click(await screen.findByTestId('byo-mode-byo')); | ||
| await issueRun(); | ||
| expect(screen.getByTestId('byo-result-more-ways')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('byo-add-computer')).toBeNull(); | ||
| // The stop-on-close line must not send them to add a computer that is already on file. | ||
| const stops = screen.getByTestId('byo-listen-stops-on-close'); | ||
| expect(stops).not.toHaveTextContent(/add this computer/); | ||
| expect(stops).toHaveTextContent(/start another agent and choose On my computer/); | ||
| // The choice the line names is on this page: clicking it opens machine mode. | ||
| fireEvent.click(screen.getByTestId('byo-result-on-my-computer')); | ||
| expect(screen.getByTestId('byo-mode-machine')).toHaveAttribute('aria-pressed', 'true'); | ||
| expect(screen.queryByText(/your connect command for/i)).toBeNull(); | ||
| }); | ||
|
|
||
| test('run path on Windows: no listener command, so no stop-on-close line', async () => { | ||
| setUserAgent(WINDOWS); | ||
| mockPage({ machines: [] }); | ||
| renderPage(); | ||
| await issueRun(); | ||
| expect(screen.queryByTestId('byo-listen-stops-on-close')).toBeNull(); | ||
| }); | ||
|
|
||
| test('daemon path with no computer: marked recommended, and Reload says the computer appears by name, online', async () => { | ||
| setUserAgent(MAC); | ||
| mockPage({ machines: [] }); | ||
| renderPage(); | ||
| const add = await screen.findByTestId('byo-add-computer'); | ||
| expect(screen.getByTestId('byo-add-computer-recommended')).toHaveTextContent(/Recommended for an agent that keeps running/); | ||
| expect(add).toHaveTextContent(/appears in the list by its name, marked online/); | ||
| expect(add).toHaveTextContent('commonly daemon register && commonly daemon install'); | ||
| }); | ||
|
|
||
| test('on Windows: no quick-try line, and the daemon is not marked recommended (systemd cannot install there)', async () => { | ||
| setUserAgent(WINDOWS); | ||
| mockPage({ machines: [] }); | ||
| renderPage(); | ||
| await waitFor(() => expect(axios.get).toHaveBeenCalledWith('/api/machines', expect.anything())); | ||
| expect(screen.queryByTestId('byo-quick-try')).toBeNull(); | ||
| expect(screen.queryByTestId('byo-add-computer-recommended')).toBeNull(); | ||
| // Windows gets no daemon block at all: systemd cannot install there, so | ||
| // there is nothing to run and nothing to offer. | ||
| expect(screen.queryByTestId('byo-add-computer')).toBeNull(); | ||
| }); | ||
|
|
||
| test('on Windows, the result page offers no daemon block either', async () => { | ||
| setUserAgent(WINDOWS); | ||
| mockPage({ machines: [] }); | ||
| renderPage(); | ||
| await issueRun(); | ||
| expect(screen.queryByTestId('byo-add-computer')).toBeNull(); | ||
| }); | ||
|
|
||
| test('with a computer already added, the quick-try line and the daemon block are both gone', async () => { | ||
| setUserAgent(MAC); | ||
| mockPage({ machines: [{ machineId: 'm1', name: 'Sams-MacBook', status: 'online', lastSeenAt: new Date().toISOString() }] }); | ||
| renderPage(); | ||
| await waitFor(() => expect(axios.get).toHaveBeenCalledWith('/api/machines', expect.anything())); | ||
| // Select Bring your own first: with mode still null the line is absent for | ||
| // a different reason, and the test would pass with the machines guard removed. | ||
| fireEvent.click(await screen.findByTestId('byo-mode-byo')); | ||
| expect(screen.queryByTestId('byo-quick-try')).toBeNull(); | ||
| expect(screen.queryByTestId('byo-add-computer')).toBeNull(); | ||
| }); | ||
| }); |
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.