Files
archie/internal/infrastructure/staterpc/values_parity_test.go
T
sam 90fda8d53a fix(statestore): carry the workflow pin across the wire
task.WorkflowDefinitionVersion/Digest/YAML had no pb.Task field and no
taskProto/taskValue mapping, so over gRPC the pin was never persisted and
any pin already in the row was zeroed by the same Update. The production
daemon's Store is the gRPC client, so the digest guard in pinWorkflowDefinition
was dead there: WorkflowDefinitionYAML was never non-empty for a task read
back over the wire, and each retry re-resolved from the active control-plane
resource instead of the version it started with
(docs/prds/runtime-control-plane.md:95).

The SQL store already wrote and read all three columns; only the contract
dropped them. Adds proto fields 28-30 and the mapping both ways.

Field parity was untied, which is why this was invisible: the task still
crossed, just with those fields silently zeroed. TestTaskProtoCarriesEveryDomainField
fills every domain field and requires the round trip to return it, so the
next forgotten field fails by name. The conformance battery now carries the
pin through Update and back out of TaskByID, failing in grpc mode only.
2026-09-21 22:59:56 +10:00

50 lines
1.7 KiB
Go

package staterpc
import (
"reflect"
"testing"
"time"
"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)
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)
}
}
}