Repository navigation
fix(vscode): keep the saved Hub URL when you disconnect #3516
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
markscott-ms
merged 3 commits into
finos:main
from
tnalbant:fix/hub-url-kept-on-disconnect
Oct 27, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,151 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import * as vscode from 'vscode'; | ||
| import { activate, disconnectFromHub, hubMenuItems } from './extension'; | ||
|
|
||
| interface ConfigUpdate { | ||
| section: string; | ||
| key: string; | ||
| value: unknown; | ||
| } | ||
|
|
||
| type CommandCallback = (...args: unknown[]) => unknown; | ||
|
|
||
| const registeredCommands = new Map<string, CommandCallback>(); | ||
| const configUpdates: ConfigUpdate[] = []; | ||
|
|
||
| function context(): vscode.ExtensionContext { | ||
| return { | ||
| subscriptions: [], | ||
| extensionUri: vscode.Uri.file('/tmp/extension'), | ||
| secrets: { | ||
| get: async () => undefined, | ||
| store: async () => {}, | ||
| delete: async () => {}, | ||
| onDidChange: () => ({ dispose: () => {} }), | ||
| }, | ||
| } as unknown as vscode.ExtensionContext; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| registeredCommands.clear(); | ||
| configUpdates.length = 0; | ||
|
|
||
| (vscode.commands as unknown as { registerCommand: unknown }).registerCommand = ( | ||
| command: string, | ||
| callback: CommandCallback | ||
| ) => { | ||
| registeredCommands.set(command, callback); | ||
| return { dispose: () => {} }; | ||
| }; | ||
|
|
||
| (vscode.workspace as unknown as { getConfiguration: unknown }).getConfiguration = ( | ||
| section?: string | ||
| ) => ({ | ||
| get: <T>(key: string, defaultValue?: T): T | undefined => { | ||
| if (key === 'url') return 'https://calmhub.example.com' as unknown as T; | ||
| // Keep activate() from starting a real connectToHub in every test. | ||
| if (key === 'autoConnect') return false as unknown as T; | ||
| return defaultValue; | ||
| }, | ||
| update: async (key: string, value: unknown) => { | ||
| configUpdates.push({ section: section ?? '', key, value }); | ||
| }, | ||
| }); | ||
|
|
||
| activate(context()); | ||
| }); | ||
|
|
||
| describe('disconnecting from CALM Hub', () => { | ||
| it('keeps the saved URL so the status bar can reconnect', async () => { | ||
| await disconnectFromHub(); | ||
|
|
||
| expect(configUpdates).toEqual([]); | ||
| }); | ||
|
|
||
| it('keeps the saved URL when the disconnect command runs', async () => { | ||
| const disconnect = registeredCommands.get('calm.disconnectFromHub'); | ||
| expect(disconnect).toBeDefined(); | ||
|
|
||
| await disconnect!(); | ||
|
|
||
| expect(configUpdates).toEqual([]); | ||
| }); | ||
|
|
||
| it('forgets the saved URL only for Clear URL', async () => { | ||
| await disconnectFromHub({ clearUrl: true }); | ||
|
|
||
| expect(configUpdates).toEqual([ | ||
| { section: 'calm.hub', key: 'url', value: undefined }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('CALM Hub menu', () => { | ||
| it('offers Disconnect, and no Clear URL, while connected', () => { | ||
| expect(hubMenuItems('connected').map((item) => item.action)).toEqual([ | ||
| 'namespaces', | ||
| 'refresh', | ||
| 'change', | ||
| 'disconnect', | ||
| ]); | ||
| }); | ||
|
|
||
| it('offers Clear URL, and no Disconnect, after a failed connection', () => { | ||
| expect(hubMenuItems('error').map((item) => item.action)).toEqual([ | ||
| 'change', | ||
| 'retry', | ||
| 'clearUrl', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('the Clear URL menu item', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it('does not connect while autoConnect is off', async () => { | ||
| const fetchStub = vi.fn(); | ||
| vi.stubGlobal('fetch', fetchStub); | ||
|
|
||
| // The stub in beforeEach reports autoConnect: false, so activating the | ||
| // extension must not send a request of its own. | ||
| activate(context()); | ||
| // activate() starts auto-connect without awaiting it, so give that path | ||
| // the chance to reach the network before asserting it never did. | ||
| await new Promise((resolve) => setTimeout(resolve, 50)); | ||
|
|
||
| expect(fetchStub).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('forgets the saved URL when the status bar is in its error state', async () => { | ||
| // A failed connection leaves the status bar in its error state, which is | ||
| // the only state that offers "Clear URL". | ||
| const fetchStub = vi.fn().mockRejectedValue(new Error('offline')); | ||
| vi.stubGlobal('fetch', fetchStub); | ||
|
|
||
| const connect = registeredCommands.get('calm.connectToHub'); | ||
| expect(connect).toBeDefined(); | ||
|
|
||
| await connect!(); | ||
| expect(fetchStub).toHaveBeenCalled(); | ||
|
|
||
| const placeholders: string[] = []; | ||
| (vscode.window as unknown as { showQuickPick: unknown }).showQuickPick = async ( | ||
| items: vscode.QuickPickItem[] & { action?: string }[], | ||
| options?: vscode.QuickPickOptions | ||
| ) => { | ||
| placeholders.push(options?.placeHolder ?? ''); | ||
| return (items as unknown as { action: string }[]).find( | ||
| (item) => item.action === 'clearUrl' | ||
| ); | ||
| }; | ||
|
|
||
| await connect!(); | ||
|
|
||
| expect(placeholders[0]).toContain('Failed to connect'); | ||
| expect(configUpdates).toEqual([ | ||
| { section: 'calm.hub', key: 'url', value: undefined }, | ||
| ]); | ||
| }); | ||
| }); |
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.