From 6fce97977d614738dbf87b7c7c6559b65f85424c Mon Sep 17 00:00:00 2001 From: mastertyko <11311479+mastertyko@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:08:13 +0200 Subject: [PATCH] fix(gsd): suppress repeated preferences section warnings --- src/resources/extensions/gsd/preferences.ts | 7 ++++++- .../extensions/gsd/tests/preferences.test.ts | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/resources/extensions/gsd/preferences.ts b/src/resources/extensions/gsd/preferences.ts index 2ca2f687d..a2c86fdbd 100644 --- a/src/resources/extensions/gsd/preferences.ts +++ b/src/resources/extensions/gsd/preferences.ts @@ -200,11 +200,13 @@ function loadPreferencesFile(path: string, scope: "global" | "project"): LoadedG } let _warnedUnrecognizedFormat = false; +let _warnedSectionParse = false; /** @internal Reset the warn-once flags — exported for testing only. */ export function _resetParseWarningFlag(): void { _warnedUnrecognizedFormat = false; _warnedFrontmatterParse = false; + _warnedSectionParse = false; } /** @internal Exported for testing only */ @@ -309,7 +311,10 @@ function parseHeadingListFormat(content: string): GSDPreferences { typed[targetSection] = value; } catch (e) { - logWarning("guided", `preferences section parse failed: ${(e as Error).message}`); + if (!_warnedSectionParse) { + _warnedSectionParse = true; + logWarning("guided", `preferences section parse failed: ${(e as Error).message}`); + } } } diff --git a/src/resources/extensions/gsd/tests/preferences.test.ts b/src/resources/extensions/gsd/tests/preferences.test.ts index 79aa04ef3..79e36893c 100644 --- a/src/resources/extensions/gsd/tests/preferences.test.ts +++ b/src/resources/extensions/gsd/tests/preferences.test.ts @@ -17,6 +17,7 @@ import { parsePreferencesMarkdown, _resetParseWarningFlag, } from "../preferences.ts"; +import { _resetLogs, peekLogs } from "../workflow-logger.ts"; import type { GSDPreferences, GSDModelConfigV2, GSDPhaseModelConfig } from "../preferences.ts"; // ── Git preferences ────────────────────────────────────────────────────────── @@ -422,6 +423,25 @@ test("parsePreferencesMarkdown parses heading+list format without frontmatter (# assert.deepStrictEqual(result!.git, { isolation: "none" }); }); +test("section parse warning is emitted at most once for heading+list YAML failures (#3759)", () => { + _resetParseWarningFlag(); + _resetLogs(); + + const content = `## Git +bad: [ +`; + + parsePreferencesMarkdown(content); + parsePreferencesMarkdown(content); + parsePreferencesMarkdown(content); + + const warnings = peekLogs().filter((entry) => entry.component === "guided" && entry.message.includes("preferences section parse failed")); + assert.equal(warnings.length, 1, `expected exactly 1 guided warning, got ${warnings.length}`); + + _resetParseWarningFlag(); + _resetLogs(); +}); + // ── Experimental preferences ───────────────────────────────────────────────── test("experimental.rtk: true is accepted and stored", () => {