返回 DeepSeek-Reasonix
composer_profile_test.go
根目录 / internal / serve / composer_profile_test.go
1 package serve
2
3 import (
4 "errors"
5 "net/http"
6 "net/http/httptest"
7 "strings"
8 "testing"
9
10 "reasonix/internal/config"
11 "reasonix/internal/control"
12 "reasonix/internal/event"
13 )
14
15 type checkedAnswerAPI struct {
16 control.SessionAPI
17 err error
18 }
19
20 func (s *checkedAnswerAPI) AnswerQuestionChecked(string, []event.AskAnswer) error { return s.err }
21
22 func TestServeComposerProfileAndCheckedAnswer(t *testing.T) {
23 bc := NewBroadcaster()
24 ctrl := control.New(control.Options{Sink: bc})
25 api := &checkedAnswerAPI{SessionAPI: ctrl}
26 srv := httptest.NewServer(New(api, bc, config.ServeConfig{}).Handler())
27 defer srv.Close()
28 post := func(path, body string) int {
29 resp, err := http.Post(srv.URL+path, "application/json", strings.NewReader(body))
30 if err != nil {
31 t.Fatal(err)
32 }
33 defer resp.Body.Close()
34 return resp.StatusCode
35 }
36 if got := post("/composer-profile", `{"collaborationMode":"plan","toolApprovalMode":"danger-full-access","goal":""}`); got != http.StatusOK {
37 t.Fatalf("composer profile status = %d, want 200", got)
38 }
39 if !ctrl.PlanMode() || ctrl.ToolApprovalMode() != control.ToolApprovalDangerFullAccess || ctrl.Goal() != "" {
40 t.Fatalf("composer profile = plan:%v approval:%q goal:%q", ctrl.PlanMode(), ctrl.ToolApprovalMode(), ctrl.Goal())
41 }
42 api.err = errors.New("ledger unavailable")
43 if got := post("/answer", `{"id":"ask-1","answers":[]}`); got != http.StatusServiceUnavailable {
44 t.Fatalf("failed answer status = %d, want 503", got)
45 }
46 api.err = nil
47 if got := post("/answer", `{"id":"ask-1","answers":[]}`); got != http.StatusNoContent {
48 t.Fatalf("retried answer status = %d, want 204", got)
49 }
50 }
51
51 lines GO