From 431463dec2219949132f18c41503afafffba75cc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 18:15:30 +0000 Subject: [PATCH] test: simplify config patch validation coverage --- src/gateway/server.config-patch.test.ts | 65 +++++++++++++------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/gateway/server.config-patch.test.ts b/src/gateway/server.config-patch.test.ts index 67efe9b79be..bc8b4fab75a 100644 --- a/src/gateway/server.config-patch.test.ts +++ b/src/gateway/server.config-patch.test.ts @@ -46,6 +46,21 @@ async function resetTempDir(name: string): Promise { return dir; } +async function getConfigHash() { + const current = await rpcReq<{ + hash?: string; + }>(requireWs(), "config.get", {}); + expect(current.ok).toBe(true); + expect(typeof current.payload?.hash).toBe("string"); + return String(current.payload?.hash); +} + +async function expectSchemaLookupInvalid(path: unknown) { + const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", { path }); + expect(res.ok).toBe(false); + expect(res.error?.message ?? "").toContain("invalid config.schema.lookup params"); +} + describe("gateway config methods", () => { it("round-trips config.set and returns the live config path", async () => { const { createConfigIO } = await import("../config/config.js"); @@ -73,12 +88,6 @@ describe("gateway config methods", () => { }); it("returns config.set validation details in the top-level error message", async () => { - const current = await rpcReq<{ - hash?: string; - }>(requireWs(), "config.get", {}); - expect(current.ok).toBe(true); - expect(typeof current.payload?.hash).toBe("string"); - const res = await rpcReq<{ ok?: boolean; error?: { @@ -86,7 +95,7 @@ describe("gateway config methods", () => { }; }>(requireWs(), "config.set", { raw: JSON.stringify({ gateway: { bind: 123 } }), - baseHash: current.payload?.hash, + baseHash: await getConfigHash(), }); const error = res.error as | { @@ -135,31 +144,22 @@ describe("gateway config methods", () => { expect(res.error?.message).toBe("config schema path not found"); }); - it("rejects config.schema.lookup when the path is only whitespace", async () => { - const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", { - path: " ", - }); - - expect(res.ok).toBe(false); - expect(res.error?.message ?? "").toContain("invalid config.schema.lookup params"); - }); - - it("rejects config.schema.lookup when the path exceeds the protocol limit", async () => { - const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", { + it.each([ + { name: "rejects config.schema.lookup when the path is only whitespace", path: " " }, + { + name: "rejects config.schema.lookup when the path exceeds the protocol limit", path: `gateway.${"a".repeat(1020)}`, - }); - - expect(res.ok).toBe(false); - expect(res.error?.message ?? "").toContain("invalid config.schema.lookup params"); - }); - - it("rejects config.schema.lookup when the path contains invalid characters", async () => { - const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", { + }, + { + name: "rejects config.schema.lookup when the path contains invalid characters", path: "gateway.auth\nspoof", - }); - - expect(res.ok).toBe(false); - expect(res.error?.message ?? "").toContain("invalid config.schema.lookup params"); + }, + { + name: "rejects config.schema.lookup when the path is not a string", + path: 42, + }, + ])("$name", async ({ path }) => { + await expectSchemaLookupInvalid(path); }); it("rejects prototype-chain config.schema.lookup paths without reflecting them", async () => { @@ -171,9 +171,10 @@ describe("gateway config methods", () => { expect(res.error?.message).toBe("config schema path not found"); }); - it("rejects config.patch when raw is not an object", async () => { + it("rejects config.patch when raw is null", async () => { const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.patch", { - raw: "[]", + raw: "null", + baseHash: await getConfigHash(), }); expect(res.ok).toBe(false); expect(res.error?.message ?? "").toContain("raw must be an object");