Let runs carry an operator title shown in the CLI and TUI
Add a bounded, never-empty title to every run. `pipelines run --title "..."` sets it explicitly and skips model generation; otherwise the server generates it from the prompt through the shared summariser and falls back to the prompt's first line, recording title_source (model/fallback/explicit) and title_model. - protocol/store: RunSummary.Title plus Label(), a set_run_title message, title columns with an idempotent migration, CreateRunTitled, and SetRunTitle renames. - summarise: Title/GenerateTitle/DeriveTitle/ExplicitTitle bounded to TitleCap. - runner: generate the title outside the admission lock and only for a request that starts a run; a replay reuses the stored title and an explicit title skips the model entirely. - CLI: `--title` on run and a `title <run-id> "<title>"` rename command; human `runs` and `inspect` show the title beside the pipeline name and version. - TUI: the run list row, run detail header, Home run cards and last-run line, and the pipeline Results line show the title via Label(). Tests cover storage/migration/fallback, explicit-title and rename, the end-to-end CLI flow, and title rendering; CLI and operations docs updated.
This commit is contained in:
@@ -11,8 +11,194 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/summarise"
|
||||
)
|
||||
|
||||
// TestRunTitleGeneratedPersistedAndFallback proves the insert path stores a
|
||||
// generated title with its provenance in list and detail responses, and falls
|
||||
// back to a derived bounded title when no generator is wired, without failing
|
||||
// run creation.
|
||||
func TestRunTitleGeneratedPersistedAndFallback(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "titles.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "titled", pipeline.Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{}}, nil
|
||||
}
|
||||
r.title = func(context.Context, string) summarise.Title {
|
||||
return summarise.Title{Text: "Fix the flaky login test", Source: summarise.SourceModel, Model: "openai/gpt"}
|
||||
}
|
||||
run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "model-title", Workspace: t.TempDir(), Input: map[string]any{"prompt": "prompt body"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
detail, err := store.GetRun(ctx, run.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if detail.Title != "Fix the flaky login test" || detail.TitleSource != summarise.SourceModel || detail.TitleModel != "openai/gpt" {
|
||||
t.Fatalf("model title not stored with provenance: %+v", detail)
|
||||
}
|
||||
list, err := store.ListRuns(ctx)
|
||||
if err != nil || len(list) != 1 || list[0].Title != "Fix the flaky login test" {
|
||||
t.Fatalf("run list omitted the title: %v %v", list, err)
|
||||
}
|
||||
|
||||
// No generator: the fallback is derived from the prompt's first line and run
|
||||
// creation still succeeds.
|
||||
r.title = nil
|
||||
fallback, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "fallback-title", Workspace: t.TempDir(), Input: map[string]any{"prompt": "Fix the widget\nand more detail"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
detail, err = store.GetRun(ctx, fallback.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if detail.Title != "Fix the widget" || detail.TitleSource != summarise.SourceFallback || detail.TitleModel != "" {
|
||||
t.Fatalf("fallback title = %+v, want the prompt's first line", detail)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunTitleGeneratorSkippedForReplayAndRejection proves the bounded
|
||||
// generation runs only for a request that starts a run: an idempotent replay and
|
||||
// a request refused for an already-reserved workspace must not pay for it.
|
||||
func TestRunTitleGeneratorSkippedForReplayAndRejection(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "skip.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "skip", pipeline.Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
release := make(chan struct{})
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
<-release
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{}}, nil
|
||||
}
|
||||
calls := 0
|
||||
r.title = func(context.Context, string) summarise.Title {
|
||||
calls++
|
||||
return summarise.Title{Text: "Generated", Source: summarise.SourceModel}
|
||||
}
|
||||
workspace := t.TempDir()
|
||||
first, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-key", Workspace: workspace, Input: map[string]any{"prompt": "first"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Fatalf("first start generated %d titles, want 1", calls)
|
||||
}
|
||||
// A replay while the first run is active reuses the stored title.
|
||||
replay, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-key", Workspace: workspace, Input: map[string]any{"prompt": "first"}})
|
||||
if err != nil || replay.ID != first.ID {
|
||||
t.Fatalf("replay = %+v, %v; want run %d", replay, err, first.ID)
|
||||
}
|
||||
// A new key in the already-reserved workspace is refused.
|
||||
if _, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-other", Workspace: workspace, Input: map[string]any{"prompt": "second"}}); err == nil {
|
||||
t.Fatal("workspace conflict was not refused")
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Fatalf("replay/rejection generated %d titles, want 1", calls)
|
||||
}
|
||||
close(release)
|
||||
r.wg.Wait()
|
||||
}
|
||||
|
||||
func TestHandlerWiresRunTitleGenerator(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "wire.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
configured := HandlerWithOptions(ctx, Options{RunTitles: summarise.GenerateTitle}, store).(*runHandler)
|
||||
bare := HandlerWithOptions(ctx, Options{}, store).(*runHandler)
|
||||
defer func() { cancel(); WaitRuns(configured); WaitRuns(bare) }()
|
||||
if configured.runner.title == nil {
|
||||
t.Fatal("configured RunTitles was not applied to the runner")
|
||||
}
|
||||
if bare.runner.title != nil {
|
||||
t.Fatal("unconfigured RunTitles must keep deterministic fallback title generation")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunnerExplicitTitleSkipsGeneratorAndRenames proves an explicit --title is
|
||||
// stored verbatim and skips the model generator, and that setTitle later
|
||||
// replaces it with an explicit provenance without touching the run's input.
|
||||
func TestRunnerExplicitTitleSkipsGeneratorAndRenames(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "explicit.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "explicit", pipeline.Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{}}, nil
|
||||
}
|
||||
generated := 0
|
||||
r.title = func(context.Context, string) summarise.Title {
|
||||
generated++
|
||||
return summarise.Title{Text: "Generated", Source: summarise.SourceModel}
|
||||
}
|
||||
run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "explicit-key", Workspace: t.TempDir(), Title: "Operator chosen title", Input: map[string]any{"prompt": "prompt body"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
if generated != 0 {
|
||||
t.Fatalf("explicit title still called the generator %d times", generated)
|
||||
}
|
||||
if run.Title != "Operator chosen title" || run.TitleSource != summarise.SourceExplicit || run.TitleModel != "" {
|
||||
t.Fatalf("explicit title = %+v", run)
|
||||
}
|
||||
|
||||
renamed, err := r.setTitle(run.ID, " Renamed after the fact ")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if renamed.Title != "Renamed after the fact" || renamed.TitleSource != summarise.SourceExplicit || renamed.Input["prompt"] != "prompt body" {
|
||||
t.Fatalf("rename = %+v", renamed)
|
||||
}
|
||||
if _, err := r.setTitle(run.ID, " "); err == nil {
|
||||
t.Fatal("blank rename was accepted")
|
||||
}
|
||||
if _, err := r.setTitle(run.ID+999, "ghost"); err == nil {
|
||||
t.Fatal("renaming an unknown run was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerRoutingPersistenceAndIdempotency(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user