diff --git a/src/deploy/functions/release/fabricator.spec.ts b/src/deploy/functions/release/fabricator.spec.ts index 1608c7c0608..b5280113769 100644 --- a/src/deploy/functions/release/fabricator.spec.ts +++ b/src/deploy/functions/release/fabricator.spec.ts @@ -1598,6 +1598,46 @@ describe("Fabricator", () => { expect(results[0].error).to.be.instanceOf(reporter.DeploymentError); expect(results[0].error?.message).to.match(/create function/); }); + it("uses different scrapers for different codebases", async () => { + const ep1 = endpoint({ httpsTrigger: {} }, { codebase: "codebaseA" }); + const ep2 = endpoint({ httpsTrigger: {} }, { codebase: "codebaseB" }); + const plan: planner.DeploymentPlan = { + "us-central1": { + endpointsToCreate: [ep1], + endpointsToUpdate: [], + endpointsToDelete: [], + endpointsToSkip: [], + }, + "us-west1": { + endpointsToCreate: [ep2], + endpointsToUpdate: [], + endpointsToDelete: [], + endpointsToSkip: [], + }, + }; + + const applyUpsertsSpy = sinon.spy(fab, "applyUpserts"); + + sinon.stub(fab, "createEndpoint").resolves(); + sinon.stub(fab, "updateEndpoint").resolves(); + sinon.stub(fab, "deleteEndpoint").resolves(); + + await fab.applyPlan(plan); + + expect(applyUpsertsSpy.calledTwice).to.be.true; + + const call1 = applyUpsertsSpy.getCall(0); + const call2 = applyUpsertsSpy.getCall(1); + + const scraperV1Call1 = call1.args[1]; + const scraperV2Call1 = call1.args[2]; + + const scraperV1Call2 = call2.args[1]; + const scraperV2Call2 = call2.args[2]; + + expect(scraperV1Call1).to.not.equal(scraperV1Call2); + expect(scraperV2Call1).to.not.equal(scraperV2Call2); + }); }); describe("getLogSuccessMessage", () => { diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index 33919b61ece..8ba6b508cbd 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -99,9 +99,22 @@ export class Fabricator { const changesets = Object.values(plan); // Phase 1: Creates and Updates - const scraperV1 = new SourceTokenScraper(); - const scraperV2 = new SourceTokenScraper(); + const scrapersV1 = new Map(); + const scrapersV2 = new Map(); + const createAndUpdatePromises = changesets.map((changes) => { + const codebase = + changes.endpointsToCreate[0]?.codebase || + changes.endpointsToUpdate[0]?.endpoint.codebase || + changes.endpointsToDelete[0]?.codebase || + changes.endpointsToSkip[0]?.codebase || + "default"; + + const scraperV1 = scrapersV1.get(codebase) ?? new SourceTokenScraper(); + scrapersV1.set(codebase, scraperV1); + const scraperV2 = scrapersV2.get(codebase) ?? new SourceTokenScraper(); + scrapersV2.set(codebase, scraperV2); + return this.applyUpserts(changes, scraperV1, scraperV2); }); const createAndUpdateResultsArray = await Promise.allSettled(createAndUpdatePromises);