Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/integrations/omp-yaml-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || (
Expand Down
14 changes: 14 additions & 0 deletions tests/integrations-writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Loading