90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// Operator-invoked scratch fixture only. No devices or live databases are used.
|
|
func TestExportReadyAttentionReviewFixture(t *testing.T) {
|
|
dir := os.Getenv("PIPELINES_ATTENTION_REVIEW_DIR")
|
|
if dir == "" {
|
|
t.Skip("explicit export directory required")
|
|
}
|
|
if err := os.Mkdir(dir, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
workspace := filepath.Join(dir, "workspace")
|
|
if err := os.Mkdir(workspace, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := context.Background()
|
|
db := filepath.Join(dir, "attention.db")
|
|
store, err := pipeline.Open(db)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
if _, err := store.Submit(ctx, "Attention fixture", humanPipelineSource); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items, err := store.List(ctx)
|
|
if err != nil || len(items) != 1 {
|
|
t.Fatal("missing fixture definition", err)
|
|
}
|
|
definition, err := store.Get(ctx, items[0].ID, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, status := range []string{"failed", "succeeded"} {
|
|
id, _, err := store.CreateRun(ctx, definition, "fixture-"+status, workspace, false, nil, map[string]any{"prompt": "Controlled " + status + " attention entry"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
outcome := "success"
|
|
if status == "failed" {
|
|
outcome = "error"
|
|
}
|
|
capture := &protocol.StageFileChanges{Status: "complete", Files: []protocol.FileChange{}}
|
|
if status == "failed" {
|
|
capture.Status, capture.Skipped, capture.Diagnostic = "partial", 2, "Controlled partial fixture: files skipped."
|
|
}
|
|
if err := store.BeginStep(ctx, id, 1, "gate", map[string]any{"prompt": "Controlled fixture step"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := store.FinishStep(ctx, id, protocol.RunStep{Sequence: 1, Stage: "gate", Status: "completed", Outcome: outcome, FileChanges: capture}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := store.FinishRun(ctx, id, status, outcome, "Controlled fixture", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
r, err := newRunner(ctx, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r.execute = successExecute
|
|
waiting, err := r.start(protocol.Message{PipelineID: definition.ID, Version: 1, RequestKey: "fixture-waiting", Workspace: workspace, Input: map[string]any{"prompt": "Controlled waiting attention entry"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r.wg.Wait()
|
|
readback, err := store.GetRun(ctx, waiting.ID)
|
|
if err != nil || readback.Status != protocol.RunStatusWaiting || len(readback.Steps) != 1 {
|
|
t.Fatalf("waiting fixture invalid: %+v %v", readback, err)
|
|
}
|
|
data, err := json.MarshalIndent(map[string]any{"database": db, "workspace": workspace, "waiting_run": waiting.ID, "failed_run": 1, "finished_run": 2}, "", " ")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "fixture.json"), data, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|