Open History to see the last commit
1import assert from "node:assert/strict";
2import { randomUUID } from "node:crypto";
3import { mkdir, writeFile } from "node:fs/promises";
4import "./node-websocket";
5import { createRealtimeClient } from "@neon/realtime/client";
6import type { AIConversationRow } from "../src/shared/types";
7if (!process.argv.includes("--generate"))
8 throw new Error("Pass --generate to authorize one real Gateway build.");
9const base = process.env.VITE_API_URL!.replace(/\/$/, "");
10let token = "";
11async function request(path: string, body?: unknown) {
12 const response = await fetch(`${base}/api${path}`, {
13 method: body === undefined ? "GET" : "POST",
14 headers: {
15 "Content-Type": "application/json",
16 ...(token ? { Authorization: `Bearer ${token}` } : {}),
17 },
18 ...(body === undefined ? {} : { body: JSON.stringify(body) }),
19 signal: AbortSignal.timeout(20000),
20 });
21 const data = await response.json();
22 assert.ok(response.ok, `${path}: ${response.status} ${data.error}`);
23 return data;
24}
25const rt = createRealtimeClient({ url: process.env.VITE_NEON_REALTIME_URL! });
26try {
27 const health = await request(`/health?qualification=${Date.now()}`);
28 assert.equal(
29 health.aiBuilder,
30 "realtime-lifecycle-2",
31 "Wait for the corrected Function release",
32 );
33 token = (
34 await request("/session", { name: "Server dispatch QA", color: "#289b74" })
35 ).token;
36 const job = await request("/ai/generations", {
37 id: randomUUID(),
38 prompt:
39 "A tiny green brick tower with a red cap, about five pieces. Keep it simple.",
40 newWorld: true,
41 });
42 const sub = rt.subscribe<AIConversationRow>(
43 await request(`/worlds/${job.target}/live/ai`),
44 );
45 let last = "";
46 sub.onChange((snapshot) => {
47 const current = snapshot.data?.find((row) => row.id === job.id);
48 if (current && current.status !== last) {
49 last = current.status;
50 console.log(`Server-owned build: ${last}`);
51 }
52 });
53 // No browser panel and no /run request: the Function owns execution.
54 await sub.awaitRows(
55 (rows) =>
56 rows.some(
57 (r) =>
58 r.id === job.id &&
59 ["ready", "failed", "cancelled"].includes(r.status),
60 ),
61 175000,
62 );
63 const result = sub.getSnapshot().data!.find((row) => row.id === job.id)!;
64 assert.equal(result.status, "ready", result.error || "Build did not finish");
65 assert.ok(result.preview?.parts.length);
66 await mkdir("artifacts/realtime-fixes", { recursive: true });
67 await writeFile(
68 "artifacts/realtime-fixes/dispatch.json",
69 JSON.stringify(
70 {
71 slug: job.target_slug,
72 world: job.target,
73 id: job.id,
74 pieces: result.piece_count,
75 status: result.status,
76 },
77 null,
78 2,
79 ),
80 );
81 console.log(
82 `PASS deployed waitUntil dispatch and trusted cancellation subscription. ${result.piece_count} pieces, QA workshop ${job.target_slug}. No client run or lifecycle polling.`,
83 );
84} finally {
85 rt.close();
86 if (token) await request("/session/revoke", {}).catch(() => {});
87}