more opencode fixes
This commit is contained in:
+24
-1
@@ -1147,11 +1147,13 @@ func TestCol(t *testing.T) {
|
||||
// ---------- llm / AL / summarize / compact via httptest (no real network) ----------
|
||||
|
||||
func TestLLMNonStreamingAndHeaders(t *testing.T) {
|
||||
var gotPath, gotAuth, gotUA string
|
||||
var gotPath, gotAuth, gotUA, gotOCClient, gotOCSession string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotPath = r.URL.Path
|
||||
gotAuth = r.Header.Get("Authorization")
|
||||
gotUA = r.Header.Get("User-Agent")
|
||||
gotOCClient = r.Header.Get("x-opencode-client")
|
||||
gotOCSession = r.Header.Get("x-opencode-session")
|
||||
w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":"hi","reasoning_content":"think"}}]}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
@@ -1173,11 +1175,32 @@ func TestLLMNonStreamingAndHeaders(t *testing.T) {
|
||||
if !strings.Contains(gotUA, "opencode/1.18.31") {
|
||||
t.Errorf("user-agent = %q", gotUA)
|
||||
}
|
||||
if gotOCClient != "cli" {
|
||||
t.Errorf("x-opencode-client = %q, want cli", gotOCClient)
|
||||
}
|
||||
if gotOCSession != opencodeSessionID() {
|
||||
t.Errorf("x-opencode-session = %q, want %q", gotOCSession, opencodeSessionID())
|
||||
}
|
||||
if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {
|
||||
t.Errorf("message = %+v", m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpencodeSessionID(t *testing.T) {
|
||||
sid := opencodeSessionID()
|
||||
if !strings.HasPrefix(sid, "ses_") {
|
||||
t.Fatalf("session id does not start with ses_: %q", sid)
|
||||
}
|
||||
if len(sid) != 30 {
|
||||
t.Fatalf("session id length = %d, want 30: %q", len(sid), sid)
|
||||
}
|
||||
for _, c := range sid[4:] {
|
||||
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
||||
t.Fatalf("invalid character %c in session id %q", c, sid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLLMNoAuthHeaderWhenNoKey(t *testing.T) {
|
||||
var gotAuth string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user