forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

ai.contract.test.ts69 lines, 3.5 KiBHistoryRawDownload
1import { api, contractBaseUrl, expectPage, isLive, json, loginAdmin, SKIP_MESSAGE } from "./helpers/live-client";
2
3if (!isLive) console.warn(SKIP_MESSAGE);
4
5// The insights and podcast doors stand in front of an AI service the scratch
6// backend does not have to be running. So every assertion here is written to
7// hold in both worlds: the reads answer their DTO either way (they only serve
8// stored rows), and the detached writes are allowed to answer 503 — what they
9// may never do is 500, or invent a receipt they did not queue.
10describe.skipIf(!isLive)(`ai contract @ ${contractBaseUrl}`, () => {
11 beforeAll(loginAdmin);
12
13 it("answers the caller's own insight with every section present", async () => {
14 const insight = await json<Record<string, unknown>>("/insights/me");
15 expect(typeof insight.user_id).toBe("string");
16 // Arrays, never null: an absent section and an empty one are different
17 // claims, and the client renders them differently.
18 expect(Array.isArray(insight.attention)).toBe(true);
19 expect(Array.isArray(insight.cards)).toBe(true);
20 expect(Array.isArray(insight.segments)).toBe(true);
21 // `summary` is null until ZEKA has computed this caller at least once.
22 expect(insight.summary === null || typeof insight.summary === "object").toBe(true);
23 });
24
25 it("pages the run ledger for a manager+ caller", async () => {
26 expectPage(await json("/insights/runs?limit=1"));
27 });
28
29 it("keeps a run row's counters and pending list on the documented shape", async () => {
30 const page = await json<{ items: Record<string, unknown>[] }>("/insights/runs?limit=1");
31 const run = page.items[0];
32 if (!run) return; // A backend that has never swept has no row to check.
33 expect(typeof run.run_day).toBe("string");
34 expect(["running", "ok", "partial", "failed", "skipped"]).toContain(run.status);
35 expect(typeof run.students_total).toBe("number");
36 expect(typeof run.budget_exceeded).toBe("boolean");
37 expect(Array.isArray(run.pending_students)).toBe(true);
38 expect(Array.isArray(run.failed_modules)).toBe(true);
39 });
40
41 it("either queues a school-wide recompute or refuses it for want of a service", async () => {
42 const response = await api("/insights/refresh", { method: "POST", body: {} });
43 expect([202, 503]).toContain(response.status);
44 if (response.status === 202) {
45 const receipt = (await response.json()) as Record<string, unknown>;
46 expect(typeof receipt.message_id).toBe("string");
47 expect(receipt.status).toBe("pending");
48 }
49 });
50
51 it("refuses a podcast job for an unknown source without pretending to queue it", async () => {
52 const response = await api("/podcast/jobs", {
53 method: "POST",
54 body: { source_id: "00000000-0000-0000-0000-000000000000" },
55 });
56 // 503 with no service, 400/404 for the missing course note once there is
57 // one. A 202 here would mean the backend minted a job for nothing.
58 expect([400, 404, 503]).toContain(response.status);
59 });
60
61 it("answers nothing for an audio job id that is not the caller's", async () => {
62 // The stream is addressed by job id and resolved from the caller's own job
63 // row, so a caller cannot name a file at all — an unknown id is a 404, and
64 // never bytes. (The old `?path=` door, which took a client-supplied path
65 // and answered 400 on escape, is gone.)
66 const response = await api(`/podcast/jobs/${encodeURIComponent("00000000-0000-0000-0000-000000000000")}/audio`);
67 expect([404, 503]).toContain(response.status);
68 });
69});