refactor: 移除顶层 defaults 配置段,简化为 target 显式字段 > 代码内置默认值
- 移除 DefaultsConfig 类型、ProbeConfig.defaults 字段 - 移除 CheckerSchemas.defaults、ResolveContext.defaults、CheckerValidationInput.defaults - 更新所有 checker schema/resolve/validate 删除 defaults 合并逻辑 - 更新 config-loader 不再读取传递 defaults - 更新测试、README、DEVELOPMENT、probes.example.yaml - 重新生成 probe-config.schema.json(不含 defaults) - 同步 delta specs 到主规范 - 归档 openspec change
This commit is contained in:
@@ -190,16 +190,6 @@ describe("loadConfig", () => {
|
||||
probes:
|
||||
execution:
|
||||
maxConcurrentChecks: 5
|
||||
defaults:
|
||||
interval: "15s"
|
||||
timeout: "5s"
|
||||
http:
|
||||
headers:
|
||||
Authorization: "Bearer token"
|
||||
maxBodyBytes: "50MB"
|
||||
cmd:
|
||||
cwd: "/tmp"
|
||||
maxOutputBytes: "10MB"
|
||||
targets:
|
||||
- name: "http-target"
|
||||
id: "http-target"
|
||||
@@ -236,19 +226,18 @@ targets:
|
||||
expect(http.type).toBe("http");
|
||||
expect(http.http.url).toBe("http://example.com");
|
||||
expect(http.http.method).toBe("POST");
|
||||
expect(http.http.headers).toEqual({ Authorization: "Bearer token" });
|
||||
expect(http.http.ignoreSSL).toBe(true);
|
||||
expect(http.http.maxBodyBytes).toBe(52428800);
|
||||
expect(http.http.maxBodyBytes).toBe(104857600);
|
||||
expect(http.http.maxRedirects).toBe(5);
|
||||
expect(http.expect?.status).toEqual(["2xx", 301]);
|
||||
expect(http.intervalMs).toBe(60000);
|
||||
expect(http.timeoutMs).toBe(5000);
|
||||
expect(http.timeoutMs).toBe(10000);
|
||||
|
||||
const cmd = config.targets[1]! as ResolvedCommandTarget;
|
||||
expect(cmd.type).toBe("cmd");
|
||||
expect(cmd.cmd.exec).toBe("ls");
|
||||
expect(cmd.cmd.args).toEqual(["/tmp"]);
|
||||
expect(cmd.cmd.maxOutputBytes).toBe(10485760);
|
||||
expect(cmd.cmd.maxOutputBytes).toBe(104857600);
|
||||
});
|
||||
|
||||
test("name 缺省时保留为 null", async () => {
|
||||
@@ -526,16 +515,11 @@ targets:
|
||||
expect(config.dataDir).toBe(dataDir);
|
||||
});
|
||||
|
||||
test("per-target 覆盖 defaults", async () => {
|
||||
test("per-target interval 和 timeout 覆盖全局默认", async () => {
|
||||
const configPath = join(tempDir, "override.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`defaults:
|
||||
interval: "30s"
|
||||
timeout: "10s"
|
||||
http:
|
||||
maxBodyBytes: "10MB"
|
||||
targets:
|
||||
`targets:
|
||||
- name: "override-all"
|
||||
id: "override-all"
|
||||
type: http
|
||||
@@ -799,15 +783,13 @@ targets:
|
||||
const configPath = join(tempDir, "bad-size.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`defaults:
|
||||
http:
|
||||
maxBodyBytes: "100TB"
|
||||
targets:
|
||||
`targets:
|
||||
- name: "t"
|
||||
id: "t"
|
||||
type: http
|
||||
http:
|
||||
url: "http://a.com"
|
||||
maxBodyBytes: "100TB"
|
||||
`,
|
||||
);
|
||||
await expectConfigLoadError(configPath, "无效的 size 格式");
|
||||
@@ -1388,9 +1370,9 @@ targets:
|
||||
);
|
||||
});
|
||||
|
||||
test("defaults.http.method 触发未知字段错误", async () => {
|
||||
test("defaults 顶层字段触发未知字段错误", async () => {
|
||||
await expectConfigError(
|
||||
"unknown-default-method.yaml",
|
||||
"unknown-defaults.yaml",
|
||||
`defaults:
|
||||
http:
|
||||
method: POST
|
||||
@@ -1401,7 +1383,7 @@ targets:
|
||||
http:
|
||||
url: "http://example.com"
|
||||
`,
|
||||
"defaults.http.method 是未知字段",
|
||||
"defaults 是未知字段",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1428,11 +1410,7 @@ targets:
|
||||
const configPath = join(tempDir, "dynamic-maps.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`defaults:
|
||||
http:
|
||||
headers:
|
||||
X-Default-Header: "default"
|
||||
targets:
|
||||
`targets:
|
||||
- name: "http-test"
|
||||
id: "http-test"
|
||||
type: http
|
||||
@@ -1458,7 +1436,6 @@ targets:
|
||||
const cmdTarget = config.targets[1] as ResolvedCommandTarget;
|
||||
expect(http.type).toBe("http");
|
||||
expect(cmdTarget.type).toBe("cmd");
|
||||
expect(http.http.headers["X-Default-Header"]).toBe("default");
|
||||
expect(http.http.headers["X-Custom-Header"]).toBe("custom");
|
||||
expect(cmdTarget.cmd.env["CUSTOM_ENV_NAME"]).toBe("custom");
|
||||
});
|
||||
@@ -1924,15 +1901,11 @@ targets:
|
||||
);
|
||||
});
|
||||
|
||||
test("tcp defaults 覆盖 banner 参数", async () => {
|
||||
test("tcp per-target banner 参数覆盖", async () => {
|
||||
const configPath = join(tempDir, "tcp-defaults.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`defaults:
|
||||
tcp:
|
||||
bannerReadTimeout: 1000
|
||||
maxBannerBytes: "8KB"
|
||||
targets:
|
||||
`targets:
|
||||
- id: "t1"
|
||||
type: tcp
|
||||
tcp:
|
||||
@@ -1949,12 +1922,12 @@ targets:
|
||||
|
||||
const config = await loadConfig(configPath);
|
||||
const t1 = config.targets[0]! as ResolvedTcpTarget;
|
||||
expect(t1.tcp.bannerReadTimeout).toBe(1000);
|
||||
expect(t1.tcp.maxBannerBytes).toBe(8192);
|
||||
expect(t1.tcp.bannerReadTimeout).toBe(2000);
|
||||
expect(t1.tcp.maxBannerBytes).toBe(4096);
|
||||
|
||||
const t2 = config.targets[1]! as ResolvedTcpTarget;
|
||||
expect(t2.tcp.bannerReadTimeout).toBe(3000);
|
||||
expect(t2.tcp.maxBannerBytes).toBe(8192);
|
||||
expect(t2.tcp.maxBannerBytes).toBe(4096);
|
||||
});
|
||||
|
||||
test("tcp expect 未知字段抛出错误", async () => {
|
||||
|
||||
Reference in New Issue
Block a user