From 6ff18f7ccbaa36c3b6142dc3eb6e161a9fe21b6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Aug 2026 02:18:32 +0000 Subject: [PATCH 1/3] improve: surface warning when config thresholds are invalid ConfigurationManager.validateConfiguration() detects when warningThreshold >= errorThreshold, but the result was never checked anywhere in production code (only unit-tested). Wire it into activate() and the configuration change listener so a misconfigured user actually sees a warning instead of silently getting the wrong complexity color coding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/extension.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index ed0ad28..12730a1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -55,6 +55,20 @@ function showFunctionDetails( detailsChannel.show(true /* preserveFocus */); } +/** + * Validates the current configuration and, if the thresholds are misconfigured + * (e.g. warningThreshold >= errorThreshold), surfaces a warning to the user so + * the issue isn't silently ignored. + */ +function checkConfigurationValidity(): void { + const { valid, warnings } = ConfigurationManager.validateConfiguration(); + if (!valid) { + vscode.window.showWarningMessage( + `Code Metrics: invalid configuration detected. ${warnings.join(" ")}` + ); + } +} + // This method is called when your extension is activated // Your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { @@ -69,7 +83,17 @@ export function activate(context: vscode.ExtensionContext) { // Register providers const codeLensDisposable = registerCodeLensProvider(); - context.subscriptions.push(showFunctionDetailsCommand, codeLensDisposable); + // Warn the user up front, and again whenever settings change, if thresholds are invalid. + checkConfigurationValidity(); + const configValidityWatcher = ConfigurationManager.onConfigurationChanged(() => { + checkConfigurationValidity(); + }); + + context.subscriptions.push( + showFunctionDetailsCommand, + codeLensDisposable, + configValidityWatcher + ); } // This method is called when your extension is deactivated From a516ad0915a36c47d284b28c9df64c6f41453a86 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 18:43:45 +0000 Subject: [PATCH 2/3] test: add unit tests for checkConfigurationValidity in extension.ts Co-authored-by: askpt <2493377+askpt@users.noreply.github.com> --- src/extension.ts | 4 +- src/test/extension.test.ts | 79 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 12730a1..00347cf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -59,8 +59,10 @@ function showFunctionDetails( * Validates the current configuration and, if the thresholds are misconfigured * (e.g. warningThreshold >= errorThreshold), surfaces a warning to the user so * the issue isn't silently ignored. + * + * Exported for unit-testing purposes. */ -function checkConfigurationValidity(): void { +export function checkConfigurationValidity(): void { const { valid, warnings } = ConfigurationManager.validateConfiguration(); if (!valid) { vscode.window.showWarningMessage( diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 4aee666..1ec73f4 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -147,4 +147,83 @@ suite("Extension Activation Tests", () => { extensionModule.deactivate(); }, "deactivate() should not throw"); }); + + suite("checkConfigurationValidity", () => { + // Stub type to capture showWarningMessage calls + type ShowWarningStub = (message: string, ...items: string[]) => Thenable; + + let warningMessages: string[]; + let originalShowWarningMessage: typeof vscode.window.showWarningMessage; + + setup(() => { + warningMessages = []; + originalShowWarningMessage = vscode.window.showWarningMessage; + (vscode.window as any).showWarningMessage = ((message: string) => { + warningMessages.push(message); + return Promise.resolve(undefined); + }) as ShowWarningStub; + }); + + teardown(async () => { + (vscode.window as any).showWarningMessage = originalShowWarningMessage; + const vsConfig = vscode.workspace.getConfiguration("codeMetrics"); + await vsConfig.update("warningThreshold", undefined, vscode.ConfigurationTarget.Global); + await vsConfig.update("errorThreshold", undefined, vscode.ConfigurationTarget.Global); + }); + + test("should not show a warning when thresholds are valid", () => { + // Default configuration has valid thresholds (warningThreshold < errorThreshold) + extensionModule.checkConfigurationValidity(); + + assert.strictEqual( + warningMessages.length, + 0, + "No warning should be shown for valid configuration" + ); + }); + + test("should show a warning when warningThreshold equals errorThreshold", async () => { + const vsConfig = vscode.workspace.getConfiguration("codeMetrics"); + await vsConfig.update("warningThreshold", 10, vscode.ConfigurationTarget.Global); + await vsConfig.update("errorThreshold", 10, vscode.ConfigurationTarget.Global); + + extensionModule.checkConfigurationValidity(); + + assert.strictEqual( + warningMessages.length, + 1, + "Exactly one warning should be shown" + ); + assert.ok( + warningMessages[0].includes("Code Metrics"), + "Warning message should be prefixed with 'Code Metrics'" + ); + assert.ok( + warningMessages[0].includes("invalid configuration"), + "Warning message should mention invalid configuration" + ); + }); + + test("should show a warning when warningThreshold exceeds errorThreshold", async () => { + const vsConfig = vscode.workspace.getConfiguration("codeMetrics"); + await vsConfig.update("warningThreshold", 20, vscode.ConfigurationTarget.Global); + await vsConfig.update("errorThreshold", 10, vscode.ConfigurationTarget.Global); + + extensionModule.checkConfigurationValidity(); + + assert.strictEqual( + warningMessages.length, + 1, + "Exactly one warning should be shown" + ); + assert.ok( + warningMessages[0].includes("Warning threshold (20)"), + "Warning message should include the invalid warningThreshold value" + ); + assert.ok( + warningMessages[0].includes("error threshold (10)"), + "Warning message should include the errorThreshold value" + ); + }); + }); }); From e06abe58979680c8193d757be0b23b5e556f60f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Aug 2026 07:23:15 +0000 Subject: [PATCH 3/3] fix: clear warningMessages before explicit call to avoid onConfigurationChanged pollution in tests Co-authored-by: askpt <2493377+askpt@users.noreply.github.com> --- src/test/extension.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 1ec73f4..0f8d959 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -187,6 +187,9 @@ suite("Extension Activation Tests", () => { await vsConfig.update("warningThreshold", 10, vscode.ConfigurationTarget.Global); await vsConfig.update("errorThreshold", 10, vscode.ConfigurationTarget.Global); + // Reset captured messages so that onConfigurationChanged calls from the + // config updates above don't pollute the assertion. + warningMessages = []; extensionModule.checkConfigurationValidity(); assert.strictEqual( @@ -209,6 +212,9 @@ suite("Extension Activation Tests", () => { await vsConfig.update("warningThreshold", 20, vscode.ConfigurationTarget.Global); await vsConfig.update("errorThreshold", 10, vscode.ConfigurationTarget.Global); + // Reset captured messages so that onConfigurationChanged calls from the + // config updates above don't pollute the assertion. + warningMessages = []; extensionModule.checkConfigurationValidity(); assert.strictEqual(