Files
Agent-System-Backend/internal/hostapi/server_test.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

63 lines
1.8 KiB
Go

package hostapi
import (
"context"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/store"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/pkg/extension"
)
func TestHostClientRoundTrip(t *testing.T) {
st, err := store.OpenSQLite(filepath.Join(t.TempDir(), "h.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { st.Close() })
srv := &Server{Token: "sek", Store: st, Dispatch: func(ctx context.Context, pluginID, owner, commandID string, params map[string]any) error {
return nil
}}
ts := httptest.NewServer(srv.Handler())
t.Cleanup(ts.Close)
c := extension.NewHostClient(ts.URL, "sek", "rdm", "acme")
if err := c.PutKV(context.Background(), "slice", "s1"); err != nil {
t.Fatal(err)
}
got, err := c.GetKV(context.Background(), "slice")
if err != nil || got != "s1" {
t.Fatalf("kv %q %v", got, err)
}
if err := c.Audit(context.Background(), "ingest", "doc", []byte(`{"ok":true}`)); err != nil {
t.Fatal(err)
}
evs, err := st.ListAuditEvents("acme", 10)
if err != nil || len(evs) != 1 || evs[0].Action != "ingest" {
t.Fatalf("audit %+v %v", evs, err)
}
if err := c.Dispatch(context.Background(), "builtin.help", nil); err != nil {
t.Fatal(err)
}
bad := extension.NewHostClient(ts.URL, "nope", "rdm", "acme")
if err := bad.PutKV(context.Background(), "x", "y"); err == nil {
t.Fatal("bad token must fail")
}
}
func TestLLMUnconfigured(t *testing.T) {
st, err := store.OpenSQLite(filepath.Join(t.TempDir(), "h.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { st.Close() })
srv := &Server{Store: st}
req := httptest.NewRequest(http.MethodPost, "/host/v1/llm", nil)
rec := httptest.NewRecorder()
srv.Handler().ServeHTTP(rec, req)
if rec.Code != http.StatusServiceUnavailable {
t.Fatalf("status %d", rec.Code)
}
}