summaryrefslogtreecommitdiff
path: root/internal/hexaicli/run_timeout_test.go
blob: 7275ddb653f29b0378629d536363d13b30817fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package hexaicli

import (
	"bytes"
	"context"
	"strings"
	"testing"

	"codeberg.org/snonux/hexai/internal/appconfig"
	"codeberg.org/snonux/hexai/internal/llm"
)

func TestRun_DefaultRequestTimeoutIsTenMinutes(t *testing.T) {
	t.Chdir(t.TempDir())
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	t.Setenv("XDG_CACHE_HOME", t.TempDir())
	t.Setenv("HEXAI_REQUEST_TIMEOUT", "")

	seenTimeout := 0
	clientFactory := func(cfg appconfig.App) (llm.Client, error) {
		seenTimeout = cfg.RequestTimeout
		return okClient{}, nil
	}

	var out, errb bytes.Buffer
	ctx := withCLIClientFactory(context.Background(), clientFactory)
	if err := Run(ctx, []string{"hello"}, strings.NewReader(""), &out, &errb); err != nil {
		t.Fatalf("Run: %v", err)
	}
	if seenTimeout != 600 {
		t.Fatalf("RequestTimeout = %d, want 600", seenTimeout)
	}
	if !strings.Contains(out.String(), "OK") {
		t.Fatalf("expected output from fake client, got %q", out.String())
	}
}