Skip to content

Commit

Permalink
feat: builder api ff (#13165)
Browse files Browse the repository at this point in the history
* feat: add ff for builder api
  • Loading branch information
anchenyi authored Feb 11, 2025
1 parent fefccb2 commit ae8d7f5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/fx-core/src/common/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class FeatureFlagName {
static readonly SyncManifest = "TEAMSFX_SYNC_MANIFEST";
static readonly KiotaIntegration = "TEAMSFX_KIOTA_INTEGRATION";
static readonly CEAEnabled = "TEAMSFX_CEA_ENABLED";
static readonly BuilderAPIEnabled = "TEAMSFX_BUILDER_API";
}

export interface FeatureFlag {
Expand Down Expand Up @@ -87,6 +88,10 @@ export class FeatureFlags {
name: FeatureFlagName.CEAEnabled,
defaultValue: "false",
};
static readonly BuilderAPIEnabled = {
name: FeatureFlagName.BuilderAPIEnabled,
defaultValue: "false",
};
}

export class FeatureFlagManager {
Expand Down
6 changes: 5 additions & 1 deletion packages/fx-core/src/component/m365/packageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { NotExtendedToM365Error } from "./errors";
import { MosServiceEndpoint } from "./serviceConstant";
import { IsDeclarativeAgentManifest } from "../../common/projectTypeChecker";
import stripBom from "strip-bom";
import { featureFlagManager, FeatureFlags } from "../../common/featureFlags";

const M365ErrorSource = "M365";
const M365ErrorComponent = "PackageService";
Expand Down Expand Up @@ -156,7 +157,10 @@ export class PackageService {
throw new Error("Invalid app package zip. manifest.json is missing");
}
const isDelcarativeAgentApp = IsDeclarativeAgentManifest(manifest);
if (isDelcarativeAgentApp) {
if (
isDelcarativeAgentApp &&
featureFlagManager.getBooleanValue(FeatureFlags.BuilderAPIEnabled)
) {
const res = await this.sideLoadingV2(token, packagePath, appScope);
let shareLink = "";
if (appScope == AppScope.Shared) {
Expand Down
57 changes: 57 additions & 0 deletions packages/fx-core/tests/component/m365/packageService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe("Package Service", () => {
sandbox.stub(axios, "create").returns(testAxiosInstance);

setTools({} as any);
process.env["TEAMSFX_BUILDER_API"] = "1";
});

it("GetSharedInstance happy path", () => {
Expand Down Expand Up @@ -687,6 +688,62 @@ describe("Package Service", () => {
chai.assert.isTrue(actualError instanceof UserError);
});

it("sideLoading Builder API Feature Flag turned off", async () => {
process.env["TEAMSFX_BUILDER_API"] = "0";
axiosGetResponses["/config/v1/environment"] = {
data: {
titlesServiceUrl: "https://test-url",
},
};
axiosPostResponses["/dev/v1/users/packages"] = {
data: {
operationId: "test-operation-id",
titlePreview: {
titleId: "test-title-id-preview",
},
},
};
axiosPostResponses["/dev/v1/users/packages/acquisitions"] = {
data: {
statusId: "test-status-id",
},
};
axiosGetResponses["/dev/v1/users/packages/status/test-status-id"] = {
status: 200,
data: {
titleId: "test-title-id",
appId: "test-app-id",
},
};
axiosGetResponses["/marketplace/v1/users/titles/test-title-id-builder-api/sharingInfo"] = {
data: {
unifiedStoreLink: "https://test-share-link",
},
};

let actualError: Error | undefined;
const packageService = new PackageService("https://test-endpoint", logger);
sandbox.stub(packageService, "getManifestFromZip" as keyof PackageService).returns({
copilotAgents: {
declarativeAgents: [
{
id: "declarativeAgent",
file: "declarativeAgent.json",
},
],
},
} as any);
try {
const result = await packageService.sideLoading("test-token", "test-path", AppScope.Shared);
chai.assert.equal(result[0], "test-title-id");
chai.assert.equal(result[1], "test-app-id");
chai.assert.equal(result[2], "");
} catch (error: any) {
actualError = error;
}
chai.assert.isUndefined(actualError);
});

it("retrieveTitleId happy path", async () => {
axiosGetResponses["/config/v1/environment"] = {
data: {
Expand Down

0 comments on commit ae8d7f5

Please sign in to comment.