Files
archie/internal/infrastructure/staterpc/values_parity_test.go
T
sam 845b192a89 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.
2026-09-26 04:01:08 +10:00

88 lines
3.3 KiB
Go

package staterpc
import (
"reflect"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
)
// TestTaskProtoCarriesEveryDomainField fills every field of task.Task with a
// distinct non-zero value and requires the proto round trip to return it
// unchanged. taskProto/taskValue assign field by field, so a field added to
// the domain type and forgotten on the wire is otherwise invisible: the task
// still crosses, just with that field silently zeroed. This test fails for the
// forgotten field by name rather than leaving it to a caller to discover in
// production (archie-core-zf8h).
func TestTaskProtoCarriesEveryDomainField(t *testing.T) {
stamp := time.Date(2026, 9, 21, 10, 30, 0, 0, time.UTC)
want := &task.Task{}
v := reflect.ValueOf(want).Elem()
for i := range v.NumField() {
field := v.Field(i)
switch {
case field.Type() == reflect.TypeFor[time.Time]():
field.Set(reflect.ValueOf(stamp.Add(time.Duration(i) * time.Hour)))
case field.Kind() == reflect.String:
field.SetString(v.Type().Field(i).Name + "-value")
case field.CanInt():
field.SetInt(int64(i) + 1)
case field.Type() == reflect.TypeFor[map[string]any]():
field.Set(reflect.ValueOf(map[string]any{"key": v.Type().Field(i).Name + "-value"}))
default:
t.Fatalf("field %s has kind %s, which this test does not know how to fill; extend it alongside the field", v.Type().Field(i).Name, field.Kind())
}
}
got := taskValue(taskProto(want))
if reflect.DeepEqual(got, want) {
return
}
for i := range v.NumField() {
name := v.Type().Field(i).Name
gotField := reflect.ValueOf(got).Elem().Field(i).Interface()
wantField := v.Field(i).Interface()
if !reflect.DeepEqual(gotField, wantField) {
t.Errorf("Task.%s did not survive the proto round trip: got %v, want %v", name, gotField, wantField)
}
}
}
// TestWorkflowStatProtoCarriesEveryField is the same contract for the
// per-workflow metric row, and the reason it exists is the same: the dashboard
// reads these counts off the wire, so a count that only the producer knows
// (Completed, the runs that finished with no pull request to open) would read
// as zero everywhere without anything failing. Each field gets a value of its
// own, so a mapping that assigns two of them from the same source -- or drops
// one -- is caught by name.
func TestWorkflowStatProtoCarriesEveryField(t *testing.T) {
want := storecontract.WorkflowStat{}
v := reflect.ValueOf(&want).Elem()
for i := range v.NumField() {
field := v.Field(i)
switch {
case field.Kind() == reflect.String:
field.SetString(v.Type().Field(i).Name + "-value")
case field.Kind() == reflect.Float64:
field.SetFloat(float64(i) + 0.5)
case field.CanInt():
field.SetInt(int64(i) + 1)
default:
t.Fatalf("field %s has kind %s, which this test does not know how to fill; extend it alongside the field", v.Type().Field(i).Name, field.Kind())
}
}
got := reflect.ValueOf(workflowStatValue(workflowStatProto(want)))
for i := range v.NumField() {
name := v.Type().Field(i).Name
gotField := got.Field(i).Interface()
wantField := v.Field(i).Interface()
if !reflect.DeepEqual(gotField, wantField) {
t.Errorf("WorkflowStat.%s did not survive the proto round trip: got %v, want %v", name, gotField, wantField)
}
}
}