style(setup): format retained field validation

This commit is contained in:
morluto committed 2026-10-13 20:20:42 +08:00
1 parent 69582df9c3
commit 3370bab50b
4 files changed
+46 -19

No files matched your search

+2 -1
View File
@@ -36,7 +36,8 @@ export const registrationFieldAccepted = (
key: string,
value: unknown,
): boolean => {
const shape: Readonly<Record<string, z.ZodType>> = registrationSchemaFor(dialect).shape;
const shape: Readonly<Record<string, z.ZodType>> =
registrationSchemaFor(dialect).shape;
const field = Object.hasOwn(shape, key) ? shape[key] : undefined;
return field === undefined || field.safeParse(value).success;
};
+7 -2
View File
@@ -14,7 +14,10 @@ import { resolve } from "node:path";
import { z } from "zod";
import { registrationSchema, registrationSchemaFor } from "./ClientRegistrationShape.js";
import {
registrationSchema,
registrationSchemaFor,
} from "./ClientRegistrationShape.js";
import { PRODUCT_IDENTITY } from "../identity.js";
import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js";
import {
@@ -322,7 +325,9 @@ const parseRegistration = (
args,
});
}
const registration = registrationSchemaFor(client.format ?? "json").parse(value);
const registration = registrationSchemaFor(client.format ?? "json").parse(
value,
);
if (
(client.format === "vscode" || client.format === "copilot_cli") &&
registration.type !== "stdio"
@@ -476,7 +476,6 @@ export const inspectClientConfiguration = async (
"The existing configuration is malformed. Repair it before setup applies any other changes.",
};
}
};
const clientRegistrationDialect = (
@@ -271,22 +271,44 @@ it("replaces a remote server entry instead of merging its fields", async () => {
).toEqual(clientRegistrationEntry("json", command, {}));
});
it.each([
["tool_timeout_sec", "900"],
["enabled_tools", "analyze_function"],
["disabled_tools", [123]],
] as const)("repairs invalid Codex field %s before reporting alignment", async (field, value) => {
const root = await createTestTempDirectory("rea-codex-field-repair-");
const configPath = join(root, "config.toml");
const client: SetupClient = { name: "codex", format: "toml", configPath };
await writeFile(configPath, serializeClientConfiguration({ mcp_servers: {
rea: { command: "rea", args: ["mcp"], [field]: value, timeout_note: "keep" },
} }, "toml"));
expect((await configureClientConfiguration(client, {}, command)).status).toBe("configured");
const entry = parseClientConfiguration(await readFile(configPath, "utf8"), "toml").servers.rea;
expect(entry).not.toHaveProperty(field);
expect(entry).toHaveProperty("timeout_note", "keep");
expect(await clientConfigurationAligned(client, {}, command)).toBe(true);
expect((await configureClientConfiguration(client, {}, command)).status).toBe("unchanged");
});
] as const)(
"repairs invalid Codex field %s before reporting alignment",
async (field, value) => {
const root = await createTestTempDirectory("rea-codex-field-repair-");
const configPath = join(root, "config.toml");
const client: SetupClient = { name: "codex", format: "toml", configPath };
await writeFile(
configPath,
serializeClientConfiguration(
{
mcp_servers: {
rea: {
command: "rea",
args: ["mcp"],
[field]: value,
timeout_note: "keep",
},
},
},
"toml",
),
);
expect(
(await configureClientConfiguration(client, {}, command)).status,
).toBe("configured");
const entry = parseClientConfiguration(
await readFile(configPath, "utf8"),
"toml",
).servers.rea;
expect(entry).not.toHaveProperty(field);
expect(entry).toHaveProperty("timeout_note", "keep");
expect(await clientConfigurationAligned(client, {}, command)).toBe(true);
expect(
(await configureClientConfiguration(client, {}, command)).status,
).toBe("unchanged");
},
);