Files
c0py/apps/web/tests/api-status.test.ts
T
Claude CodeandClaude Opus 5 a1b3fef1ac
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / contracts (push) Successful in 31s
Component conformance / Component conformance (blocking) (push) Failing after 45s
CI (SIAX Cloud) / quality (push) Successful in 1m53s
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / security (pull_request) Successful in 35s
security / scan (pull_request) Failing after 26s
Component conformance / Component conformance (blocking) (pull_request) Failing after 46s
CI (SIAX Cloud) / contracts (pull_request) Successful in 50s
CI (SIAX Cloud) / quality (pull_request) Successful in 2m15s
fix(web): byt ut platshallarsidan mot en riktig C0PY-konsol
c0py.siax.io och c0py-web.siax.io renderade bokstavligen <div>c0py</div>
(4 tecken synlig text) - rotsidan var en platshallare i repot, inte ett
driftfel. Headless-matning 2026-11-11 fran server11: HTTP 200, tom title,
textLen=4, 0 lankar, 0 knappar.

Rotsidan renderar nu riktigt innehall grundat i repots egna fakta:

* produktidentitet och syfte ur README.md,
* LIVE API-status last server-side ur API:ets egen publika /health
  (status, CL0UD-bindning, API-tid, lastid) - och en uttrycklig
  "kunde inte lasas"-text nar API:et inte svarar, aldrig en pahittad status,
* den faktiska API-ytan (/health publik, /v1/c0py/registries|scans bearer)
  enligt apps/api/src,
* den kanoniska pipelinen ur README/MASTERPLAN.

Dessutom:
* /api/health for c0py-web (status, commit, apiBaseUrl) - samma monster som
  ovriga SIAX-produkter; Dockerfile.web skriver commit till /app/.c0py-commit
  och HEALTHCHECK pekar nu pa /api/health i stallet for /,
* app/icon.svg - c0py-surfacen gav 404 pa /favicon.ico vid varje sidladdning,
* 7 enhetstester for statuslasningen (inkl. att fel och timeout INTE
  rapporteras som ok) ersatter noop-testet.

SIAX-design: Inter, blacksvart rubrik #15151B, violett sidkant #5326CC,
morkt identitetsfalt. Inga nya beroenden (lockfilen oforandrad), inga lokala
DES1GN-primitivnamn exporteras.

Verifierat lokalt: validate:architecture OK, typecheck OK, 7/7 webbtester,
next build OK, next start ger 1475 tecken synlig text och /api/health 200
med live API-status (HTTP 200, status ok, cl0ud disabled).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-11 01:10:48 +01:00

71 lines
2.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
API_SURFACE,
DEFAULT_API_BASE_URL,
PIPELINE,
apiBaseUrl,
fetchApiStatus,
} from "../src/lib/api-status";
function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
}
describe("apiBaseUrl", () => {
it("falls back to the canonical API host", () => {
expect(apiBaseUrl({})).toBe(DEFAULT_API_BASE_URL);
});
it("uses the configured base URL and strips trailing slashes", () => {
expect(apiBaseUrl({ C0PY_API_BASE_URL: "https://c0py-api.example.test/" })).toBe(
"https://c0py-api.example.test",
);
});
});
describe("fetchApiStatus", () => {
it("reports the status the API actually returned", async () => {
const result = await fetchApiStatus("https://api.test", async (input) => {
expect(String(input)).toBe("https://api.test/health");
return jsonResponse({ status: "ok", timestamp: "2026-11-11T00:00:00.000Z", cl0ud: "disabled" });
});
expect(result.reachable).toBe(true);
if (!result.reachable) throw new Error("expected reachable");
expect(result.status).toBe("ok");
expect(result.cl0ud).toBe("disabled");
expect(result.timestamp).toBe("2026-11-11T00:00:00.000Z");
});
it("does not invent a status when the API answers an error code", async () => {
const result = await fetchApiStatus("https://api.test", async () => jsonResponse({}, 503));
expect(result.reachable).toBe(false);
if (result.reachable) throw new Error("expected unreachable");
expect(result.httpStatus).toBe(503);
expect(result.reason).toContain("503");
});
it("does not invent a status when the API cannot be reached", async () => {
const result = await fetchApiStatus("https://api.test", async () => {
throw new Error("getaddrinfo ENOTFOUND api.test");
});
expect(result.reachable).toBe(false);
if (result.reachable) throw new Error("expected unreachable");
expect(result.reason).toContain("ENOTFOUND");
});
});
describe("declared product surface", () => {
it("documents the public health route and the bearer-only v1 routes", () => {
expect(API_SURFACE.find((r) => r.path === "/health")?.auth).toBe("public");
const v1 = API_SURFACE.filter((r) => r.path.startsWith("/v1/c0py/"));
expect(v1.length).toBeGreaterThanOrEqual(4);
expect(v1.every((r) => r.auth === "bearer")).toBe(true);
});
it("keeps the canonical pipeline from the masterplan", () => {
expect(PIPELINE[0]).toBe("Source product");
expect(PIPELINE).toContain("Evidence Graph / Canonical IR");
expect(PIPELINE.at(-1)).toBe("typed repair loop");
});
});