fix: trust publish runner success over stale timeout

This commit is contained in:
Oleg Isonen committed 2026-11-15 16:14:42 +00:00
1 parent 852023b5c8
commit 875a9f4b58
2 files changed
+56 -10

No files matched your search

@@ -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(() => {});
@@ -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 };
}
}