mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 11:33:10 +00:00
A bare toThrow() or rejects.toThrow() passes on any error, including one from a broken fixture or a refusal for the wrong reason. The suite's 429 bare sites now assert the specific refusal, so turn on vitest/require-to-throw-message as an error to keep it that way. Tighten the one site added since (malformed TOML now asserts smol-toml's line and column). The two sites whose refusal cannot be observed outside Linux or without a native capture bound keep a bare matcher with a disable comment saying why.
144 lines
4.3 KiB
TypeScript
144 lines
4.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { PRODUCT_IDENTITY } from "../identity.js";
|
|
import {
|
|
parseClientToml,
|
|
serializeCodexConfiguration,
|
|
serializeGrokConfiguration,
|
|
} from "./ClientConfigurationToml.js";
|
|
|
|
const KEY = PRODUCT_IDENTITY.mcpServerKey;
|
|
|
|
describe("parseClientToml", () => {
|
|
it("keeps TOML integers distinct from integral floats as bigints", () => {
|
|
const parsed = parseClientToml("count = 42\nratio = 42.0\n");
|
|
expect(parsed).toEqual({ count: 42n, ratio: 42 });
|
|
expect(typeof parsed.count).toBe("bigint");
|
|
expect(typeof parsed.ratio).toBe("number");
|
|
});
|
|
|
|
it("accepts signed 64-bit integer bounds and rejects out-of-range integers", () => {
|
|
const bounds = parseClientToml(
|
|
"min = -9223372036854775808\nmax = 9223372036854775807\n",
|
|
);
|
|
expect(bounds).toEqual({
|
|
min: -(2n ** 63n),
|
|
max: 2n ** 63n - 1n,
|
|
});
|
|
expect(() => parseClientToml("overflow = 9223372036854775808\n")).toThrow(
|
|
SyntaxError,
|
|
);
|
|
expect(() => parseClientToml("underflow = -9223372036854775809\n")).toThrow(
|
|
SyntaxError,
|
|
);
|
|
});
|
|
|
|
it("rejects malformed TOML syntax", () => {
|
|
// smol-toml reports where the unterminated table header stops parsing.
|
|
expect(() => parseClientToml("[unterminated\nkey = 1\n")).toThrow(
|
|
expect.objectContaining({ line: 1, column: 14 }),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("serializeCodexConfiguration", () => {
|
|
it("preserves comments, unrelated tables, and quoted sibling server keys", () => {
|
|
const original = [
|
|
"# Top user comment",
|
|
'model = "o3"',
|
|
"",
|
|
'[mcp_servers."rea.env"]',
|
|
'command = "other"',
|
|
"",
|
|
`[mcp_servers.${KEY}]`,
|
|
'command = "old-npx"',
|
|
'args = ["old"]',
|
|
"",
|
|
"[mcp_servers.other]",
|
|
'command = "keep-me"',
|
|
"",
|
|
].join("\n");
|
|
|
|
const updated = {
|
|
model: "o3",
|
|
mcp_servers: {
|
|
"rea.env": { command: "other" },
|
|
[KEY]: { command: "npx", args: ["-y", "rea-agents@latest", "mcp"] },
|
|
other: { command: "keep-me" },
|
|
},
|
|
};
|
|
|
|
const first = serializeCodexConfiguration(updated, original);
|
|
expect(first).toContain("# Top user comment");
|
|
expect(first).toContain('[mcp_servers."rea.env"]');
|
|
expect(first).toContain('command = "keep-me"');
|
|
expect(parseClientToml(first)).toEqual(updated);
|
|
|
|
// Repeating the same serialization must be idempotent.
|
|
const second = serializeCodexConfiguration(updated, first);
|
|
expect(second).toBe(first);
|
|
});
|
|
|
|
it("removes the REA server section cleanly while preserving other settings", () => {
|
|
const original = [
|
|
"# Keep comment",
|
|
"retries = 3",
|
|
"",
|
|
`[mcp_servers.${KEY}]`,
|
|
'command = "npx"',
|
|
"",
|
|
].join("\n");
|
|
|
|
const removed = serializeCodexConfiguration({ retries: 3n }, original);
|
|
expect(removed).toContain("# Keep comment");
|
|
expect(parseClientToml(removed)).toEqual({ retries: 3n });
|
|
});
|
|
|
|
it("serializes from scratch when original text is absent or blank", () => {
|
|
const doc = {
|
|
mcp_servers: {
|
|
[KEY]: { command: "npx", args: ["rea-agents", "mcp"] },
|
|
},
|
|
};
|
|
const fromUndefined = serializeCodexConfiguration(doc, undefined);
|
|
const fromBlank = serializeCodexConfiguration(doc, " \n ");
|
|
expect(parseClientToml(fromUndefined)).toEqual(doc);
|
|
expect(parseClientToml(fromBlank)).toEqual(doc);
|
|
});
|
|
});
|
|
|
|
describe("serializeGrokConfiguration", () => {
|
|
it("updates the REA server section while preserving unrelated Grok sections", () => {
|
|
const original = [
|
|
"# Grok config",
|
|
'theme = "dark"',
|
|
"",
|
|
"[mcp_servers.custom]",
|
|
'command = "custom-mcp"',
|
|
"",
|
|
].join("\n");
|
|
|
|
const doc = {
|
|
theme: "dark",
|
|
mcp_servers: {
|
|
custom: { command: "custom-mcp" },
|
|
[KEY]: { command: "npx", args: ["rea-agents", "mcp"] },
|
|
},
|
|
};
|
|
|
|
const serialized = serializeGrokConfiguration(doc, original);
|
|
expect(serialized).toContain("# Grok config");
|
|
expect(parseClientToml(serialized)).toEqual(doc);
|
|
});
|
|
|
|
it("serializes a fresh document when original text is undefined", () => {
|
|
const doc = {
|
|
mcp_servers: {
|
|
[KEY]: { command: "npx", args: ["rea-agents", "mcp"] },
|
|
},
|
|
};
|
|
expect(parseClientToml(serializeGrokConfiguration(doc, undefined))).toEqual(
|
|
doc,
|
|
);
|
|
});
|
|
});
|