Files
reverse-engineering-anything/src/application/ClientConfigurationDocument.capacity.test.ts
T
morluto e103ae0ce5 fix(clients): advance TOML statement lines without document rescans
Reuse the writer's monotonic statement index to find the last physical line
of an assignment. Remove the full line-start scan performed for every key.
Preserve source edits, multiline values, BOM, CRLF and final-line handling.

Add LF/CRLF controls with adjacent assignments, multiline values, an empty
value and EOF without a newline. Validated 85 focused tests across six files,
check:fast, docs:check and discovery of all 1553 test files.

Twelve bounded public CLI uninstall tasks preserve equivalent replies,
configuration and original backups. Warm 10000-assignment elapsed medians
were 0.538/0.520 s and CPU 0.817/0.744 s before/after; small-input timings
were noisy and slower in the candidate. No general speedup, cold-cache,
real-client or analysis-provider claim. Heavy profiling remains stopped.

Fixes #4873
2026-10-18 03:41:32 +08:00

101 lines
3.4 KiB
TypeScript

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.each(["\n", "\r\n"])(
"retains adjacent assignments and multiline values with %j breaks",
(newline) => {
const prefix = Array.from(
{ length: 128 },
(_, index) =>
`[foreign.entry_${index}]\nvalue = ${index}\nnote = """first\n# [mcp_servers.rea]\nlast"""\nitems = [\n${index},\n]\n`,
).join("");
// Include a BOM, an empty value, and a final statement without a newline.
const original =
"\uFEFF" +
`${prefix}[mcp_servers.rea]\ncommand = "previous"\n[tail]\nempty = ""\nlast = 7`.replaceAll(
"\n",
newline,
);
const parsed = parseClientConfiguration(original, "toml");
const desired = withClientServers(parsed, {
...parsed.servers,
rea: registration,
});
const configured = serializeClientConfiguration(
desired,
"toml",
original,
);
expect(
configured.startsWith("\uFEFF" + prefix.replaceAll("\n", newline)),
).toBe(true);
expect(parseClientConfiguration(configured, "toml").document).toEqual(
desired,
);
const removed = serializeClientConfiguration(
withClientServers(parsed, {}),
"toml",
configured,
);
const expectedForeignDocument = { ...parsed.document };
delete expectedForeignDocument.mcp_servers;
expect(parseClientConfiguration(removed, "toml").document).toEqual(
expectedForeignDocument,
);
},
);
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,
});
});
});