@@ -10,11 +10,14 @@ import * as Network from "../../../src/cli/network"
1010import * as Win32 from "../../../src/cli/cmd/tui/win32"
1111import { TuiConfig } from "../../../src/config/tui"
1212import { Instance } from "../../../src/project/instance"
13+ import { Provider } from "../../../src/provider/provider"
1314
1415const stop = new Error ( "stop" )
1516const seen = {
1617 tui : [ ] as string [ ] ,
1718 inst : [ ] as string [ ] ,
19+ model : [ ] as ( string | undefined ) [ ] ,
20+ variant : [ ] as ( string | undefined ) [ ] ,
1821}
1922
2023function setup ( ) {
@@ -25,6 +28,8 @@ function setup() {
2528 // https://github.com/oven-sh/bun/issues/7823 and #12823.
2629 spyOn ( App , "tui" ) . mockImplementation ( async ( input ) => {
2730 if ( input . directory ) seen . tui . push ( input . directory )
31+ seen . model . push ( input . args . model )
32+ seen . variant . push ( input . args . variant )
2833 throw stop
2934 } )
3035 spyOn ( Rpc , "client" ) . mockImplementation ( ( ) => ( {
@@ -47,21 +52,26 @@ function setup() {
4752 seen . inst . push ( input . directory )
4853 return input . fn ( )
4954 } )
55+ spyOn ( Provider , "resolveSelection" ) . mockImplementation ( async ( model , variant ) => ( {
56+ model : model === "free" ? "opencode/freebie" : model ,
57+ variant : variant === "any" ? "high" : variant ,
58+ } ) )
5059}
5160
5261describe ( "tui thread" , ( ) => {
5362 afterEach ( ( ) => {
5463 mock . restore ( )
5564 } )
5665
57- async function call ( project ?: string ) {
66+ async function call ( project ?: string , model ?: string , variant ?: string ) {
5867 const { TuiThreadCommand } = await import ( "../../../src/cli/cmd/tui/thread" )
5968 const args : Parameters < NonNullable < typeof TuiThreadCommand . handler > > [ 0 ] = {
6069 _ : [ ] ,
6170 $0 : "opencode" ,
6271 project,
6372 prompt : "hi" ,
64- model : undefined ,
73+ model,
74+ variant,
6575 agent : undefined ,
6676 session : undefined ,
6777 continue : false ,
@@ -76,7 +86,12 @@ describe("tui thread", () => {
7686 return TuiThreadCommand . handler ( args )
7787 }
7888
79- async function check ( project ?: string ) {
89+ async function check (
90+ project ?: string ,
91+ model ?: string ,
92+ variant ?: string ,
93+ expected ?: { model ?: string ; variant ?: string } ,
94+ ) {
8095 setup ( )
8196 await using tmp = await tmpdir ( { git : true } )
8297 const cwd = process . cwd ( )
@@ -87,6 +102,8 @@ describe("tui thread", () => {
87102 const type = process . platform === "win32" ? "junction" : "dir"
88103 seen . tui . length = 0
89104 seen . inst . length = 0
105+ seen . model . length = 0
106+ seen . variant . length = 0
90107 await fs . symlink ( tmp . path , link , type )
91108
92109 Object . defineProperty ( process . stdin , "isTTY" , {
@@ -104,9 +121,11 @@ describe("tui thread", () => {
104121 try {
105122 process . chdir ( tmp . path )
106123 process . env . PWD = link
107- await expect ( call ( project ) ) . rejects . toBe ( stop )
124+ await expect ( call ( project , model , variant ) ) . rejects . toBe ( stop )
108125 expect ( seen . inst [ 0 ] ) . toBe ( tmp . path )
109126 expect ( seen . tui [ 0 ] ) . toBe ( tmp . path )
127+ if ( expected ?. model ) expect ( seen . model [ 0 ] ) . toBe ( expected . model )
128+ if ( expected ?. variant ) expect ( seen . variant [ 0 ] ) . toBe ( expected . variant )
110129 } finally {
111130 process . chdir ( cwd )
112131 if ( pwd === undefined ) delete process . env . PWD
@@ -125,4 +144,12 @@ describe("tui thread", () => {
125144 test ( "uses the real cwd after resolving a relative project from PWD" , async ( ) => {
126145 await check ( "." )
127146 } )
147+
148+ test ( "resolves the free model alias before launching the tui" , async ( ) => {
149+ await check ( undefined , "free" , undefined , { model : "opencode/freebie" } )
150+ } )
151+
152+ test ( "passes the resolved any variant before launching the tui" , async ( ) => {
153+ await check ( undefined , "free" , "any" , { model : "opencode/freebie" , variant : "high" } )
154+ } )
128155} )
0 commit comments