From 71dc1abb2bc930e63dfc05e71ff47796d0d9a9e6 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Tue, 2 Jul 2024 16:39:07 +0800 Subject: [PATCH 01/19] test: add e2e test --- .../CopilotPluginWithOAuth.tests.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts new file mode 100644 index 0000000000..aab9975219 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +import { Capability } from "../../utils/constants"; +import { CaseFactory } from "../caseFactory"; +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; + +class CopilotPluginOAuthTestCase extends CaseFactory {} + +new CopilotPluginOAuthTestCase( + Capability.CopilotPluginFromScratch, + 27569691, + "huimiao@microsoft.com", + ["function"], + ProgrammingLanguage.TS, + {} +).test(); From 12d5895251d95f615218f3d8379746a3ca735ff2 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Tue, 2 Jul 2024 17:08:38 +0800 Subject: [PATCH 02/19] test: add e2e test --- .../src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index aab9975219..bdb89eb9eb 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -6,11 +6,15 @@ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; class CopilotPluginOAuthTestCase extends CaseFactory {} +const copilotPluginOAuth: Record = {}; +copilotPluginOAuth["api-auth"] = "oauth"; + new CopilotPluginOAuthTestCase( Capability.CopilotPluginFromScratch, 27569691, "huimiao@microsoft.com", ["function"], ProgrammingLanguage.TS, - {} + {}, + copilotPluginOAuth ).test(); From 38ca36c7faa40b13238a7ef12b10456e349ffc45 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Wed, 3 Jul 2024 10:41:16 +0800 Subject: [PATCH 03/19] test: e2e --- .../e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index bdb89eb9eb..80a9137170 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -4,7 +4,14 @@ import { Capability } from "../../utils/constants"; import { CaseFactory } from "../caseFactory"; import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -class CopilotPluginOAuthTestCase extends CaseFactory {} +class CopilotPluginOAuthTestCase extends CaseFactory { + public onBefore(): Promise { + const env = Object.assign({}, process.env); + env["API_COPILOT_PLUGIN"] = "true"; + env["DEVELOP_COPILOT_PLUGIN"] = "true"; + return Promise.resolve(); + } +} const copilotPluginOAuth: Record = {}; copilotPluginOAuth["api-auth"] = "oauth"; From 9f4ef2e0cb6f366bdc20b8c215239e8aa226def6 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Wed, 3 Jul 2024 11:27:17 +0800 Subject: [PATCH 04/19] test: e2e --- packages/tests/src/e2e/caseFactory.ts | 15 +++++++++++---- .../CopilotPluginWithOAuth.tests.ts | 16 +++++++--------- packages/tests/src/utils/executor.ts | 5 +++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/tests/src/e2e/caseFactory.ts b/packages/tests/src/e2e/caseFactory.ts index dfad962e82..2a17f1a8d0 100644 --- a/packages/tests/src/e2e/caseFactory.ts +++ b/packages/tests/src/e2e/caseFactory.ts @@ -53,6 +53,7 @@ export abstract class CaseFactory { skipPackage?: boolean; }; public custimized?: Record; + public processEnv?: NodeJS.ProcessEnv; public constructor( capability: Capability, @@ -75,7 +76,8 @@ export abstract class CaseFactory { skipValidate?: boolean; skipPackage?: boolean; } = {}, - custimized?: Record + custimized?: Record, + processEnv?: NodeJS.ProcessEnv ) { this.capability = capability; this.testPlanCaseId = testPlanCaseId; @@ -84,6 +86,7 @@ export abstract class CaseFactory { this.programmingLanguage = programmingLanguage; this.options = options; this.custimized = custimized; + this.processEnv = processEnv; } public onBefore(): Promise { @@ -103,14 +106,16 @@ export abstract class CaseFactory { testFolder: string, capability: Capability, programmingLanguage?: ProgrammingLanguage, - custimized?: Record + custimized?: Record, + processEnv?: NodeJS.ProcessEnv ): Promise { await Executor.createProject( testFolder, appName, capability, programmingLanguage ? programmingLanguage : ProgrammingLanguage.TS, - custimized + custimized, + processEnv ); } @@ -127,6 +132,7 @@ export abstract class CaseFactory { programmingLanguage, options, custimized, + processEnv, onBefore, onAfter, onAfterCreate, @@ -153,7 +159,8 @@ export abstract class CaseFactory { testFolder, capability, programmingLanguage, - custimized + custimized, + processEnv ); expect(fs.pathExistsSync(projectPath)).to.be.true; diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index 80a9137170..c9ef451533 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -4,18 +4,15 @@ import { Capability } from "../../utils/constants"; import { CaseFactory } from "../caseFactory"; import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -class CopilotPluginOAuthTestCase extends CaseFactory { - public onBefore(): Promise { - const env = Object.assign({}, process.env); - env["API_COPILOT_PLUGIN"] = "true"; - env["DEVELOP_COPILOT_PLUGIN"] = "true"; - return Promise.resolve(); - } -} +class CopilotPluginOAuthTestCase extends CaseFactory {} const copilotPluginOAuth: Record = {}; copilotPluginOAuth["api-auth"] = "oauth"; +const env = Object.assign({}, process.env); +env["API_COPILOT_PLUGIN"] = "true"; +env["DEVELOP_COPILOT_PLUGIN"] = "true"; + new CopilotPluginOAuthTestCase( Capability.CopilotPluginFromScratch, 27569691, @@ -23,5 +20,6 @@ new CopilotPluginOAuthTestCase( ["function"], ProgrammingLanguage.TS, {}, - copilotPluginOAuth + copilotPluginOAuth, + env ).test(); diff --git a/packages/tests/src/utils/executor.ts b/packages/tests/src/utils/executor.ts index 4212549ba1..23df2951a3 100644 --- a/packages/tests/src/utils/executor.ts +++ b/packages/tests/src/utils/executor.ts @@ -96,14 +96,15 @@ export class Executor { appName: string, capability: Capability, language: ProgrammingLanguage, - customized: Record = {} + customized: Record = {}, + processEnv?: NodeJS.ProcessEnv ) { const command = `teamsapp new --interactive false --app-name ${appName} --capability ${capability} --programming-language ${language} ` + Object.entries(customized) .map(([key, value]) => "--" + key + " " + value) .join(" "); - return this.execute(command, workspace); + return this.execute(command, workspace, processEnv); } static async addEnv(workspace: string, newEnv: string, env = "dev") { From 1e56315041913f2a77729351e5b562b46c010910 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Wed, 3 Jul 2024 13:06:22 +0800 Subject: [PATCH 05/19] test: e2e --- packages/tests/src/e2e/caseFactory.ts | 9 ++++++++- .../CopilotPluginWithOAuth.tests.ts | 6 +++++- packages/tests/src/utils/executor.ts | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/tests/src/e2e/caseFactory.ts b/packages/tests/src/e2e/caseFactory.ts index 2a17f1a8d0..e064c005a3 100644 --- a/packages/tests/src/e2e/caseFactory.ts +++ b/packages/tests/src/e2e/caseFactory.ts @@ -51,6 +51,7 @@ export abstract class CaseFactory { skipDeploy?: boolean; skipValidate?: boolean; skipPackage?: boolean; + skipErrorMessage?: string; }; public custimized?: Record; public processEnv?: NodeJS.ProcessEnv; @@ -75,6 +76,7 @@ export abstract class CaseFactory { skipDeploy?: boolean; skipValidate?: boolean; skipPackage?: boolean; + skipErrorMessage?: string; } = {}, custimized?: Record, processEnv?: NodeJS.ProcessEnv @@ -180,7 +182,12 @@ export abstract class CaseFactory { expect(result).to.be.true; process.env["AZURE_RESOURCE_GROUP_NAME"] = appName + "-rg"; - const { success } = await Executor.provision(projectPath); + const { success } = await Executor.provision( + projectPath, + "dev", + true, + options?.skipErrorMessage + ); expect(success).to.be.true; // Validate Provision diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index c9ef451533..9f486cb01f 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -13,13 +13,17 @@ const env = Object.assign({}, process.env); env["API_COPILOT_PLUGIN"] = "true"; env["DEVELOP_COPILOT_PLUGIN"] = "true"; +const options = { + skipErrorMessage: "No elements found in the manifest", +}; + new CopilotPluginOAuthTestCase( Capability.CopilotPluginFromScratch, 27569691, "huimiao@microsoft.com", ["function"], ProgrammingLanguage.TS, - {}, + options, copilotPluginOAuth, env ).test(); diff --git a/packages/tests/src/utils/executor.ts b/packages/tests/src/utils/executor.ts index 23df2951a3..28d5f9e345 100644 --- a/packages/tests/src/utils/executor.ts +++ b/packages/tests/src/utils/executor.ts @@ -153,8 +153,21 @@ export class Executor { ); } - static async provision(workspace: string, env = "dev", isV3 = true) { - return this.executeCmd(workspace, "provision", env, undefined, false, isV3); + static async provision( + workspace: string, + env = "dev", + isV3 = true, + skipErrorMessage?: string + ) { + return this.executeCmd( + workspace, + "provision", + env, + undefined, + false, + isV3, + skipErrorMessage + ); } static async provisionWithCustomizedProcessEnv( From 3862b4a9e6bbdff963c1c7171f97cfde62e7dcdb Mon Sep 17 00:00:00 2001 From: Yimin-Jin Date: Thu, 4 Jul 2024 15:46:34 +0800 Subject: [PATCH 06/19] test: fix executor skipErrorMessage logic --- packages/tests/src/utils/executor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/tests/src/utils/executor.ts b/packages/tests/src/utils/executor.ts index 28d5f9e345..7d034cef3f 100644 --- a/packages/tests/src/utils/executor.ts +++ b/packages/tests/src/utils/executor.ts @@ -52,6 +52,10 @@ export class Executor { return { success: true, ...result }; } } catch (e: any) { + if (skipErrorMessage && e.message.includes(skipErrorMessage)) { + console.log(`[Skip Warning] ${e.message}`); + return { success: true, ...e }; + } if (e.killed && e.signal == "SIGTERM") { console.error(`[Failed] "${command}" in ${cwd}. Timeout and killed.`); } else { From f8e8268777b0e6fb331b01bcad28b48f61dd2c1e Mon Sep 17 00:00:00 2001 From: Yimin-Jin Date: Fri, 5 Jul 2024 14:10:05 +0800 Subject: [PATCH 07/19] test: add none-auth&api-key auth e2e test --- .../CopilotPluginWithApiKey.tests.ts | 55 +++++++++++++++++++ .../CopilotPluginWithNoneAuth.tests.ts | 48 ++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts new file mode 100644 index 0000000000..3fedaeb26c --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { Capability } from "../../utils/constants"; +import { CaseFactory } from "../caseFactory"; +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import * as path from "path"; +import * as fs from "fs-extra"; +import { expect } from "chai"; + +class CopilotPluginWithApiKeyCase extends CaseFactory { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + for (const file of files) { + const filePath = path.join(projectPath, file); + expect(fs.existsSync(filePath), `${filePath} must exist.`).to.eq(true); + } + + const userFile = path.resolve(projectPath, "env", `.env.dev.user`); + const newSecretKey = 'SECRET_API_KEY="test-secret-api-key"'; + let fileContent = fs.readFileSync(userFile, "utf8"); + fileContent = fileContent.replace(/(SECRET_API_KEY=).*/, newSecretKey); + fs.writeFileSync(userFile, fileContent, "utf8"); + console.log(`Updated ${newSecretKey} in .env.dev.user file`); + } +} + +const env = Object.assign({}, process.env); +env["API_COPILOT_PLUGIN"] = "true"; +env["DEVELOP_COPILOT_PLUGIN"] = "true"; +const record: Record = {}; +record["api-auth"] = "api-key"; + +const options = { + skipErrorMessage: "No elements found in the manifest", + skipValidate: true, +}; + +new CopilotPluginWithApiKeyCase( + Capability.CopilotPluginFromScratch, + 27569734, + "yiminjin@microsoft.com", + ["function"], + ProgrammingLanguage.TS, + options, + record, + env +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts new file mode 100644 index 0000000000..5a33e03554 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { Capability } from "../../utils/constants"; +import { CaseFactory } from "../caseFactory"; +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import * as path from "path"; +import * as fs from "fs-extra"; +import { expect } from "chai"; + +class CopilotPluginWithNoneAuthCase extends CaseFactory { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + for (const file of files) { + const filePath = path.join(projectPath, file); + expect(fs.existsSync(filePath), `${filePath} must exist.`).to.eq(true); + } + } +} + +const env = Object.assign({}, process.env); +env["API_COPILOT_PLUGIN"] = "true"; +env["DEVELOP_COPILOT_PLUGIN"] = "true"; +const record: Record = {}; +record["api-auth"] = "none"; + +const options = { + skipErrorMessage: "No elements found in the manifest", + skipValidate: true, +}; + +new CopilotPluginWithNoneAuthCase( + Capability.CopilotPluginFromScratch, + 27569734, + "yiminjin@microsoft.com", + ["function"], + ProgrammingLanguage.TS, + options, + record, + env +).test(); From 951e0a48763eb3e27d2a7af3e651ce3401a2e561 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Fri, 5 Jul 2024 22:11:11 +0800 Subject: [PATCH 08/19] test: e2e test --- packages/tests/src/commonlib/functionValidator.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/tests/src/commonlib/functionValidator.ts b/packages/tests/src/commonlib/functionValidator.ts index eaf27081a1..d18dfedbeb 100644 --- a/packages/tests/src/commonlib/functionValidator.ts +++ b/packages/tests/src/commonlib/functionValidator.ts @@ -8,6 +8,7 @@ import * as chai from "chai"; import glob from "glob"; import path from "path"; import { EnvConstants, PluginId, StateConfigKey } from "./constants"; +// eslint-disable-next-line import/no-cycle import { getResourceGroupNameFromResourceId, getSiteNameFromResourceId, @@ -39,6 +40,7 @@ enum BaseConfig { API_ENDPOINT = "API_ENDPOINT", M365_APPLICATION_ID_URI = "M365_APPLICATION_ID_URI", IDENTITY_ID = "IDENTITY_ID", + WEBSITE_CONTENTSHARE = "WEBSITE_CONTENTSHARE", } enum SQLConfig { @@ -110,14 +112,11 @@ export class FunctionValidator { token as string ); chai.assert.exists(webappSettingsResponse); - const endpoint = - (this.ctx[EnvConstants.FUNCTION_ENDPOINT] as string) ?? - (this.ctx[EnvConstants.FUNCTION_ENDPOINT_2] as string); - chai.assert.equal( - webappSettingsResponse[BaseConfig.API_ENDPOINT], - endpoint - ); + const contentShare = + webappSettingsResponse[BaseConfig.WEBSITE_CONTENTSHARE]; + const functionNameInAzure = contentShare.split("-")[0]; + chai.assert.equal(functionNameInAzure, this.functionAppName); console.log("Successfully validate Function Provision."); } From 175e5609a5610d7cd78aaa044949532215f18997 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 8 Jul 2024 11:10:23 +0800 Subject: [PATCH 09/19] test: add skipValidate option to CopilotPluginWithOAuth tests --- .../tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index 9f486cb01f..ccd362c16d 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -14,6 +14,7 @@ env["API_COPILOT_PLUGIN"] = "true"; env["DEVELOP_COPILOT_PLUGIN"] = "true"; const options = { + skipValidate: true, skipErrorMessage: "No elements found in the manifest", }; From 1f9867003b3fbfc964926afcccb4a8a35f02213a Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 8 Jul 2024 11:28:45 +0800 Subject: [PATCH 10/19] test: lint error --- packages/tests/src/utils/executor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tests/src/utils/executor.ts b/packages/tests/src/utils/executor.ts index 7d034cef3f..8f604fd9b1 100644 --- a/packages/tests/src/utils/executor.ts +++ b/packages/tests/src/utils/executor.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +// eslint-disable-next-line import/no-cycle import { execAsync, editDotEnvFile } from "./commonUtils"; import { TemplateProjectFolder, From f73ce312a6fe4030db61527fd369b1e49ac7bbfc Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 8 Jul 2024 13:33:11 +0800 Subject: [PATCH 11/19] test: add CopilotPluginCommonTest class for common test setup --- .../CopilotPluginWithOAuth.tests.ts | 28 ++++--------- .../copilotplugin/copilotPluginCommonTest.ts | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index ccd362c16d..a1dfb14789 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -1,30 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Capability } from "../../utils/constants"; -import { CaseFactory } from "../caseFactory"; -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; - -class CopilotPluginOAuthTestCase extends CaseFactory {} -const copilotPluginOAuth: Record = {}; -copilotPluginOAuth["api-auth"] = "oauth"; +/** + * @author Hui Miao + */ -const env = Object.assign({}, process.env); -env["API_COPILOT_PLUGIN"] = "true"; -env["DEVELOP_COPILOT_PLUGIN"] = "true"; +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./CopilotPluginCommonTest"; -const options = { - skipValidate: true, - skipErrorMessage: "No elements found in the manifest", -}; +class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} new CopilotPluginOAuthTestCase( - Capability.CopilotPluginFromScratch, 27569691, "huimiao@microsoft.com", - ["function"], - ProgrammingLanguage.TS, - options, - copilotPluginOAuth, - env + "oauth", + ProgrammingLanguage.TS ).test(); diff --git a/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts new file mode 100644 index 0000000000..73f3e2b44d --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Hui Miao + */ + +import { Capability } from "../../utils/constants"; +import { CaseFactory } from "../caseFactory"; +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; + +export class CopilotPluginCommonTest extends CaseFactory { + public constructor( + testPlanCaseId: number, + author: string, + authOption: "none" | "api-key" | "oauth", + programmingLanguage?: ProgrammingLanguage + ) { + const env = Object.assign({}, process.env); + env["API_COPILOT_PLUGIN"] = "true"; + env["DEVELOP_COPILOT_PLUGIN"] = "true"; + + const skipOptions = { + skipValidate: true, + skipErrorMessage: "No elements found in the manifest", + }; + + const authOptions: Record = {}; + authOptions["api-auth"] = authOption; + + super( + Capability.CopilotPluginFromScratch, + testPlanCaseId, + author, + ["function"], + programmingLanguage, + skipOptions, + authOptions, + env + ); + } +} From 10381b0e8c2aeca500ce91c953aa42310ff3eaae Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 8 Jul 2024 13:47:56 +0800 Subject: [PATCH 12/19] test: fix import --- .../tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts index a1dfb14789..93bfe574e2 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -6,7 +6,7 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { CopilotPluginCommonTest } from "./CopilotPluginCommonTest"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} From 2374bf4b6f47a1fd661dbcd7017e3da5d43e2255 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 8 Jul 2024 14:56:07 +0800 Subject: [PATCH 13/19] test: add e2e tests for CopilotPluginWithOAuthForDotNet and CopilotPluginWithOAuthForJS --- .../CopilotPluginWithOAuthForDotNet.tests.ts | 18 ++++++++++++++++++ .../CopilotPluginWithOAuthForJS.tests.ts | 18 ++++++++++++++++++ ...ts => CopilotPluginWithOAuthForTS.tests.ts} | 0 .../copilotplugin/copilotPluginCommonTest.ts | 4 +++- packages/tests/src/utils/executor.ts | 6 +++++- 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts rename packages/tests/src/e2e/copilotplugin/{CopilotPluginWithOAuth.tests.ts => CopilotPluginWithOAuthForTS.tests.ts} (100%) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts new file mode 100644 index 0000000000..6221c06665 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Hui Miao + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; + +class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} + +new CopilotPluginOAuthTestCase( + 27569691, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.CSharp +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts new file mode 100644 index 0000000000..5cd81b7878 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Hui Miao + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; + +class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} + +new CopilotPluginOAuthTestCase( + 27569691, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.JS +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts similarity index 100% rename from packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts rename to packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts diff --git a/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts index 73f3e2b44d..d519794034 100644 --- a/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts +++ b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts @@ -17,8 +17,10 @@ export class CopilotPluginCommonTest extends CaseFactory { programmingLanguage?: ProgrammingLanguage ) { const env = Object.assign({}, process.env); - env["API_COPILOT_PLUGIN"] = "true"; env["DEVELOP_COPILOT_PLUGIN"] = "true"; + if (programmingLanguage === ProgrammingLanguage.CSharp) { + env["TEAMSFX_CLI_DOTNET"] = "true"; + } const skipOptions = { skipValidate: true, diff --git a/packages/tests/src/utils/executor.ts b/packages/tests/src/utils/executor.ts index 8f604fd9b1..f237df8b45 100644 --- a/packages/tests/src/utils/executor.ts +++ b/packages/tests/src/utils/executor.ts @@ -104,8 +104,12 @@ export class Executor { customized: Record = {}, processEnv?: NodeJS.ProcessEnv ) { + const langCommand = + language === ProgrammingLanguage.CSharp + ? "--runtime dotnet" + : `--programming-language ${language}`; const command = - `teamsapp new --interactive false --app-name ${appName} --capability ${capability} --programming-language ${language} ` + + `teamsapp new --interactive false --app-name ${appName} --capability ${capability} ${langCommand} ` + Object.entries(customized) .map(([key, value]) => "--" + key + " " + value) .join(" "); From fd0de8af967684b33e84b43ddf4ac9c0e9963bda Mon Sep 17 00:00:00 2001 From: Yimin-Jin Date: Mon, 8 Jul 2024 15:22:04 +0800 Subject: [PATCH 14/19] test: add ts,js,c# test case --- .../CopilotPluginWithApiKey.dotnet.tests.ts | 37 +++++++++++++ .../CopilotPluginWithApiKey.tests.ts | 55 ------------------- .../CopilotPluginWithApiKeyForJs.tests.ts | 32 +++++++++++ .../CopilotPluginWithApiKeyForTs.tests.ts | 32 +++++++++++ .../CopilotPluginWithNoneAuth.dotnet.tests.ts | 27 +++++++++ .../CopilotPluginWithNoneAuth.tests.ts | 48 ---------------- .../CopilotPluginWithNoneAuthForJs.tests.ts | 27 +++++++++ .../CopilotPluginWithNoneAuthForTs.tests.ts | 27 +++++++++ .../CopilotPluginWithOAuth.dotnet.tests.ts | 27 +++++++++ .../CopilotPluginWithOAuthForDotNet.tests.ts | 18 ------ .../CopilotPluginWithOAuthForJS.tests.ts | 13 ++++- .../CopilotPluginWithOAuthForTS.tests.ts | 13 ++++- .../tests/src/e2e/copilotplugin/helper.ts | 24 ++++++++ 13 files changed, 255 insertions(+), 125 deletions(-) create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/helper.ts diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts new file mode 100644 index 0000000000..84f2eb17a1 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { replaceSecretKey, validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import * as path from "path"; + +class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "TeamsApp/appPackage/ai-plugin.json", + "TeamsApp/appPackage/manifest.json", + "TeamsApp/GenerateApiKey.ps1", + ]; + validateFiles(projectPath, files); + + const userFile = path.resolve( + projectPath, + "TeamsApp", + "env", + `.env.dev.user` + ); + replaceSecretKey(userFile); + } +} + +new CopilotPluginWithNoneAuthForJsCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.CSharp +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts deleted file mode 100644 index 3fedaeb26c..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.tests.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { Capability } from "../../utils/constants"; -import { CaseFactory } from "../caseFactory"; -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import * as path from "path"; -import * as fs from "fs-extra"; -import { expect } from "chai"; - -class CopilotPluginWithApiKeyCase extends CaseFactory { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - ]; - for (const file of files) { - const filePath = path.join(projectPath, file); - expect(fs.existsSync(filePath), `${filePath} must exist.`).to.eq(true); - } - - const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - const newSecretKey = 'SECRET_API_KEY="test-secret-api-key"'; - let fileContent = fs.readFileSync(userFile, "utf8"); - fileContent = fileContent.replace(/(SECRET_API_KEY=).*/, newSecretKey); - fs.writeFileSync(userFile, fileContent, "utf8"); - console.log(`Updated ${newSecretKey} in .env.dev.user file`); - } -} - -const env = Object.assign({}, process.env); -env["API_COPILOT_PLUGIN"] = "true"; -env["DEVELOP_COPILOT_PLUGIN"] = "true"; -const record: Record = {}; -record["api-auth"] = "api-key"; - -const options = { - skipErrorMessage: "No elements found in the manifest", - skipValidate: true, -}; - -new CopilotPluginWithApiKeyCase( - Capability.CopilotPluginFromScratch, - 27569734, - "yiminjin@microsoft.com", - ["function"], - ProgrammingLanguage.TS, - options, - record, - env -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts new file mode 100644 index 0000000000..48f55508fc --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { replaceSecretKey, validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import * as path from "path"; + +class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "src/keyGen.js", + ]; + validateFiles(projectPath, files); + + const userFile = path.resolve(projectPath, "env", `.env.dev.user`); + replaceSecretKey(userFile); + } +} + +new CopilotPluginWithNoneAuthForJsCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.JS +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts new file mode 100644 index 0000000000..d481de822c --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { replaceSecretKey, validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import * as path from "path"; + +class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "src/keyGen.ts", + ]; + validateFiles(projectPath, files); + + const userFile = path.resolve(projectPath, "env", `.env.dev.user`); + replaceSecretKey(userFile); + } +} + +new CopilotPluginWithNoneAuthForTsCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.TS +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts new file mode 100644 index 0000000000..79706f2dda --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; + +class CopilotPluginWithNoneAuthForCsharpCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "TeamsApp/appPackage/ai-plugin.json", + "TeamsApp/appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} + +new CopilotPluginWithNoneAuthForCsharpCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.CSharp +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts deleted file mode 100644 index 5a33e03554..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { Capability } from "../../utils/constants"; -import { CaseFactory } from "../caseFactory"; -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import * as path from "path"; -import * as fs from "fs-extra"; -import { expect } from "chai"; - -class CopilotPluginWithNoneAuthCase extends CaseFactory { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - ]; - for (const file of files) { - const filePath = path.join(projectPath, file); - expect(fs.existsSync(filePath), `${filePath} must exist.`).to.eq(true); - } - } -} - -const env = Object.assign({}, process.env); -env["API_COPILOT_PLUGIN"] = "true"; -env["DEVELOP_COPILOT_PLUGIN"] = "true"; -const record: Record = {}; -record["api-auth"] = "none"; - -const options = { - skipErrorMessage: "No elements found in the manifest", - skipValidate: true, -}; - -new CopilotPluginWithNoneAuthCase( - Capability.CopilotPluginFromScratch, - 27569734, - "yiminjin@microsoft.com", - ["function"], - ProgrammingLanguage.TS, - options, - record, - env -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts new file mode 100644 index 0000000000..efb2ea972b --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; + +class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} + +new CopilotPluginWithNoneAuthForJsCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.JS +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts new file mode 100644 index 0000000000..bffc6bda63 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { validateFiles } from "./helper.ts"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; + +class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} + +new CopilotPluginWithNoneAuthForTsCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.TS +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts new file mode 100644 index 0000000000..2fed9c47ad --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Hui Miao + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; +import { validateFiles } from "./helper"; + +class CopilotPluginOAuthForCsharpTestCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "TeamsApp/appPackage/ai-plugin.json", + "TeamsApp/appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} + +new CopilotPluginOAuthForCsharpTestCase( + 27569691, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.CSharp +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts deleted file mode 100644 index 6221c06665..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForDotNet.tests.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Hui Miao - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; - -class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} - -new CopilotPluginOAuthTestCase( - 27569691, - "huimiao@microsoft.com", - "oauth", - ProgrammingLanguage.CSharp -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts index 5cd81b7878..2a7ae4988d 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts @@ -7,10 +7,19 @@ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; +import { validateFiles } from "./helper"; -class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} +class CopilotPluginOAuthForJsTestCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} -new CopilotPluginOAuthTestCase( +new CopilotPluginOAuthForJsTestCase( 27569691, "huimiao@microsoft.com", "oauth", diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts index 93bfe574e2..59dd89c8ed 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts @@ -7,10 +7,19 @@ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; +import { validateFiles } from "./helper"; -class CopilotPluginOAuthTestCase extends CopilotPluginCommonTest {} +class CopilotPluginOAuthForTsTestCase extends CopilotPluginCommonTest { + public override async onAfterCreate(projectPath: string): Promise { + const files: string[] = [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + ]; + validateFiles(projectPath, files); + } +} -new CopilotPluginOAuthTestCase( +new CopilotPluginOAuthForTsTestCase( 27569691, "huimiao@microsoft.com", "oauth", diff --git a/packages/tests/src/e2e/copilotplugin/helper.ts b/packages/tests/src/e2e/copilotplugin/helper.ts new file mode 100644 index 0000000000..0f8ef76df5 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/helper.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +import * as path from "path"; +import * as fs from "fs-extra"; +import { expect } from "chai"; + +export async function validateFiles( + projectPath: string, + files: string[] +): Promise { + for (const file of files) { + const filePath = path.join(projectPath, file); + expect(fs.existsSync(filePath), `${filePath} must exist.`).to.eq(true); + } + console.log("Files validation successful"); +} + +export async function replaceSecretKey(userFile: string): Promise { + const newSecretKey = 'SECRET_API_KEY="test-secret-api-key"'; + let fileContent = fs.readFileSync(userFile, "utf8"); + fileContent = fileContent.replace(/(SECRET_API_KEY=).*/, newSecretKey); + fs.writeFileSync(userFile, fileContent, "utf8"); + console.log(`Updated ${newSecretKey} in .env.dev.user file`); +} From ec73efca5cef9ea0a86f356b23194e911c01be2c Mon Sep 17 00:00:00 2001 From: Yimin-Jin Date: Mon, 8 Jul 2024 15:43:41 +0800 Subject: [PATCH 15/19] test: update test case id --- .../e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts | 2 +- .../e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts | 2 +- .../e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts index 84f2eb17a1..a46e35b76b 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts @@ -30,7 +30,7 @@ class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { } new CopilotPluginWithNoneAuthForJsCase( - 28640069, + 28641218, "yimin@microsoft.com", "api-key", ProgrammingLanguage.CSharp diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts index 79706f2dda..09b8791b0c 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts @@ -20,7 +20,7 @@ class CopilotPluginWithNoneAuthForCsharpCase extends CopilotPluginCommonTest { } new CopilotPluginWithNoneAuthForCsharpCase( - 27569734, + 28641262, "yimin@microsoft.com", "none", ProgrammingLanguage.CSharp diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts index 2fed9c47ad..f70a54224a 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts @@ -20,7 +20,7 @@ class CopilotPluginOAuthForCsharpTestCase extends CopilotPluginCommonTest { } new CopilotPluginOAuthForCsharpTestCase( - 27569691, + 28641204, "huimiao@microsoft.com", "oauth", ProgrammingLanguage.CSharp From 3f2aee28b7bea454f055ddfecab2fd4af7d345f6 Mon Sep 17 00:00:00 2001 From: Yimin-Jin Date: Mon, 8 Jul 2024 16:02:55 +0800 Subject: [PATCH 16/19] test: update import path --- .../copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts | 4 ++-- .../e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts | 4 ++-- .../e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts | 4 ++-- .../copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts | 5 ++--- .../copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts | 4 ++-- .../copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts index a46e35b76b..74436364c7 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts @@ -6,8 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import { replaceSecretKey, validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; import * as path from "path"; class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts index 48f55508fc..e287e21814 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts @@ -6,8 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import { replaceSecretKey, validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; import * as path from "path"; class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts index d481de822c..092f3aef17 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts @@ -6,8 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import { replaceSecretKey, validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; import * as path from "path"; class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts index 09b8791b0c..86deccf1bd 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts @@ -6,9 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; - +import { validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; class CopilotPluginWithNoneAuthForCsharpCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts index efb2ea972b..f082b9eec4 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts @@ -6,8 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import { validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts index bffc6bda63..ae92286293 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts @@ -6,8 +6,8 @@ */ import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper.ts"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest.ts"; +import { validateFiles } from "./helper"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { From b7cb7ae41fe3ce286eb0c129b4da614811060815 Mon Sep 17 00:00:00 2001 From: Yimin Jin Date: Tue, 9 Jul 2024 10:44:14 +0800 Subject: [PATCH 17/19] test: fix validate logic and oauth file name --- .../CopilotPluginWithApiKey.dotnet.tests.ts | 17 ++++++----------- .../CopilotPluginWithApiKeyForJs.tests.ts | 4 ++-- .../CopilotPluginWithApiKeyForTs.tests.ts | 4 ++-- .../CopilotPluginWithNoneAuth.dotnet.tests.ts | 6 +++--- .../CopilotPluginWithNoneAuthForJs.tests.ts | 2 +- .../CopilotPluginWithNoneAuthForTs.tests.ts | 2 +- .../CopilotPluginWithOAuth.dotnet.tests.ts | 6 +++--- .../CopilotPluginWithOAuthForJS.tests.ts | 4 ++-- .../CopilotPluginWithOAuthForTS.tests.ts | 4 ++-- 9 files changed, 22 insertions(+), 27 deletions(-) diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts index 74436364c7..1da4c83d3c 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts @@ -13,19 +13,14 @@ import * as path from "path"; class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ - "TeamsApp/appPackage/ai-plugin.json", - "TeamsApp/appPackage/manifest.json", - "TeamsApp/GenerateApiKey.ps1", + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "GenerateApiKey.ps1", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); - const userFile = path.resolve( - projectPath, - "TeamsApp", - "env", - `.env.dev.user` - ); - replaceSecretKey(userFile); + const userFile = path.resolve(projectPath, "env", `.env.dev.user`); + await replaceSecretKey(userFile); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts index e287e21814..227cd29214 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts @@ -17,10 +17,10 @@ class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { "appPackage/manifest.json", "src/keyGen.js", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - replaceSecretKey(userFile); + await replaceSecretKey(userFile); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts index 092f3aef17..94beacf561 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts @@ -17,10 +17,10 @@ class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { "appPackage/manifest.json", "src/keyGen.ts", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - replaceSecretKey(userFile); + await replaceSecretKey(userFile); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts index 86deccf1bd..f5720fbf4d 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts @@ -11,10 +11,10 @@ import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; class CopilotPluginWithNoneAuthForCsharpCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ - "TeamsApp/appPackage/ai-plugin.json", - "TeamsApp/appPackage/manifest.json", + "appPackage/ai-plugin.json", + "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts index f082b9eec4..e60f9f3f1f 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts @@ -15,7 +15,7 @@ class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { "appPackage/ai-plugin.json", "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts index ae92286293..cad7b2610e 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts @@ -15,7 +15,7 @@ class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { "appPackage/ai-plugin.json", "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts index f70a54224a..71e5e27d40 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts @@ -12,10 +12,10 @@ import { validateFiles } from "./helper"; class CopilotPluginOAuthForCsharpTestCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ - "TeamsApp/appPackage/ai-plugin.json", - "TeamsApp/appPackage/manifest.json", + "appPackage/ai-plugin.dev.json", + "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts index 2a7ae4988d..5e71d31b93 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts @@ -12,10 +12,10 @@ import { validateFiles } from "./helper"; class CopilotPluginOAuthForJsTestCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ - "appPackage/ai-plugin.json", + "appPackage/ai-plugin.dev.json", "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts index 59dd89c8ed..c220d22525 100644 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts @@ -12,10 +12,10 @@ import { validateFiles } from "./helper"; class CopilotPluginOAuthForTsTestCase extends CopilotPluginCommonTest { public override async onAfterCreate(projectPath: string): Promise { const files: string[] = [ - "appPackage/ai-plugin.json", + "appPackage/ai-plugin.dev.json", "appPackage/manifest.json", ]; - validateFiles(projectPath, files); + await validateFiles(projectPath, files); } } From 6c75a3ea62df1116c9f38faa78f77722482cd4af Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Wed, 10 Jul 2024 16:23:45 +0800 Subject: [PATCH 18/19] test: typo --- packages/tests/src/e2e/caseFactory.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/tests/src/e2e/caseFactory.ts b/packages/tests/src/e2e/caseFactory.ts index e064c005a3..91dea51b99 100644 --- a/packages/tests/src/e2e/caseFactory.ts +++ b/packages/tests/src/e2e/caseFactory.ts @@ -53,7 +53,7 @@ export abstract class CaseFactory { skipPackage?: boolean; skipErrorMessage?: string; }; - public custimized?: Record; + public customized?: Record; public processEnv?: NodeJS.ProcessEnv; public constructor( @@ -78,7 +78,7 @@ export abstract class CaseFactory { skipPackage?: boolean; skipErrorMessage?: string; } = {}, - custimized?: Record, + customized?: Record, processEnv?: NodeJS.ProcessEnv ) { this.capability = capability; @@ -87,7 +87,7 @@ export abstract class CaseFactory { this.validate = validate; this.programmingLanguage = programmingLanguage; this.options = options; - this.custimized = custimized; + this.customized = customized; this.processEnv = processEnv; } @@ -108,7 +108,7 @@ export abstract class CaseFactory { testFolder: string, capability: Capability, programmingLanguage?: ProgrammingLanguage, - custimized?: Record, + customized?: Record, processEnv?: NodeJS.ProcessEnv ): Promise { await Executor.createProject( @@ -116,7 +116,7 @@ export abstract class CaseFactory { appName, capability, programmingLanguage ? programmingLanguage : ProgrammingLanguage.TS, - custimized, + customized, processEnv ); } @@ -133,7 +133,7 @@ export abstract class CaseFactory { validate, programmingLanguage, options, - custimized, + customized, processEnv, onBefore, onAfter, @@ -161,7 +161,7 @@ export abstract class CaseFactory { testFolder, capability, programmingLanguage, - custimized, + customized, processEnv ); expect(fs.pathExistsSync(projectPath)).to.be.true; From fe5cf7adc476a10525e494af47850949bf2ed39b Mon Sep 17 00:00:00 2001 From: Yimin Jin Date: Fri, 12 Jul 2024 11:23:51 +0800 Subject: [PATCH 19/19] test: simplify test case --- packages/tests/src/e2e/caseFactory.ts | 2 +- .../CopilotPluginWithApiKey.dotnet.tests.ts | 32 ------------ .../CopilotPluginWithApiKeyAuth.tests.ts | 51 +++++++++++++++++++ .../CopilotPluginWithApiKeyForJs.tests.ts | 32 ------------ .../CopilotPluginWithApiKeyForTs.tests.ts | 32 ------------ .../CopilotPluginWithNoneAuth.dotnet.tests.ts | 26 ---------- .../CopilotPluginWithNoneAuth.tests.ts | 36 +++++++++++++ .../CopilotPluginWithNoneAuthForJs.tests.ts | 27 ---------- .../CopilotPluginWithNoneAuthForTs.tests.ts | 27 ---------- .../CopilotPluginWithOAuth.dotnet.tests.ts | 27 ---------- .../CopilotPluginWithOAuth.tests.ts | 39 ++++++++++++++ .../CopilotPluginWithOAuthForJS.tests.ts | 27 ---------- .../CopilotPluginWithOAuthForTS.tests.ts | 27 ---------- .../copilotplugin/copilotPluginCommonTest.ts | 21 +++++++- 14 files changed, 146 insertions(+), 260 deletions(-) delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyAuth.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts create mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts delete mode 100644 packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts diff --git a/packages/tests/src/e2e/caseFactory.ts b/packages/tests/src/e2e/caseFactory.ts index 91dea51b99..ddc9c0771e 100644 --- a/packages/tests/src/e2e/caseFactory.ts +++ b/packages/tests/src/e2e/caseFactory.ts @@ -141,7 +141,7 @@ export abstract class CaseFactory { onBeforeProvision, onCreate, } = this; - describe(`template Test: ${capability}`, function () { + describe(`template Test: ${capability} - ${programmingLanguage}`, function () { const testFolder = getTestFolder(); const appName = getUniqueAppName(); const projectPath = path.resolve(testFolder, appName); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts deleted file mode 100644 index 1da4c83d3c..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKey.dotnet.tests.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import * as path from "path"; - -class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - "GenerateApiKey.ps1", - ]; - await validateFiles(projectPath, files); - - const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - await replaceSecretKey(userFile); - } -} - -new CopilotPluginWithNoneAuthForJsCase( - 28641218, - "yimin@microsoft.com", - "api-key", - ProgrammingLanguage.CSharp -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyAuth.tests.ts new file mode 100644 index 0000000000..c05c8556c0 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyAuth.tests.ts @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; + +class CopilotPluginWithApiKeyAuthCase extends CopilotPluginCommonTest {} +const validateFiles = { + [ProgrammingLanguage.JS]: [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "src/keyGen.js", + ], + [ProgrammingLanguage.TS]: [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "src/keyGen.ts", + ], + [ProgrammingLanguage.CSharp]: [ + "appPackage/ai-plugin.json", + "appPackage/manifest.json", + "GenerateApiKey.ps1", + ], +}; +new CopilotPluginWithApiKeyAuthCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.JS, + validateFiles[ProgrammingLanguage.JS] +).test(); + +new CopilotPluginWithApiKeyAuthCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.TS, + validateFiles[ProgrammingLanguage.TS] +).test(); + +new CopilotPluginWithApiKeyAuthCase( + 28640069, + "yimin@microsoft.com", + "api-key", + ProgrammingLanguage.CSharp, + validateFiles[ProgrammingLanguage.CSharp] +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts deleted file mode 100644 index 227cd29214..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForJs.tests.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import * as path from "path"; - -class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - "src/keyGen.js", - ]; - await validateFiles(projectPath, files); - - const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - await replaceSecretKey(userFile); - } -} - -new CopilotPluginWithNoneAuthForJsCase( - 28640069, - "yimin@microsoft.com", - "api-key", - ProgrammingLanguage.JS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts deleted file mode 100644 index 94beacf561..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithApiKeyForTs.tests.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { replaceSecretKey, validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import * as path from "path"; - -class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - "src/keyGen.ts", - ]; - await validateFiles(projectPath, files); - - const userFile = path.resolve(projectPath, "env", `.env.dev.user`); - await replaceSecretKey(userFile); - } -} - -new CopilotPluginWithNoneAuthForTsCase( - 28640069, - "yimin@microsoft.com", - "api-key", - ProgrammingLanguage.TS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts deleted file mode 100644 index f5720fbf4d..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.dotnet.tests.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -class CopilotPluginWithNoneAuthForCsharpCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginWithNoneAuthForCsharpCase( - 28641262, - "yimin@microsoft.com", - "none", - ProgrammingLanguage.CSharp -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts new file mode 100644 index 0000000000..160f1612c3 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuth.tests.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Yimin Jin + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; + +class CopilotPluginWithNoneAuthCase extends CopilotPluginCommonTest {} +const validateFiles = ["appPackage/ai-plugin.json", "appPackage/manifest.json"]; + +new CopilotPluginWithNoneAuthCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.JS, + validateFiles +).test(); + +new CopilotPluginWithNoneAuthCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.TS, + validateFiles +).test(); + +new CopilotPluginWithNoneAuthCase( + 27569734, + "yimin@microsoft.com", + "none", + ProgrammingLanguage.CSharp, + validateFiles +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts deleted file mode 100644 index e60f9f3f1f..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForJs.tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; - -class CopilotPluginWithNoneAuthForJsCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginWithNoneAuthForJsCase( - 27569734, - "yimin@microsoft.com", - "none", - ProgrammingLanguage.JS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts deleted file mode 100644 index cad7b2610e..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithNoneAuthForTs.tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Yimin Jin - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { validateFiles } from "./helper"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; - -class CopilotPluginWithNoneAuthForTsCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginWithNoneAuthForTsCase( - 27569734, - "yimin@microsoft.com", - "none", - ProgrammingLanguage.TS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts deleted file mode 100644 index 71e5e27d40..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.dotnet.tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Hui Miao - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import { validateFiles } from "./helper"; - -class CopilotPluginOAuthForCsharpTestCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.dev.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginOAuthForCsharpTestCase( - 28641204, - "huimiao@microsoft.com", - "oauth", - ProgrammingLanguage.CSharp -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts new file mode 100644 index 0000000000..af9646eba0 --- /dev/null +++ b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuth.tests.ts @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @author Hui Miao + */ + +import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; +import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; + +class CopilotPluginWithOAuthCase extends CopilotPluginCommonTest {} +const validateFiles = [ + "appPackage/ai-plugin.dev.json", + "appPackage/manifest.json", +]; + +new CopilotPluginWithOAuthCase( + 28641204, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.JS, + validateFiles +).test(); + +new CopilotPluginWithOAuthCase( + 28641204, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.TS, + validateFiles +).test(); + +new CopilotPluginWithOAuthCase( + 28641204, + "huimiao@microsoft.com", + "oauth", + ProgrammingLanguage.CSharp, + validateFiles +).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts deleted file mode 100644 index 5e71d31b93..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForJS.tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Hui Miao - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import { validateFiles } from "./helper"; - -class CopilotPluginOAuthForJsTestCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.dev.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginOAuthForJsTestCase( - 27569691, - "huimiao@microsoft.com", - "oauth", - ProgrammingLanguage.JS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts b/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts deleted file mode 100644 index c220d22525..0000000000 --- a/packages/tests/src/e2e/copilotplugin/CopilotPluginWithOAuthForTS.tests.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @author Hui Miao - */ - -import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; -import { CopilotPluginCommonTest } from "./copilotPluginCommonTest"; -import { validateFiles } from "./helper"; - -class CopilotPluginOAuthForTsTestCase extends CopilotPluginCommonTest { - public override async onAfterCreate(projectPath: string): Promise { - const files: string[] = [ - "appPackage/ai-plugin.dev.json", - "appPackage/manifest.json", - ]; - await validateFiles(projectPath, files); - } -} - -new CopilotPluginOAuthForTsTestCase( - 27569691, - "huimiao@microsoft.com", - "oauth", - ProgrammingLanguage.TS -).test(); diff --git a/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts index d519794034..179e9dd570 100644 --- a/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts +++ b/packages/tests/src/e2e/copilotplugin/copilotPluginCommonTest.ts @@ -8,13 +8,18 @@ import { Capability } from "../../utils/constants"; import { CaseFactory } from "../caseFactory"; import { ProgrammingLanguage } from "@microsoft/teamsfx-core"; - +import { replaceSecretKey, validateFiles } from "./helper"; +import * as path from "path"; export class CopilotPluginCommonTest extends CaseFactory { + validateFileList?: string[]; + authOption?: string; + public constructor( testPlanCaseId: number, author: string, authOption: "none" | "api-key" | "oauth", - programmingLanguage?: ProgrammingLanguage + programmingLanguage?: ProgrammingLanguage, + validateFileList?: string[] ) { const env = Object.assign({}, process.env); env["DEVELOP_COPILOT_PLUGIN"] = "true"; @@ -40,5 +45,17 @@ export class CopilotPluginCommonTest extends CaseFactory { authOptions, env ); + this.validateFileList = validateFileList; + this.authOption = authOption; + this.onAfterCreate = this.onAfterCreate.bind(this); + } + + public override async onAfterCreate(projectPath: string): Promise { + await validateFiles(projectPath, this.validateFileList || []); + + if (this.authOption === "api-key") { + const userFile = path.resolve(projectPath, "env", `.env.dev.user`); + await replaceSecretKey(userFile); + } } }