feat: 配置变量系统与 target id/name 双字段标识
- 新增顶层 variables 段支持 string/number/boolean 字面量
- target 字符串字段支持 、、{...} 转义语法
- 变量解析优先级: variables -> process.env -> 默认值 -> 报错
- 完整引用保留原始类型,部分引用拼接为字符串
- 变量替换在 YAML 解析后、AJV 校验前执行
- 替换仅作用于 targets,跳过 id/type 字段
- target 新增必填 id 字段作为唯一标识,name 改为可选展示名称
- 数据库存储/API/前端全面迁移到 id 标识
- 统一 checker 运行时类型检查为 es-toolkit predicates
- 同步 delta specs 到主 specs,归档 config-variables 变更
This commit is contained in:
@@ -50,6 +50,7 @@ describe("API 路由", () => {
|
||||
method: "GET",
|
||||
url: "http://a.com",
|
||||
},
|
||||
id: "test-a",
|
||||
intervalMs: 30000,
|
||||
name: "test-a",
|
||||
timeoutMs: 10000,
|
||||
@@ -64,6 +65,7 @@ describe("API 路由", () => {
|
||||
maxOutputBytes: 104857600,
|
||||
},
|
||||
group: "default",
|
||||
id: "test-b",
|
||||
intervalMs: 60000,
|
||||
name: "test-b",
|
||||
timeoutMs: 5000,
|
||||
@@ -204,6 +206,7 @@ describe("API 路由", () => {
|
||||
expect(body.targets).toHaveLength(2);
|
||||
|
||||
const tA = body.targets.find((t) => t.name === "test-a")!;
|
||||
expect(tA.id).toBe("test-a");
|
||||
expect(tA.type).toBe("http");
|
||||
expect(tA.target).toBe("http://a.com");
|
||||
expect(tA.group).toBe("default");
|
||||
@@ -372,9 +375,9 @@ describe("API 路由", () => {
|
||||
expect(body["error"]).toContain("from and to");
|
||||
});
|
||||
|
||||
test("metrics 无效 targetId 返回 400", async () => {
|
||||
test("metrics 无效 target id 返回 400", async () => {
|
||||
const response = await fetch(
|
||||
`${baseUrl}/api/targets/invalid/metrics?from=2024-01-01T00:00:00Z&to=2024-01-02T00:00:00Z`,
|
||||
`${baseUrl}/api/targets/_invalid/metrics?from=2024-01-01T00:00:00Z&to=2024-01-02T00:00:00Z`,
|
||||
);
|
||||
const body = (await response.json()) as Record<string, unknown>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user