Gateway: add path-scoped config schema lookup (#37266)

Merged via squash.

Prepared head SHA: 0c4d187f6f
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-03-06 02:50:48 -05:00
committed by GitHub
parent c5828cbc08
commit ff97195500
18 changed files with 633 additions and 7 deletions

View File

@@ -47,6 +47,73 @@ async function resetTempDir(name: string): Promise<string> {
}
describe("gateway config methods", () => {
it("returns a path-scoped config schema lookup", async () => {
const res = await rpcReq<{
path: string;
hintPath?: string;
children?: Array<{ key: string; path: string; required: boolean; hintPath?: string }>;
schema?: { properties?: unknown };
}>(requireWs(), "config.schema.lookup", {
path: "gateway.auth",
});
expect(res.ok).toBe(true);
expect(res.payload?.path).toBe("gateway.auth");
expect(res.payload?.hintPath).toBe("gateway.auth");
const tokenChild = res.payload?.children?.find((child) => child.key === "token");
expect(tokenChild).toMatchObject({
key: "token",
path: "gateway.auth.token",
hintPath: "gateway.auth.token",
});
expect(res.payload?.schema?.properties).toBeUndefined();
});
it("rejects config.schema.lookup when the path is missing", async () => {
const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", {
path: "gateway.notReal.path",
});
expect(res.ok).toBe(false);
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", {
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", {
path: "gateway.auth\nspoof",
});
expect(res.ok).toBe(false);
expect(res.error?.message ?? "").toContain("invalid config.schema.lookup params");
});
it("rejects prototype-chain config.schema.lookup paths without reflecting them", async () => {
const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.schema.lookup", {
path: "constructor",
});
expect(res.ok).toBe(false);
expect(res.error?.message).toBe("config schema path not found");
});
it("rejects config.patch when raw is not an object", async () => {
const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.patch", {
raw: "[]",