fix(web): byt ut platshallarsidan mot en riktig C0PY-konsol #24
+3
-2
@@ -13,7 +13,8 @@ RUN apk add --no-cache git wget \
|
||||
&& corepack enable \
|
||||
&& corepack prepare pnpm@9.15.9 --activate
|
||||
|
||||
RUN git clone --depth 1 --branch "${C0PY_REF}" "${C0PY_REPO}" /app
|
||||
RUN git clone --depth 1 --branch "${C0PY_REF}" "${C0PY_REPO}" /app \
|
||||
&& git -C /app rev-parse HEAD > /app/.c0py-commit
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -28,6 +29,6 @@ ENV NEXT_TELEMETRY_DISABLED=1
|
||||
EXPOSE 3000
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD wget -qO- http://127.0.0.1:3000/ >/dev/null 2>&1 || exit 1
|
||||
CMD wget -qO- http://127.0.0.1:3000/api/health >/dev/null 2>&1 || exit 1
|
||||
|
||||
CMD ["pnpm", "--filter", "@siax/c0py-web", "start"]
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { apiBaseUrl } from "../../../lib/api-status";
|
||||
|
||||
/** Build commit, written by Dockerfile.web into .c0py-commit at image build time. */
|
||||
function commit(): string {
|
||||
const fromEnv = process.env.C0PY_WEB_COMMIT?.trim();
|
||||
if (fromEnv) return fromEnv;
|
||||
for (const path of [".c0py-commit", "/app/.c0py-commit"]) {
|
||||
try {
|
||||
const value = readFileSync(path, "utf8").trim();
|
||||
if (value) return value;
|
||||
} catch {
|
||||
/* not present in this environment */
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
return Response.json({
|
||||
status: "ok",
|
||||
service: "c0py-web",
|
||||
commit: commit(),
|
||||
apiBaseUrl: apiBaseUrl(),
|
||||
time: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="C0PY">
|
||||
<rect width="32" height="32" rx="7" fill="#15151B"/>
|
||||
<rect x="7" y="7" width="13" height="13" rx="2.5" fill="none" stroke="#5326CC" stroke-width="2.2"/>
|
||||
<rect x="12" y="12" width="13" height="13" rx="2.5" fill="none" stroke="#F6F6FA" stroke-width="2.2"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 358 B |
@@ -1,3 +1,44 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "C0PY — evidence-driven capture console",
|
||||
description:
|
||||
"C0PY is the canonical SIAX engine for evidence-driven web product capture, digital-twin specification, reconstruction and verification.",
|
||||
};
|
||||
|
||||
const globalCss = `
|
||||
:root {
|
||||
--c0py-ink: #15151b;
|
||||
--c0py-accent: #5326cc;
|
||||
--c0py-paper: #ffffff;
|
||||
--c0py-muted: #5b5b66;
|
||||
--c0py-line: #e4e4ec;
|
||||
--c0py-band: #15151b;
|
||||
--c0py-ok: #1b7f4f;
|
||||
--c0py-warn: #96591a;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; }
|
||||
body {
|
||||
background: var(--c0py-paper);
|
||||
color: var(--c0py-ink);
|
||||
font-family: Inter, "Inter var", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 1.55;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
h1, h2, h3 { color: var(--c0py-ink); margin: 0; font-weight: 650; letter-spacing: -0.01em; }
|
||||
a { color: var(--c0py-accent); }
|
||||
code, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875em; }
|
||||
`;
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return <html lang="sv"><body>{children}</body></html>;
|
||||
return (
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<style dangerouslySetInnerHTML={{ __html: globalCss }} />
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
+133
-3
@@ -1,4 +1,134 @@
|
||||
// Placeholder - Next.js app router entry
|
||||
export default function Home() {
|
||||
return <div>c0py</div>;
|
||||
import { API_SURFACE, PIPELINE, apiBaseUrl, fetchApiStatus } from "../lib/api-status";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const band: React.CSSProperties = {
|
||||
background: "var(--c0py-band)",
|
||||
color: "#f6f6fa",
|
||||
padding: "1.1rem 1.5rem",
|
||||
display: "flex",
|
||||
gap: "0.9rem",
|
||||
alignItems: "baseline",
|
||||
flexWrap: "wrap",
|
||||
};
|
||||
const shell: React.CSSProperties = {
|
||||
maxWidth: 1020,
|
||||
margin: "0 auto",
|
||||
padding: "2rem 1.5rem 3.5rem",
|
||||
borderLeft: "4px solid var(--c0py-accent)",
|
||||
};
|
||||
const panel: React.CSSProperties = {
|
||||
border: "1px solid var(--c0py-line)",
|
||||
borderRadius: 10,
|
||||
padding: "1.1rem 1.25rem",
|
||||
marginTop: "1.25rem",
|
||||
};
|
||||
const th: React.CSSProperties = {
|
||||
textAlign: "left",
|
||||
borderBottom: "1px solid var(--c0py-line)",
|
||||
padding: "0.45rem 0.6rem",
|
||||
fontSize: "0.78rem",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.06em",
|
||||
color: "var(--c0py-muted)",
|
||||
};
|
||||
const td: React.CSSProperties = {
|
||||
borderBottom: "1px solid var(--c0py-line)",
|
||||
padding: "0.45rem 0.6rem",
|
||||
verticalAlign: "top",
|
||||
};
|
||||
|
||||
export default async function Home() {
|
||||
const base = apiBaseUrl();
|
||||
const api = await fetchApiStatus(base);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={band}>
|
||||
<strong style={{ fontSize: "1.15rem", letterSpacing: "0.04em" }}>C0PY</strong>
|
||||
<span style={{ color: "#b9b4d8", fontSize: "0.9rem" }}>
|
||||
SIAX · evidence-driven capture, digital-twin specification and verification
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<main style={shell}>
|
||||
<h1 style={{ fontSize: "1.9rem", marginBottom: "0.6rem" }}>Capture console</h1>
|
||||
<p style={{ color: "var(--c0py-muted)", maxWidth: 760, marginTop: 0 }}>
|
||||
C0PY consumes an authorized web target and produces a versioned Evidence Graph / Canonical IR
|
||||
covering routes, DOM and runtime state, styles, assets, responsive behaviour, interactions,
|
||||
workflows, network contracts, motion, accessibility and product topology. Reconstruction
|
||||
builders consume frozen C0PY specs; they never become the source of truth.
|
||||
</p>
|
||||
|
||||
<section style={panel} aria-labelledby="api-status-heading">
|
||||
<h2 id="api-status-heading" style={{ fontSize: "1.05rem" }}>API status</h2>
|
||||
{api.reachable ? (
|
||||
<p style={{ margin: "0.5rem 0 0" }}>
|
||||
<span style={{ color: "var(--c0py-ok)", fontWeight: 600 }}>
|
||||
{base} answered HTTP {api.httpStatus}: status {api.status}
|
||||
</span>
|
||||
<br />
|
||||
<span className="mono" style={{ color: "var(--c0py-muted)" }}>
|
||||
CL0UD binding: {api.cl0ud ?? "not reported"} · API time: {api.timestamp ?? "not reported"} · read at{" "}
|
||||
{api.checkedAt}
|
||||
</span>
|
||||
</p>
|
||||
) : (
|
||||
<p style={{ margin: "0.5rem 0 0" }}>
|
||||
<span style={{ color: "var(--c0py-warn)", fontWeight: 600 }}>
|
||||
{base} could not be read ({api.reason}
|
||||
{api.httpStatus ? `, HTTP ${api.httpStatus}` : ""}).
|
||||
</span>
|
||||
<br />
|
||||
<span className="mono" style={{ color: "var(--c0py-muted)" }}>
|
||||
This console reports what it measured at {api.checkedAt}; it does not invent a status.
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section style={panel} aria-labelledby="surface-heading">
|
||||
<h2 id="surface-heading" style={{ fontSize: "1.05rem" }}>API surface</h2>
|
||||
<p style={{ color: "var(--c0py-muted)", marginTop: "0.4rem" }}>
|
||||
The routes the C0PY API serves today. Everything except <code>/health</code> requires a bearer
|
||||
token; this console never asks for one and never stores one.
|
||||
</p>
|
||||
<table style={{ borderCollapse: "collapse", width: "100%" }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>Method</th>
|
||||
<th style={th}>Path</th>
|
||||
<th style={th}>Access</th>
|
||||
<th style={th}>Purpose</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{API_SURFACE.map((route) => (
|
||||
<tr key={`${route.method} ${route.path}`}>
|
||||
<td style={td} className="mono">{route.method}</td>
|
||||
<td style={td} className="mono">{route.path}</td>
|
||||
<td style={td}>{route.auth}</td>
|
||||
<td style={td}>{route.purpose}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section style={panel} aria-labelledby="pipeline-heading">
|
||||
<h2 id="pipeline-heading" style={{ fontSize: "1.05rem" }}>Canonical pipeline</h2>
|
||||
<ol style={{ margin: "0.6rem 0 0", paddingLeft: "1.3rem", color: "var(--c0py-ink)" }}>
|
||||
{PIPELINE.map((step) => (
|
||||
<li key={step} style={{ marginBottom: "0.2rem" }}>{step}</li>
|
||||
))}
|
||||
</ol>
|
||||
</section>
|
||||
|
||||
<p style={{ marginTop: "1.6rem", color: "var(--c0py-muted)", fontSize: "0.85rem" }}>
|
||||
C0PY web · own liveness at <a href="/api/health">/api/health</a> · API liveness at{" "}
|
||||
<a href={`${base}/health`}>{base}/health</a>
|
||||
</p>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Live status for the C0PY API, read from the API's own public /health route.
|
||||
*
|
||||
* Honesty rule (docs/STANDARDS.md): the console never renders an invented
|
||||
* status. If the API cannot be reached, that is what the UI says.
|
||||
*/
|
||||
export type ApiStatus =
|
||||
| {
|
||||
reachable: true;
|
||||
httpStatus: number;
|
||||
status: string;
|
||||
timestamp: string | null;
|
||||
cl0ud: string | null;
|
||||
checkedAt: string;
|
||||
}
|
||||
| {
|
||||
reachable: false;
|
||||
httpStatus: number | null;
|
||||
reason: string;
|
||||
checkedAt: string;
|
||||
};
|
||||
|
||||
export const DEFAULT_API_BASE_URL = "https://c0py-api.siax.io";
|
||||
|
||||
export function apiBaseUrl(env: Record<string, string | undefined> = process.env): string {
|
||||
const raw = env.C0PY_API_BASE_URL?.trim();
|
||||
return (raw && raw.length > 0 ? raw : DEFAULT_API_BASE_URL).replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
export async function fetchApiStatus(
|
||||
baseUrl: string,
|
||||
fetchImpl: typeof fetch = fetch,
|
||||
timeoutMs = 4000,
|
||||
): Promise<ApiStatus> {
|
||||
const checkedAt = new Date().toISOString();
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const res = await fetchImpl(`${baseUrl}/health`, {
|
||||
cache: "no-store",
|
||||
signal: controller.signal,
|
||||
headers: { accept: "application/json" },
|
||||
});
|
||||
if (!res.ok) {
|
||||
return { reachable: false, httpStatus: res.status, reason: `API /health answered HTTP ${res.status}`, checkedAt };
|
||||
}
|
||||
const body: unknown = await res.json();
|
||||
const obj = (body ?? {}) as Record<string, unknown>;
|
||||
return {
|
||||
reachable: true,
|
||||
httpStatus: res.status,
|
||||
status: typeof obj.status === "string" ? obj.status : "unknown",
|
||||
timestamp: typeof obj.timestamp === "string" ? obj.timestamp : null,
|
||||
cl0ud: typeof obj.cl0ud === "string" ? obj.cl0ud : null,
|
||||
checkedAt,
|
||||
};
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.name === "AbortError" ? `no answer within ${timeoutMs} ms` : error.message : "unknown error";
|
||||
return { reachable: false, httpStatus: null, reason, checkedAt };
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
/** The routes the API actually serves today (apps/api/src). */
|
||||
export const API_SURFACE: ReadonlyArray<{ method: string; path: string; auth: "public" | "bearer"; purpose: string }> = [
|
||||
{ method: "GET", path: "/health", auth: "public", purpose: "Liveness and CL0UD binding mode" },
|
||||
{ method: "GET", path: "/v1/c0py/registries", auth: "bearer", purpose: "Registered capture registries" },
|
||||
{ method: "GET", path: "/v1/c0py/registries/:id", auth: "bearer", purpose: "One registry and its provenance" },
|
||||
{ method: "GET", path: "/v1/c0py/scans", auth: "bearer", purpose: "Capture/scan runs" },
|
||||
{ method: "GET", path: "/v1/c0py/scans/:id", auth: "bearer", purpose: "One run, its evidence and fidelity" },
|
||||
];
|
||||
|
||||
/** The canonical pipeline, as declared in README.md / docs/MASTERPLAN.md. */
|
||||
export const PIPELINE: ReadonlyArray<string> = [
|
||||
"Source product",
|
||||
"discovery",
|
||||
"Playwright/CDP deterministic capture",
|
||||
"semantic workflow exploration",
|
||||
"Evidence Graph / Canonical IR",
|
||||
"frozen reconstruction specs",
|
||||
"builders (v0 / Lovable / Codex / generic)",
|
||||
"preview deployment",
|
||||
"multidimensional QA",
|
||||
"typed repair loop",
|
||||
];
|
||||
@@ -0,0 +1,70 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
describe("noop", () => {
|
||||
it("passes", () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user