Skip to content

Commit 1c1061c

Browse files
committed
account for if tailLines exceeds window size
1 parent c6f5f7f commit 1c1061c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

pkg/github/actions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,12 @@ func downloadLogContent(logURL string, tailLines int) (string, int, *http.Respon
758758
tailLines = 1000
759759
}
760760

761-
processedInput, totalLines, httpResp, err := buffer.ProcessAsRingBufferToEnd(httpResp, maxJobLogLines)
761+
bufferSize := tailLines
762+
if bufferSize > maxJobLogLines {
763+
bufferSize = maxJobLogLines
764+
}
765+
766+
processedInput, totalLines, httpResp, err := buffer.ProcessAsRingBufferToEnd(httpResp, bufferSize)
762767
if err != nil {
763768
return "", 0, httpResp, fmt.Errorf("failed to process log content: %w", err)
764769
}

pkg/github/actions_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,3 +1167,50 @@ func Test_GetJobLogs_WithContentReturnAndTailLines(t *testing.T) {
11671167
assert.Equal(t, "Job logs content retrieved successfully", response["message"])
11681168
assert.NotContains(t, response, "logs_url") // Should not have URL when returning content
11691169
}
1170+
1171+
func Test_GetJobLogs_WithContentReturnAndLargeTailLines(t *testing.T) {
1172+
logContent := "Line 1\nLine 2\nLine 3"
1173+
expectedLogContent := "Line 1\nLine 2\nLine 3"
1174+
1175+
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
1176+
w.WriteHeader(http.StatusOK)
1177+
_, _ = w.Write([]byte(logContent))
1178+
}))
1179+
defer testServer.Close()
1180+
1181+
mockedClient := mock.NewMockedHTTPClient(
1182+
mock.WithRequestMatchHandler(
1183+
mock.GetReposActionsJobsLogsByOwnerByRepoByJobId,
1184+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
1185+
w.Header().Set("Location", testServer.URL)
1186+
w.WriteHeader(http.StatusFound)
1187+
}),
1188+
),
1189+
)
1190+
1191+
client := github.NewClient(mockedClient)
1192+
_, handler := GetJobLogs(stubGetClientFn(client), translations.NullTranslationHelper)
1193+
1194+
request := createMCPRequest(map[string]any{
1195+
"owner": "owner",
1196+
"repo": "repo",
1197+
"job_id": float64(123),
1198+
"return_content": true,
1199+
"tail_lines": float64(100),
1200+
})
1201+
1202+
result, err := handler(context.Background(), request)
1203+
require.NoError(t, err)
1204+
require.False(t, result.IsError)
1205+
1206+
textContent := getTextResult(t, result)
1207+
var response map[string]any
1208+
err = json.Unmarshal([]byte(textContent.Text), &response)
1209+
require.NoError(t, err)
1210+
1211+
assert.Equal(t, float64(123), response["job_id"])
1212+
assert.Equal(t, float64(3), response["original_length"])
1213+
assert.Equal(t, expectedLogContent, response["logs_content"])
1214+
assert.Equal(t, "Job logs content retrieved successfully", response["message"])
1215+
assert.NotContains(t, response, "logs_url")
1216+
}

0 commit comments

Comments
 (0)