Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for HTTP logging filename feature and remove DEBUG env var …
…usage

Co-authored-by: pelikhan <[email protected]>
  • Loading branch information
Copilot and pelikhan committed Jul 24, 2025
commit fca40f4c0a19589c73945feff2880ab9fc73f947
49 changes: 49 additions & 0 deletions cmd/run/http_log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the file as requested. Commit: d19f533


import (
"context"
"testing"

"github.com/github/gh-models/internal/azuremodels"
"github.com/github/gh-models/internal/sse"
"github.com/github/gh-models/pkg/command"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)

func TestHttpLogPassthrough(t *testing.T) {
// Test that the httpLog parameter is correctly passed through the call chain
var capturedHttpLog string

client := azuremodels.NewMockClient()
client.MockGetChatCompletionStream = func(ctx context.Context, opt azuremodels.ChatCompletionOptions, org, httpLogFile string) (*azuremodels.ChatCompletionResponse, error) {
capturedHttpLog = httpLogFile
reader := sse.NewMockEventReader([]azuremodels.ChatCompletion{})
return &azuremodels.ChatCompletionResponse{Reader: reader}, nil
}

cfg := command.NewConfig(nil, nil, client, false, 80)

// Create a command with the http-log flag
cmd := &cobra.Command{}
cmd.Flags().String("http-log", "", "Path to log HTTP requests to (optional)")
cmd.Flags().Set("http-log", "/tmp/test.log")

// Create handler
handler := newRunCommandHandler(cmd, cfg, []string{})

// Test that httpLog is set correctly
require.Equal(t, "/tmp/test.log", handler.httpLog)

// Test that it's passed to the client call
req := azuremodels.ChatCompletionOptions{
Model: "test-model",
Messages: []azuremodels.ChatMessage{
{Role: azuremodels.ChatMessageRoleUser, Content: &[]string{"test"}[0]},
},
}

_, err := handler.getChatCompletionStreamReader(req, "")
require.NoError(t, err)
require.Equal(t, "/tmp/test.log", capturedHttpLog)
}
36 changes: 36 additions & 0 deletions internal/azuremodels/debug_removal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package azuremodels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the file as requested. Commit: d19f533


import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

func TestHttpLoggingParameterReplacement(t *testing.T) {
// Test that the code no longer references os.Getenv("DEBUG")
// This is a simple test to ensure we removed the DEBUG dependency

// We'll do a simple code inspection test
// The GetChatCompletionStream method should now use httpLogFile parameter
// instead of checking os.Getenv("DEBUG")

// Create a mock client to test the interface
client := NewMockClient()

// Test that the interface accepts the httpLogFile parameter
var capturedHttpLogFile string
client.MockGetChatCompletionStream = func(ctx context.Context, req ChatCompletionOptions, org, httpLogFile string) (*ChatCompletionResponse, error) {
capturedHttpLogFile = httpLogFile
return &ChatCompletionResponse{}, nil
}

// Test with empty httpLogFile
_, _ = client.GetChatCompletionStream(nil, ChatCompletionOptions{}, "", "")
require.Equal(t, "", capturedHttpLogFile)

// Test with specific httpLogFile
testLogFile := "/tmp/test.log"
_, _ = client.GetChatCompletionStream(nil, ChatCompletionOptions{}, "", testLogFile)
require.Equal(t, testLogFile, capturedHttpLogFile)
}