1
0

feat: 新增 target description 字段,收紧 id/name 长度,调整延迟列和名称列

This commit is contained in:
2026-05-17 18:42:46 +08:00
parent 7926514986
commit f7193e98ff
36 changed files with 385 additions and 58 deletions

View File

@@ -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");
});
});