@@ -388,6 +388,97 @@ func TestBuildAWFConfigJSON(t *testing.T) {
388388 assert .Contains (t , jsonStr , "my-proxy.internal.example.com" , "should include the openai host" )
389389 })
390390
391+ t .Run ("HTTP API target schemes follow the effective AWF version" , func (t * testing.T ) {
392+ tests := []struct {
393+ name string
394+ engine string
395+ envVar string
396+ baseURL string
397+ version string
398+ provider string
399+ expectedHost string
400+ }{
401+ {
402+ name : "openai preserves HTTP with the default AWF version" ,
403+ engine : "codex" ,
404+ envVar : "OPENAI_BASE_URL" ,
405+ baseURL : "http://openai-gateway.example.com/v1" ,
406+ provider : "openai" ,
407+ expectedHost : "http://openai-gateway.example.com" ,
408+ },
409+ {
410+ name : "anthropic preserves HTTP at the minimum AWF version" ,
411+ engine : "claude" ,
412+ envVar : "ANTHROPIC_BASE_URL" ,
413+ baseURL : "http://anthropic-gateway.example.com/v1" ,
414+ version : string (constants .AWFHTTPAPITargetMinVersion ),
415+ provider : "anthropic" ,
416+ expectedHost : "http://anthropic-gateway.example.com" ,
417+ },
418+ {
419+ name : "gemini preserves HTTP with a newer AWF version" ,
420+ engine : "gemini" ,
421+ envVar : "GEMINI_API_BASE_URL" ,
422+ baseURL : "http://gemini-gateway.example.com/v1" ,
423+ version : "v0.28.14" ,
424+ provider : "gemini" ,
425+ expectedHost : "http://gemini-gateway.example.com" ,
426+ },
427+ {
428+ name : "older AWF versions keep HTTP targets bare" ,
429+ engine : "codex" ,
430+ envVar : "OPENAI_BASE_URL" ,
431+ baseURL : "http://legacy-gateway.example.com/v1" ,
432+ version : "v0.28.12" ,
433+ provider : "openai" ,
434+ expectedHost : "legacy-gateway.example.com" ,
435+ },
436+ {
437+ name : "HTTPS targets remain bare" ,
438+ engine : "claude" ,
439+ envVar : "ANTHROPIC_BASE_URL" ,
440+ baseURL : "https://secure-gateway.example.com/v1" ,
441+ provider : "anthropic" ,
442+ expectedHost : "secure-gateway.example.com" ,
443+ },
444+ {
445+ name : "bare targets remain bare" ,
446+ engine : "gemini" ,
447+ envVar : "GEMINI_API_BASE_URL" ,
448+ baseURL : "bare-gateway.example.com/v1" ,
449+ provider : "gemini" ,
450+ expectedHost : "bare-gateway.example.com" ,
451+ },
452+ }
453+
454+ for _ , tt := range tests {
455+ t .Run (tt .name , func (t * testing.T ) {
456+ config := AWFCommandConfig {
457+ EngineName : tt .engine ,
458+ AllowedDomains : "github.com" ,
459+ WorkflowData : & WorkflowData {
460+ EngineConfig : & EngineConfig {
461+ ID : tt .engine ,
462+ Env : map [string ]string {tt .envVar : tt .baseURL },
463+ },
464+ NetworkPermissions : & NetworkPermissions {
465+ Firewall : & FirewallConfig {Enabled : true , Version : tt .version },
466+ },
467+ },
468+ }
469+
470+ jsonStr , err := BuildAWFConfigJSON (config )
471+ require .NoError (t , err )
472+
473+ var parsed AWFConfigFile
474+ require .NoError (t , json .Unmarshal ([]byte (jsonStr ), & parsed ))
475+ require .NotNil (t , parsed .APIProxy )
476+ require .Contains (t , parsed .APIProxy .Targets , tt .provider )
477+ assert .Equal (t , tt .expectedHost , parsed .APIProxy .Targets [tt .provider ].Host )
478+ })
479+ }
480+ })
481+
391482 t .Run ("default max-ai-credits is enabled when frontmatter is unset" , func (t * testing.T ) {
392483 config := AWFCommandConfig {
393484 EngineName : "copilot" ,
0 commit comments