- CheckResult: statusDetail -> observation (持久化) + detail (API 动态派生) - 存储: status_detail 列 -> observation TEXT (JSON) - CheckerDefinition: 新增 buildDetail(observation) 方法 - 各 checker 返回结构化 observation,API 层通过 registry 调用 buildDetail - HTTP: bodyPreview 在 status/header 失败时也提前采集 - UDP: observation 包含 durationMs,未响应归为 error failure - CMD: 超时/输出超限时保留已收集 observation - TCP: connectTimeMs 仅含连接建立耗时,不含 banner 等待 - 新增 buildDetail 单测和 mapCheckResult 覆盖测试 - 同步 openspec 主规范,归档 checker-observation 变更
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import "../../../tests/web/test-utils";
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { TargetMetricsResponse, TargetStatus } from "../../../src/shared/api";
|
|
|
|
import { OverviewTab } from "../../../src/web/components/OverviewTab";
|
|
|
|
describe("OverviewTab", () => {
|
|
const target: TargetStatus = {
|
|
currentStreak: null,
|
|
description: null,
|
|
group: "default",
|
|
id: "1",
|
|
interval: "30s",
|
|
latestCheck: {
|
|
detail: "200 OK",
|
|
durationMs: 100,
|
|
failure: null,
|
|
matched: true,
|
|
observation: null,
|
|
timestamp: "2025-01-15T10:00:00.000Z",
|
|
},
|
|
name: "test-target",
|
|
recentSamples: [],
|
|
stats: { availability: 100, downChecks: 0, totalChecks: 10, upChecks: 10 },
|
|
target: "https://example.com",
|
|
type: "http",
|
|
};
|
|
|
|
const metricsData: TargetMetricsResponse = {
|
|
stats: {
|
|
availability: 95,
|
|
avgDurationMs: 150,
|
|
currentStreak: { count: 5, up: true },
|
|
downChecks: 1,
|
|
incidentCount: 1,
|
|
longestOutage: 60000,
|
|
mttr: 30000,
|
|
p95DurationMs: 200,
|
|
p99DurationMs: 250,
|
|
totalChecks: 20,
|
|
upChecks: 19,
|
|
},
|
|
targetId: "1",
|
|
trend: [],
|
|
window: { bucket: "1h", from: "", to: "" },
|
|
};
|
|
|
|
test("有数据不崩溃", () => {
|
|
const { container } = render(<OverviewTab metricsData={metricsData} metricsLoading={false} target={target} />);
|
|
expect(container.firstChild).not.toBeNull();
|
|
});
|
|
|
|
test("loading 状态不崩溃", () => {
|
|
const { container } = render(<OverviewTab metricsData={null} metricsLoading={true} target={target} />);
|
|
expect(container.firstChild).not.toBeNull();
|
|
});
|
|
|
|
test("无指标数据不崩溃", () => {
|
|
const { container } = render(<OverviewTab metricsData={null} metricsLoading={false} target={target} />);
|
|
expect(container.firstChild).not.toBeNull();
|
|
});
|
|
|
|
test("显示趋势图表不崩溃", () => {
|
|
const { container } = render(<OverviewTab metricsData={metricsData} metricsLoading={false} target={target} />);
|
|
expect(container.firstChild).not.toBeNull();
|
|
});
|
|
});
|