@@ -281,25 +281,34 @@ func TestPrepareCodexLaunchIncludesModelCatalog(t *testing.T) {
281281 t .Fatalf ("prepareCodexLaunch returned error: %v" , err )
282282 }
283283
284+ if len (prepared .Args ) != 2 || prepared .Args [0 ] != "--model" || prepared .Args [1 ] != "Qwen/Qwen3.5-2B" {
285+ t .Fatalf ("prepared args = %#v, want only --model override" , prepared .Args )
286+ }
287+ data , err := os .ReadFile (filepath .Join (home , ".codex" , "config.toml" ))
288+ if err != nil {
289+ t .Fatalf ("read codex config: %v" , err )
290+ }
291+ configText := string (data )
284292 for _ , want := range []string {
285- `model_provider="csghub_lite"` ,
286- `model_providers.csghub_lite.name="OpenCSG"` ,
287- `model_providers.csghub_lite.base_url=` + strconv .Quote (server .URL + "/v1" ),
288- `model_providers.csghub_lite.supports_websockets=false` ,
293+ `model_provider = "csghub_lite"` ,
294+ `[model_providers.csghub_lite]` ,
295+ `name = "OpenCSG"` ,
296+ `base_url = ` + strconv .Quote (server .URL + "/v1" ),
297+ `supports_websockets = false` ,
289298 } {
290- if ! hasConfigOverride ( prepared . Args , want ) {
291- t .Fatalf ("missing Codex config override %q in args %#v " , want , prepared . Args )
299+ if ! strings . Contains ( configText , want ) {
300+ t .Fatalf ("codex config missing %q: \n %s " , want , configText )
292301 }
293302 }
294- catalogValue := configValue ( prepared . Args , "model_catalog_json= " )
303+ catalogValue := configValueFromConfig ( configText , "model_catalog_json" )
295304 if catalogValue == "" {
296- t .Fatalf ("missing model_catalog_json config in args %#v " , prepared . Args )
305+ t .Fatalf ("missing model_catalog_json config: \n %s " , configText )
297306 }
298307 catalogPath , err := strconv .Unquote (catalogValue )
299308 if err != nil {
300309 t .Fatalf ("unquote model_catalog_json %q: %v" , catalogValue , err )
301310 }
302- data , err : = os .ReadFile (catalogPath )
311+ data , err = os .ReadFile (catalogPath )
303312 if err != nil {
304313 t .Fatalf ("read model catalog: %v" , err )
305314 }
@@ -319,10 +328,10 @@ func TestPrepareCodexLaunchIncludesModelCatalog(t *testing.T) {
319328 if len (payload .Models ) != 2 {
320329 t .Fatalf ("model catalog count = %d, want 2" , len (payload .Models ))
321330 }
322- if payload .Models [0 ].Slug != "Qwen/Qwen3.5-2B" || payload . Models [ 0 ]. DisplayName != "Qwen 3.5 2B" {
331+ if payload .Models [0 ].Slug != "Qwen/Qwen3.5-2B" {
323332 t .Fatalf ("unexpected first model entry: %#v" , payload .Models [0 ])
324333 }
325- if payload .Models [1 ].Slug != "afrideva/Qwen2-0.5B-Instruct-GGUF:fh23aijhzx8g" || payload . Models [ 1 ]. DisplayName != "Qwen2-0.5B-Instruct-GGUF" {
334+ if payload .Models [1 ].Slug != "afrideva/Qwen2-0.5B-Instruct-GGUF:fh23aijhzx8g" {
326335 t .Fatalf ("unexpected second model entry: %#v" , payload .Models [1 ])
327336 }
328337 if payload .Models [0 ].Visibility != "list" || payload .Models [1 ].Visibility != "list" {
@@ -772,6 +781,21 @@ func configValue(args []string, prefix string) string {
772781 return ""
773782}
774783
784+ func configValueFromConfig (configText , key string ) string {
785+ for _ , line := range strings .Split (configText , "\n " ) {
786+ line = strings .TrimSpace (line )
787+ if line == "" || strings .HasPrefix (line , "#" ) {
788+ continue
789+ }
790+ before , after , ok := strings .Cut (line , "=" )
791+ if ! ok || strings .TrimSpace (before ) != key {
792+ continue
793+ }
794+ return strings .TrimSpace (after )
795+ }
796+ return ""
797+ }
798+
775799func argValue (args []string , flag string ) string {
776800 for i := 0 ; i + 1 < len (args ); i ++ {
777801 if args [i ] == flag {
0 commit comments