-
Notifications
You must be signed in to change notification settings - Fork 18
Add --http-log CLI flag to replace DEBUG environment variable for HTTP request logging #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelikhan
merged 7 commits into
pelikhan/promptpex
from
copilot/fix-0d68a403-cf43-4d99-9fbb-14250f0675fc
Jul 24, 2025
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6f4173
Initial plan
Copilot 59fad69
Update interface and all calls to support HTTP logging filename param…
Copilot fca40f4
Add tests for HTTP logging filename feature and remove DEBUG env var …
Copilot a46680e
Refactor HTTP log to use Context instead of function parameters
Copilot 3cdc67e
Group HTTP log writes into single fprintf call for better performance
Copilot d19f533
Remove test files as requested
Copilot 7903afa
Update internal/azuremodels/azure_client.go
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add tests for HTTP logging filename feature and remove DEBUG env var …
…usage Co-authored-by: pelikhan <[email protected]>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package run | ||
|
|
||
| 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package azuremodels | ||
|
||
|
|
||
| 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) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file
There was a problem hiding this comment.
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