repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

1.0 KB · 39 lines · Go Raw History
 1package main
 2
 3import (
 4	"context"
 5	"fmt"
 6	"net/http"
 7	"net/http/httptest"
 8	"testing"
 9)
10
11// The gateway keeps every prompt it forwards, so an incognito turn that writes
12// nothing here would still be readable there without this header.
13func TestAnIncognitoTurnAsksTheGatewayNotToLog(t *testing.T) {
14	var seen string
15	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16		seen = r.Header.Get(incognitoHeader)
17		w.Header().Set("Content-Type", "application/json")
18		fmt.Fprint(w, `{"choices":[{"message":{"content":"hi"}}]}`)
19	}))
20	defer srv.Close()
21
22	l := NewLLM(srv.URL, "local", "key")
23	var out chatResp
24	if err := l.post(WithIncognito(context.Background()), chatReq{Model: "local"}, &out); err != nil {
25		t.Fatalf("post: %v", err)
26	}
27	if seen != "1" {
28		t.Errorf("incognito header = %q, want 1", seen)
29	}
30
31	seen = ""
32	if err := l.post(context.Background(), chatReq{Model: "local"}, &out); err != nil {
33		t.Fatalf("post: %v", err)
34	}
35	if seen != "" {
36		t.Errorf("an ordinary turn sent the incognito header = %q", seen)
37	}
38}