Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -6,7 +6,7 @@ import { afterEach, describe, it } from "vitest";
import { formatHealthBaselineResult, verifyHealthBaseline } from "./verify-health-baseline.mjs";
const VALID_DOCKERFILE = `FROM node:20-bookworm-slim AS base
const VALID_DOCKERFILE = `FROM node:24-bookworm-slim AS base
FROM base AS build
FROM base AS worker
HEALTHCHECK CMD node apps/worker/dist/health.js
@@ -24,19 +24,32 @@ const VALID_WEB_HEALTHCHECK = `export const loader = async () => {
};
`;
const VALID_WEB_HEALTHZ = `export const loader = async () => {
return Response.json({ status: "ok", service: "web", revision: process.env.APP_REVISION || "unknown" }, { status: 200 });
const VALID_WEB_HEALTHZ = `import { loadWebConfig } from "@hivegrid/config";
import { getWebServiceName } from "../../build-surface";
export const loader = async () => {
const { releaseRevision, runtimeSurface } = loadWebConfig().config;
return Response.json({
status: "ok",
service: getWebServiceName(runtimeSurface),
surface: runtimeSurface,
revision: releaseRevision,
}, { status: 200 });
};
`;
const VALID_WEB_READYZ = `import { db } from "~/utils/db.server";
const VALID_WEB_READYZ = `import { loadWebConfig } from "@hivegrid/config";
import { db } from "~/utils/db.server";
import { getWebServiceName } from "../../build-surface";
export const loader = async () => {
const { releaseRevision, runtimeSurface } = loadWebConfig().config;
const service = getWebServiceName(runtimeSurface);
try {
await db.appConfiguration.count();
return Response.json({ status: "ready", service: "web" }, { status: 200 });
return Response.json({ status: "ready", service, surface: runtimeSurface, revision: releaseRevision }, { status: 200 });
} catch {
return Response.json({ status: "not_ready", service: "web", error: "database_unavailable" }, { status: 503 });
return Response.json({ status: "not_ready", service, surface: runtimeSurface, revision: releaseRevision, error: "database_unavailable" }, { status: 503 });
}
};
`;
@@ -164,8 +177,17 @@ describe("verify-health-baseline", () => {
assert.deepEqual(result.failures, []);
assert.ok(result.passes.some((pass) => pass === "apps/web/app/routes/healthcheck.tsx: legacy liveness healthcheck avoids DB and self-fetch"));
assert.ok(result.passes.some((pass) => pass === "apps/web/app/routes/healthz.tsx: liveness route does not require DB"));
assert.ok(result.passes.some((pass) => pass === "apps/web/app/routes/healthz.tsx: liveness route reports ok web service identity"));
assert.ok(
result.passes.some(
(pass) => pass === "apps/web/app/routes/healthz.tsx: liveness route reports the dynamic web/admin/portal service, surface, and revision identity"
)
);
assert.ok(result.passes.some((pass) => pass === "apps/web/app/routes/readyz.tsx: readiness imports and checks db"));
assert.ok(
result.passes.some(
(pass) => pass === "apps/web/app/routes/readyz.tsx: readiness route reports the dynamic web/admin/portal service, surface, and revision identity"
)
);
assert.ok(result.passes.some((pass) => pass === "apps/api/src/app.ts: /healthz reports service \"api\""));
assert.ok(result.passes.some((pass) => pass === "apps/api/src/app.ts: /healthz includes requestId"));
assert.ok(result.passes.some((pass) => pass === "apps/api/src/app.ts: /readyz returns 503 not-ready dependency diagnostics"));
@@ -236,6 +258,21 @@ app.get("/v1/health", (c) => {
assert.match(result.failures.join("\n"), /app\/routes\/healthz\.tsx: missing web \/healthz liveness route/);
});
it("accepts an object-based web Docker healthcheck with canonical host routing", () => {
const dockerfile = VALID_DOCKERFILE.replace(
'HEALTHCHECK CMD curl -fsS "http://127.0.0.1:${PORT}/healthz"',
'HEALTHCHECK CMD node -e "const http=require(\'node:http\');http.get({hostname:\'127.0.0.1\',port:process.env.PORT,path:\'/healthz\',headers:{host:process.env.WEB_APP_HOST}},()=>{})"',
);
const rootDir = createFixture({
dockerfile,
});
const result = verifyHealthBaseline(rootDir);
assert.notEqual(dockerfile, VALID_DOCKERFILE);
assert.equal(result.failures.filter((failure) => /web target HEALTHCHECK/.test(failure)).length, 0);
});
it("fails when web /readyz is missing", () => {
const rootDir = createFixture({ remove: ["apps/web/app/routes/readyz.tsx"] });
@@ -261,23 +298,97 @@ export const loader = async () => {
it("fails when web /healthz reports the wrong service identity", () => {
const rootDir = createFixture({
webHealthz: `export const loader = async () => {
return Response.json({ status: "ok", service: "oops", revision: process.env.APP_REVISION || "unknown" }, { status: 200 });
};
`,
webHealthz: VALID_WEB_HEALTHZ.replace(
"getWebServiceName(runtimeSurface)",
'"hivegrid-web"'
),
});
const result = verifyHealthBaseline(rootDir);
assert.match(result.failures.join("\n"), /app\/routes\/healthz\.tsx: liveness route must report status ok and service web/);
assert.match(
result.failures.join("\n"),
/app\/routes\/healthz\.tsx: liveness route must report status ok with dynamic hivegrid-web\/core, hivegrid-admin\/admin, or hivegrid-portal\/portal identity and revision/
);
});
it("fails when web /healthz bypasses loadWebConfig runtime identity", () => {
const rootDir = createFixture({
webHealthz: VALID_WEB_HEALTHZ.replace(
" const { releaseRevision, runtimeSurface } = loadWebConfig().config;",
' const releaseRevision = "unknown";\n const runtimeSurface = "core";'
),
});
const result = verifyHealthBaseline(rootDir);
assert.match(
result.failures.join("\n"),
/app\/routes\/healthz\.tsx: liveness route must load releaseRevision and runtimeSurface from loadWebConfig\(\)\.config/
);
});
it("fails when web /healthz omits its runtime surface", () => {
const rootDir = createFixture({
webHealthz: VALID_WEB_HEALTHZ.replace(" surface: runtimeSurface,\n", ""),
});
const result = verifyHealthBaseline(rootDir);
assert.match(
result.failures.join("\n"),
/app\/routes\/healthz\.tsx: liveness route must report status ok with dynamic hivegrid-web\/core, hivegrid-admin\/admin, or hivegrid-portal\/portal identity and revision/
);
});
it("fails when web /readyz bypasses loadWebConfig runtime identity", () => {
const rootDir = createFixture({
webReadyz: VALID_WEB_READYZ.replace(
" const { releaseRevision, runtimeSurface } = loadWebConfig().config;",
' const releaseRevision = "unknown";\n const runtimeSurface = "core";'
),
});
const result = verifyHealthBaseline(rootDir);
assert.match(
result.failures.join("\n"),
/app\/routes\/readyz\.tsx: readiness route must load releaseRevision and runtimeSurface from loadWebConfig\(\)\.config/
);
});
it("fails when web /readyz maps the portal surface to the core service", () => {
const rootDir = createFixture({
webReadyz: VALID_WEB_READYZ.replace(
"getWebServiceName(runtimeSurface)",
'"hivegrid-web"'
),
});
const result = verifyHealthBaseline(rootDir);
assert.match(
result.failures.join("\n"),
/app\/routes\/readyz\.tsx: readiness route must report dynamic hivegrid-web\/core, hivegrid-admin\/admin, or hivegrid-portal\/portal identity and revision/
);
});
it("fails when web /readyz omits its image-baked revision", () => {
const rootDir = createFixture({
webReadyz: VALID_WEB_READYZ.replaceAll(", revision: releaseRevision", ""),
});
const result = verifyHealthBaseline(rootDir);
assert.match(
result.failures.join("\n"),
/app\/routes\/readyz\.tsx: readiness route must report dynamic hivegrid-web\/core, hivegrid-admin\/admin, or hivegrid-portal\/portal identity and revision/
);
});
it("fails when web /readyz does not check db", () => {
const rootDir = createFixture({
webReadyz: `export const loader = async () => {
return Response.json({ status: "ready", service: "web" }, { status: 200 });
};
`,
webReadyz: VALID_WEB_READYZ.replace(" await db.appConfiguration.count();\n", ""),
});
const result = verifyHealthBaseline(rootDir);