feat(taskstate): count completed runs in the per-workflow stats
The transition table moved the no-change outcomes to StatusCompleted, so a run that opens no pull request now ends in a status the per-workflow stats did not count at all: it was not merged, not in review, not parked, and the workflows page would have shown it as a run that went nowhere. The count travels the whole State Store path, since every dashboard consumer reads it through the gRPC client rather than the local store. - WorkflowStats filters `completed` beside merged and pr_open; the SQL is the count, so a wrong filter reads as zero rather than failing, and TestWorkflowStatsCountsCompletedRuns holds it against a real store. - storecontract.WorkflowStat gains Completed (json "completed"), the proto message gains field 9, and workflowStatProto/workflowStatValue carry it; TestWorkflowStatProtoCarriesEveryField round-trips every field by name. - The gateway's chat task report names the status. - The dashboard counts a completed run as delivered in GatePulseCard's totals and badge numerator, and the WorkflowStat/WorkflowStats/WorkflowRow interfaces carry the field. - TestOutcomeSitesAreTransitionsFromRunning is the guard that keeps the producer and the table agreeing: it re-reads this package's tc.Outcome assignment sites from source and requires each status to be one internal/taskstate allows from running, so a new or moved site has to be adjudicated against the table instead of discovered on a live run.
This commit is contained in:
14 files changed
+279
-10
No files matched your search
@@ -108,6 +108,7 @@ func (s *Store) WorkflowStats(ctx context.Context) ([]storecontract.WorkflowStat
|
||||
Workflow: r.Workflow,
|
||||
Runs: int(r.Runs),
|
||||
Merged: int(r.Merged),
|
||||
Completed: int(r.Completed),
|
||||
PROpen: int(r.PrOpen),
|
||||
Parked: int(r.Parked),
|
||||
AvgTokens: int(r.AvgTokens),
|
||||
|
||||
@@ -295,6 +295,7 @@ const workflowStats = `-- name: WorkflowStats :many
|
||||
SELECT workflow,
|
||||
COUNT(*)::int AS runs,
|
||||
COUNT(*) FILTER (WHERE status = 'merged')::int AS merged,
|
||||
COUNT(*) FILTER (WHERE status = 'completed')::int AS completed,
|
||||
COUNT(*) FILTER (WHERE status = 'pr_open')::int AS pr_open,
|
||||
COUNT(*) FILTER (WHERE status = 'parked')::int AS parked,
|
||||
CAST(AVG(tokens_used) AS bigint) AS avg_tokens,
|
||||
@@ -310,6 +311,7 @@ type WorkflowStatsRow struct {
|
||||
Workflow string
|
||||
Runs int32
|
||||
Merged int32
|
||||
Completed int32
|
||||
PrOpen int32
|
||||
Parked int32
|
||||
AvgTokens int64
|
||||
@@ -330,6 +332,7 @@ func (q *Queries) WorkflowStats(ctx context.Context) ([]WorkflowStatsRow, error)
|
||||
&i.Workflow,
|
||||
&i.Runs,
|
||||
&i.Merged,
|
||||
&i.Completed,
|
||||
&i.PrOpen,
|
||||
&i.Parked,
|
||||
&i.AvgTokens,
|
||||
|
||||
@@ -39,6 +39,7 @@ ORDER BY id;
|
||||
SELECT workflow,
|
||||
COUNT(*)::int AS runs,
|
||||
COUNT(*) FILTER (WHERE status = 'merged')::int AS merged,
|
||||
COUNT(*) FILTER (WHERE status = 'completed')::int AS completed,
|
||||
COUNT(*) FILTER (WHERE status = 'pr_open')::int AS pr_open,
|
||||
COUNT(*) FILTER (WHERE status = 'parked')::int AS parked,
|
||||
CAST(AVG(tokens_used) AS bigint) AS avg_tokens,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
// TestWorkflowStatsCountsCompletedRuns pins the per-workflow count the
|
||||
// transition table made reachable: a run that finishes with no pull request
|
||||
// (a no-change build, a triage that needed no code) ends in taskstate.Completed,
|
||||
// so the workflows page has to be able to see those runs at all. The count is a
|
||||
// status filter in SQL, which fails silently when it is wrong -- a typo'd or
|
||||
// missing filter reads as zero, not as an error -- so it is asserted against the
|
||||
// store rather than left to the dashboard to notice.
|
||||
func TestWorkflowStatsCountsCompletedRuns(t *testing.T) {
|
||||
pool, q := migrated(t)
|
||||
store := New(pool)
|
||||
|
||||
finished := insertChatTask(t, q)
|
||||
merged := insertChatTask(t, q)
|
||||
finish := func(id int64, to string) {
|
||||
t.Helper()
|
||||
if err := store.Transition(t.Context(), id, taskstate.Queued, taskstate.Running, ""); err != nil {
|
||||
t.Fatalf("queued -> running: %v", err)
|
||||
}
|
||||
if err := store.Transition(t.Context(), id, taskstate.Running, to, ""); err != nil {
|
||||
t.Fatalf("running -> %s: %v", to, err)
|
||||
}
|
||||
}
|
||||
finish(finished.ID, taskstate.Completed)
|
||||
finish(merged.ID, taskstate.Merged)
|
||||
|
||||
stats, err := store.WorkflowStats(t.Context())
|
||||
if err != nil {
|
||||
t.Fatalf("WorkflowStats: %v", err)
|
||||
}
|
||||
if len(stats) != 1 {
|
||||
t.Fatalf("WorkflowStats = %+v, want one row for %q", stats, finished.Workflow)
|
||||
}
|
||||
got := stats[0]
|
||||
if got.Workflow != merged.Workflow {
|
||||
t.Fatalf("WorkflowStats row is %q, want %q", got.Workflow, merged.Workflow)
|
||||
}
|
||||
if got.Runs != 2 || got.Completed != 1 || got.Merged != 1 {
|
||||
t.Errorf("WorkflowStats = %+v, want runs 2, completed 1, merged 1: the completed count has to be its own status, not a share of merged", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user