TestCodexModelFlagPositionAfterExec verifies that the --model flag appears after the exec subcommand in the generated Codex command, not before it. Regression test for: Codex lock compiler places --model flag before exec subcommand.
(t *testing.T)
| 477 | // subcommand in the generated Codex command, not before it. |
| 478 | // Regression test for: Codex lock compiler places --model flag before exec subcommand. |
| 479 | func TestCodexModelFlagPositionAfterExec(t *testing.T) { |
| 480 | workflowData := &WorkflowData{ |
| 481 | Name: "test-codex-model-position", |
| 482 | AI: "codex", |
| 483 | Tools: map[string]any{ |
| 484 | "bash": []any{"echo"}, |
| 485 | }, |
| 486 | SafeOutputs: &SafeOutputsConfig{}, |
| 487 | } |
| 488 | |
| 489 | engine, err := GetGlobalEngineRegistry().GetEngine("codex") |
| 490 | if err != nil { |
| 491 | t.Fatalf("Failed to get engine: %v", err) |
| 492 | } |
| 493 | |
| 494 | steps := engine.GetExecutionSteps(workflowData, "/tmp/test.log") |
| 495 | |
| 496 | var stepsStr strings.Builder |
| 497 | for _, step := range steps { |
| 498 | for _, line := range step { |
| 499 | stepsStr.WriteString(line) |
| 500 | stepsStr.WriteString("\n") |
| 501 | } |
| 502 | } |
| 503 | stepsContent := stepsStr.String() |
| 504 | |
| 505 | // Find the model shell expansion pattern in the generated command |
| 506 | modelPattern := "${" + constants.EnvVarModelAgentCodex + ":+" |
| 507 | beforeModel, _, found := strings.Cut(stepsContent, modelPattern) |
| 508 | if !found { |
| 509 | t.Fatalf("Model expansion pattern '%s' not found in steps:\n%s", modelPattern, stepsContent) |
| 510 | } |
| 511 | |
| 512 | // Find "codex exec" before the model pattern. Using "codex exec" (not just "exec") avoids |
| 513 | // false positives from unrelated occurrences like "GH_AW_NODE_EXEC" in the step content. |
| 514 | execMarker := "codex exec" |
| 515 | execIdx := strings.LastIndex(beforeModel, execMarker) |
| 516 | if execIdx == -1 { |
| 517 | t.Errorf("'codex exec' must appear before the model flag '%s' in the generated command.\n"+ |
| 518 | "This indicates the model flag is placed before 'exec', causing Codex to ignore it.\n"+ |
| 519 | "Got:\n%s", modelPattern, stepsContent) |
| 520 | } |
| 521 | } |
nothing calls this directly
no test coverage detected