From e0fdbaf26a2a718a30539c81d36e851b7f7cdf71 Mon Sep 17 00:00:00 2001 From: luvs01 Date: Tue, 11 Aug 2026 09:54:01 +0900 Subject: [PATCH] fix(omp): allow quoted hashes in managed YAML --- src/integrations/omp-yaml-source.ts | 19 ++++++++++- tests/omp-yaml-source-inline-comments.test.ts | 32 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/integrations/omp-yaml-source.ts b/src/integrations/omp-yaml-source.ts index 94c4972eb4..5be42c1390 100644 --- a/src/integrations/omp-yaml-source.ts +++ b/src/integrations/omp-yaml-source.ts @@ -51,7 +51,24 @@ function isComment(line: string): boolean { } function hasInlineComment(line: string): boolean { - return line.includes("#"); + let quote: "'" | "\"" | null = null; + for (let index = 0; index < line.length; index += 1) { + const character = line[index]!; + if (quote === "\"") { + if (character === "\\") index += 1; + else if (character === quote) quote = null; + continue; + } + if (quote === "'") { + if (character !== quote) continue; + if (line[index + 1] === quote) index += 1; + else quote = null; + continue; + } + if (character === "'" || character === "\"") quote = character; + else if (character === "#" && /\s/u.test(line[index - 1] ?? "")) return true; + } + return false; } function isPlainBlockKey(line: string, indent: number, key: string): boolean { diff --git a/tests/omp-yaml-source-inline-comments.test.ts b/tests/omp-yaml-source-inline-comments.test.ts index 9405f86089..83167377c3 100644 --- a/tests/omp-yaml-source-inline-comments.test.ts +++ b/tests/omp-yaml-source-inline-comments.test.ts @@ -14,6 +14,22 @@ const CURRENT_VALUE = { api: "openai-completions", }; +const SOURCE_WITH_QUOTED_HASH = [ + "providers:", + " opencodex:", + " models:", + " - id: \"provider/model#variant\"", + " name: 'model#variant (provider)'", + "", +].join("\n"); + +const VALUE_WITH_QUOTED_HASH = { + models: [{ + id: "provider/model#variant", + name: "model#variant (provider)", + }], +}; + describe("OMP managed YAML inline comments", () => { test("refresh refuses to replace a managed block containing a nested inline comment", () => { const nextValue = { @@ -35,4 +51,20 @@ describe("OMP managed YAML inline comments", () => { {}, )).toBeNull(); }); + + test("refresh accepts hash characters inside quoted model scalars", () => { + expect(patchOmpYamlSource( + SOURCE_WITH_QUOTED_HASH, + { kind: "upsert", value: VALUE_WITH_QUOTED_HASH }, + { providers: { opencodex: VALUE_WITH_QUOTED_HASH } }, + )).not.toBeNull(); + }); + + test("disable accepts hash characters inside quoted model scalars", () => { + expect(patchOmpYamlSource( + SOURCE_WITH_QUOTED_HASH, + { kind: "remove", removeEmptyProviders: true }, + {}, + )).toBe(""); + }); });