46 lines
2.0 KiB
Go
46 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestPrepareExample(t *testing.T) {
|
|
var output bytes.Buffer
|
|
if err := run(t.Context(), ".", &output); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var got struct {
|
|
PromptID string `json:"prompt_id"`
|
|
Profile string `json:"selected_profile"`
|
|
Model string `json:"model"`
|
|
MessageCount int `json:"message_count"`
|
|
Timeout int `json:"profile_timeout_seconds"`
|
|
Namespaces []string `json:"namespaces"`
|
|
Collections []map[string]json.RawMessage `json:"collections"`
|
|
ScopedPrompts []string `json:"scoped_prompts"`
|
|
ReviewPrompts []string `json:"review_prompts"`
|
|
}
|
|
if err := json.Unmarshal(output.Bytes(), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.PromptID != "support/prepare" || got.Profile != "support/fast" || got.Model != "offline-model" ||
|
|
got.MessageCount <= 0 || got.Timeout != 30 || !reflect.DeepEqual(got.Namespaces, []string{"review", "support"}) ||
|
|
!reflect.DeepEqual(got.ScopedPrompts, []string{"support/prepare"}) || !reflect.DeepEqual(got.ReviewPrompts, []string{"review/check"}) || len(got.Collections) != 2 {
|
|
t.Fatalf("unexpected preparation summary: %+v", got)
|
|
}
|
|
for index, want := range []struct{ namespace, release string }{{"review", ""}, {"support", "1.4.0"}} {
|
|
var namespace string
|
|
if err := json.Unmarshal(got.Collections[index]["namespace"], &namespace); err != nil || namespace != want.namespace {
|
|
t.Fatalf("collection namespace = %q, %v", namespace, err)
|
|
}
|
|
value, present := got.Collections[index]["release_version"]
|
|
var release *string
|
|
if !present || json.Unmarshal(value, &release) != nil || (index == 0 && release != nil) || (index == 1 && (release == nil || *release != want.release)) {
|
|
t.Fatalf("collection release = %s, present %t; want %q", value, present, want.release)
|
|
}
|
|
}
|
|
}
|