Files
Assistant/cmd/cognitive-worker/advisory_test.go
T
m f9cdd67229
CI / test (push) Successful in 12s
CI / test (pull_request) Successful in 11s
feat: add cognitive advisory contract
2026-08-16 20:05:12 +03:00

39 lines
1.5 KiB
Go

package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"git.cin.su/m/Assistant/contracts/cognitive"
)
func TestDeterministicAdvisoryRejectsUnknownJSONField(t *testing.T) {
body := `{"Version":"creator-advisory-v1","Unexpected":"provider override"}`
request := httptest.NewRequest(http.MethodPost, "/v1/advisories/deterministic", strings.NewReader(body))
response := httptest.NewRecorder()
deterministicAdvisory(response, request)
if response.Code != http.StatusBadRequest {
t.Fatalf("status=%d, want 400", response.Code)
}
}
func TestDeterministicAdvisoryReturnsUnavailableContract(t *testing.T) {
body := `{"Version":"creator-advisory-v1","RequestID":"request-1","ActorID":"actor","PrincipalID":"principal","ScopeID":"scope","Message":"help","Context":[],"Locale":"en","MaxOutputBytes":4096,"ProviderBindingID":"fake-binding","ProviderBindingRevision":1}`
request := httptest.NewRequest(http.MethodPost, "/v1/advisories/deterministic", strings.NewReader(body))
response := httptest.NewRecorder()
deterministicAdvisory(response, request)
if response.Code != http.StatusOK {
t.Fatalf("status=%d body=%s", response.Code, response.Body.String())
}
var advisory cognitive.AdvisoryResponse
if err := json.NewDecoder(response.Body).Decode(&advisory); err != nil {
t.Fatal(err)
}
if advisory.FinishReason != cognitive.FinishProviderUnavailable || advisory.AdvisoryText != "" {
t.Fatalf("unexpected response: %+v", advisory)
}
}