From 565b5b559a95612c28936d540419bed0c57518b2 Mon Sep 17 00:00:00 2001 From: luvs01 Date: Thu, 13 Aug 2026 10:28:53 +0900 Subject: [PATCH] fix(integrations): refuse invalid OMP alias removal --- src/integrations/omp-yaml-source.ts | 7 ++++++- tests/integrations-writer.test.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/integrations/omp-yaml-source.ts b/src/integrations/omp-yaml-source.ts index 94c4972eb..2a0dc3839 100644 --- a/src/integrations/omp-yaml-source.ts +++ b/src/integrations/omp-yaml-source.ts @@ -200,7 +200,12 @@ export function patchOmpYamlSource( let patched = `${text.slice(0, startOffset)}${text.slice(endOffset)}`; if (mutation.removeEmptyProviders) { - const remaining = Bun.YAML.parse(patched) as { providers?: unknown } | null; + let remaining: { providers?: unknown } | null; + try { + remaining = Bun.YAML.parse(patched) as { providers?: unknown } | null; + } catch { + return null; + } if (remaining && Object.hasOwn(remaining, "providers")) { const provider = remaining.providers; const empty = provider === null || ( diff --git a/tests/integrations-writer.test.ts b/tests/integrations-writer.test.ts index 7477e11fd..2bd3ee657 100644 --- a/tests/integrations-writer.test.ts +++ b/tests/integrations-writer.test.ts @@ -311,6 +311,20 @@ describe("OMP source preservation", () => { if (!result.ok) expect(result.reason).toBe("unsafe"); expect(readFileSync(configPath, "utf8")).toBe(edited); }); + + test("refuses disable when removing the managed block would break a YAML alias", () => { + const configPath = installOmp(); + expect(applyIntegration(input({ clientId: "omp" })).ok).toBe(true); + const edited = readFileSync(configPath, "utf8") + .replace(" baseUrl:", " baseUrl: &opencodex_url") + .concat("settings:\n inheritedBase: *opencodex_url\n"); + writeFileSync(configPath, edited); + + const result = disableIntegration(input({ clientId: "omp" })); + expect(result.ok).toBe(false); + if (!result.ok) expect(result.reason).toBe("unsafe"); + expect(readFileSync(configPath, "utf8")).toBe(edited); + }); }); describe("restore", () => {