From 875a9f4b5802734bfa48641e23926fabda5ac0da Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sun, 15 Nov 2026 15:47:21 +0000 Subject: [PATCH] fix: trust publish runner success over stale timeout --- .../publish/publish-progress.test.tsx | 45 +++++++++++++++++-- .../features/publish/publish-progress.tsx | 21 ++++++--- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/apps/builder/app/builder/features/publish/publish-progress.test.tsx b/apps/builder/app/builder/features/publish/publish-progress.test.tsx index a09dde2894..1af5116321 100644 --- a/apps/builder/app/builder/features/publish/publish-progress.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-progress.test.tsx @@ -54,7 +54,7 @@ test("a pending runner cannot promote a refreshed Build to success", async () => createdAt: new Date().toISOString(), publishStatus: "PUBLISHED", }, - }) as Project + } as Project) ); const getJob = vi .fn() @@ -84,7 +84,7 @@ test("a pending runner cannot turn a timed-out Build into failure", async () => createdAt: "2026-11-13T10:00:00Z", publishStatus: "PENDING", }, - }) as Project + } as Project) ); const getJob = vi .fn() @@ -112,7 +112,7 @@ test("static status waits for the matching runner before download readiness", as updatedAt: new Date().toISOString(), publishStatus: "PUBLISHED", }, - }) as Project + } as Project) ); const getJob = vi .fn() @@ -150,7 +150,7 @@ test.each(["site", "static"] as const)( ({ latestBuildVirtual: target === "site" ? newerBuild : null, latestStaticBuild: target === "static" ? newerBuild : null, - }) as Project + } as Project) ); const getJob = vi.fn(async () => ({ status: "success" })); const waiting = waitForPublishStatus( @@ -172,6 +172,43 @@ test.each(["site", "static"] as const)( } ); +test.each(["site", "static"] as const)( + "does not treat a stale %s pending build as failed after runner success", + async (target) => { + vi.useFakeTimers(); + vi.setSystemTime(new Date("2026-11-13T10:10:00Z")); + const staleBuild = { + buildId: "build-1", + createdAt: "2026-11-13T10:00:00Z", + updatedAt: "2026-11-13T10:00:00Z", + publishStatus: "PENDING", + }; + const refresh = vi.fn( + async () => + ({ + latestBuildVirtual: target === "site" ? staleBuild : null, + latestStaticBuild: target === "static" ? staleBuild : null, + } as Project) + ); + const getJob = vi.fn(async () => ({ status: "success" })); + const result = await waitForPublishStatus( + refresh, + () => true, + undefined, + { + projectId: "project", + buildId: "build-1", + logHandle: "handle-1", + target, + }, + getJob + ); + + expect(result?.status).toBe("PUBLISHED"); + expect(refresh).toHaveBeenCalledOnce(); + } +); + test("reopening refresh retries after a rejected status request", async () => { vi.useFakeTimers(); const errorLog = vi.spyOn(console, "error").mockImplementation(() => {}); diff --git a/apps/builder/app/builder/features/publish/publish-progress.tsx b/apps/builder/app/builder/features/publish/publish-progress.tsx index 9b42df7e6a..03e0b10510 100644 --- a/apps/builder/app/builder/features/publish/publish-progress.tsx +++ b/apps/builder/app/builder/features/publish/publish-progress.tsx @@ -80,13 +80,22 @@ export const waitForPublishStatus = async ( refreshedProject.latestStaticBuild != null ? getStaticPublishStatusDisplay(refreshedProject.latestStaticBuild) : refreshedProject.latestBuildVirtual != null - ? getPublishStatusDisplay(refreshedProject.latestBuildVirtual) - : { - statusContent: "Not published", - status: "PENDING" as const, - }; + ? getPublishStatusDisplay(refreshedProject.latestBuildVirtual) + : { + statusContent: "Not published", + status: "PENDING" as const, + }; - if (!runnerPending && (status === "PUBLISHED" || status === "FAILED")) { + const inferredFailure = + status === "FAILED" && + (execution?.target === "static" + ? refreshedProject.latestStaticBuild?.publishStatus + : refreshedProject.latestBuildVirtual?.publishStatus) === "PENDING"; + if ( + !runnerPending && + (status === "PUBLISHED" || status === "FAILED") && + !(runnerSucceeded && inferredFailure) + ) { return { status, statusContent }; } }