Show full audited run graphs and scope searchable run history

This commit is contained in:
2026-10-10 00:26:32 +01:00
parent a1c0eb4a72
commit e9a8eaf8ae
15 changed files with 438 additions and 66 deletions
+8 -1
View File
@@ -105,7 +105,7 @@ func scanRun(row interface{ Scan(...any) error }, r *protocol.RunSummary) error
}
func (s *Store) ListRuns(ctx context.Context) ([]protocol.RunSummary, error) {
rows, err := s.db.QueryContext(ctx, runSelect+" ORDER BY r.id DESC LIMIT 50")
rows, err := s.db.QueryContext(ctx, runSelect+" ORDER BY r.id DESC")
if err != nil {
return nil, err
}
@@ -150,6 +150,13 @@ func (s *Store) GetRun(ctx context.Context, id int64) (*protocol.RunDetail, erro
return nil, err
}
var input, output, paths string
var graphJSON string
if err := tx.QueryRowContext(ctx, "SELECT graph_json FROM pipeline_versions WHERE pipeline_id=? AND version=?", r.PipelineID, r.Version).Scan(&graphJSON); err != nil {
return nil, err
}
if err := json.Unmarshal([]byte(graphJSON), &r.Graph); err != nil {
return nil, err
}
if err := tx.QueryRowContext(ctx, "SELECT workspace,allow_tools,write_paths,input_json,output_json,COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=pipeline_runs.id),0) FROM pipeline_runs WHERE id=?", id).Scan(&r.Workspace, &r.AllowTools, &paths, &input, &output, &r.RetryOf); err != nil {
return nil, err
}
+37
View File
@@ -2,10 +2,41 @@ package pipeline
import (
"context"
"fmt"
"path/filepath"
"reflect"
"testing"
)
func TestRunListIncludesHistoryBeyondFiftyForSearchAndPipelineScope(t *testing.T) {
ctx := context.Background()
store, err := Open(filepath.Join(t.TempDir(), "runs.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
if _, err := store.Submit(ctx, "history", Template([]string{"one"}, true)); err != nil {
t.Fatal(err)
}
items, err := store.List(ctx)
if err != nil {
t.Fatal(err)
}
definition, err := store.Get(ctx, items[0].ID, 1)
if err != nil {
t.Fatal(err)
}
for i := 0; i < 55; i++ {
if _, _, err := store.CreateRun(ctx, definition, fmt.Sprintf("history-%d", i), "workspace", false, nil, nil); err != nil {
t.Fatal(err)
}
}
runs, err := store.ListRuns(ctx)
if err != nil || len(runs) != 55 || runs[len(runs)-1].ID != 1 {
t.Fatal("older searchable runs missing", len(runs), err)
}
}
func TestRunRecoveryAndVersionPinning(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "audit.db")
@@ -44,6 +75,9 @@ func TestRunRecoveryAndVersionPinning(t *testing.T) {
if err := store.RecoverRuns(ctx); err != nil {
t.Fatal(err)
}
if _, err := store.Submit(ctx, "audit", Template([]string{"replacement", "another"}, true)); err != nil {
t.Fatal(err)
}
run, err := store.GetRun(ctx, id)
if err != nil {
t.Fatal(err)
@@ -51,6 +85,9 @@ func TestRunRecoveryAndVersionPinning(t *testing.T) {
if run.Status != "interrupted" || run.Steps[0].Status != "interrupted" || run.Steps[0].AgentActive || run.ContentHash != definition.ContentHash || run.Version != 1 {
t.Fatal("recovery silently resumed or changed version", run)
}
if !reflect.DeepEqual(run.Graph, definition.Graph) {
t.Fatal("run graph did not retain its pinned definition", run.Graph)
}
loaded, _ := store.Get(ctx, definition.ID, 1)
if loaded.Source != source {
t.Fatal("run modified immutable source")
+3 -3
View File
@@ -80,8 +80,8 @@ func TestUsageStatsCountAllHistoryAndZeroFillDailyActivity(t *testing.T) {
if total != 60 {
t.Fatal("daily totals", stats.Days)
}
latest, err := store.ListRuns(ctx)
if err != nil || len(latest) != 50 {
t.Fatal("fixture must exceed latest-runs cap", latest, err)
runs, err := store.ListRuns(ctx)
if err != nil || len(runs) != stats.Total {
t.Fatal("run list and all-history statistics disagree", len(runs), stats.Total, err)
}
}