feat: prepare 2.6.1-rc5 shared databases and build SSE

This commit is contained in:
2026-10-05 11:09:52 +00:00 Unverified
parent f76165603e
commit 828bf3a328
25 changed files with 2557 additions and 196 deletions
+68
View File
@@ -7,6 +7,7 @@ import {
apiUpload,
} from "../../lib/api";
import type { KuberSession } from "../../lib/session";
import { createVersionObserver } from "../../lib/version-update";
const originalFetch = globalThis.fetch;
const session: KuberSession = {
@@ -19,6 +20,73 @@ afterEach(() => {
globalThis.fetch = originalFetch;
});
test("observes the response header on JSON, errors, uploads and streaming without delaying payloads", async () => {
const seen: Array<string | null> = [];
const onServerVersion = (version: string | null) => {
seen.push(version);
};
const options = {
authenticated: false,
baseUrl: "https://api.test",
onServerVersion,
};
const encoder = new TextEncoder();
globalThis.fetch = mock(async (input) => {
const path = new URL(String(input)).pathname;
const headers = { "x-kuber-version": "2.7.0" };
if (path === "/error")
return Response.json({ detail: "failure" }, { status: 503, headers });
if (path === "/upload") return new Response(null, { status: 204, headers });
if (path === "/stream")
return new Response(
new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode('{"n":1}\n'));
},
}),
{ headers },
);
return Response.json({ ok: true }, { headers });
}) as unknown as typeof fetch;
expect(await apiRequest<{ ok: boolean }>("/json", {}, options)).toEqual({
ok: true,
});
await expect(apiRequest("/error", {}, options)).rejects.toBeInstanceOf(
KuberApiError,
);
await apiUpload("/upload", new Uint8Array([1]), { ...options, offset: 0 });
let complete!: (success: boolean) => void;
const pending = new Promise<boolean>((resolve) => {
complete = resolve;
});
const lines: string[] = [];
const observer = createVersionObserver({
currentVersion: "2.6.1",
runner: () => pending,
report: (line) => lines.push(line),
});
const records = apiStreamNdjson<{ n: number }>(
"/stream",
{},
{
...options,
onServerVersion: (version) => {
onServerVersion(version);
observer(version);
},
},
);
expect((await records.next()).value).toEqual({ n: 1 });
expect(seen).toEqual(["2.7.0", "2.7.0", "2.7.0", "2.7.0"]);
expect(lines).toEqual([]);
await records.return();
complete(false);
await new Promise<void>((resolve) => setTimeout(resolve, 0));
expect(lines).toEqual(["\x1b[90m+ New version available: 2.7.0\x1b[0m\n"]);
});
describe("authenticated API transport", () => {
test("sends authentication and serializes JSON", async () => {
const fetchMock = mock(