Improve workflow UI, retain stage diffs, and add portable pipeline transfers
Make OpenCode authoring responsive and expand the managed skill references. Add conflict-aware import/export, real-provider reference workflows, and tracked V2 generation for reliable budget accounting.
This commit is contained in:
@@ -3,7 +3,9 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
@@ -99,6 +101,114 @@ func TestStageNotificationEventsAndArtifactAudit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Regress the exact research -> report terminal-path recipe from the authoring guide.
|
||||
// A completion-alert request must not require native delivery or change run routing.
|
||||
func TestResearchTerminalNotificationRecipe(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "recipe.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
var source string
|
||||
for _, template := range examples.Catalog() {
|
||||
if template.Key == "research" {
|
||||
source = template.Source
|
||||
}
|
||||
}
|
||||
if source == "" {
|
||||
t.Fatal("research template missing")
|
||||
}
|
||||
source = strings.Replace(source, "# stage research", "# stage research\n```notify\non=failure\n```", 1)
|
||||
source = strings.Replace(source, "# stage report", "# stage report\n```notify\non=success,failure\n```", 1)
|
||||
if _, err = store.Submit(ctx, "research notification recipe", source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, err := store.List(ctx)
|
||||
if err != nil || len(items) != 1 {
|
||||
t.Fatal("recipe missing", err)
|
||||
}
|
||||
id := items[0].ID
|
||||
var calls atomic.Int32
|
||||
var deliveryFailure atomic.Bool
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
calls.Add(1)
|
||||
if req.Header.Get("Filename") != "" {
|
||||
t.Error("event alert unexpectedly changed output to add attachments")
|
||||
}
|
||||
if deliveryFailure.Load() {
|
||||
http.Error(w, "unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"id": "recipe-receipt", "event": "message"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Setenv("PIPELINES_NTFY_URL", srv.URL+"/pipelines")
|
||||
t.Setenv("PIPELINES_NTFY_TOKEN", "")
|
||||
t.Setenv("PIPELINES_NTFY_TOKEN_FILE", "")
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for index, test := range []struct {
|
||||
name, stage, outcome, status string
|
||||
executionError, deliveryError bool
|
||||
}{
|
||||
{"success", "report", "success", "succeeded", false, false},
|
||||
{"research blocked", "research", "blocked", "failed", false, false},
|
||||
{"research execution error", "research", "error", "failed", true, false},
|
||||
{"report blocked", "report", "blocked", "failed", false, false},
|
||||
{"report execution error", "report", "error", "failed", true, false},
|
||||
{"delivery error preserves success", "report", "success", "succeeded", false, true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
deliveryFailure.Store(test.deliveryError)
|
||||
r.execute = func(_ context.Context, def stage.Definition, _ stage.Values) (stage.Result, error) {
|
||||
if def.Key == test.stage {
|
||||
if test.executionError {
|
||||
return stage.Result{}, errors.New("fixture execution failed")
|
||||
}
|
||||
return stage.Result{Outcome: test.outcome, Output: stage.Values{"report": "retained evidence"}}, nil
|
||||
}
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"question": "topic", "evidence": []any{"source fact"}}}, nil
|
||||
}
|
||||
before := calls.Load()
|
||||
run, err := r.start(protocol.Message{PipelineID: id, Version: 1, RequestKey: fmt.Sprintf("recipe-%d", index), Workspace: t.TempDir(), Input: map[string]any{"prompt": "research a topic"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
detail, err := store.GetRun(ctx, run.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if detail.Status != test.status || calls.Load()-before != 1 {
|
||||
t.Fatal("wrong verdict or duplicate/missing terminal alert", detail.Status, calls.Load()-before)
|
||||
}
|
||||
last := detail.Steps[len(detail.Steps)-1]
|
||||
if last.Stage != test.stage || len(last.Notifications) != 1 {
|
||||
t.Fatal("notification not retained on terminal stage", last)
|
||||
}
|
||||
for _, step := range detail.Steps[:len(detail.Steps)-1] {
|
||||
if len(step.Notifications) != 0 {
|
||||
t.Fatal("intermediate success alerted", step)
|
||||
}
|
||||
}
|
||||
want := "sent"
|
||||
if test.deliveryError {
|
||||
want = "failed"
|
||||
}
|
||||
if last.Notifications[0].Status != want {
|
||||
t.Fatal("delivery receipt wrong", last.Notifications)
|
||||
}
|
||||
if !test.executionError && detail.Output["report"] != "retained evidence" {
|
||||
t.Fatal("notification changed output handoff", detail.Output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationFailureDoesNotChangeRunRouting(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user