-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generate customize gpt and GPT plugin (#11441)
* refactor: generate customize gpt plugin * refactor: more * refactor: more * refactor: more * test: ut * test: ut * refactor: pr comment
- Loading branch information
1 parent
17e10df
commit f55496d
Showing
12 changed files
with
270 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/fx-core/tests/component/driver/teamsApp/copilotGptManifest.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import "mocha"; | ||
import * as sinon from "sinon"; | ||
import chai from "chai"; | ||
import fs from "fs-extra"; | ||
import { CopilotGptManifestSchema } from "@microsoft/teamsfx-api"; | ||
import { copilotGptManifestUtils } from "../../../../src/component/driver/teamsApp/utils/CopilotGptManifestUtils"; | ||
import { FileNotFoundError, WriteFileError } from "../../../../src/error"; | ||
|
||
describe("copilotGptManifestUtils", () => { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
afterEach(async () => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const gptManifest: CopilotGptManifestSchema = { | ||
name: "name", | ||
description: "description", | ||
}; | ||
|
||
it("add plugin success", async () => { | ||
sandbox.stub(fs, "pathExists").resolves(true); | ||
sandbox.stub(fs, "readFile").resolves(JSON.stringify(gptManifest) as any); | ||
sandbox.stub(fs, "writeFile").resolves(); | ||
|
||
const res = await copilotGptManifestUtils.addPlugin("testPath", "testId", "testFile"); | ||
|
||
chai.assert.isTrue(res.isOk()); | ||
if (res.isOk()) { | ||
const updatedManifest = res.value; | ||
chai.assert.deepEqual(updatedManifest.actions![0], { | ||
id: "testId", | ||
file: "testFile", | ||
}); | ||
} | ||
}); | ||
|
||
it("add plugin error: read manifest error", async () => { | ||
sandbox.stub(fs, "pathExists").resolves(false); | ||
const res = await copilotGptManifestUtils.addPlugin("testPath", "testId", "testFile"); | ||
chai.assert.isTrue(res.isErr()); | ||
if (res.isErr()) { | ||
chai.assert.isTrue(res.error instanceof FileNotFoundError); | ||
} | ||
}); | ||
|
||
it("add plugin error: write file error", async () => { | ||
sandbox.stub(fs, "pathExists").resolves(true); | ||
sandbox.stub(fs, "readFile").resolves(JSON.stringify(gptManifest) as any); | ||
sandbox.stub(fs, "writeFile").throws("some error"); | ||
const res = await copilotGptManifestUtils.addPlugin("testPath", "testId", "testFile"); | ||
chai.assert.isTrue(res.isErr()); | ||
if (res.isErr()) { | ||
chai.assert.isTrue(res.error instanceof WriteFileError); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.