Repository navigation
fix(web): refresh T3 Connect switch after startup reconcile #7193
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5865f5c
fix(web): refresh T3 Connect switch after startup reconcile
maslinedwin 4253c5a
fix(web): bound T3 Connect refresh and keep onboarding from downgrading
maslinedwin 33cf2df
fix(web): skip onboarding reconcile when both Connect toggles are off
maslinedwin ee96d97
fix(web): scope onboarding tunnel bit and keep switches clickable
maslinedwin 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,136 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| resolveOnboardingManagedTunnelActive, | ||
| resolveOnboardingReconcileDesired, | ||
| shouldSyncOnboardingToggleFromLinkState, | ||
| } from "./connectOnboarding"; | ||
|
|
||
| describe("shouldSyncOnboardingToggleFromLinkState", () => { | ||
| it("resyncs an untouched toggle for the account being onboarded", () => { | ||
| expect( | ||
| shouldSyncOnboardingToggleFromLinkState({ | ||
| touched: false, | ||
| openForAccount: "user-1", | ||
| linked: true, | ||
| cloudUserId: "user-1", | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("does not overwrite a toggle the user has already changed", () => { | ||
| expect( | ||
| shouldSyncOnboardingToggleFromLinkState({ | ||
| touched: true, | ||
| openForAccount: "user-1", | ||
| linked: true, | ||
| cloudUserId: "user-1", | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("ignores link state from another account", () => { | ||
| expect( | ||
| shouldSyncOnboardingToggleFromLinkState({ | ||
| touched: false, | ||
| openForAccount: "user-1", | ||
| linked: true, | ||
| cloudUserId: "user-2", | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("does not sync when the wizard is closed or the environment is unlinked", () => { | ||
| expect( | ||
| shouldSyncOnboardingToggleFromLinkState({ | ||
| touched: false, | ||
| openForAccount: null, | ||
| linked: true, | ||
| cloudUserId: "user-1", | ||
| }), | ||
| ).toBe(false); | ||
| expect( | ||
| shouldSyncOnboardingToggleFromLinkState({ | ||
| touched: false, | ||
| openForAccount: "user-1", | ||
| linked: false, | ||
| cloudUserId: "user-1", | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveOnboardingManagedTunnelActive", () => { | ||
| it("uses the current tunnel only when the cached link belongs to this account", () => { | ||
| expect( | ||
| resolveOnboardingManagedTunnelActive({ | ||
| managedTunnelActive: true, | ||
| cloudUserId: "user-1", | ||
| openForAccount: "user-1", | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("ignores a previous account's active tunnel after an account switch", () => { | ||
| expect( | ||
| resolveOnboardingManagedTunnelActive({ | ||
| managedTunnelActive: true, | ||
| cloudUserId: "user-1", | ||
| openForAccount: "user-2", | ||
| }), | ||
| ).toBe(false); | ||
| expect( | ||
| resolveOnboardingReconcileDesired({ | ||
| exposeEnvironment: false, | ||
| publishAgentActivity: true, | ||
| managedTunnelActive: resolveOnboardingManagedTunnelActive({ | ||
| managedTunnelActive: true, | ||
| cloudUserId: "user-1", | ||
| openForAccount: "user-2", | ||
| }), | ||
| }), | ||
| ).toEqual({ managedTunnel: false, publish: true }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveOnboardingReconcileDesired", () => { | ||
| it("does not tear down an active tunnel after a stale inactive prefill", () => { | ||
| expect( | ||
| resolveOnboardingReconcileDesired({ | ||
| exposeEnvironment: false, | ||
| publishAgentActivity: true, | ||
| managedTunnelActive: true, | ||
| }), | ||
| ).toEqual({ managedTunnel: true, publish: true }); | ||
| }); | ||
|
|
||
| it("skips reconcile when nothing would be enabled", () => { | ||
| expect( | ||
| resolveOnboardingReconcileDesired({ | ||
| exposeEnvironment: false, | ||
| publishAgentActivity: false, | ||
| managedTunnelActive: false, | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("does not rewrite publish when both toggles are off and a tunnel is already active", () => { | ||
| expect( | ||
| resolveOnboardingReconcileDesired({ | ||
| exposeEnvironment: false, | ||
| publishAgentActivity: false, | ||
| managedTunnelActive: true, | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps an explicit request to enable the managed tunnel", () => { | ||
| expect( | ||
| resolveOnboardingReconcileDesired({ | ||
| exposeEnvironment: true, | ||
| publishAgentActivity: false, | ||
| managedTunnelActive: false, | ||
| }), | ||
| ).toEqual({ managedTunnel: true, publish: false }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import type { CloudLinkTarget } from "./linkEnvironment"; | ||
| import { | ||
| __resetStartupCloudLinkRefreshForTests, | ||
| CONNECTIONS_CLOUD_LINK_RETRY_BUDGET_MS, | ||
| resolveManagedTunnelActive, | ||
| scheduleStartupReconcileLinkStateRefresh, | ||
| shouldContinueConnectionsCloudLinkRetry, | ||
| STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS, | ||
| stopStartupReconcileLinkStateRefresh, | ||
| } from "./primaryCloudLinkState"; | ||
|
|
||
| const TARGET: CloudLinkTarget = { | ||
| environmentId: "environment-1", | ||
| label: "Desktop", | ||
| httpBaseUrl: "http://127.0.0.1:3000", | ||
| wsBaseUrl: "ws://127.0.0.1:3000", | ||
| }; | ||
|
|
||
| describe("resolveManagedTunnelActive", () => { | ||
| it("falls back to linked when older servers omit managedTunnelActive", () => { | ||
| expect(resolveManagedTunnelActive({ linked: true })).toBe(true); | ||
| expect(resolveManagedTunnelActive({ linked: false })).toBe(false); | ||
| }); | ||
|
|
||
| it("does not treat a publish-only or pre-reconcile link as an active tunnel", () => { | ||
| expect(resolveManagedTunnelActive({ linked: true, managedTunnelActive: false })).toBe(false); | ||
| }); | ||
|
|
||
| it("is inactive when link state has not loaded", () => { | ||
| expect(resolveManagedTunnelActive(null)).toBe(false); | ||
| expect(resolveManagedTunnelActive(undefined)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("shouldContinueConnectionsCloudLinkRetry", () => { | ||
| it("stops once the managed tunnel is active", () => { | ||
| expect(shouldContinueConnectionsCloudLinkRetry(0, true)).toBe(false); | ||
| }); | ||
|
|
||
| it("retries while inactive inside the budget and stops after it", () => { | ||
| expect(shouldContinueConnectionsCloudLinkRetry(0, false)).toBe(true); | ||
| expect( | ||
| shouldContinueConnectionsCloudLinkRetry(CONNECTIONS_CLOUD_LINK_RETRY_BUDGET_MS - 1, false), | ||
| ).toBe(true); | ||
| expect( | ||
| shouldContinueConnectionsCloudLinkRetry(CONNECTIONS_CLOUD_LINK_RETRY_BUDGET_MS, false), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("scheduleStartupReconcileLinkStateRefresh", () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| __resetStartupCloudLinkRefreshForTests(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| __resetStartupCloudLinkRefreshForTests(); | ||
| }); | ||
|
|
||
| it("replaces a startup-stale inactive switch across the bounded refresh series", () => { | ||
| let state: { linked: boolean; managedTunnelActive?: boolean } = { | ||
| linked: true, | ||
| managedTunnelActive: false, | ||
| }; | ||
| const refresh = vi.fn(() => { | ||
| if (refresh.mock.calls.length >= 2) { | ||
| state = { linked: true, managedTunnelActive: true }; | ||
| } | ||
| }); | ||
|
|
||
| expect(resolveManagedTunnelActive(state)).toBe(false); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(TARGET, refresh)).toBe(true); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(TARGET, refresh)).toBe(false); | ||
|
|
||
| vi.advanceTimersByTime(STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[0] - 1); | ||
| expect(refresh).not.toHaveBeenCalled(); | ||
| expect(resolveManagedTunnelActive(state)).toBe(false); | ||
|
|
||
| vi.advanceTimersByTime(1); | ||
| expect(refresh).toHaveBeenCalledTimes(1); | ||
| expect(resolveManagedTunnelActive(state)).toBe(false); | ||
|
|
||
| vi.advanceTimersByTime( | ||
| STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[1] - | ||
| STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[0], | ||
| ); | ||
| expect(refresh).toHaveBeenCalledTimes(2); | ||
| expect(resolveManagedTunnelActive(state)).toBe(true); | ||
|
|
||
| vi.advanceTimersByTime( | ||
| STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[2] - | ||
| STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[1], | ||
| ); | ||
| expect(refresh).toHaveBeenCalledTimes(3); | ||
| expect(refresh).toHaveBeenNthCalledWith(1, TARGET); | ||
| expect(refresh).toHaveBeenNthCalledWith(2, TARGET); | ||
| expect(refresh).toHaveBeenNthCalledWith(3, TARGET); | ||
| }); | ||
|
|
||
| it("cancels remaining startup refreshes once the tunnel is active", () => { | ||
| const refresh = vi.fn(); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(TARGET, refresh)).toBe(true); | ||
|
|
||
| vi.advanceTimersByTime(STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[0]); | ||
| expect(refresh).toHaveBeenCalledTimes(1); | ||
|
|
||
| stopStartupReconcileLinkStateRefresh(TARGET); | ||
| vi.advanceTimersByTime(STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[2]); | ||
| expect(refresh).toHaveBeenCalledTimes(1); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(TARGET, refresh)).toBe(false); | ||
| }); | ||
|
|
||
| it("does not schedule without a target", () => { | ||
| const refresh = vi.fn(); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(null, refresh)).toBe(false); | ||
| vi.advanceTimersByTime(STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[2]); | ||
| expect(refresh).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("schedules a separate follow-up for a different environment", () => { | ||
| const refresh = vi.fn(); | ||
| const otherTarget = { ...TARGET, environmentId: "environment-2" }; | ||
|
|
||
| expect(scheduleStartupReconcileLinkStateRefresh(TARGET, refresh)).toBe(true); | ||
| expect(scheduleStartupReconcileLinkStateRefresh(otherTarget, refresh)).toBe(true); | ||
|
|
||
| vi.advanceTimersByTime(STARTUP_CLOUD_LINK_RECONCILE_REFRESH_DELAYS_MS[0]); | ||
| expect(refresh).toHaveBeenCalledTimes(2); | ||
| expect(refresh).toHaveBeenNthCalledWith(1, TARGET); | ||
| expect(refresh).toHaveBeenNthCalledWith(2, otherTarget); | ||
| }); | ||
| }); |
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.