feat: 运行时日志系统,Pino + pino-pretty + pino-roll,console/file 双输出,敏感信息 redaction
This commit is contained in:
@@ -15,6 +15,7 @@ import { checkerRegistry } from "../../src/server/checker/runner";
|
||||
import { CommandChecker } from "../../src/server/checker/runner/cmd/execute";
|
||||
import { HttpChecker } from "../../src/server/checker/runner/http/execute";
|
||||
import { ProbeStore } from "../../src/server/checker/store";
|
||||
import { createNoopLogger } from "../../src/server/logger";
|
||||
import { startServer } from "../../src/server/server";
|
||||
import { rmRetry } from "../helpers";
|
||||
|
||||
@@ -173,6 +174,7 @@ describe("API 路由", () => {
|
||||
|
||||
server = startServer({
|
||||
config: { host: "127.0.0.1", port: 0 },
|
||||
logger: createNoopLogger(),
|
||||
mode: "test",
|
||||
store,
|
||||
version: "0.1.0",
|
||||
@@ -410,6 +412,7 @@ describe("API 路由", () => {
|
||||
test("生产响应包含安全 headers", async () => {
|
||||
const prodServer = startServer({
|
||||
config: { host: "127.0.0.1", port: 0 },
|
||||
logger: createNoopLogger(),
|
||||
mode: "production",
|
||||
store,
|
||||
version: "0.1.0",
|
||||
@@ -424,35 +427,29 @@ describe("API 路由", () => {
|
||||
});
|
||||
|
||||
test("损坏的 failure JSON 返回 null 而不崩溃", async () => {
|
||||
const originalWarn = console.warn;
|
||||
console.warn = () => undefined;
|
||||
try {
|
||||
const targets = store.getTargets();
|
||||
const t1Id = targets[0]!.id;
|
||||
const targets = store.getTargets();
|
||||
const t1Id = targets[0]!.id;
|
||||
|
||||
store.insertCheckResult({
|
||||
durationMs: 100,
|
||||
failure: { kind: "error", message: "test", path: "$", phase: "body" },
|
||||
matched: false,
|
||||
observation: null,
|
||||
targetId: t1Id,
|
||||
timestamp: "2025-06-01T00:00:00.000Z",
|
||||
});
|
||||
store.insertCheckResult({
|
||||
durationMs: 100,
|
||||
failure: { kind: "error", message: "test", path: "$", phase: "body" },
|
||||
matched: false,
|
||||
observation: null,
|
||||
targetId: t1Id,
|
||||
timestamp: "2025-06-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
(store as unknown as { db: { prepare: (sql: string) => { run: (...args: unknown[]) => void } } }).db
|
||||
.prepare("UPDATE check_results SET failure = ? WHERE target_id = ? AND timestamp = ?")
|
||||
.run("{invalid json!!!", t1Id, "2025-06-01T00:00:00.000Z");
|
||||
(store as unknown as { db: { prepare: (sql: string) => { run: (...args: unknown[]) => void } } }).db
|
||||
.prepare("UPDATE check_results SET failure = ? WHERE target_id = ? AND timestamp = ?")
|
||||
.run("{invalid json!!!", t1Id, "2025-06-01T00:00:00.000Z");
|
||||
|
||||
const from = "2025-06-01T00:00:00.000Z";
|
||||
const to = "2025-06-01T23:59:59.999Z";
|
||||
const response = await fetch(`${baseUrl}/api/targets/${t1Id}/history?from=${from}&to=${to}`);
|
||||
const body = (await response.json()) as HistoryResponse;
|
||||
const from = "2025-06-01T00:00:00.000Z";
|
||||
const to = "2025-06-01T23:59:59.999Z";
|
||||
const response = await fetch(`${baseUrl}/api/targets/${t1Id}/history?from=${from}&to=${to}`);
|
||||
const body = (await response.json()) as HistoryResponse;
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(body.items).toHaveLength(1);
|
||||
expect(body.items[0]!.failure).toBeNull();
|
||||
} finally {
|
||||
console.warn = originalWarn;
|
||||
}
|
||||
expect(response.status).toBe(200);
|
||||
expect(body.items).toHaveLength(1);
|
||||
expect(body.items[0]!.failure).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user