69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package author
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"git.a-wan.net/alan/pipelines/internal/draft"
|
|
"git.a-wan.net/alan/pipelines/internal/opencode"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStableAuthoringInstructionsPreloadedWithoutInference(t *testing.T) {
|
|
executable := os.Getenv("PIPELINES_TEST_OPENCODE_V1")
|
|
if executable == "" {
|
|
t.Skip("set PIPELINES_TEST_OPENCODE_V1 for no-inference authoring preload test")
|
|
}
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("XDG_CONFIG_HOME", home+"/config")
|
|
t.Setenv("XDG_DATA_HOME", home+"/data")
|
|
t.Setenv("XDG_CACHE_HOME", home+"/cache")
|
|
t.Setenv("XDG_STATE_HOME", home+"/state")
|
|
t.Setenv("PIPELINES_DRAFT_DIR", home+"/drafts")
|
|
d, err := draft.Create("native authoring", "draft source", "ws://localhost", true, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
workspace, err := Workspace(d)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
defer cancel()
|
|
id, err := PrepareSession(ctx, executable, workspace, d.Name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err := opencode.Open(ctx, executable, workspace, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
defer c.Native(context.Background(), "delete", "/session/"+id, nil)
|
|
data, err := c.Native(ctx, "get", "/session/"+id+"/message", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var messages []struct {
|
|
Info struct {
|
|
Role string `json:"role"`
|
|
} `json:"info"`
|
|
Parts []struct{ Type, Text string } `json:"parts"`
|
|
}
|
|
if json.Unmarshal(data, &messages) != nil || len(messages) != 1 || messages[0].Info.Role != "user" {
|
|
t.Fatal("preload ran inference or missing message", string(data))
|
|
}
|
|
text := messages[0].Parts[0].Text
|
|
if !strings.Contains(text, "Do not submit or run by default") && !strings.Contains(text, "Do not submit or run") {
|
|
if !strings.Contains(text, "Do not submit") {
|
|
t.Fatal("draft-only instruction not preloaded", text)
|
|
}
|
|
}
|
|
if !strings.Contains(text, "Definition reference") || !strings.Contains(text, "provider=opencode-go") {
|
|
t.Fatal("format reference not preloaded")
|
|
}
|
|
}
|