From b623536058e9e4fbbc1c119448102af9faa1af6c Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Fri, 10 Apr 2026 18:57:56 +0000 Subject: [PATCH 1/7] Function rename deletion sequence change --- .../functions/release/fabricator.spec.ts | 45 ++++- src/deploy/functions/release/fabricator.ts | 166 ++++++++++-------- 2 files changed, 138 insertions(+), 73 deletions(-) diff --git a/src/deploy/functions/release/fabricator.spec.ts b/src/deploy/functions/release/fabricator.spec.ts index 30de84a4572..c697885b399 100644 --- a/src/deploy/functions/release/fabricator.spec.ts +++ b/src/deploy/functions/release/fabricator.spec.ts @@ -1580,7 +1580,7 @@ describe("Fabricator", () => { const updateEndpoint = sinon.stub(fab, "updateEndpoint"); updateEndpoint.callsFake(fakeUpsert); - await fab.applyChangeset(changes); + await fab.applyPlan({ "us-central1": changes }); }); it("handles errors and wraps them in results", async () => { @@ -1593,7 +1593,8 @@ describe("Fabricator", () => { endpointsToSkip: [], }; - const results = await fab.applyChangeset(changes); + const summary = await fab.applyPlan({ "us-central1": changes }); + const results = summary.results; expect(results[0].error).to.be.instanceOf(reporter.DeploymentError); expect(results[0].error?.message).to.match(/create function/); }); @@ -1645,7 +1646,8 @@ describe("Fabricator", () => { endpointsToSkip: [], }; - const results = await fab.applyChangeset(changes); + const summary = await fab.applyPlan({ "us-central1": changes }); + const results = summary.results; const result = results.find((r) => r.endpoint.id === deleteEP.id); expect(result?.error).to.be.instanceOf(reporter.AbortedDeploymentError); expect(result?.durationMs).to.equal(0); @@ -1671,7 +1673,8 @@ describe("Fabricator", () => { const deleteEndpoint = sinon.stub(fab, "deleteEndpoint"); deleteEndpoint.resolves(); - const results = await fab.applyChangeset(changes); + const summary = await fab.applyPlan({ "us-central1": changes }); + const results = summary.results; expect(createEndpoint).to.have.been.calledWithMatch(createEP); expect(updateEndpoint).to.have.been.calledWithMatch(update); expect(deleteEndpoint).to.have.been.calledWith(deleteEP); @@ -1712,6 +1715,40 @@ describe("Fabricator", () => { expect(ep2Result?.error).to.be.instanceOf(reporter.DeploymentError); expect(ep2Result?.error?.message).to.match(/delete function/); }); + + it("waits for all creates/updates to complete before doing deletes", async () => { + const ep1 = endpoint({ httpsTrigger: {} }, { region: "us-central1", id: "A" }); + const ep2 = endpoint({ httpsTrigger: {} }, { region: "us-west1", id: "B" }); + const plan: planner.DeploymentPlan = { + "us-central1": { + endpointsToCreate: [ep1], + endpointsToUpdate: [], + endpointsToDelete: [], + endpointsToSkip: [], + }, + "us-west1": { + endpointsToCreate: [], + endpointsToUpdate: [], + endpointsToDelete: [ep2], + endpointsToSkip: [], + }, + }; + + let createFinished = false; + const createEndpoint = sinon.stub(fab, "createEndpoint").callsFake(async () => { + await new Promise((resolve) => setTimeout(resolve, 100)); + createFinished = true; + }); + + const deleteEndpoint = sinon.stub(fab, "deleteEndpoint").callsFake(async () => { + expect(createFinished).to.be.true; + }); + + await fab.applyPlan(plan); + + expect(createEndpoint).to.have.been.calledOnce; + expect(deleteEndpoint).to.have.been.calledOnce; + }); }); describe("createRunFunction", () => { diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index c3051e86b8f..0233b6a72aa 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -95,87 +95,115 @@ export class Fabricator { totalTime: 0, results: [], }; - const deployChangesets = Object.values(plan).map(async (changes): Promise => { - const results = await this.applyChangeset(changes); - summary.results.push(...results); - return; + + const changesets = Object.values(plan); + + // Phase 1: Creates and Updates + const createAndUpdatePromises = changesets.map(async (changes) => { + const scraperV1 = new SourceTokenScraper(); + const scraperV2 = new SourceTokenScraper(); + return this.applyChangeset(changes, scraperV1, scraperV2, "createsAndUpdates"); }); - const promiseResults = await utils.allSettled(deployChangesets); - - const errs = promiseResults - .filter((r) => r.status === "rejected") - .map((r) => (r as utils.PromiseRejectedResult).reason); - if (errs.length) { - logger.debug( - "Fabricator.applyRegionalChanges returned an unhandled exception. This should never happen", - JSON.stringify(errs, null, 2), - ); + const createAndUpdateResultsArray = await utils.allSettled(createAndUpdatePromises); + + for (const r of createAndUpdateResultsArray) { + if (r.status === "fulfilled") { + summary.results.push(...r.value); + } else { + logger.debug( + "Fabricator.applyChangeset returned an unhandled exception. This should never happen", + JSON.stringify(r.reason, null, 2), + ); + } + } + + const hasFailures = summary.results.some((r) => r.error); + + if (hasFailures) { + utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes."); + for (const changes of changesets) { + for (const endpoint of changes.endpointsToDelete) { + summary.results.push({ + endpoint, + durationMs: 0, + error: new reporter.AbortedDeploymentError(endpoint), + }); + } + } + } else { + // Phase 2: Deletes + const deletePromises = changesets.map(async (changes) => { + return this.applyChangeset(changes, new SourceTokenScraper(), new SourceTokenScraper(), "deletes"); + }); + const deleteResultsArray = await utils.allSettled(deletePromises); + + for (const r of deleteResultsArray) { + if (r.status === "fulfilled") { + summary.results.push(...r.value); + } else { + logger.debug( + "Fabricator.applyChangeset returned an unhandled exception. This should never happen", + JSON.stringify(r.reason, null, 2), + ); + } + } } summary.totalTime = timer.stop(); return summary; } - async applyChangeset(changes: planner.Changeset): Promise> { - const deployResults: reporter.DeployResult[] = []; - const handle = async ( - op: reporter.OperationType, - endpoint: backend.Endpoint, - fn: () => Promise, - ): Promise => { - const timer = new Timer(); - const result: Partial = { endpoint }; - try { - await fn(); - this.logOpSuccess(op, endpoint); - } catch (err: any) { - result.error = err as Error; + async applyChangeset( + changes: planner.Changeset, + scraperV1: SourceTokenScraper, + scraperV2: SourceTokenScraper, + phase: "createsAndUpdates" | "deletes", + ): Promise> { + const ops: Array> = []; + + if (phase === "createsAndUpdates") { + for (const endpoint of changes.endpointsToCreate) { + this.logOpStart("creating", endpoint); + ops.push( + this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)), + ); } - result.durationMs = timer.stop(); - deployResults.push(result as reporter.DeployResult); - }; - - const upserts: Array> = []; - const scraperV1 = new SourceTokenScraper(); - const scraperV2 = new SourceTokenScraper(); - for (const endpoint of changes.endpointsToCreate) { - this.logOpStart("creating", endpoint); - upserts.push( - handle("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)), - ); - } - for (const endpoint of changes.endpointsToSkip) { - utils.logSuccess(this.getLogSuccessMessage("skip", endpoint)); - } - for (const update of changes.endpointsToUpdate) { - this.logOpStart("updating", update.endpoint); - upserts.push( - handle("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)), - ); - } - await utils.allSettled(upserts); - - // Note: every promise is generated by handle which records error in results. - // We've used hasErrors as a cheater here instead of viewing the results of allSettled - if (deployResults.find((r) => r.error)) { + + for (const endpoint of changes.endpointsToSkip) { + utils.logSuccess(this.getLogSuccessMessage("skip", endpoint)); + } + + for (const update of changes.endpointsToUpdate) { + this.logOpStart("updating", update.endpoint); + ops.push( + this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)), + ); + } + } else if (phase === "deletes") { for (const endpoint of changes.endpointsToDelete) { - deployResults.push({ - endpoint, - durationMs: 0, - error: new reporter.AbortedDeploymentError(endpoint), - }); + this.logOpStart("deleting", endpoint); + ops.push(this.wrapOperation("delete", endpoint, () => this.deleteEndpoint(endpoint))); } - return deployResults; } + + return Promise.all(ops); + } - const deletes: Array> = []; - for (const endpoint of changes.endpointsToDelete) { - this.logOpStart("deleting", endpoint); - deletes.push(handle("delete", endpoint, () => this.deleteEndpoint(endpoint))); - } - await utils.allSettled(deletes); - - return deployResults; + private async wrapOperation( + op: reporter.OperationType, + endpoint: backend.Endpoint, + fn: () => Promise, + ): Promise { + const timer = new Timer(); + const result: Partial = { endpoint }; + try { + await fn(); + this.logOpSuccess(op, endpoint); + } catch (err: any) { + result.error = err as Error; + } + result.durationMs = timer.stop(); + return result as reporter.DeployResult; } async createEndpoint( From e0ad07b421ed381195c0ea4c4109e610cf9886ba Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Fri, 10 Apr 2026 19:34:42 +0000 Subject: [PATCH 2/7] addressing review comments --- src/deploy/functions/release/fabricator.ts | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index 0233b6a72aa..5373237a2d1 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -106,18 +106,29 @@ export class Fabricator { }); const createAndUpdateResultsArray = await utils.allSettled(createAndUpdatePromises); - for (const r of createAndUpdateResultsArray) { + createAndUpdateResultsArray.forEach((r, i) => { if (r.status === "fulfilled") { summary.results.push(...r.value); } else { logger.debug( - "Fabricator.applyChangeset returned an unhandled exception. This should never happen", + "Fabricator.applyChangeset returned an unhandled exception.", JSON.stringify(r.reason, null, 2), ); + // Map failure back to all endpoints in the changeset so the reporter knows they failed. + const changes = changesets[i]; + const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); + for (const endpoint of changes.endpointsToCreate) { + summary.results.push({ endpoint, durationMs: 0, error }); + } + for (const update of changes.endpointsToUpdate) { + summary.results.push({ endpoint: update.endpoint, durationMs: 0, error }); + } } - } + }); - const hasFailures = summary.results.some((r) => r.error); + const hasFailures = + summary.results.some((r) => r.error) || + createAndUpdateResultsArray.some((r) => r.status === "rejected"); if (hasFailures) { utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes."); @@ -133,7 +144,7 @@ export class Fabricator { } else { // Phase 2: Deletes const deletePromises = changesets.map(async (changes) => { - return this.applyChangeset(changes, new SourceTokenScraper(), new SourceTokenScraper(), "deletes"); + return this.applyChangeset(changes, undefined, undefined, "deletes"); }); const deleteResultsArray = await utils.allSettled(deletePromises); @@ -155,8 +166,8 @@ export class Fabricator { async applyChangeset( changes: planner.Changeset, - scraperV1: SourceTokenScraper, - scraperV2: SourceTokenScraper, + scraperV1: SourceTokenScraper | undefined, + scraperV2: SourceTokenScraper | undefined, phase: "createsAndUpdates" | "deletes", ): Promise> { const ops: Array> = []; @@ -165,7 +176,7 @@ export class Fabricator { for (const endpoint of changes.endpointsToCreate) { this.logOpStart("creating", endpoint); ops.push( - this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)), + this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1!, scraperV2!)), ); } @@ -176,7 +187,7 @@ export class Fabricator { for (const update of changes.endpointsToUpdate) { this.logOpStart("updating", update.endpoint); ops.push( - this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)), + this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1!, scraperV2!)), ); } } else if (phase === "deletes") { From 1dfaea3b3d57557fa9ef578497c034fd8f93da7d Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Fri, 10 Apr 2026 19:43:05 +0000 Subject: [PATCH 3/7] linting fixes --- src/deploy/functions/release/fabricator.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index 5373237a2d1..fbfd63055bd 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -171,23 +171,31 @@ export class Fabricator { phase: "createsAndUpdates" | "deletes", ): Promise> { const ops: Array> = []; - + if (phase === "createsAndUpdates") { + if (!scraperV1 || !scraperV2) { + throw new FirebaseError("Internal error: scrapers are required for creates and updates", { + exit: 1, + }); + } + const s1 = scraperV1; + const s2 = scraperV2; + for (const endpoint of changes.endpointsToCreate) { this.logOpStart("creating", endpoint); ops.push( - this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1!, scraperV2!)), + this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, s1, s2)), ); } - + for (const endpoint of changes.endpointsToSkip) { utils.logSuccess(this.getLogSuccessMessage("skip", endpoint)); } - + for (const update of changes.endpointsToUpdate) { this.logOpStart("updating", update.endpoint); ops.push( - this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1!, scraperV2!)), + this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, s1, s2)), ); } } else if (phase === "deletes") { @@ -196,7 +204,7 @@ export class Fabricator { ops.push(this.wrapOperation("delete", endpoint, () => this.deleteEndpoint(endpoint))); } } - + return Promise.all(ops); } From 48c797f30832c43752d6add9de589acc0e0f5360 Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Mon, 13 Apr 2026 19:27:38 +0000 Subject: [PATCH 4/7] Review changes --- .../functions/release/fabricator.spec.ts | 17 +- src/deploy/functions/release/fabricator.ts | 165 +++++++++--------- 2 files changed, 97 insertions(+), 85 deletions(-) diff --git a/src/deploy/functions/release/fabricator.spec.ts b/src/deploy/functions/release/fabricator.spec.ts index c697885b399..a664c5f2895 100644 --- a/src/deploy/functions/release/fabricator.spec.ts +++ b/src/deploy/functions/release/fabricator.spec.ts @@ -1734,9 +1734,14 @@ describe("Fabricator", () => { }, }; + let resolveCreate: () => void; + const createPromise = new Promise((resolve) => { + resolveCreate = resolve; + }); + let createFinished = false; const createEndpoint = sinon.stub(fab, "createEndpoint").callsFake(async () => { - await new Promise((resolve) => setTimeout(resolve, 100)); + await createPromise; createFinished = true; }); @@ -1744,7 +1749,15 @@ describe("Fabricator", () => { expect(createFinished).to.be.true; }); - await fab.applyPlan(plan); + const applyPlanPromise = fab.applyPlan(plan); + + // At this point, create should be pending, and delete should NOT have run yet. + expect(deleteEndpoint).to.not.have.been.called; + + // Resolve the create operation + resolveCreate!(); + + await applyPlanPromise; expect(createEndpoint).to.have.been.calledOnce; expect(deleteEndpoint).to.have.been.calledOnce; diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index fbfd63055bd..d679be569ae 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -99,110 +99,109 @@ export class Fabricator { const changesets = Object.values(plan); // Phase 1: Creates and Updates - const createAndUpdatePromises = changesets.map(async (changes) => { - const scraperV1 = new SourceTokenScraper(); - const scraperV2 = new SourceTokenScraper(); - return this.applyChangeset(changes, scraperV1, scraperV2, "createsAndUpdates"); + const scraperV1 = new SourceTokenScraper(); + const scraperV2 = new SourceTokenScraper(); + const createAndUpdatePromises = changesets.map((changes) => { + return this.applyUpserts(changes, scraperV1, scraperV2); }); const createAndUpdateResultsArray = await utils.allSettled(createAndUpdatePromises); - createAndUpdateResultsArray.forEach((r, i) => { + // Process results of Phase 1 + const upsertResults = createAndUpdateResultsArray.reduce((acc, r, i) => { if (r.status === "fulfilled") { - summary.results.push(...r.value); - } else { - logger.debug( - "Fabricator.applyChangeset returned an unhandled exception.", - JSON.stringify(r.reason, null, 2), - ); - // Map failure back to all endpoints in the changeset so the reporter knows they failed. - const changes = changesets[i]; - const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); - for (const endpoint of changes.endpointsToCreate) { - summary.results.push({ endpoint, durationMs: 0, error }); - } - for (const update of changes.endpointsToUpdate) { - summary.results.push({ endpoint: update.endpoint, durationMs: 0, error }); - } + return [...acc, ...r.value]; } - }); - - const hasFailures = - summary.results.some((r) => r.error) || - createAndUpdateResultsArray.some((r) => r.status === "rejected"); + // Handle rejection + logger.debug( + "Fabricator.applyUpserts returned an unhandled exception.", + JSON.stringify(r.reason, null, 2), + ); + const changes = changesets[i]; + const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); + const aborts = [ + ...changes.endpointsToCreate.map((endpoint) => ({ endpoint, durationMs: 0, error })), + ...changes.endpointsToUpdate.map((update) => ({ endpoint: update.endpoint, durationMs: 0, error })), + ]; + return [...acc, ...aborts]; + }, []); + + summary.results.push(...upsertResults); + + // Simplify failure check (remove redundant check on createAndUpdateResultsArray) + const hasFailures = summary.results.some((r) => r.error); if (hasFailures) { utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes."); - for (const changes of changesets) { - for (const endpoint of changes.endpointsToDelete) { - summary.results.push({ - endpoint, - durationMs: 0, - error: new reporter.AbortedDeploymentError(endpoint), - }); - } - } - } else { - // Phase 2: Deletes - const deletePromises = changesets.map(async (changes) => { - return this.applyChangeset(changes, undefined, undefined, "deletes"); - }); - const deleteResultsArray = await utils.allSettled(deletePromises); - - for (const r of deleteResultsArray) { - if (r.status === "fulfilled") { - summary.results.push(...r.value); - } else { - logger.debug( - "Fabricator.applyChangeset returned an unhandled exception. This should never happen", - JSON.stringify(r.reason, null, 2), - ); - } - } + + const aborts = changesets.reduce((accum, changes) => { + const currentAborts = changes.endpointsToDelete.map((endpoint) => ({ + endpoint, + durationMs: 0, + error: new reporter.AbortedDeploymentError(endpoint), + })); + return [...accum, ...currentAborts]; + }, []); + + summary.results.push(...aborts); + summary.totalTime = timer.stop(); + return summary; // Early exit! } + // Phase 2: Deletes + const deletePromises = changesets.map((changes) => this.applyDeletes(changes)); + const deleteResultsArray = await utils.allSettled(deletePromises); + + const deleteResults = deleteResultsArray.reduce((acc, r) => { + if (r.status === "fulfilled") { + return [...acc, ...r.value]; + } + logger.debug( + "Fabricator.applyDeletes returned an unhandled exception. This should never happen", + JSON.stringify(r.reason, null, 2), + ); + return acc; + }, []); + + summary.results.push(...deleteResults); + summary.totalTime = timer.stop(); return summary; } - async applyChangeset( + async applyUpserts( changes: planner.Changeset, - scraperV1: SourceTokenScraper | undefined, - scraperV2: SourceTokenScraper | undefined, - phase: "createsAndUpdates" | "deletes", + scraperV1: SourceTokenScraper, + scraperV2: SourceTokenScraper, ): Promise> { const ops: Array> = []; - if (phase === "createsAndUpdates") { - if (!scraperV1 || !scraperV2) { - throw new FirebaseError("Internal error: scrapers are required for creates and updates", { - exit: 1, - }); - } - const s1 = scraperV1; - const s2 = scraperV2; + for (const endpoint of changes.endpointsToCreate) { + this.logOpStart("creating", endpoint); + ops.push( + this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)), + ); + } - for (const endpoint of changes.endpointsToCreate) { - this.logOpStart("creating", endpoint); - ops.push( - this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, s1, s2)), - ); - } + for (const endpoint of changes.endpointsToSkip) { + utils.logSuccess(this.getLogSuccessMessage("skip", endpoint)); + } - for (const endpoint of changes.endpointsToSkip) { - utils.logSuccess(this.getLogSuccessMessage("skip", endpoint)); - } + for (const update of changes.endpointsToUpdate) { + this.logOpStart("updating", update.endpoint); + ops.push( + this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)), + ); + } - for (const update of changes.endpointsToUpdate) { - this.logOpStart("updating", update.endpoint); - ops.push( - this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, s1, s2)), - ); - } - } else if (phase === "deletes") { - for (const endpoint of changes.endpointsToDelete) { - this.logOpStart("deleting", endpoint); - ops.push(this.wrapOperation("delete", endpoint, () => this.deleteEndpoint(endpoint))); - } + return Promise.all(ops); + } + + async applyDeletes(changes: planner.Changeset): Promise> { + const ops: Array> = []; + + for (const endpoint of changes.endpointsToDelete) { + this.logOpStart("deleting", endpoint); + ops.push(this.wrapOperation("delete", endpoint, () => this.deleteEndpoint(endpoint))); } return Promise.all(ops); From 7d05025e2988751dd50aec0e87bfc3795e988731 Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Mon, 13 Apr 2026 20:39:10 +0000 Subject: [PATCH 5/7] Lint fixes --- .../functions/release/fabricator.spec.ts | 2 +- src/deploy/functions/release/fabricator.ts | 55 +++++++++++-------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/deploy/functions/release/fabricator.spec.ts b/src/deploy/functions/release/fabricator.spec.ts index a664c5f2895..1608c7c0608 100644 --- a/src/deploy/functions/release/fabricator.spec.ts +++ b/src/deploy/functions/release/fabricator.spec.ts @@ -1753,7 +1753,7 @@ describe("Fabricator", () => { // At this point, create should be pending, and delete should NOT have run yet. expect(deleteEndpoint).to.not.have.been.called; - + // Resolve the create operation resolveCreate!(); diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index d679be569ae..2a3d644fe88 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -107,24 +107,31 @@ export class Fabricator { const createAndUpdateResultsArray = await utils.allSettled(createAndUpdatePromises); // Process results of Phase 1 - const upsertResults = createAndUpdateResultsArray.reduce((acc, r, i) => { - if (r.status === "fulfilled") { - return [...acc, ...r.value]; - } - // Handle rejection - logger.debug( - "Fabricator.applyUpserts returned an unhandled exception.", - JSON.stringify(r.reason, null, 2), - ); - const changes = changesets[i]; - const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); - const aborts = [ - ...changes.endpointsToCreate.map((endpoint) => ({ endpoint, durationMs: 0, error })), - ...changes.endpointsToUpdate.map((update) => ({ endpoint: update.endpoint, durationMs: 0, error })), - ]; - return [...acc, ...aborts]; - }, []); - + const upsertResults = createAndUpdateResultsArray.reduce( + (acc, r, i) => { + if (r.status === "fulfilled") { + return [...acc, ...r.value]; + } + // Handle rejection + logger.debug( + "Fabricator.applyUpserts returned an unhandled exception.", + JSON.stringify(r.reason, null, 2), + ); + const changes = changesets[i]; + const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); + const aborts = [ + ...changes.endpointsToCreate.map((endpoint) => ({ endpoint, durationMs: 0, error })), + ...changes.endpointsToUpdate.map((update) => ({ + endpoint: update.endpoint, + durationMs: 0, + error, + })), + ]; + return [...acc, ...aborts]; + }, + [], + ); + summary.results.push(...upsertResults); // Simplify failure check (remove redundant check on createAndUpdateResultsArray) @@ -132,7 +139,7 @@ export class Fabricator { if (hasFailures) { utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes."); - + const aborts = changesets.reduce((accum, changes) => { const currentAborts = changes.endpointsToDelete.map((endpoint) => ({ endpoint, @@ -141,7 +148,7 @@ export class Fabricator { })); return [...accum, ...currentAborts]; }, []); - + summary.results.push(...aborts); summary.totalTime = timer.stop(); return summary; // Early exit! @@ -178,7 +185,9 @@ export class Fabricator { for (const endpoint of changes.endpointsToCreate) { this.logOpStart("creating", endpoint); ops.push( - this.wrapOperation("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2)), + this.wrapOperation("create", endpoint, () => + this.createEndpoint(endpoint, scraperV1, scraperV2), + ), ); } @@ -189,7 +198,9 @@ export class Fabricator { for (const update of changes.endpointsToUpdate) { this.logOpStart("updating", update.endpoint); ops.push( - this.wrapOperation("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2)), + this.wrapOperation("update", update.endpoint, () => + this.updateEndpoint(update, scraperV1, scraperV2), + ), ); } From 95fa91fc65cd962393af68e262d47b31a191875d Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Wed, 15 Apr 2026 19:05:15 +0000 Subject: [PATCH 6/7] Review comments --- src/deploy/functions/release/fabricator.ts | 51 ++++++++-------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/deploy/functions/release/fabricator.ts b/src/deploy/functions/release/fabricator.ts index 2a3d644fe88..458a10f4570 100644 --- a/src/deploy/functions/release/fabricator.ts +++ b/src/deploy/functions/release/fabricator.ts @@ -104,35 +104,20 @@ export class Fabricator { const createAndUpdatePromises = changesets.map((changes) => { return this.applyUpserts(changes, scraperV1, scraperV2); }); - const createAndUpdateResultsArray = await utils.allSettled(createAndUpdatePromises); + const createAndUpdateResultsArray = await Promise.allSettled(createAndUpdatePromises); // Process results of Phase 1 - const upsertResults = createAndUpdateResultsArray.reduce( - (acc, r, i) => { - if (r.status === "fulfilled") { - return [...acc, ...r.value]; - } - // Handle rejection - logger.debug( - "Fabricator.applyUpserts returned an unhandled exception.", - JSON.stringify(r.reason, null, 2), - ); - const changes = changesets[i]; - const error = r.reason instanceof Error ? r.reason : new Error(String(r.reason)); - const aborts = [ - ...changes.endpointsToCreate.map((endpoint) => ({ endpoint, durationMs: 0, error })), - ...changes.endpointsToUpdate.map((update) => ({ - endpoint: update.endpoint, - durationMs: 0, - error, - })), - ]; - return [...acc, ...aborts]; - }, - [], - ); - - summary.results.push(...upsertResults); + summary.results = createAndUpdateResultsArray.reduce((acc, r) => { + if (r.status === "fulfilled") { + return [...acc, ...r.value]; + } + // Handle rejection + logger.debug( + "Fabricator.applyUpserts returned an unhandled exception.", + JSON.stringify(r.reason, null, 2), + ); + return acc; + }, []); // Simplify failure check (remove redundant check on createAndUpdateResultsArray) const hasFailures = summary.results.some((r) => r.error); @@ -140,23 +125,23 @@ export class Fabricator { if (hasFailures) { utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes."); - const aborts = changesets.reduce((accum, changes) => { + summary.results = changesets.reduce((accum, changes) => { const currentAborts = changes.endpointsToDelete.map((endpoint) => ({ endpoint, durationMs: 0, error: new reporter.AbortedDeploymentError(endpoint), })); return [...accum, ...currentAborts]; - }, []); + }, summary.results); - summary.results.push(...aborts); summary.totalTime = timer.stop(); - return summary; // Early exit! + return summary; } // Phase 2: Deletes - const deletePromises = changesets.map((changes) => this.applyDeletes(changes)); - const deleteResultsArray = await utils.allSettled(deletePromises); + const deleteResultsArray = await Promise.allSettled( + changesets.map((changes) => this.applyDeletes(changes)), + ); const deleteResults = deleteResultsArray.reduce((acc, r) => { if (r.status === "fulfilled") { From 12868bd79088b68be1181c4e894245396b992260 Mon Sep 17 00:00:00 2001 From: Varun Shetty Date: Wed, 15 Apr 2026 21:16:36 +0000 Subject: [PATCH 7/7] trigger ci