From a81d2ab38c1b017f6634f85bfaa496a0688f569a Mon Sep 17 00:00:00 2001 From: Bowen Song Date: Wed, 15 Jan 2025 14:12:44 +0800 Subject: [PATCH] perf(auth): add command for add auth in vsc (#13053) --- packages/vscode-extension/package.json | 5 +++++ packages/vscode-extension/package.nls.json | 1 + packages/vscode-extension/src/extension.ts | 7 +++++++ .../src/handlers/lifecycleHandlers.ts | 6 ++++++ .../src/handlers/sharedOpts.ts | 4 ++++ .../src/telemetry/extTelemetry.ts | 2 ++ .../src/telemetry/extTelemetryEvents.ts | 3 +++ .../test/handlers/lifecycleHandlers.test.ts | 18 ++++++++++++++++++ .../vscode-extension/test/mocks/mockCore.ts | 4 ++++ 9 files changed, 50 insertions(+) diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index ab22d4fca0..972ea0b166 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -958,6 +958,11 @@ "command": "fx-extension.findSimilarIssue", "title": "%teamstoolkit.handlers.similarIssues%", "category": "Teams" + }, + { + "command": "fx-extension.addAuthAction", + "title": "%teamstoolkit.commands.addAuthAction%", + "category": "Teams" } ], "taskDefinitions": [ diff --git a/packages/vscode-extension/package.nls.json b/packages/vscode-extension/package.nls.json index 340ab7cd4a..3c4924630d 100644 --- a/packages/vscode-extension/package.nls.json +++ b/packages/vscode-extension/package.nls.json @@ -206,6 +206,7 @@ "teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugTitle": "Stop Previewing Your Office Add-in", "teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugDescription": "Stop debugging the Office Add-in project", "teamstoolkit.commandsTreeViewProvider.syncManifest": "Sync Manifest", + "teamstoolkit.commands.addAuthAction": "Add Configurations to Support Actions with Authentication in Declarative Agent", "teamstoolkit.common.readMore": "Read more", "teamstoolkit.common.signin": "Sign in", "teamstoolkit.common.signout": "Sign out", diff --git a/packages/vscode-extension/src/extension.ts b/packages/vscode-extension/src/extension.ts index 9607768a36..2041567363 100644 --- a/packages/vscode-extension/src/extension.ts +++ b/packages/vscode-extension/src/extension.ts @@ -115,6 +115,7 @@ import { refreshEnvironment, } from "./handlers/envHandlers"; import { + addAuthActionHandler, addPluginHandler, addWebpartHandler, copilotPluginAddAPIHandler, @@ -727,6 +728,12 @@ function registerTeamsFxCommands(context: vscode.ExtensionContext) { if (featureFlagManager.getBooleanValue(FeatureFlags.SyncManifest)) { registerInCommandController(context, "fx-extension.syncManifest", syncManifestHandler); } + + const addAuthActionCmd = vscode.commands.registerCommand( + "fx-extension.addAuthAction", + (...args) => Correlator.run(addAuthActionHandler, args) + ); + context.subscriptions.push(addAuthActionCmd); } /** diff --git a/packages/vscode-extension/src/handlers/lifecycleHandlers.ts b/packages/vscode-extension/src/handlers/lifecycleHandlers.ts index eb885ce3b6..06746cd169 100644 --- a/packages/vscode-extension/src/handlers/lifecycleHandlers.ts +++ b/packages/vscode-extension/src/handlers/lifecycleHandlers.ts @@ -252,6 +252,12 @@ export async function copilotPluginAddAPIHandler(args: any[]) { return result; } +export async function addAuthActionHandler(...args: unknown[]) { + ExtTelemetry.sendTelemetryEvent(TelemetryEvent.AddAuthActionStart, getTriggerFromProperty(args)); + const inputs = getSystemInputs(); + return await runCommand(Stage.addAuthAction, inputs); +} + function handleTriggerKiotaCommand( args: any[], result: any, diff --git a/packages/vscode-extension/src/handlers/sharedOpts.ts b/packages/vscode-extension/src/handlers/sharedOpts.ts index 9a2d37239d..f9fcc99547 100644 --- a/packages/vscode-extension/src/handlers/sharedOpts.ts +++ b/packages/vscode-extension/src/handlers/sharedOpts.ts @@ -130,6 +130,10 @@ export async function runCommand( result = await core.kiotaRegenerate(inputs); break; } + case Stage.addAuthAction: { + result = await core.addAuthAction(inputs); + break; + } default: throw new SystemError( ExtensionSource, diff --git a/packages/vscode-extension/src/telemetry/extTelemetry.ts b/packages/vscode-extension/src/telemetry/extTelemetry.ts index a28857a69c..e7e6e7365c 100644 --- a/packages/vscode-extension/src/telemetry/extTelemetry.ts +++ b/packages/vscode-extension/src/telemetry/extTelemetry.ts @@ -82,6 +82,8 @@ export namespace ExtTelemetry { return TelemetryEvent.SyncManifest; case Stage.addPlugin: return TelemetryEvent.AddPlugin; + case Stage.addAuthAction: + return TelemetryEvent.AddAuthAction; default: return undefined; } diff --git a/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts b/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts index 5410c13499..225d94f80b 100644 --- a/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts +++ b/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts @@ -317,6 +317,9 @@ export enum TelemetryEvent { KiotaRegenerateStart = "kiota-regenerate-start", KiotaRegenerate = "kiota-regenerate", + + AddAuthActionStart = "add-auth-action-start", + AddAuthAction = "add-auth-action", } export enum TelemetryProperty { diff --git a/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts b/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts index 100c683100..fb3d397daa 100644 --- a/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts +++ b/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts @@ -14,6 +14,7 @@ import * as vscode from "vscode"; import * as globalVariables from "../../src/globalVariables"; import * as copilotHandler from "../../src/handlers/copilotChatHandlers"; import { + addAuthActionHandler, addPluginHandler, addWebpartHandler, copilotPluginAddAPIHandler, @@ -588,4 +589,21 @@ describe("Lifecycle handlers", () => { mockedEnvRestore(); }); }); + + describe("AddAuthActionHandler", async () => { + const sandbox = sinon.createSandbox(); + + afterEach(() => { + sandbox.restore(); + }); + + it("happy path", async () => { + sandbox.stub(globalVariables, "core").value(new MockCore()); + const addPluginHanlder = sandbox.spy(globalVariables.core, "addAuthAction"); + + await addAuthActionHandler(); + + sinon.assert.calledOnce(addPluginHanlder); + }); + }); }); diff --git a/packages/vscode-extension/test/mocks/mockCore.ts b/packages/vscode-extension/test/mocks/mockCore.ts index f4a8fe5453..e97422cb6b 100644 --- a/packages/vscode-extension/test/mocks/mockCore.ts +++ b/packages/vscode-extension/test/mocks/mockCore.ts @@ -163,4 +163,8 @@ export class MockCore { async kiotaRegenerate(inputs: Inputs): Promise> { return ok(undefined); } + + async addAuthAction(inputs: Inputs): Promise> { + return ok(undefined); + } }