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:
@@ -303,7 +303,7 @@ describe("TcpChecker resolve", () => {
|
||||
test("最简 tcp 配置解析默认值", () => {
|
||||
const target = checker.resolve(
|
||||
{ id: "t", tcp: { host: "127.0.0.1", port: 6379 }, type: "tcp" },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.tcp.host).toBe("127.0.0.1");
|
||||
expect(target.tcp.port).toBe(6379);
|
||||
@@ -325,44 +325,17 @@ describe("TcpChecker resolve", () => {
|
||||
tcp: { bannerReadTimeout: 5000, host: "127.0.0.1", maxBannerBytes: "1KB", port: 80, readBanner: true },
|
||||
type: "tcp",
|
||||
},
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.tcp.bannerReadTimeout).toBe(5000);
|
||||
expect(target.tcp.maxBannerBytes).toBe(1024);
|
||||
expect(target.tcp.readBanner).toBe(true);
|
||||
});
|
||||
|
||||
test("defaults.tcp 合并到 target", () => {
|
||||
const target = checker.resolve(
|
||||
{ id: "t", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" },
|
||||
{
|
||||
configDir: "/tmp",
|
||||
defaultIntervalMs: 30000,
|
||||
defaults: { tcp: { bannerReadTimeout: 1000, maxBannerBytes: "8KB" } },
|
||||
defaultTimeoutMs: 10000,
|
||||
},
|
||||
);
|
||||
expect(target.tcp.bannerReadTimeout).toBe(1000);
|
||||
expect(target.tcp.maxBannerBytes).toBe(8192);
|
||||
});
|
||||
|
||||
test("per-target 覆盖 defaults.tcp", () => {
|
||||
const target = checker.resolve(
|
||||
{ id: "t", tcp: { bannerReadTimeout: 5000, host: "127.0.0.1", port: 80 }, type: "tcp" },
|
||||
{
|
||||
configDir: "/tmp",
|
||||
defaultIntervalMs: 30000,
|
||||
defaults: { tcp: { bannerReadTimeout: 1000 } },
|
||||
defaultTimeoutMs: 10000,
|
||||
},
|
||||
);
|
||||
expect(target.tcp.bannerReadTimeout).toBe(5000);
|
||||
});
|
||||
|
||||
test("maxBannerBytes 整数默认值解析", () => {
|
||||
const target = checker.resolve(
|
||||
{ id: "t", tcp: { host: "127.0.0.1", maxBannerBytes: 2048, port: 80 }, type: "tcp" },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.tcp.maxBannerBytes).toBe(2048);
|
||||
});
|
||||
@@ -375,7 +348,7 @@ describe("TcpChecker resolve", () => {
|
||||
tcp: { host: "127.0.0.1", port: 80, readBanner: true },
|
||||
type: "tcp",
|
||||
},
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.expect).toEqual({
|
||||
banner: [{ kind: "value", matcher: { contains: "ESMTP" } }],
|
||||
@@ -388,7 +361,7 @@ describe("TcpChecker resolve", () => {
|
||||
test("name 和 group 解析", () => {
|
||||
const target = checker.resolve(
|
||||
{ group: "infra", id: "t", name: "redis", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.name).toBe("redis");
|
||||
expect(target.group).toBe("infra");
|
||||
|
||||
@@ -4,9 +4,8 @@ import type { CheckerValidationInput } from "../../../../../src/server/checker/r
|
||||
|
||||
import { validateTcpConfig } from "../../../../../src/server/checker/runner/tcp/validate";
|
||||
|
||||
function makeInput(targets: unknown[], defaults?: Record<string, unknown>): CheckerValidationInput {
|
||||
function makeInput(targets: unknown[]): CheckerValidationInput {
|
||||
return {
|
||||
defaults: defaults ?? {},
|
||||
targets: targets as CheckerValidationInput["targets"],
|
||||
};
|
||||
}
|
||||
@@ -152,40 +151,4 @@ describe("validateTcpConfig", () => {
|
||||
const issues = validateTcpConfig(makeInput([{ http: { url: "http://example.com" }, id: "t1", type: "http" }]));
|
||||
expect(issues).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("defaults.tcp 合法字段无错误", () => {
|
||||
const issues = validateTcpConfig(
|
||||
makeInput([{ id: "t1", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" }], {
|
||||
tcp: { bannerReadTimeout: 1000, maxBannerBytes: "8KB" },
|
||||
}),
|
||||
);
|
||||
expect(issues).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("defaults.tcp 未知字段", () => {
|
||||
const issues = validateTcpConfig(
|
||||
makeInput([{ id: "t1", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" }], {
|
||||
tcp: { bannerReadTimeout: 1000, host: "127.0.0.1" },
|
||||
}),
|
||||
);
|
||||
expect(issues.some((i) => i.message.includes("未知字段"))).toBe(true);
|
||||
});
|
||||
|
||||
test("defaults.tcp bannerReadTimeout 非法", () => {
|
||||
const issues = validateTcpConfig(
|
||||
makeInput([{ id: "t1", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" }], {
|
||||
tcp: { bannerReadTimeout: "slow" },
|
||||
}),
|
||||
);
|
||||
expect(issues.some((i) => i.path.includes("bannerReadTimeout"))).toBe(true);
|
||||
});
|
||||
|
||||
test("defaults.tcp maxBannerBytes 非法", () => {
|
||||
const issues = validateTcpConfig(
|
||||
makeInput([{ id: "t1", tcp: { host: "127.0.0.1", port: 80 }, type: "tcp" }], {
|
||||
tcp: { maxBannerBytes: true },
|
||||
}),
|
||||
);
|
||||
expect(issues.some((i) => i.path.includes("maxBannerBytes"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user