@@ -9,10 +9,13 @@ import * as Timeout from "../../../src/util/timeout"
99import * as Network from "../../../src/cli/network"
1010import * as Win32 from "../../../src/cli/cmd/tui/win32"
1111import { TuiConfig } from "../../../src/cli/cmd/tui/config/tui"
12+ import { Provider } from "../../../src/provider"
1213
1314const stop = new Error ( "stop" )
1415const seen = {
1516 tui : [ ] as string [ ] ,
17+ model : [ ] as ( string | undefined ) [ ] ,
18+ variant : [ ] as ( string | undefined ) [ ] ,
1619}
1720
1821function setup ( ) {
@@ -23,6 +26,8 @@ function setup() {
2326 // https://github.com/oven-sh/bun/issues/7823 and #12823.
2427 spyOn ( App , "tui" ) . mockImplementation ( async ( input ) => {
2528 if ( input . directory ) seen . tui . push ( input . directory )
29+ seen . model . push ( input . args . model )
30+ seen . variant . push ( input . args . variant )
2631 throw stop
2732 } )
2833 spyOn ( Rpc , "client" ) . mockImplementation ( ( ) => ( {
@@ -40,21 +45,26 @@ function setup() {
4045 } )
4146 spyOn ( Win32 , "win32DisableProcessedInput" ) . mockImplementation ( ( ) => { } )
4247 spyOn ( Win32 , "win32InstallCtrlCGuard" ) . mockReturnValue ( undefined )
48+ spyOn ( Provider , "resolveSelection" ) . mockImplementation ( async ( model , variant ) => ( {
49+ model : model === "free" ? "opencode/freebie" : model ,
50+ variant : variant === "any" ? "high" : variant ,
51+ } ) )
4352}
4453
4554describe ( "tui thread" , ( ) => {
4655 afterEach ( ( ) => {
4756 mock . restore ( )
4857 } )
4958
50- async function call ( project ?: string ) {
59+ async function call ( project ?: string , model ?: string , variant ?: string ) {
5160 const { TuiThreadCommand } = await import ( "../../../src/cli/cmd/tui/thread" )
5261 const args : Parameters < NonNullable < typeof TuiThreadCommand . handler > > [ 0 ] = {
5362 _ : [ ] ,
5463 $0 : "opencode" ,
5564 project,
5665 prompt : "hi" ,
57- model : undefined ,
66+ model,
67+ variant,
5868 agent : undefined ,
5969 session : undefined ,
6070 continue : false ,
@@ -69,7 +79,12 @@ describe("tui thread", () => {
6979 return TuiThreadCommand . handler ( args )
7080 }
7181
72- async function check ( project ?: string ) {
82+ async function check (
83+ project ?: string ,
84+ model ?: string ,
85+ variant ?: string ,
86+ expected ?: { model ?: string ; variant ?: string } ,
87+ ) {
7388 setup ( )
7489 await using tmp = await tmpdir ( { git : true } )
7590 const cwd = process . cwd ( )
@@ -79,6 +94,8 @@ describe("tui thread", () => {
7994 const link = path . join ( path . dirname ( tmp . path ) , path . basename ( tmp . path ) + "-link" )
8095 const type = process . platform === "win32" ? "junction" : "dir"
8196 seen . tui . length = 0
97+ seen . model . length = 0
98+ seen . variant . length = 0
8299 await fs . symlink ( tmp . path , link , type )
83100
84101 Object . defineProperty ( process . stdin , "isTTY" , {
@@ -96,8 +113,10 @@ describe("tui thread", () => {
96113 try {
97114 process . chdir ( tmp . path )
98115 process . env . PWD = link
99- await expect ( call ( project ) ) . rejects . toBe ( stop )
116+ await expect ( call ( project , model , variant ) ) . rejects . toBe ( stop )
100117 expect ( seen . tui [ 0 ] ) . toBe ( tmp . path )
118+ if ( expected ?. model ) expect ( seen . model [ 0 ] ) . toBe ( expected . model )
119+ if ( expected ?. variant ) expect ( seen . variant [ 0 ] ) . toBe ( expected . variant )
101120 } finally {
102121 process . chdir ( cwd )
103122 if ( pwd === undefined ) delete process . env . PWD
@@ -116,4 +135,12 @@ describe("tui thread", () => {
116135 test ( "uses the real cwd after resolving a relative project from PWD" , async ( ) => {
117136 await check ( "." )
118137 } )
138+
139+ test ( "resolves the free model alias before launching the tui" , async ( ) => {
140+ await check ( undefined , "free" , undefined , { model : "opencode/freebie" } )
141+ } )
142+
143+ test ( "passes the resolved any variant before launching the tui" , async ( ) => {
144+ await check ( undefined , "free" , "any" , { model : "opencode/freebie" , variant : "high" } )
145+ } )
119146} )
0 commit comments