73 lines
3.2 KiB
TypeScript
73 lines
3.2 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, it } from "vitest";
|
|
import { getSystemHealthSnapshot } from "./system-health.server";
|
|
|
|
describe("admin system health service", () => {
|
|
it("collects runtime configuration without exposing secret values", async () => {
|
|
const snapshot = await getSystemHealthSnapshot({
|
|
env: {
|
|
NODE_ENV: "production",
|
|
SENTRY_ENVIRONMENT: "staging",
|
|
SENTRY_RELEASE: "abc123",
|
|
DATABASE_URL: "postgres://secret@example/db",
|
|
BULLMQ_REDIS_URL: "redis://secret@redis/0",
|
|
MEILI_URL: "http://meili.local",
|
|
MEILI_API_KEY: "meili-secret",
|
|
STORAGE_PROVIDER: "s3",
|
|
STORAGE_ENDPOINT: "https://storage.example",
|
|
STORAGE_REGION: "fsn1",
|
|
STORAGE_BUCKET: "hivegrid-staging",
|
|
STORAGE_ACCESS_KEY_ID: "access-secret",
|
|
STORAGE_SECRET_ACCESS_KEY: "secret-secret",
|
|
LAGO_API_URL: "https://lago.example",
|
|
LAGO_API_KEY: "lago-secret",
|
|
MOLLIE_API_KEY: "mollie-secret",
|
|
MOLLIE_PROFILE_ID: "profile",
|
|
MAILJET_API_KEY: "mailjet-key",
|
|
MAILJET_SECRET_KEY: "mailjet-secret",
|
|
MAILJET_FROM_EMAIL: "billing@hivegrid.de",
|
|
SENTRY_DSN_WEB: "https://dsn@example/1",
|
|
MCP_RESOURCE_URL: "https://mcp.hivegrid.de",
|
|
},
|
|
pingDatabase: async () => true,
|
|
});
|
|
|
|
expect(snapshot.deploy).toEqual({ environment: "staging", release: "abc123", nodeEnv: "production" });
|
|
expect(snapshot.services.find((service) => service.id === "postgres")).toMatchObject({ configured: true, reachable: true });
|
|
expect(snapshot.services.find((service) => service.id === "mollie")).toMatchObject({ configured: true });
|
|
expect(JSON.stringify(snapshot)).not.toContain("mollie-secret");
|
|
expect(JSON.stringify(snapshot)).not.toContain("secret-secret");
|
|
});
|
|
|
|
it("skips blank release variables instead of rendering an empty release", async () => {
|
|
// Regression guard: the local `??` chain accepted an empty SENTRY_RELEASE,
|
|
// so the /system header read "Release: " while /deploys showed the commit.
|
|
const snapshot = await getSystemHealthSnapshot({
|
|
env: { NODE_ENV: "production", SENTRY_ENVIRONMENT: "staging", SENTRY_RELEASE: " ", GIT_SHA: "b05b699" },
|
|
pingDatabase: async () => true,
|
|
});
|
|
|
|
expect(snapshot.deploy.release).toBe("b05b699");
|
|
});
|
|
|
|
it("falls back to a readable placeholder when no release variable is set", async () => {
|
|
const snapshot = await getSystemHealthSnapshot({
|
|
env: { NODE_ENV: "production", SENTRY_RELEASE: "" },
|
|
pingDatabase: async () => true,
|
|
});
|
|
|
|
expect(snapshot.deploy.release).toBe("local");
|
|
});
|
|
|
|
it("marks missing optional integrations as warnings for the VM", async () => {
|
|
const snapshot = await getSystemHealthSnapshot({
|
|
env: { NODE_ENV: "development" },
|
|
pingDatabase: async () => false,
|
|
});
|
|
|
|
expect(snapshot.services.find((service) => service.id === "postgres")).toMatchObject({ configured: false, reachable: false });
|
|
expect(snapshot.services.find((service) => service.id === "lago")).toMatchObject({ configured: false, reachable: null });
|
|
expect(snapshot.services.find((service) => service.id === "web")).toMatchObject({ configured: true, reachable: true });
|
|
});
|
|
});
|