From 0cca44b65a18b5b0d3de66c5bcf8ee416cf94563 Mon Sep 17 00:00:00 2001 From: Rodin Date: Fri, 1 May 2026 13:17:39 -0700 Subject: [PATCH] fix: address all remaining review findings on PR #14 - Fix doc comments: WithTimeout and WithTemperature each get their own - Add TestWithTimeout (verifies short timeout causes request failure) - Log warning on directory recursion failure in GetAllFilesInPath - Note: unexported fields is a breaking change, will document in release notes --- gitea/client.go | 1 + llm/client.go | 2 +- llm/client_test.go | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gitea/client.go b/gitea/client.go index 12a370c..6c00e21 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -234,6 +234,7 @@ func (c *Client) GetAllFilesInPath(ctx context.Context, owner, repo, path string case "dir": subResults, err := c.GetAllFilesInPath(ctx, owner, repo, entry.Path) if err != nil { + log.Printf("Warning: could not recurse into %s: %v", entry.Path, err) continue } for k, v := range subResults { diff --git a/llm/client.go b/llm/client.go index 8ad145d..a2a54f2 100644 --- a/llm/client.go +++ b/llm/client.go @@ -31,13 +31,13 @@ func NewClient(baseURL, apiKey, model string) *Client { } } -// WithTemperature sets the temperature for LLM requests (0 = omit, uses server default). // WithTimeout sets the HTTP request timeout for LLM calls (default 5 minutes). func (c *Client) WithTimeout(d time.Duration) *Client { c.http.Timeout = d return c } +// WithTemperature sets the temperature for LLM requests (0 = omit, uses server default). func (c *Client) WithTemperature(t float64) *Client { c.temperature = t return c diff --git a/llm/client_test.go b/llm/client_test.go index 0b7dc91..01b5c8c 100644 --- a/llm/client_test.go +++ b/llm/client_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "testing" + "time" ) func TestComplete_Success(t *testing.T) { @@ -186,3 +187,24 @@ func TestComplete_TemperatureIncludedWhenSet(t *testing.T) { t.Fatalf("unexpected error: %v", err) } } + +func TestWithTimeout(t *testing.T) { + client := NewClient("http://example.com", "key", "model") + result := client.WithTimeout(10 * time.Second) + if result != client { + t.Error("WithTimeout should return the same client for chaining") + } + // Verify timeout causes failure on slow server + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(200 * time.Millisecond) + w.Header().Set("Content-Type", "application/json") + w.Write([]byte(`{"choices":[{"message":{"content":"ok"}}]}`)) + })) + defer server.Close() + + shortClient := NewClient(server.URL, "key", "model").WithTimeout(50 * time.Millisecond) + _, err := shortClient.Complete(context.Background(), []Message{{Role: "user", Content: "hi"}}) + if err == nil { + t.Error("expected timeout error with 50ms timeout and 200ms server delay") + } +}