mirror of
https://github.com/morluto/rea.git
synced 2026-11-10 08:47:00 +00:00
fix(clients): preserve large TOML documents without argument spreads
Fixes #4856
This commit is contained in:
1 parent
3460ceac3f
commit
c43bc0bf66
3 files changed
+139
-3
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
parseClientConfiguration,
|
||||
serializeClientConfiguration,
|
||||
withClientServers,
|
||||
} from "./ClientConfigurationDocument.js";
|
||||
|
||||
const registration = { command: "rea", args: ["mcp"] };
|
||||
|
||||
describe("TOML configuration source capacity", () => {
|
||||
it("retains a large multiline foreign value inside an inline server table", () => {
|
||||
const note = `first\n${"x\n".repeat(500_000)}last`;
|
||||
const original = `mcp_servers = { other = {command="other",env={NOTE="""${note}"""}}}\n`;
|
||||
const parsed = parseClientConfiguration(original, "toml");
|
||||
const desired = withClientServers(parsed, {
|
||||
...parsed.servers,
|
||||
rea: registration,
|
||||
});
|
||||
const configured = serializeClientConfiguration(desired, "toml", original);
|
||||
expect(configured).toContain(`NOTE="""${note}"""`);
|
||||
expect(parseClientConfiguration(configured, "toml").document).toEqual(
|
||||
desired,
|
||||
);
|
||||
const removed = serializeClientConfiguration(
|
||||
parsed.document,
|
||||
"toml",
|
||||
configured,
|
||||
);
|
||||
expect(removed).toContain(`NOTE="""${note}"""`);
|
||||
expect(parseClientConfiguration(removed, "toml").document).toEqual(
|
||||
parsed.document,
|
||||
);
|
||||
});
|
||||
|
||||
it("removes only REA from a large multiline Grok disabled-server list", () => {
|
||||
const otherNames = '"other",\n'.repeat(500_000);
|
||||
const original =
|
||||
`disabled_mcp_servers = [\n"rea",\n${otherNames}]\n` +
|
||||
'[mcp_servers.other]\ncommand = "other"\n';
|
||||
const parsed = parseClientConfiguration(original, "grok");
|
||||
const desired = withClientServers(parsed, {
|
||||
...parsed.servers,
|
||||
rea: registration,
|
||||
});
|
||||
const configured = serializeClientConfiguration(desired, "grok", original);
|
||||
const result = parseClientConfiguration(configured, "grok");
|
||||
expect(result.document.disabled_mcp_servers).toEqual(
|
||||
Array<string>(500_000).fill("other"),
|
||||
);
|
||||
expect(result.servers).toEqual({
|
||||
other: { command: "other" },
|
||||
rea: registration,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -967,8 +967,12 @@ const upsertTomlServerSection = (
|
||||
const discardPending = (): void => {
|
||||
pending.length = 0;
|
||||
};
|
||||
// Document line counts must not become engine-limited argument counts.
|
||||
const appendLines = (lines: readonly string[]): void => {
|
||||
for (const line of lines) kept.push(line);
|
||||
};
|
||||
const flushPending = (): void => {
|
||||
kept.push(...pending);
|
||||
appendLines(pending);
|
||||
pending.length = 0;
|
||||
};
|
||||
const lineIndexAt = (offset: number): number => {
|
||||
@@ -1039,7 +1043,7 @@ const upsertTomlServerSection = (
|
||||
: undefined;
|
||||
if (disabledLines !== undefined) {
|
||||
flushPending();
|
||||
kept.push(...disabledLines);
|
||||
appendLines(disabledLines);
|
||||
lineIndex = endLine + 1;
|
||||
mode = "none";
|
||||
continue;
|
||||
@@ -1064,7 +1068,7 @@ const upsertTomlServerSection = (
|
||||
edited === undefined
|
||||
? text.slice(lineStart, statementEnd)
|
||||
: `${prefix}${edited}${suffix}`;
|
||||
kept.push(...replacement.split("\n"));
|
||||
appendLines(replacement.split("\n"));
|
||||
inlineServerTable = true;
|
||||
} else discardPending();
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user