chore(ops): strip redundant force-dynamic and probe Redis in ops health
CI / check (push) Successful in 25s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m8s

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-07-30 21:33:40 +02:00
1 parent 3e584aadaf
commit 3ac5d6f4f6
60 files changed
+95 -114

No files matched your search

+18 -3
View File
@@ -1,21 +1,25 @@
import "server-only";
import { env } from "@/env";
import { prisma } from "@/lib/prisma";
import { redis } from "@/lib/redis";
import { rcon } from "@/lib/services/rcon";
export type OpsHealth = {
dbOk: boolean;
dbLatencyMs: number;
/** null = REDIS_URL unset (optional); true/false = probe result */
redisOk: boolean | null;
emulatorOk: boolean;
onlineUsers: number;
};
/**
* Shared DB + emulator health probe for CommandoCentrum, DevOps, and APIs.
* Emulator = real RCON `ping` (same semantics as CommandoCentrum /public health).
* Shared DB + Redis + emulator health probe for CommandoCentrum, DevOps, and APIs.
* Semantics match `/api/health` for Redis (null when not configured).
*/
export async function fetchOpsHealth(): Promise<OpsHealth> {
const [db, emulatorOk, onlineUsers] = await Promise.all([
const [db, redisOk, emulatorOk, onlineUsers] = await Promise.all([
(async () => {
try {
const start = Date.now();
@@ -25,6 +29,16 @@ export async function fetchOpsHealth(): Promise<OpsHealth> {
return { dbOk: false, dbLatencyMs: 0 };
}
})(),
(async (): Promise<boolean | null> => {
if (!env.REDIS_URL) return null;
if (!redis) return false;
try {
const pong = await redis.ping();
return pong === "PONG";
} catch {
return false;
}
})(),
rcon.send("ping", null).catch(() => false),
prisma.user.count({ where: { online: "1" } }).catch(() => 0),
]);
@@ -32,6 +46,7 @@ export async function fetchOpsHealth(): Promise<OpsHealth> {
return {
dbOk: db.dbOk,
dbLatencyMs: db.dbLatencyMs,
redisOk,
emulatorOk: Boolean(emulatorOk),
onlineUsers,
};
+29 -1
View File
@@ -1,4 +1,5 @@
import { existsSync, readFileSync } from "node:fs";
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
describe("staff smoke contract", () => {
@@ -50,10 +51,37 @@ describe("staff smoke contract", () => {
it("ships shared ops + ticket queue helpers", () => {
expect(existsSync("src/lib/admin/ops-health.ts")).toBe(true);
const ops = readFileSync("src/lib/admin/ops-health.ts", "utf8");
expect(ops).toContain("redisOk");
expect(ops).toContain("redis.ping");
expect(existsSync("src/lib/admin/ticket-queue-counts.ts")).toBe(true);
expect(existsSync("src/lib/admin/ops-online-users.ts")).toBe(true);
});
it("keeps force-dynamic only on admin/mod layouts", () => {
const hits: string[] = [];
function walk(dir: string) {
for (const name of readdirSync(dir)) {
const p = join(dir, name);
if (statSync(p).isDirectory()) walk(p);
else if (/\.(tsx?|jsx?)$/.test(name)) {
const src = readFileSync(p, "utf8");
if (
/export\s+const\s+dynamic\s*=\s*["']force-dynamic["']/.test(src)
) {
hits.push(p.replace(/\\/g, "/"));
}
}
}
}
walk("src/app/admin");
walk("src/app/mod");
expect(hits.sort()).toEqual([
"src/app/admin/layout.tsx",
"src/app/mod/layout.tsx",
]);
});
it("caches analytics via redisCache", () => {
for (const path of [
"src/app/admin/analytics/page.tsx",