feat: 新增 target description 字段,收紧 id/name 长度,调整延迟列和名称列
This commit is contained in:
@@ -41,6 +41,7 @@ describe("API 路由", () => {
|
||||
store = new ProbeStore(join(tempDir, "test.db"));
|
||||
store.syncTargets([
|
||||
{
|
||||
description: null,
|
||||
group: "default",
|
||||
http: {
|
||||
headers: {},
|
||||
@@ -64,6 +65,7 @@ describe("API 路由", () => {
|
||||
exec: "echo",
|
||||
maxOutputBytes: 104857600,
|
||||
},
|
||||
description: null,
|
||||
group: "default",
|
||||
id: "test-b",
|
||||
intervalMs: 60000,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { bootstrap, type BootstrapDependencies } from "../../src/server/bootstra
|
||||
type ShutdownSignal = "SIGINT" | "SIGTERM";
|
||||
|
||||
const target: ResolvedTargetBase = {
|
||||
description: null,
|
||||
group: "default",
|
||||
id: "test",
|
||||
intervalMs: 30000,
|
||||
|
||||
@@ -1534,4 +1534,150 @@ targets:
|
||||
"无效的时长格式",
|
||||
);
|
||||
});
|
||||
|
||||
test("解析 description 字段", async () => {
|
||||
const configPath = join(tempDir, "description.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "api-health"
|
||||
description: "检查生产 API 健康状态"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
const config = await loadConfig(configPath);
|
||||
expect(config.targets[0]!.description).toBe("检查生产 API 健康状态");
|
||||
});
|
||||
|
||||
test("description 使用变量替换", async () => {
|
||||
const configPath = join(tempDir, "description-var.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`variables:
|
||||
env: "生产"
|
||||
targets:
|
||||
- id: "api-health"
|
||||
description: "\${env} 环境健康检查"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
const config = await loadConfig(configPath);
|
||||
expect(config.targets[0]!.description).toBe("生产 环境健康检查");
|
||||
});
|
||||
|
||||
test("description 缺省为 null", async () => {
|
||||
const configPath = join(tempDir, "no-description.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "api-health"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
const config = await loadConfig(configPath);
|
||||
expect(config.targets[0]!.description).toBeNull();
|
||||
});
|
||||
|
||||
test("description 为空字符串通过", async () => {
|
||||
const configPath = join(tempDir, "empty-description.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "api-health"
|
||||
description: ""
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
const config = await loadConfig(configPath);
|
||||
expect(config.targets[0]!.description).toBe("");
|
||||
});
|
||||
|
||||
test("description 非字符串抛出错误", async () => {
|
||||
const configPath = join(tempDir, "bad-description-type.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "api-health"
|
||||
description: 123
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await expect(loadConfig(configPath)).rejects.toThrow("description");
|
||||
});
|
||||
|
||||
test("description 超过 500 字符抛出错误", async () => {
|
||||
const configPath = join(tempDir, "long-description.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "api-health"
|
||||
description: "${"a".repeat(501)}"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await expect(loadConfig(configPath)).rejects.toThrow("description");
|
||||
});
|
||||
|
||||
test("变量替换后 description 超长抛出错误", async () => {
|
||||
const configPath = join(tempDir, "var-long-description.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`variables:
|
||||
prefix: "${"x".repeat(490)}"
|
||||
targets:
|
||||
- id: "api-health"
|
||||
description: "\${prefix}${"a".repeat(15)}"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await expect(loadConfig(configPath)).rejects.toThrow("description");
|
||||
});
|
||||
|
||||
test("id 超过 30 字符抛出错误", async () => {
|
||||
const configPath = join(tempDir, "long-id.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "${"a".repeat(31)}"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await expect(loadConfig(configPath)).rejects.toThrow("id");
|
||||
});
|
||||
|
||||
test("name 超过 30 字符抛出错误", async () => {
|
||||
const configPath = join(tempDir, "long-name.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`targets:
|
||||
- id: "test"
|
||||
name: "${"a".repeat(31)}"
|
||||
type: http
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||
await expect(loadConfig(configPath)).rejects.toThrow("name");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,6 +55,7 @@ function makeCommandTarget(name: string, overrides?: Partial<ResolvedCommandTarg
|
||||
exec: "bun",
|
||||
maxOutputBytes: 1024 * 1024,
|
||||
},
|
||||
description: null,
|
||||
group: "default",
|
||||
id: name,
|
||||
intervalMs: 60000,
|
||||
@@ -259,6 +260,7 @@ describe("ProbeEngine", () => {
|
||||
|
||||
try {
|
||||
const httpTarget: ResolvedHttpTarget = {
|
||||
description: null,
|
||||
group: "default",
|
||||
http: {
|
||||
headers: {},
|
||||
|
||||
@@ -30,6 +30,7 @@ function makeTarget(
|
||||
maxOutputBytes: 1024 * 1024,
|
||||
...cmd,
|
||||
},
|
||||
description: null,
|
||||
group: "default",
|
||||
id: "test-cmd",
|
||||
intervalMs: 60000,
|
||||
|
||||
@@ -19,6 +19,7 @@ function makeTarget(db: Partial<ResolvedDbTarget["db"]>, overrides?: Partial<Res
|
||||
url: "sqlite://:memory:",
|
||||
...db,
|
||||
},
|
||||
description: null,
|
||||
group: "default",
|
||||
id: "test-db",
|
||||
intervalMs: 60000,
|
||||
|
||||
@@ -155,6 +155,7 @@ describe("HttpChecker", () => {
|
||||
url?: string;
|
||||
}): ResolvedHttpTarget {
|
||||
return {
|
||||
description: null,
|
||||
expect: overrides.expect,
|
||||
group: "default",
|
||||
http: {
|
||||
|
||||
@@ -29,6 +29,7 @@ function targetId(store: ProbeStore, name: string): string {
|
||||
}
|
||||
|
||||
const httpTarget: ResolvedHttpTarget = {
|
||||
description: null,
|
||||
expect: { maxDurationMs: 3000, status: [200] },
|
||||
group: "default",
|
||||
http: {
|
||||
@@ -54,6 +55,7 @@ const commandTarget: ResolvedCommandTarget = {
|
||||
exec: "ping",
|
||||
maxOutputBytes: 104857600,
|
||||
},
|
||||
description: null,
|
||||
group: "default",
|
||||
id: "test-cmd",
|
||||
intervalMs: 60000,
|
||||
@@ -364,6 +366,7 @@ describe("ProbeStore", () => {
|
||||
test("删除 target 级联删除 check_results", () => {
|
||||
const cascadeStore = new ProbeStore(join(tempDir, "cascade.db"));
|
||||
const cascadeTarget: ResolvedHttpTarget = {
|
||||
description: null,
|
||||
group: "default",
|
||||
http: {
|
||||
headers: {},
|
||||
@@ -427,6 +430,7 @@ describe("ProbeStore", () => {
|
||||
const freshStore = new ProbeStore(join(tempDir, "fresh-map.db"));
|
||||
freshStore.syncTargets([
|
||||
{
|
||||
description: null,
|
||||
group: "default",
|
||||
http: {
|
||||
headers: {},
|
||||
@@ -474,6 +478,7 @@ describe("ProbeStore", () => {
|
||||
const freshStore = new ProbeStore(join(tempDir, "fresh-stats.db"));
|
||||
freshStore.syncTargets([
|
||||
{
|
||||
description: null,
|
||||
group: "default",
|
||||
http: {
|
||||
headers: {},
|
||||
@@ -662,4 +667,35 @@ describe("ProbeStore", () => {
|
||||
|
||||
pruneStore.close();
|
||||
});
|
||||
|
||||
test("syncTargets 持久化 description", () => {
|
||||
const descStore = new ProbeStore(join(tempDir, "desc.db"));
|
||||
const targetWithDesc: ResolvedHttpTarget = {
|
||||
...httpTarget,
|
||||
description: "检查 API 健康状态",
|
||||
id: "desc-test",
|
||||
name: "desc-test",
|
||||
};
|
||||
descStore.syncTargets([targetWithDesc]);
|
||||
const t = descStore.getTargets()[0]!;
|
||||
expect(t.description).toBe("检查 API 健康状态");
|
||||
descStore.close();
|
||||
});
|
||||
|
||||
test("未配置 description 时持久化为 null", () => {
|
||||
const noDescStore = new ProbeStore(join(tempDir, "no-desc.db"));
|
||||
noDescStore.syncTargets([{ ...httpTarget, description: null, id: "no-desc", name: "no-desc" }]);
|
||||
const t = noDescStore.getTargets()[0]!;
|
||||
expect(t.description).toBeNull();
|
||||
noDescStore.close();
|
||||
});
|
||||
|
||||
test("同步更新 description", () => {
|
||||
const updateDescStore = new ProbeStore(join(tempDir, "update-desc.db"));
|
||||
updateDescStore.syncTargets([{ ...httpTarget, description: "旧描述", id: "update-desc", name: "update-desc" }]);
|
||||
updateDescStore.syncTargets([{ ...httpTarget, description: "新描述", id: "update-desc", name: "update-desc" }]);
|
||||
const t = updateDescStore.getTargets()[0]!;
|
||||
expect(t.description).toBe("新描述");
|
||||
updateDescStore.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user