diff --git a/src/application/ClientConfigurationDocument.tomlComments.test.ts b/src/application/ClientConfigurationDocument.tomlComments.test.ts index 3bb3852425..856689df05 100644 --- a/src/application/ClientConfigurationDocument.tomlComments.test.ts +++ b/src/application/ClientConfigurationDocument.tomlComments.test.ts @@ -25,52 +25,53 @@ const original = [ "", ].join("\n"); -for (const format of ["toml", "grok"] as const) - for (const lineBreak of ["\n", "\r\n"] as const) - it.each(["replace", "remove"] as const)( - `retains real comments through %s in ${format} with ${JSON.stringify(lineBreak)}`, - (operation) => { - const source = original.replaceAll("\n", lineBreak); - const parsed = parseClientConfiguration(source, format); - const { rea: removed, ...peers } = parsed.servers; - expect(removed).toBeDefined(); - const servers = - operation === "replace" - ? { ...peers, rea: { command: "new", args: [] } } - : peers; - const result = serializeClientConfiguration( - withClientServers(parsed, servers, HOST_PLATFORM.platform), - format, - source, - ); - if (!result.ok) throw new Error("TOML edit was refused"); - for (const comment of [ - "# server header note", - "# command note", - "# array note", - "# multiline note", - "# literal note", - "# tool header note", - "# caller approval", - "# peer note", - ]) - expect(result.value.split(comment)).toHaveLength(2); - for (const stringContent of [ - "# command token", - "# value token", - "# multiline value token", - ]) - expect(result.value).not.toContain(stringContent); - expect(parseClientConfiguration(result.value, format).document).toEqual( - { - root: "retained # root string", - mcp_servers: servers, - }, - ); - if (lineBreak === "\r\n") - expect(result.value.replaceAll("\r\n", "")).not.toContain("\n"); - }, +it.each([ + ["toml", "\n", "replace"], + ["toml", "\r\n", "remove"], + ["grok", "\r\n", "replace"], + ["grok", "\n", "remove"], +] as const)( + "keeps real comments through %s %j %s", + (format, lineBreak, operation) => { + const source = original.replaceAll("\n", lineBreak); + const parsed = parseClientConfiguration(source, format); + const other = { command: "other" }; + const servers = + operation === "replace" + ? { other, rea: { command: "new", args: [] } } + : { other }; + const result = serializeClientConfiguration( + withClientServers(parsed, servers, HOST_PLATFORM.platform), + format, + source, ); + if (!result.ok) throw new Error("TOML edit was refused"); + for (const comment of [ + "# server header note", + "# command note", + "# array note", + "# multiline note", + "# literal note", + "# tool header note", + "# caller approval", + "# peer note", + ]) + expect(result.value.split(comment)).toHaveLength(2); + for (const stringContent of [ + "# command token", + "# value token", + "# multiline value token", + "literal # value token", + ]) + expect(result.value).not.toContain(stringContent); + expect(parseClientConfiguration(result.value, format).document).toEqual({ + root: "retained # root string", + mcp_servers: servers, + }); + if (lineBreak === "\r\n") + expect(result.value.replaceAll(lineBreak, "")).not.toContain("\n"); + }, +); it("retains comments from dotted REA assignments and nested inline values", () => { for (const source of [ diff --git a/tests/acceptance/setup/tomlCommentPreservationCli.test.ts b/tests/acceptance/setup/tomlCommentPreservationCli.test.ts index 379393cdaa..c4c51c35d6 100644 --- a/tests/acceptance/setup/tomlCommentPreservationCli.test.ts +++ b/tests/acceptance/setup/tomlCommentPreservationCli.test.ts @@ -6,25 +6,11 @@ import { expect } from "vitest"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; -const clients = [ - { name: "codex", path: ".codex/config.toml" }, - { name: "grok_build", path: ".grok/config.toml" }, -] as const; - -/** Parsed values other than REA's registration. */ -const unrelatedValues = (text: string) => { - const document = parseToml(text); - const servers = document.mcp_servers; - if (typeof servers === "object" && servers !== null) { - Reflect.deleteProperty(servers, "rea"); - if (Object.keys(servers).length === 0) delete document.mcp_servers; - } - return document; -}; - const scenarios = [ { - name: "a stale REA table between other tables", + client: "grok_build", + path: ".grok/config.toml", + unrelated: { model: "x", mcp_servers: { other: { command: "other" } } }, original: [ "# root explanation", 'model = "x" # inline model note', @@ -60,7 +46,9 @@ const scenarios = [ ], }, { - name: "a leading REA table and a final note without a line break", + client: "codex", + path: ".codex/config.toml", + unrelated: {}, original: [ "# about rea", "[mcp_servers.rea]", @@ -72,93 +60,93 @@ const scenarios = [ }, ] as const; -for (const scenario of scenarios) - cliTest( - `TOML client setup and uninstall keep comments around ${scenario.name}`, - async ({ cli }) => { - const home = await createTestTempDirectory("rea-toml-comments-"); - const paths = clients.map(({ path }) => join(home, path)); - for (const path of paths) { - await mkdir(dirname(path), { recursive: true }); - await writeFile(path, scenario.original); - } - const run = (arguments_: readonly string[]) => - cli.run({ - arguments: arguments_, - cwd: home, - environment: { - HOME: home, - USERPROFILE: home, - CODEX_HOME: join(home, ".codex"), - GROK_HOME: join(home, ".grok"), - XDG_CONFIG_HOME: join(home, ".config"), - TMPDIR: home, - }, - }); - const setup = [ - "setup", - ...clients.flatMap(({ name }) => ["--client", name]), - "--skill=false", - "--json", - ]; +/** Read unrelated values independently of the installed launcher's spelling. */ +const unrelatedValues = (text: string) => { + const document = parseToml(text); + const servers = document.mcp_servers; + if (typeof servers === "object" && servers !== null) { + Reflect.deleteProperty(servers, "rea"); + if (Object.keys(servers).length === 0) delete document.mcp_servers; + } + return document; +}; - const preview = await run([...setup, "--dry-run"]); - expect(preview.exitCode, preview.stdout).toBe(0); - expect(preview.json).toMatchObject({ status: "planned" }); - for (const path of paths) - expect(await readFile(path, "utf8")).toBe(scenario.original); - - const applied = await run([...setup, "--yes"]); - expect(applied.exitCode, applied.stdout).toBe(0); - expect(applied.json).toMatchObject({ - status: "ready", - clients: { - codex: { status: "configured" }, - grok_build: { status: "configured" }, +cliTest( + "TOML setup and uninstall keep comments around middle and final registrations", + async ({ cli }) => { + const home = await createTestTempDirectory("rea-toml-comments-"); + const configs = scenarios.map((scenario) => ({ + ...scenario, + path: join(home, scenario.path), + })); + for (const config of configs) { + await mkdir(dirname(config.path), { recursive: true }); + await writeFile(config.path, config.original); + } + const run = (arguments_: readonly string[]) => + cli.run({ + arguments: arguments_, + cwd: home, + environment: { + HOME: home, + USERPROFILE: home, + CODEX_HOME: join(home, ".codex"), + GROK_HOME: join(home, ".grok"), + XDG_CONFIG_HOME: join(home, ".config"), + TMPDIR: home, }, }); - const configured: string[] = []; - for (const path of paths) { - const text = await readFile(path, "utf8"); - configured.push(text); - for (const comment of scenario.comments) - expect(text, path).toContain(comment); - expect(text, path).not.toContain("rea-agents@6.1.0"); - expect(unrelatedValues(text), path).toEqual( - unrelatedValues(scenario.original), - ); - expect(parseToml(text), path).toHaveProperty("mcp_servers.rea.command"); - expect(await readFile(`${path}.rea.backup`, "utf8"), path).toBe( - scenario.original, - ); - } + const setup = [ + "setup", + ...configs.flatMap(({ client }) => ["--client", client]), + "--skill=false", + "--json", + ]; - const repeated = await run([...setup, "--yes"]); - expect(repeated.exitCode, repeated.stdout).toBe(0); - expect(repeated.json).toMatchObject({ - status: "ready", - appliedActions: [], - }); - for (const [index, path] of paths.entries()) - expect(await readFile(path, "utf8"), path).toBe(configured[index]); + const preview = await run([...setup, "--dry-run"]); + expect(preview.exitCode, preview.stdout).toBe(0); + expect(preview.json).toMatchObject({ status: "planned" }); + for (const { path, original } of configs) + expect(await readFile(path, "utf8"), path).toBe(original); - const removed = await run(["uninstall", "--json"]); - expect(removed.exitCode, removed.stdout).toBe(0); - expect(removed.json).toMatchObject({ status: "complete" }); - const remaining: string[] = []; - for (const path of paths) { - const text = await readFile(path, "utf8"); - remaining.push(text); - for (const comment of scenario.comments) - expect(text, path).toContain(comment); - expect(parseToml(text), path).not.toHaveProperty("mcp_servers.rea"); - expect(unrelatedValues(text), path).toEqual( - unrelatedValues(scenario.original), - ); - // Setup ended the file with REA's table; removing it keeps that break. - expect(text.endsWith("\n"), path).toBe(true); - } - // Both TOML clients share one editor, so their text matches. - expect(remaining[1]).toBe(remaining[0]); - }, - ); + const applied = await run([...setup, "--yes"]); + expect(applied.exitCode, applied.stdout).toBe(0); + expect(applied.json).toMatchObject({ + status: "ready", + clients: { + codex: { status: "configured" }, + grok_build: { status: "configured" }, + }, + }); + const configured = []; + for (const { path, original, comments, unrelated } of configs) { + const text = await readFile(path, "utf8"); + configured.push({ path, text }); + for (const comment of comments) expect(text, path).toContain(comment); + expect(text, path).not.toContain("rea-agents@6.1.0"); + expect(unrelatedValues(text), path).toEqual(unrelated); + expect(parseToml(text), path).toHaveProperty("mcp_servers.rea.command"); + expect(await readFile(`${path}.rea.backup`, "utf8"), path).toBe(original); + } + + const repeated = await run([...setup, "--yes"]); + expect(repeated.exitCode, repeated.stdout).toBe(0); + expect(repeated.json).toMatchObject({ + status: "ready", + appliedActions: [], + }); + for (const { path, text } of configured) + expect(await readFile(path, "utf8"), path).toBe(text); + + const removed = await run(["uninstall", "--json"]); + expect(removed.exitCode, removed.stdout).toBe(0); + expect(removed.json).toMatchObject({ status: "complete" }); + for (const { path, comments, unrelated } of configs) { + const text = await readFile(path, "utf8"); + for (const comment of comments) expect(text, path).toContain(comment); + expect(parseToml(text), path).not.toHaveProperty("mcp_servers.rea"); + expect(unrelatedValues(text), path).toEqual(unrelated); + expect(text.endsWith("\n"), path).toBe(true); + } + }, +); diff --git a/tests/boundary/filesystem/clientLifecycle.test.ts b/tests/boundary/filesystem/clientLifecycle.test.ts index 67b972f26c..de0859a8c8 100644 --- a/tests/boundary/filesystem/clientLifecycle.test.ts +++ b/tests/boundary/filesystem/clientLifecycle.test.ts @@ -430,132 +430,65 @@ describe("Grok Build server table edits", () => { }); }); -describe("Grok Build disabled server list", () => { - it("removes rea from disabled_mcp_servers and leaves other names", async () => { - const home = await createTestTempDirectory("rea-grok-disabled-"); - const configPath = join(home, ".grok/config.toml"); - await mkdir(dirname(configPath), { recursive: true }); - await writeFile( - configPath, - [ - "disabled_mcp_servers = [", - ' "other",', - ' "r\\u0065a",', - ' "rea", # was off', - ' "github",', - "]", - "[mcp_servers.rea]", - "enabled = false", - 'command = "rea"', - 'args = ["mcp"]', - "startup_timeout_sec = 30", - ].join("\n"), - ); - expect( - await configureClientConfiguration( - { - name: "grok_build", - registrationProfile: supportedClientRegistrationProfile("grok_build"), - configPath, - format: "grok", - }, - undefined, - ["rea", "mcp"], - ), - ).toMatchObject({ status: "configured" }); - const configured = await readFile(configPath, "utf8"); - expect(configured).toContain("# was off"); - expect(configured).not.toContain("enabled"); - expect(parseToml(configured)).toMatchObject({ - disabled_mcp_servers: ["other", "github"], - mcp_servers: { - rea: { command: "rea", args: ["mcp"], startup_timeout_sec: 30 }, - }, - }); - expect( - await configureClientConfiguration( - { - name: "grok_build", - registrationProfile: supportedClientRegistrationProfile("grok_build"), - configPath, - format: "grok", - }, - undefined, - ["rea", "mcp"], - ), - ).toEqual({ status: "unchanged" }); - await writeFile(configPath, 'disabled_mcp_servers = ["rea"] # note\n'); - expect( - await configureClientConfiguration( - { - name: "grok_build", - registrationProfile: supportedClientRegistrationProfile("grok_build"), - configPath, - format: "grok", - }, - undefined, - ["rea", "mcp"], - ), - ).toMatchObject({ status: "configured" }); - const created = await readFile(configPath, "utf8"); - expect(created).toContain("# note"); - expect(created).not.toContain("disabled_mcp_servers"); - expect(parseToml(created)).toMatchObject({ - mcp_servers: { rea: { command: "rea", args: ["mcp"] } }, - }); +it("reenables Grok Build REA without changing other disable-list entries", async () => { + const home = await createTestTempDirectory("rea-grok-disabled-"); + const configPath = join(home, ".grok/config.toml"); + await mkdir(dirname(configPath), { recursive: true }); + const client = { + name: "grok_build", + registrationProfile: supportedClientRegistrationProfile("grok_build"), + configPath, + format: "grok", + } as const; + const configure = () => + configureClientConfiguration(client, undefined, ["rea", "mcp"]); + const scopedList = + '[profile]\ndisabled_mcp_servers = ["rea"] # unrelated setting'; + await writeFile( + configPath, + [ + "disabled_mcp_servers = [", + ' "other",', + ' "r\\u0065a",', + ' "rea", # was off', + ' """rea""",', + " '''rea''',", + ' """', + 'rea""",', + ' """rea', + '""",', + ' "github",', + "]", + scopedList, + "[mcp_servers.rea]", + "enabled = false", + 'command = "rea"', + 'args = ["mcp"]', + "startup_timeout_sec = 30", + ].join("\n"), + ); + expect(await configure()).toMatchObject({ status: "configured" }); + const configured = await readFile(configPath, "utf8"); + expect(configured).toContain("# was off"); + expect(configured).toContain(scopedList); + const active = parseToml(configured); + expect(active).toMatchObject({ + disabled_mcp_servers: ["other", "rea\n", "github"], + mcp_servers: { + rea: { command: "rea", args: ["mcp"], startup_timeout_sec: 30 }, + }, }); + expect(active).not.toHaveProperty("mcp_servers.rea.enabled"); + expect(await configure()).toEqual({ status: "unchanged" }); + expect(await readFile(configPath, "utf8")).toBe(configured); - it("removes multiline rea entries from disabled_mcp_servers", async () => { - const home = await createTestTempDirectory("rea-grok-disabled-multiline-"); - const configPath = join(home, ".grok/config.toml"); - await mkdir(dirname(configPath), { recursive: true }); - await writeFile( - configPath, - [ - "disabled_mcp_servers = [", - ' """rea""",', - " '''rea''',", - ' """', - 'rea""",', - ' """rea', - '""",', - ' "github",', - "]", - ].join("\n"), - ); - expect( - await configureClientConfiguration( - { - name: "grok_build", - registrationProfile: supportedClientRegistrationProfile("grok_build"), - configPath, - format: "grok", - }, - undefined, - ["rea", "mcp"], - ), - ).toMatchObject({ status: "configured" }); - const configured = await readFile(configPath, "utf8"); - expect(parseToml(configured)).toMatchObject({ - disabled_mcp_servers: ["rea\n", "github"], - mcp_servers: { rea: { command: "rea", args: ["mcp"] } }, - }); - await writeFile(configPath, 'disabled_mcp_servers = ["""rea"""] # note\n'); - expect( - await configureClientConfiguration( - { - name: "grok_build", - registrationProfile: supportedClientRegistrationProfile("grok_build"), - configPath, - format: "grok", - }, - undefined, - ["rea", "mcp"], - ), - ).toMatchObject({ status: "configured" }); - const created = await readFile(configPath, "utf8"); - expect(created).toContain("# note"); - expect(created).not.toContain("disabled_mcp_servers"); + await writeFile(configPath, 'disabled_mcp_servers = ["""rea"""] # note\n'); + expect(await configure()).toMatchObject({ status: "configured" }); + const created = await readFile(configPath, "utf8"); + expect(created).toContain("# note"); + expect(parseToml(created)).not.toHaveProperty("disabled_mcp_servers"); + expect(parseToml(created)).toMatchObject({ + mcp_servers: { rea: { command: "rea", args: ["mcp"] } }, }); }); @@ -1592,39 +1525,6 @@ describe("Grok Bot registration", () => { }); }); -describe("Codex configuration comments", () => { - it("keeps Codex comments and value spelling through setup and uninstall", async () => { - const home = await createTestTempDirectory("rea-toml-comments-"); - const configPath = join(home, ".codex/config.toml"); - const original = - '# Keep this explanation.\nnotify = ["a", "b"]\nliteral = \'C:\\demo\\path\'\n'; - await mkdir(dirname(configPath), { recursive: true }); - await writeFile(configPath, original); - - expect( - await configureClientConfiguration( - { - name: "codex", - registrationProfile: supportedClientRegistrationProfile("codex"), - configPath, - format: "toml", - }, - {}, - [PRODUCT_IDENTITY.cliBinary, "mcp"], - ), - ).toMatchObject({ status: "configured" }); - const configured = await readFile(configPath, "utf8"); - expect(configured.startsWith(original)).toBe(true); - expect(configured).toContain("[mcp_servers.rea]"); - - const removed = await runUninstall(false, systemUninstallHost(home)); - expect(removed.items).toContainEqual( - expect.objectContaining({ name: "codex", status: "removed" }), - ); - expect(await readFile(configPath, "utf8")).toBe(original); - }); -}); - describe("managed data purge root validation", () => { it.each(["existing", "dangling"] as const)( "retains cache and state when the managed-root symlink is %s",