@@ -3,6 +3,7 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
33import { tmpdir } from "node:os" ;
44import { join } from "node:path" ;
55import test from "node:test" ;
6+ import { DEFAULT_AI_MODELS } from "../src/ai/groq.js" ;
67import type {
78 AiClient ,
89 AiCompletionRequest ,
@@ -124,6 +125,56 @@ test("analyze warns and continues when package.json is malformed", async () => {
124125 }
125126} ) ;
126127
128+ test ( "analyze auto routing uses 20B normally and 120B for deep analysis" , async ( ) => {
129+ const projectRoot = await mkdtemp ( join ( tmpdir ( ) , "devmap-model-routing-" ) ) ;
130+ const requests : AiCompletionRequest [ ] = [ ] ;
131+ const client : AiClient = {
132+ async complete ( request ) : Promise < AiCompletionResult > {
133+ requests . push ( request ) ;
134+ return {
135+ content : "Architecture result." ,
136+ model : request . model
137+ } ;
138+ }
139+ } ;
140+
141+ try {
142+ await writeFile (
143+ join ( projectRoot , "package.json" ) ,
144+ JSON . stringify ( { name : "model-routing-fixture" } ) ,
145+ "utf8"
146+ ) ;
147+ await writeFile ( join ( projectRoot , "index.ts" ) , "export const ready = true;\n" , "utf8" ) ;
148+
149+ const dependencies = {
150+ loadConfig : async ( ) => ( {
151+ provider : "groq" as const ,
152+ apiKey : "gsk_fixture" ,
153+ model : "auto"
154+ } ) ,
155+ createAiClient : ( ) => client
156+ } ;
157+
158+ await captureOutput ( ( ) => analyzeCommand (
159+ projectRoot ,
160+ { fresh : true } ,
161+ dependencies
162+ ) ) ;
163+ await captureOutput ( ( ) => analyzeCommand (
164+ projectRoot ,
165+ { deep : true , fresh : true } ,
166+ dependencies
167+ ) ) ;
168+
169+ assert . equal ( requests [ 0 ] ?. model , DEFAULT_AI_MODELS . analyze ) ;
170+ assert . equal ( requests [ 1 ] ?. model , DEFAULT_AI_MODELS . deepAnalyze ) ;
171+ assert . equal ( requests [ 0 ] ?. fallbackModel , DEFAULT_AI_MODELS . fallback ) ;
172+ assert . equal ( requests [ 1 ] ?. fallbackModel , DEFAULT_AI_MODELS . fallback ) ;
173+ } finally {
174+ await rm ( projectRoot , { recursive : true , force : true } ) ;
175+ }
176+ } ) ;
177+
127178function stripAnsi ( value : string ) : string {
128179 return value . replace ( / \u001B \[ [ 0 - 9 ; ] * m / g, "" ) ;
129180}
0 commit comments