From 2b0b613775f28bbddbcedad014b40742a915ee6c Mon Sep 17 00:00:00 2001 From: Louis Johnston Date: Thu, 19 Nov 2026 09:04:33 +0000 Subject: [PATCH 1/3] Invite signed-in users to try the version 3 pre-release, once Co-authored-by: Isaac --- packages/databricks-vscode/src/extension.ts | 9 + .../PreReleaseInvitationManager.test.ts | 315 ++++++++++++++++++ .../PreReleaseInvitationManager.ts | 158 +++++++++ .../src/telemetry/constants.ts | 18 + .../src/vscode-objs/StateStorage.ts | 6 + 5 files changed, 506 insertions(+) create mode 100644 packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts create mode 100644 packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts diff --git a/packages/databricks-vscode/src/extension.ts b/packages/databricks-vscode/src/extension.ts index 76f5ed26f..56987c357 100644 --- a/packages/databricks-vscode/src/extension.ts +++ b/packages/databricks-vscode/src/extension.ts @@ -48,6 +48,7 @@ import { } from "./workspace-fs"; import {CustomWhenContext} from "./vscode-objs/CustomWhenContext"; import {StateStorage} from "./vscode-objs/StateStorage"; +import {PreReleaseInvitationManager} from "./prerelease-invitation/PreReleaseInvitationManager"; import path from "node:path"; import {existsSync} from "node:fs"; import {FeatureId, FeatureManager} from "./feature-manager/FeatureManager"; @@ -1124,6 +1125,14 @@ export async function activate( }) ); + // Offers the version 3 pre-release once the bundle connection is up. + const preReleaseInvitation = new PreReleaseInvitationManager( + connectionManager, + stateStorage, + telemetry + ); + context.subscriptions.push(preReleaseInvitation); + const metadataService = await connectionManager.startMetadataService(); context.subscriptions.push(metadataService); diff --git a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts new file mode 100644 index 000000000..789e7c967 --- /dev/null +++ b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts @@ -0,0 +1,315 @@ +import assert from "assert"; +import FakeTimers from "@sinonjs/fake-timers"; +import { + EventEmitter, + ExtensionContext, + Memento, + commands, + env, + window, +} from "vscode"; +import type {ConnectionState} from "../configuration/models/WorkspaceConnectionModel"; +import type {Telemetry} from "../telemetry"; +import {StateStorage} from "../vscode-objs/StateStorage"; +import { + PreReleaseInvitationManager, + SHOW_DELAY_MS, + isInvitationHost, +} from "./PreReleaseInvitationManager"; + +const SWITCH = "Switch to Pre-Release"; +const RELOAD = "Reload Window"; +const RELEASE_NOTES = "Release notes"; + +// Replaces a VS Code API function for one test. ts-mockito can't stub the +// vscode namespace, so swap the functions, as the other tests do. +const restores: Array<() => void> = []; +function stub(target: T, key: keyof T & string, fn: unknown) { + const original = target[key]; + Object.assign(target, {[key]: fn}); + restores.push(() => Object.assign(target, {[key]: original})); +} + +// For a getter-only property such as env.uriScheme. +function stubGetter( + target: T, + key: keyof T & string, + value: unknown +) { + const original = Object.getOwnPropertyDescriptor(target, key); + Object.defineProperty(target, key, {value, configurable: true}); + restores.push(() => { + if (original) { + Object.defineProperty(target, key, original); + } + }); +} + +function createStorage() { + const store = new Map(); + const memento = { + keys: () => [...store.keys()], + get: (key: string, defaultValue?: T) => + (store.has(key) ? store.get(key) : defaultValue) as T, + update: async (key: string, value: unknown) => { + if (value === undefined) { + store.delete(key); + } else { + store.set(key, value); + } + }, + } as Memento; + return new StateStorage({ + globalState: memento, + workspaceState: memento, + } as unknown as ExtensionContext); +} + +function createConnection(state: ConnectionState) { + const emitter = new EventEmitter(); + const connection = { + state, + onDidChangeState: emitter.event, + change(next: ConnectionState) { + connection.state = next; + emitter.fire(next); + }, + }; + return connection; +} + +const managers: PreReleaseInvitationManager[] = []; + +/** + * A manager whose prompts answer from `answers` in order. The VS Code test + * host runs 1.138 locally, so the host check passes without stubbing. + */ +function setUp( + options: { + answers?: Array; + connected?: boolean; + switchError?: Error; + } = {} +) { + const storage = createStorage(); + const answers = [...(options.answers ?? [])]; + const prompts: string[] = []; + const errors: string[] = []; + const commandCalls: unknown[][] = []; + const recorded: unknown[] = []; + + stub(window, "showInformationMessage", async (message: string) => { + prompts.push(message); + return answers.shift(); + }); + stub(window, "showErrorMessage", async (message: string) => { + errors.push(message); + }); + stub(env, "openExternal", async () => true); + stub(commands, "executeCommand", async (...args: unknown[]) => { + commandCalls.push(args); + if ( + args[0] === "workbench.extensions.installExtension" && + options.switchError + ) { + throw options.switchError; + } + }); + + const connection = createConnection( + options.connected === false ? "DISCONNECTED" : "CONNECTED" + ); + const telemetry: Pick = { + recordEvent: (_name, props) => { + recorded.push(props); + }, + }; + const manager = new PreReleaseInvitationManager( + connection, + storage, + telemetry + ); + managers.push(manager); + return { + manager, + connection, + storage, + prompts, + errors, + commandCalls, + recorded, + }; +} + +describe("PreReleaseInvitation host rules", () => { + const local = { + uriScheme: "vscode", + remoteName: undefined, + vscodeVersion: "1.128.0", + }; + + it("allows local VS Code 1.128.0 and later, Insiders included", () => { + assert.ok(isInvitationHost(local)); + assert.ok(isInvitationHost({...local, vscodeVersion: "1.146.0"})); + assert.ok( + isInvitationHost({ + uriScheme: "vscode-insiders", + remoteName: undefined, + vscodeVersion: "1.128.0-insider", + }) + ); + }); + + it("rejects forks, remote windows, older VS Code and unreadable versions", () => { + assert.ok(!isInvitationHost({...local, uriScheme: "cursor"})); + assert.ok(!isInvitationHost({...local, remoteName: "ssh-remote"})); + assert.ok(!isInvitationHost({...local, vscodeVersion: "1.127.9"})); + assert.ok(!isInvitationHost({...local, vscodeVersion: "unknown"})); + }); +}); + +describe("PreReleaseInvitationManager", () => { + let clock: FakeTimers.Clock; + beforeEach(() => { + // Timeouts and Date only: the other timers stay real for the storage writes. + clock = FakeTimers.install({ + toFake: ["setTimeout", "clearTimeout", "Date"], + shouldClearNativeTimers: true, + now: Date.UTC(2026, 10, 18), + }); + }); + afterEach(() => { + // Dispose while the fake clock is still installed, so no real timer is left armed. + managers.splice(0).forEach((m) => m.dispose()); + // Undo the stubs in reverse, so a key stubbed twice ends on its original value. + restores + .splice(0) + .reverse() + .forEach((restore) => restore()); + clock.uninstall(); + }); + + // Advances the fake clock, then lets the awaited storage writes settle. + async function elapse(ms: number) { + await clock.tickAsync(ms); + await new Promise((r) => setImmediate(r)); + } + + it("shows the invitation only after the connection has been up for the delay", async () => { + const {connection, prompts, recorded} = setUp({ + connected: false, + answers: [undefined], + }); + connection.change("CONNECTED"); + await elapse(SHOW_DELAY_MS - 1); + assert.strictEqual(prompts.length, 0, "shown before the delay"); + await elapse(1); + assert.strictEqual(prompts.length, 1); + assert.deepStrictEqual(recorded, [ + {answer: "shown"}, + {answer: "dismissed"}, + ]); + }); + + it("is cancelled if the connection drops within the delay", async () => { + const {connection, prompts} = setUp(); + await elapse(SHOW_DELAY_MS / 2); + connection.change("DISCONNECTED"); + await elapse(SHOW_DELAY_MS); + assert.strictEqual(prompts.length, 0); + }); + + it("dispose cancels a pending showing", async () => { + const {manager, prompts} = setUp(); + manager.dispose(); + await elapse(SHOW_DELAY_MS); + assert.strictEqual(prompts.length, 0); + }); + + it("is not shown in a fork", async () => { + stubGetter(env, "uriScheme", "cursor"); + const {manager, prompts} = setUp(); + await manager.showIfDue(); + assert.strictEqual(prompts.length, 0); + }); + + it("is not shown in a remote window", async () => { + stubGetter(env, "remoteName", "ssh-remote"); + const {manager, prompts} = setUp(); + await manager.showIfDue(); + assert.strictEqual(prompts.length, 0); + }); + + it("does not show again once shown, whatever the answer", async () => { + const {manager, prompts, storage} = setUp({ + answers: [undefined], + }); + await manager.showIfDue(); + await manager.showIfDue(); + assert.strictEqual(prompts.length, 1); + assert.strictEqual( + await storage.get("databricks.prereleaseInvitation.shown"), + true + ); + }); + + it("is not offered from 2026-12-03 (UTC)", async () => { + const before = setUp({answers: [undefined]}); + clock.setSystemTime(Date.UTC(2026, 11, 2, 23, 59)); + await before.manager.showIfDue(); + assert.strictEqual(before.prompts.length, 1); + + const after = setUp({answers: [undefined]}); + clock.setSystemTime(Date.UTC(2026, 11, 3)); + await after.manager.showIfDue(); + assert.strictEqual(after.prompts.length, 0); + }); + + it("switches to the pre-release and reloads on Reload Window", async () => { + const {manager, commandCalls, recorded} = setUp({ + answers: [SWITCH, RELOAD], + }); + await manager.showIfDue(); + assert.deepStrictEqual(commandCalls, [ + [ + "workbench.extensions.installExtension", + "databricks.databricks", + {installPreReleaseVersion: true}, + ], + ["workbench.action.reloadWindow"], + ]); + assert.deepStrictEqual(recorded, [ + {answer: "shown"}, + {answer: "switch"}, + ]); + }); + + it("does not reload when the reload prompt is closed", async () => { + const {manager, prompts, commandCalls} = setUp({ + answers: [SWITCH, undefined], + }); + await manager.showIfDue(); + assert.strictEqual(prompts.length, 2, "invitation and reload prompt"); + assert.strictEqual(commandCalls.length, 1); + }); + + it("shows a generic error and records a failed switch", async () => { + const {manager, errors, prompts, recorded} = setUp({ + answers: [SWITCH], + switchError: new Error("gallery unreachable"), + }); + await manager.showIfDue(); + assert.strictEqual(errors.length, 1); + assert.ok(!errors[0].includes("gallery unreachable")); + assert.strictEqual(prompts.length, 1, "no reload prompt"); + assert.deepStrictEqual(recorded.at(-1), {answer: "switchFailed"}); + }); + + it("opens the release notes", async () => { + const {manager, recorded} = setUp({ + answers: [RELEASE_NOTES], + }); + await manager.showIfDue(); + assert.deepStrictEqual(recorded.at(-1), {answer: "releaseNotes"}); + }); +}); diff --git a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts new file mode 100644 index 000000000..730d0b8fd --- /dev/null +++ b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts @@ -0,0 +1,158 @@ +import * as semver from "semver"; +import {commands, env, version as vscodeVersion, window} from "vscode"; +import type {Disposable} from "vscode"; +import {logging} from "@databricks/sdk-experimental"; +import type {ConnectionManager} from "../configuration/ConnectionManager"; +import {Loggers} from "../logger"; +import type {Telemetry} from "../telemetry"; +import {Events} from "../telemetry/constants"; +import type {PreReleaseInvitationAnswer} from "../telemetry/constants"; +import type {StateStorage} from "../vscode-objs/StateStorage"; +import {UrlUtils} from "../utils"; + +const logger = logging.NamedLogger.getOrCreate(Loggers.Extension); +const EXTENSION_ID = "databricks.databricks"; +// Lets a sign-in or another prompt settle before this one appears. +export const SHOW_DELAY_MS = 5000; +// Not offered from 2026-12-03 (UTC). +const OFFERED_UNTIL = Date.UTC(2026, 11, 3); +// Version 3 needs VS Code's engine 1.128.0. +const MIN_VSCODE_VERSION = "1.128.0"; +// Forks (Cursor, VSCodium, ...) have their own URI schemes and no version 3. +const VS_CODE_URI_SCHEMES = ["vscode", "vscode-insiders"]; + +const SWITCH = "Switch to Pre-Release"; +const RELEASE_NOTES = "Release notes"; +const RELOAD_WINDOW = "Reload Window"; +const RELEASE_NOTES_URL = + "https://github.com/databricks/databricks-vscode/blob/release-v3.1.0/packages/databricks-vscode/CHANGELOG.md"; + +export function isInvitationHost(host: { + uriScheme: string; + remoteName: string | undefined; + vscodeVersion: string; +}): boolean { + // coerce drops a build suffix such as "-insider". + const version = semver.coerce(host.vscodeVersion); + return ( + host.remoteName === undefined && + VS_CODE_URI_SCHEMES.includes(host.uriScheme) && + version !== null && + semver.gte(version, MIN_VSCODE_VERSION) + ); +} + +/** + * Offers the version 3 pre-release to signed-in users of local VS Code, once + * the bundle connection is up. Shown once, whatever the answer. + */ +export class PreReleaseInvitationManager implements Disposable { + private readonly subscription: Disposable; + private timer?: ReturnType; + + constructor( + private readonly connection: Pick< + ConnectionManager, + "state" | "onDidChangeState" + >, + private readonly stateStorage: Pick, + private readonly telemetry: Pick + ) { + this.subscription = connection.onDidChangeState((state) => + this.onState(state) + ); + this.onState(connection.state); + } + + private onState(state: string) { + clearTimeout(this.timer); + this.timer = + state === "CONNECTED" + ? setTimeout(() => { + this.showIfDue().catch((e) => + logger.error( + "Failed to show the pre-release invitation", + e + ) + ); + }, SHOW_DELAY_MS) + : undefined; + } + + async showIfDue(): Promise { + if ( + this.connection.state !== "CONNECTED" || + !isInvitationHost({ + uriScheme: env.uriScheme, + remoteName: env.remoteName, + vscodeVersion, + }) || + Date.now() >= OFFERED_UNTIL || + this.stateStorage.get("databricks.prereleaseInvitation.shown") + ) { + return; + } + // Saved before the prompt, so closing it still counts as the showing. + await this.stateStorage.set( + "databricks.prereleaseInvitation.shown", + true + ); + // Shown once, so the connection no longer matters. + this.subscription.dispose(); + this.record("shown"); + + const choice = await window.showInformationMessage( + "Try the version 3 pre-release of the Databricks extension? It adds Unity Gateway models in VS Code Chat and a redesigned sidebar. You can switch back to version 2 anytime.", + SWITCH, + RELEASE_NOTES + ); + switch (choice) { + case SWITCH: + await this.switchToPreRelease(); + return; + case RELEASE_NOTES: + this.record("releaseNotes"); + await UrlUtils.openExternal(RELEASE_NOTES_URL); + return; + default: + this.record("dismissed"); + } + } + + private async switchToPreRelease() { + try { + await commands.executeCommand( + "workbench.extensions.installExtension", + EXTENSION_ID, + {installPreReleaseVersion: true} + ); + } catch (e) { + logger.error( + "Failed to switch to the pre-release of the Databricks extension", + e + ); + this.record("switchFailed"); + await window.showErrorMessage( + "Couldn't switch to the pre-release of the Databricks extension. See the Databricks Logs for details." + ); + return; + } + this.record("switch"); + const choice = await window.showInformationMessage( + "Reload the window to finish switching to version 3.", + RELOAD_WINDOW + ); + if (choice === RELOAD_WINDOW) { + await commands.executeCommand("workbench.action.reloadWindow"); + } + } + + private record(answer: PreReleaseInvitationAnswer) { + this.telemetry.recordEvent(Events.PRERELEASE_INVITATION, {answer}); + } + + dispose() { + clearTimeout(this.timer); + this.subscription.dispose(); + } +} diff --git a/packages/databricks-vscode/src/telemetry/constants.ts b/packages/databricks-vscode/src/telemetry/constants.ts index 703d6bc1b..7f203dd60 100644 --- a/packages/databricks-vscode/src/telemetry/constants.ts +++ b/packages/databricks-vscode/src/telemetry/constants.ts @@ -36,6 +36,7 @@ export enum Events { AITOOLS_UNINSTALL = "aitoolsUninstall", AITOOLS_CURSOR_PLUGIN_PROMPT = "aitoolsCursorPluginPrompt", AITOOLS_COPILOT_CLI_INSTALL = "aitoolsCopilotCliInstall", + PRERELEASE_INVITATION = "prereleaseInvitation", } /* eslint-enable @typescript-eslint/naming-convention */ @@ -56,6 +57,13 @@ export type LaunchType = "run" | "debug"; export type ComputeType = "cluster" | "serverless"; export type AiToolsScope = "project" | "global"; +export type PreReleaseInvitationAnswer = + | "shown" + | "switch" + | "switchFailed" + | "releaseNotes" + | "dismissed"; + /** * Where an AI tools install was triggered from: the first-load init modal prompt * or the manual affordance in the configuration side pane. @@ -470,6 +478,16 @@ export class EventTypes { "true if GitHub Copilot CLI was usable once the installer terminal closed", }, }; + [Events.PRERELEASE_INVITATION]: EventType<{ + answer: PreReleaseInvitationAnswer; + }> = { + comment: + "The one-time invitation to try the version 3 pre-release, shown to signed-in users of local VS Code.", + answer: { + comment: + "'shown', then 'switch' or 'switchFailed', 'releaseNotes', or 'dismissed' (closed)", + }, + }; [Events.PYTHON_ENV_SETUP_DETECTED]: EventType<{ managersDetected: PackageManager[]; primaryManager: PrimaryManager; diff --git a/packages/databricks-vscode/src/vscode-objs/StateStorage.ts b/packages/databricks-vscode/src/vscode-objs/StateStorage.ts index 50f6c1dad..e463c683c 100644 --- a/packages/databricks-vscode/src/vscode-objs/StateStorage.ts +++ b/packages/databricks-vscode/src/vscode-objs/StateStorage.ts @@ -125,6 +125,12 @@ const StorageConfigurations = { defaultValue: false, }), + // Set once the version 3 pre-release invitation has been shown. + "databricks.prereleaseInvitation.shown": withType()({ + location: "global", + defaultValue: false, + }), + // The ~/.databrickscfg profile of the Unity Gateway sign-in, with its host // and workspace id. Global because that sign-in is per user, separate from // each project's bundle sign-in. Both are checked on restore, since the From e7ba5901789120455af1ce532054e5db231ff5c7 Mon Sep 17 00:00:00 2001 From: Louis Johnston Date: Thu, 19 Nov 2026 12:18:02 +0000 Subject: [PATCH 2/3] Use VS Code wording in the pre-release invitation Co-authored-by: Isaac --- .../PreReleaseInvitationManager.test.ts | 4 ++-- .../prerelease-invitation/PreReleaseInvitationManager.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts index 789e7c967..ac236e359 100644 --- a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts +++ b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.test.ts @@ -17,9 +17,9 @@ import { isInvitationHost, } from "./PreReleaseInvitationManager"; -const SWITCH = "Switch to Pre-Release"; +const SWITCH = "Switch to Pre-Release Version"; const RELOAD = "Reload Window"; -const RELEASE_NOTES = "Release notes"; +const RELEASE_NOTES = "Release Notes"; // Replaces a VS Code API function for one test. ts-mockito can't stub the // vscode namespace, so swap the functions, as the other tests do. diff --git a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts index 730d0b8fd..f34df2e08 100644 --- a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts +++ b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts @@ -21,8 +21,8 @@ const MIN_VSCODE_VERSION = "1.128.0"; // Forks (Cursor, VSCodium, ...) have their own URI schemes and no version 3. const VS_CODE_URI_SCHEMES = ["vscode", "vscode-insiders"]; -const SWITCH = "Switch to Pre-Release"; -const RELEASE_NOTES = "Release notes"; +const SWITCH = "Switch to Pre-Release Version"; +const RELEASE_NOTES = "Release Notes"; const RELOAD_WINDOW = "Reload Window"; const RELEASE_NOTES_URL = "https://github.com/databricks/databricks-vscode/blob/release-v3.1.0/packages/databricks-vscode/CHANGELOG.md"; @@ -102,7 +102,7 @@ export class PreReleaseInvitationManager implements Disposable { this.record("shown"); const choice = await window.showInformationMessage( - "Try the version 3 pre-release of the Databricks extension? It adds Unity Gateway models in VS Code Chat and a redesigned sidebar. You can switch back to version 2 anytime.", + "Version 3 of the Databricks extension is available as a pre-release, with Unity Gateway models in VS Code Chat and a redesigned sidebar. You can switch back to version 2 at any time.", SWITCH, RELEASE_NOTES ); From f7b171befa6e86988928b9db69197749835b24e3 Mon Sep 17 00:00:00 2001 From: Louis Johnston Date: Thu, 19 Nov 2026 14:02:33 +0000 Subject: [PATCH 3/3] Shorten the pre-release invitation text Co-authored-by: Isaac --- .../src/prerelease-invitation/PreReleaseInvitationManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts index f34df2e08..cb27888d4 100644 --- a/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts +++ b/packages/databricks-vscode/src/prerelease-invitation/PreReleaseInvitationManager.ts @@ -102,7 +102,7 @@ export class PreReleaseInvitationManager implements Disposable { this.record("shown"); const choice = await window.showInformationMessage( - "Version 3 of the Databricks extension is available as a pre-release, with Unity Gateway models in VS Code Chat and a redesigned sidebar. You can switch back to version 2 at any time.", + "Try v3 of the Databricks extension as a pre-release. Access Unity Gateway models in VS Code Chat and a redesigned sidebar. You can switch back to v2 anytime.", SWITCH, RELEASE_NOTES );