Files
creator-hub/web/tests/gateway-health.test.cjs
T
rogee a94bdf7921 feat(gateway): 网关健康状态——后台定时探活只保留最近一次结果并在列表展示
- 迁移 1043:gateway 表加 health_status/last_check_reason/last_checked_at
- Store.RecordGatewayCheck 覆盖写最近一次探活结果,Create/Update/List/Get 全量返回健康字段
- api.RecordGatewayHealthChecks 并发探 /healthz:连接失败或 5xx 判离线,其余判在线(401 等异常写入原因供排查)
- workers 每 30 秒一轮,app 启动接线
- 网关管理列表新增健康状态列:在线/离线/未检查 Tag,原因与检查时间收进 Tooltip
2026-09-29 14:47:49 +08:00

41 lines
2.0 KiB
JavaScript

const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
const ts = require('typescript');
// 网关健康状态列:后台定时探活只落最近一次结果,列表直接展示,不保留历史。
const source = ts.createSourceFile(
'gateways-page',
readFileSync(`${__dirname}/../src/pages/gateways/index.tsx`, 'utf8'),
ts.ScriptTarget.Latest,
true,
ts.ScriptKind.TSX,
);
const code = source.getFullText();
test('网关列表展示最近一次健康检查结果', () => {
assert.match(code, /健康状态/, '应有健康状态列');
assert.match(code, /dataIndex: 'health_status'/, '应绑定 health_status 字段');
assert.match(code, /gateway\.last_check_reason/, '应展示最近一次检查原因');
assert.match(code, /gateway\.last_checked_at/, '应展示最近一次检查时间');
assert.match(code, /online|在线/, '健康应展示为在线');
assert.match(code, /offline|离线/, '不健康应展示为离线');
});
test('健康状态未检查时不误报异常', () => {
// 未检查(unchecked)必须落在独立的静默分支,不允许与离线混用同一个颜色/文案。
const render = code.match(/function HealthCell[\s\S]*?\n}/);
assert.ok(render, '应有独立的 HealthCell 组件');
assert.match(render[0], /未检查/, '应存在未检查文案');
const branches = render[0].match(/status === '[a-z]+'/g) ?? [];
assert.ok(branches.includes("status === 'healthy'"), '应判断 healthy');
assert.ok(branches.includes("status === 'unhealthy'"), '应判断 unhealthy');
});
test('检查原因与时间收进 Tooltip,不挤占表格密度', () => {
const render = code.match(/function HealthCell[\s\S]*?\n}/);
assert.ok(render, '应有独立的 HealthCell 组件');
assert.match(render[0], /Tooltip/, '原因与时间应放 Tooltip');
assert.doesNotMatch(render[0], /Typography\.Text type="secondary"/, '不应在单元格内平铺长文本');
});