Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 16 additions & 18 deletions internal/logger/jsonl_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/githubnext/gh-aw-mcpg/internal/logger/sanitize"
Expand Down Expand Up @@ -150,7 +149,7 @@ func TestSanitizePayload(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
assert := assert.New(t)

result := sanitize.SanitizeJSON([]byte(tt.input))
require.NotNil(result, "sanitize.SanitizeJSON returned nil")

Expand Down Expand Up @@ -342,7 +341,7 @@ func TestMultipleMessagesInJSONL(t *testing.T) {
func TestSanitizePayloadCompactsJSON(t *testing.T) {
require := require.New(t)
assert := assert.New(t)

// Test that multi-line JSON is compacted to a single line
multilineJSON := `{
"jsonrpc": "2.0",
Expand Down Expand Up @@ -372,7 +371,7 @@ func TestSanitizePayloadCompactsJSON(t *testing.T) {

func TestInitJSONLLoggerWithInvalidPath(t *testing.T) {
assert := assert.New(t)

// Test initialization with an invalid directory path (permission denied scenario)
// Using /proc/self as it's read-only and will fail to create subdirectories
err := InitJSONLLogger("/proc/self/invalid", "test.jsonl")
Expand All @@ -381,7 +380,6 @@ func TestInitJSONLLoggerWithInvalidPath(t *testing.T) {

func TestLogRPCMessageJSONLDirectionTypes(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
tmpDir := t.TempDir()
logDir := filepath.Join(tmpDir, "logs")

Expand Down Expand Up @@ -423,32 +421,32 @@ func TestLogRPCMessageJSONLDirectionTypes(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
testPayload := []byte(`{"jsonrpc":"2.0","id":1}`)

// Clear previous log file
logPath := filepath.Join(logDir, "test.jsonl")
os.Remove(logPath)


// Re-init logger for each subtest
CloseJSONLLogger()
err := InitJSONLLogger(logDir, "test.jsonl")
require.NoError(err, "Re-init failed")

LogRPCMessageJSONL(tt.direction, tt.msgType, "test-server", "test-method", testPayload, nil)
CloseJSONLLogger()

// Re-init for next iteration
if t.Name() != tests[len(tests)-1].name {
InitJSONLLogger(logDir, "test.jsonl")
}


// Read and verify
content, err := os.ReadFile(logPath)
if err != nil {
return // File might not exist yet
}

var entry JSONLRPCMessage
json.Unmarshal(content, &entry)
assert.Equal(tt.expected["direction"], entry.Direction, "Direction should match")
assert.Equal(tt.expected["type"], entry.Type, "Type should match")

a.Equal(tt.expected["direction"], entry.Direction, "Direction should match")
a.Equal(tt.expected["type"], entry.Type, "Type should match")
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func authMiddleware(apiKey string, next http.HandlerFunc) http.HandlerFunc {
logAuth.Printf("Initialized auth middleware")
return func(w http.ResponseWriter, r *http.Request) {
logAuth.Printf("Authenticating request: method=%s, path=%s, remote=%s", r.Method, r.URL.Path, r.RemoteAddr)

// Extract Authorization header
authHeader := r.Header.Get("Authorization")

Expand Down Expand Up @@ -52,7 +52,7 @@ func authMiddleware(apiKey string, next http.HandlerFunc) http.HandlerFunc {
// logRuntimeError logs runtime errors to stdout per spec section 9.2
func logRuntimeError(errorType, detail string, r *http.Request, serverName *string) {
logAuth.Printf("Logging runtime error: type=%s, detail=%s", errorType, detail)

timestamp := time.Now().UTC().Format(time.RFC3339)
requestID := r.Header.Get("X-Request-ID")
if requestID == "" {
Expand Down