test(server): wait for spawned runtime metadata

The provisioning row enters starting state before the spawned process identifier is persisted. Wait for both conditions so the test observes the intended post-spawn record instead of the valid intermediate row.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-08-10 08:24:55 +00:00
1 parent 59958f9550
commit a31d6fcf55
1 file changed
+9 -3
@@ -5495,7 +5495,10 @@ describeEmbeddedPostgres("workspace runtime service control persistence", () =>
}
throw new Error("Timed out waiting for runtime service process marker");
};
const waitForPersistedStatus = async (status: string) => {
const waitForPersistedStatus = async (
status: string,
isReady?: (row: typeof workspaceRuntimeServices.$inferSelect) => boolean,
) => {
const deadline = Date.now() + 5_000;
while (Date.now() < deadline) {
const row = await db
@@ -5503,7 +5506,7 @@ describeEmbeddedPostgres("workspace runtime service control persistence", () =>
.from(workspaceRuntimeServices)
.where(eq(workspaceRuntimeServices.executionWorkspaceId, executionWorkspaceId))
.then((rows) => rows[0] ?? null);
if (row?.status === status) return row;
if (row?.status === status && (!isReady || isReady(row))) return row;
await new Promise((resolve) => setTimeout(resolve, 25));
}
throw new Error(`Timed out waiting for persisted runtime service status ${status}`);
@@ -5570,7 +5573,10 @@ describeEmbeddedPostgres("workspace runtime service control persistence", () =>
expect(existsSync(markerPath)).toBe(false);
await waitForMarker(markerPath);
const startingRow = await waitForPersistedStatus("starting");
const startingRow = await waitForPersistedStatus(
"starting",
(row) => typeof row.providerRef === "string",
);
expect(startingRow).toMatchObject({
companyId,
projectId,