From 230939e5585b16fe3227218dc7132032eee3a896 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 7 Apr 2026 10:48:41 -0500 Subject: [PATCH] test(gsd): add regression test for verbose-gated model change notification Verifies that the Model [phase] [tier] notification in selectAndApplyModel is gated behind the verbose flag to prevent auto-mode notification noise. --- .../gsd/tests/auto-model-selection.test.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/resources/extensions/gsd/tests/auto-model-selection.test.ts b/src/resources/extensions/gsd/tests/auto-model-selection.test.ts index 4ea3245a3..9cec5afac 100644 --- a/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +++ b/src/resources/extensions/gsd/tests/auto-model-selection.test.ts @@ -1,8 +1,11 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; -import { join } from "node:path"; +import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; import { tmpdir } from "node:os"; +import { fileURLToPath } from "node:url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); import { resolvePreferredModelConfig, resolveModelId } from "../auto-model-selection.js"; @@ -196,6 +199,34 @@ test("resolveModelId: bare ID with claude-code as only provider still resolves", assert.equal(result.provider, "claude-code"); }); +// ─── selectAndApplyModel verbose-gating tests ────────────────────────── + +test("model change notify in selectAndApplyModel is gated behind verbose flag", () => { + // The Model [phase] [tier] notification should only fire when verbose=true. + // The dashboard header already shows the active model, so the notification + // is redundant noise during auto-mode (#3719). + const gsdDir = join(__dirname, ".."); + const src = readFileSync(join(gsdDir, "auto-model-selection.ts"), "utf-8"); + + // Find the block where setModel succeeds (appliedModel = model) and + // verify notify is inside an `if (verbose)` guard. + const setModelBlock = src.match( + /const ok = await pi\.setModel\(model[\s\S]*?appliedModel = model;([\s\S]*?)break;/, + ); + assert.ok(setModelBlock, "should find the setModel success block"); + + const blockBody = setModelBlock![1]; + // The notify call must be inside an if (verbose) block + assert.ok( + blockBody.includes("if (verbose)"), + "Model change ctx.ui.notify must be gated behind if (verbose) to avoid auto-mode notification noise", + ); + assert.ok( + blockBody.includes("ctx.ui.notify"), + "notify call should still exist (just verbose-gated)", + ); +}); + test("resolveModelId: anthropic wins over claude-code regardless of list order", () => { const availableModels = [ { id: "claude-sonnet-4-6", provider: "claude-code" },