Repository navigation
fix(agent): re-handshake the agent socket on an off-cloud workspace switch #22004
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
9 commits
Select commit
Hold shift + click to select a range
76e7f69
fix(agent): re-handshake the agent socket on an off-cloud workspace s…
christian-byrne e270516
fix(agent): do not handshake on the null leg of a workspace switch
christian-byrne 7a99905
fix(agent): only skip a null workspace when Desktop is not pinning one
christian-byrne 0c4929a
test(agent): give the api mock resetSocket
christian-byrne 8fcc15b
fix(agent): reauthenticate Desktop workspace changes
christian-byrne d841979
test(agent): tighten workspace switch fixtures
christian-byrne 357db1e
test(agent): seed workspace onboarding state
christian-byrne cb7f66f
test(agent): avoid redundant workspace menu reopen
christian-byrne 8d5b6c7
test(agent): bind workspace identity to bearer
christian-byrne 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { expect } from '@playwright/test' | ||
| import { | ||
| PERSONAL_WORKSPACE_NAME, | ||
| TEAM_WORKSPACE_NAME | ||
| } from '@e2e/fixtures/data/workspaceSwitcher' | ||
| import { agentWorkspaceSwitcherTest as test } from '@e2e/tests/agent/agentWorkspaceSwitchFixture' | ||
|
|
||
| test.describe('Agent workspace switching', { tag: '@ui' }, () => { | ||
| test('retires the old socket and recovers the panel under the new workspace identity', async ({ | ||
| agentIdentityReads, | ||
| agentPanel, | ||
| getAgentSocket, | ||
| nextAgentSocket, | ||
| page | ||
| }) => { | ||
| await agentPanel.open() | ||
| await expect(agentPanel.composer).toBeVisible() | ||
| const originalSocket = await getAgentSocket() | ||
| expect(new URL(originalSocket.url()).searchParams.get('token')).toBe( | ||
| 'mock-workspace-token-ws-personal' | ||
| ) | ||
| let originalSocketClosed = false | ||
| originalSocket.onClose(() => { | ||
| originalSocketClosed = true | ||
| }) | ||
| const replacementSocketOpened = nextAgentSocket() | ||
|
|
||
| await page.getByRole('button', { name: 'Current user' }).click() | ||
| await expect(page.getByTestId('workspace-switcher-trigger')).toContainText( | ||
| PERSONAL_WORKSPACE_NAME | ||
| ) | ||
| await page.getByTestId('workspace-switcher-trigger').click() | ||
| await page | ||
| .getByTestId('workspace-switcher-panel') | ||
| .getByText(TEAM_WORKSPACE_NAME, { exact: true }) | ||
| .click() | ||
|
|
||
| const replacementSocket = await replacementSocketOpened | ||
| await expect.poll(() => originalSocketClosed).toBe(true) | ||
| expect(new URL(replacementSocket.url()).searchParams.get('token')).toBe( | ||
| 'mock-workspace-token-ws-team' | ||
| ) | ||
| await expect | ||
| .poll(() => agentIdentityReads) | ||
| .toContainEqual({ | ||
| workspaceId: 'ws-team' | ||
| }) | ||
| await expect(agentPanel.composer).toBeVisible() | ||
| }) | ||
| }) |
145 changes: 145 additions & 0 deletions
145
browser_tests/tests/agent/agentWorkspaceSwitchFixture.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,145 @@ | ||
| import type { | ||
| AgentIdentity, | ||
| AgentRunMode, | ||
| ExchangeTokenRequest, | ||
| ListMembersResponse | ||
| } from '@comfyorg/ingest-types' | ||
| import { mergeTests } from '@playwright/test' | ||
|
|
||
| import type { WorkspaceTokenResponse } from '@/platform/workspace/stores/workspaceAuthStore' | ||
|
|
||
| import { agentTest, bootAgentApp } from '@e2e/fixtures/agentPanelFixture' | ||
| import { AgentPanel } from '@e2e/fixtures/components/AgentPanel' | ||
| import { emptyAgentThreadList } from '@e2e/fixtures/data/agent/agentThreadList' | ||
| import { createBillingCapabilities } from '@e2e/fixtures/data/billingCapabilities' | ||
| import { | ||
| EMPTY_BILLING_BALANCE, | ||
| EMPTY_BILLING_PLANS, | ||
| ENDED_STANDARD_BILLING_STATUS | ||
| } from '@e2e/fixtures/data/cloudWorkspace' | ||
| import { | ||
| WORKSPACE_SWITCHER_REMOTE_CONFIG, | ||
| WORKSPACE_SWITCHER_WORKSPACES | ||
| } from '@e2e/fixtures/data/workspaceSwitcher' | ||
| import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' | ||
| import { mockWorkspaceList } from '@e2e/fixtures/utils/workspaceMocks' | ||
| import { webSocketFixture } from '@e2e/fixtures/ws' | ||
|
|
||
| interface AgentIdentityRead { | ||
| workspaceId: string | ||
| } | ||
|
|
||
| const base = mergeTests(agentTest, webSocketFixture) | ||
|
|
||
| export const agentWorkspaceSwitcherTest = base.extend<{ | ||
| agentIdentityReads: AgentIdentityRead[] | ||
| agentPanel: AgentPanel | ||
| }>({ | ||
| agentIdentityReads: async ({ page, agentFlagEnabled }, use) => { | ||
| const reads: AgentIdentityRead[] = [] | ||
| let workspaceId = 'ws-personal' | ||
| const runMode: AgentRunMode = { | ||
| mode: 'ask_approval', | ||
| credit_limit: null | ||
| } | ||
|
|
||
| await page.addInitScript( | ||
| (workspaceIds) => { | ||
| for (const workspaceId of workspaceIds) { | ||
| localStorage.setItem( | ||
| `Comfy.AgentPanel.onboarded.test-user-e2e.${workspaceId}`, | ||
| 'true' | ||
| ) | ||
| } | ||
| }, | ||
| ['ws-personal', 'ws-team'] | ||
| ) | ||
|
|
||
| await bootAgentApp(page, agentFlagEnabled, { | ||
| features: WORKSPACE_SWITCHER_REMOTE_CONFIG, | ||
| settings: { 'Comfy.UseNewMenu': 'Top' }, | ||
| beforeNavigate: async (page) => { | ||
| await mockWorkspaceList(page, WORKSPACE_SWITCHER_WORKSPACES) | ||
| await page.route('**/api/workspace/members**', (route) => | ||
| route.fulfill( | ||
| jsonRoute({ | ||
| members: [], | ||
| pagination: { offset: 0, limit: 50, total: 0, has_more: false } | ||
| } satisfies ListMembersResponse) | ||
| ) | ||
| ) | ||
| await page.route('**/api/auth/token', async (route) => { | ||
| const request = route.request().postDataJSON() as ExchangeTokenRequest | ||
| workspaceId = request.workspace_id ?? 'ws-personal' | ||
| const workspace = WORKSPACE_SWITCHER_WORKSPACES.find( | ||
| ({ id }) => id === workspaceId | ||
| ) | ||
| if (!workspace) { | ||
| await route.fulfill({ status: 404 }) | ||
| return | ||
| } | ||
| const response: WorkspaceTokenResponse = { | ||
| token: `mock-workspace-token-${workspace.id}`, | ||
| expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(), | ||
| user_id: 'uid-1', | ||
| workspace: { | ||
| id: workspace.id, | ||
| name: workspace.name, | ||
| type: workspace.type | ||
| }, | ||
| role: workspace.role, | ||
| permissions: [] | ||
| } | ||
| await route.fulfill(jsonRoute(response)) | ||
| }) | ||
| await page.route('**/api/auth/session', (route) => | ||
| route.fulfill({ status: 204 }) | ||
| ) | ||
| await page.route('**/api/billing/status', (route) => | ||
| route.fulfill(jsonRoute(ENDED_STANDARD_BILLING_STATUS)) | ||
| ) | ||
| await page.route('**/api/billing/balance', (route) => | ||
| route.fulfill(jsonRoute(EMPTY_BILLING_BALANCE)) | ||
| ) | ||
| await page.route('**/api/billing/plans', (route) => | ||
| route.fulfill(jsonRoute(EMPTY_BILLING_PLANS)) | ||
| ) | ||
| await page.route('**/api/billing/capabilities', (route) => | ||
| route.fulfill(jsonRoute(createBillingCapabilities(workspaceId))) | ||
| ) | ||
| await page.route('**/api/experiment/models', (route) => | ||
| route.fulfill(jsonRoute([])) | ||
| ) | ||
| await page.route('**/api/agent/threads?*', (route) => | ||
| route.fulfill(jsonRoute(emptyAgentThreadList())) | ||
| ) | ||
| await page.route('**/api/agent/run-mode', (route) => | ||
| route.fulfill(jsonRoute(runMode)) | ||
| ) | ||
| await page.route('**/api/agent/identity', (route) => { | ||
| const token = route | ||
| .request() | ||
| .headers() | ||
| ['authorization']?.replace(/^Bearer /, '') | ||
| const identityWorkspace = WORKSPACE_SWITCHER_WORKSPACES.find( | ||
| ({ id }) => token === `mock-workspace-token-${id}` | ||
| ) | ||
| if (!identityWorkspace) { | ||
| return route.fulfill({ status: 401 }) | ||
| } | ||
| reads.push({ workspaceId: identityWorkspace.id }) | ||
| const identity: AgentIdentity = { | ||
| workspace_id: identityWorkspace.id, | ||
| user_id: 'uid-1' | ||
| } | ||
| return route.fulfill(jsonRoute(identity)) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| await use(reads) | ||
| }, | ||
| agentPanel: async ({ page }, use) => { | ||
| await use(new AgentPanel(page)) | ||
| } | ||
| }) |
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.
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.