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:
@@ -334,7 +334,7 @@ describe("UdpChecker resolve", () => {
|
||||
const checker = new UdpChecker();
|
||||
const target = checker.resolve(
|
||||
{ id: "test", type: "udp", udp: { host: "127.0.0.1", port: 9000 } },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaults: {}, defaultTimeoutMs: 10000 },
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.udp.payload).toBe("");
|
||||
expect(target.udp.encoding).toBe("text");
|
||||
@@ -344,32 +344,11 @@ describe("UdpChecker resolve", () => {
|
||||
expect(target.expect).toEqual({ responded: true });
|
||||
});
|
||||
|
||||
it("should use defaults.udp for missing fields", () => {
|
||||
const checker = new UdpChecker();
|
||||
const target = checker.resolve(
|
||||
{ id: "test", type: "udp", udp: { host: "127.0.0.1", port: 9000 } },
|
||||
{
|
||||
configDir: "/tmp",
|
||||
defaultIntervalMs: 30000,
|
||||
defaults: { udp: { encoding: "hex", maxResponseBytes: "8KB", responseEncoding: "hex" } },
|
||||
defaultTimeoutMs: 10000,
|
||||
},
|
||||
);
|
||||
expect(target.udp.encoding).toBe("hex");
|
||||
expect(target.udp.responseEncoding).toBe("hex");
|
||||
expect(target.udp.maxResponseBytes).toBe(8192);
|
||||
});
|
||||
|
||||
it("should override defaults with target-level config", () => {
|
||||
const checker = new UdpChecker();
|
||||
const target = checker.resolve(
|
||||
{ id: "test", type: "udp", udp: { encoding: "base64", host: "127.0.0.1", port: 9000 } },
|
||||
{
|
||||
configDir: "/tmp",
|
||||
defaultIntervalMs: 30000,
|
||||
defaults: { udp: { encoding: "hex" } },
|
||||
defaultTimeoutMs: 10000,
|
||||
},
|
||||
{ configDir: "/tmp", defaultIntervalMs: 30000, defaultTimeoutMs: 10000 },
|
||||
);
|
||||
expect(target.udp.encoding).toBe("base64");
|
||||
});
|
||||
|
||||
@@ -5,11 +5,7 @@ import type { CheckerValidationInput } from "../../../../../src/server/checker/r
|
||||
import { validateUdpConfig } from "../../../../../src/server/checker/runner/udp/validate";
|
||||
|
||||
describe("validateUdpConfig", () => {
|
||||
const makeInput = (overrides: {
|
||||
defaults?: Record<string, unknown>;
|
||||
targets?: Array<Record<string, unknown>>;
|
||||
}): CheckerValidationInput => ({
|
||||
defaults: overrides.defaults ?? {},
|
||||
const makeInput = (overrides: { targets?: Array<Record<string, unknown>> }): CheckerValidationInput => ({
|
||||
targets: (overrides.targets ?? []) as CheckerValidationInput["targets"],
|
||||
});
|
||||
|
||||
@@ -67,29 +63,6 @@ describe("validateUdpConfig", () => {
|
||||
expect(issues[0]!.path).toContain("udp");
|
||||
});
|
||||
|
||||
it("accepts valid defaults.udp with encoding, responseEncoding, maxResponseBytes", () => {
|
||||
const issues = validateUdpConfig(
|
||||
makeInput({
|
||||
defaults: {
|
||||
udp: { encoding: "hex", maxResponseBytes: 1024, responseEncoding: "text" },
|
||||
},
|
||||
targets: [{ id: "test", type: "udp", udp: { host: "127.0.0.1", port: 53 } }],
|
||||
}),
|
||||
);
|
||||
expect(issues).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("reports unknown-field in defaults.udp", () => {
|
||||
const issues = validateUdpConfig(
|
||||
makeInput({
|
||||
defaults: { udp: { unknownField: true } },
|
||||
targets: [{ id: "test", type: "udp", udp: { host: "127.0.0.1", port: 53 } }],
|
||||
}),
|
||||
);
|
||||
expect(issues).toHaveLength(1);
|
||||
expect(issues[0]!.code).toBe("unknown-field");
|
||||
});
|
||||
|
||||
it("reports invalid-value for udp.encoding with bad value", () => {
|
||||
const issues = validateUdpConfig(
|
||||
makeInput({
|
||||
|
||||
Reference in New Issue
Block a user