diff --git a/src/resources/extensions/gsd/auto-model-selection.ts b/src/resources/extensions/gsd/auto-model-selection.ts index ad26edca8..e1ef81e3a 100644 --- a/src/resources/extensions/gsd/auto-model-selection.ts +++ b/src/resources/extensions/gsd/auto-model-selection.ts @@ -246,11 +246,13 @@ export async function selectAndApplyModel( const ok = await pi.setModel(model, { persist: false }); if (ok) { appliedModel = model; - const fallbackNote = modelId === effectiveModelConfig.primary - ? "" - : ` (fallback from ${effectiveModelConfig.primary})`; - const phase = unitPhaseLabel(unitType); - ctx.ui.notify(`Model [${phase}]${routingTierLabel}: ${model.provider}/${model.id}${fallbackNote}`, "info"); + if (verbose) { + const fallbackNote = modelId === effectiveModelConfig.primary + ? "" + : ` (fallback from ${effectiveModelConfig.primary})`; + const phase = unitPhaseLabel(unitType); + ctx.ui.notify(`Model [${phase}]${routingTierLabel}: ${model.provider}/${model.id}${fallbackNote}`, "info"); + } break; } else { const nextModel = modelsToTry[modelsToTry.indexOf(modelId) + 1]; 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" },