fix(chat): canonicalise a held action's stored input before comparing it (#2072, #2096)

The binding is read back from a jsonb column with a space after every colon,
so an unchanged approved action failed the byte comparison and never ran.
This commit is contained in:
sam committed 2026-11-22 02:09:32 +11:00
1 parent 48d0212784
commit 9c0ea938b8
2 files changed
+24

No files matched your search

+3
View File
@@ -158,6 +158,9 @@ func recorded(a store.Action) (Binding, string) {
if sum, err := stored.Digest(); err != nil || sum != a.BindingDigest {
return Binding{}, "its binding is incomplete or was altered"
}
// The binding comes back from a jsonb column reformatted, so its input is
// canonicalised again before it is compared byte for byte.
stored.Input = connectors.Canonical(stored.Input)
return stored, ""
}
+21
View File
@@ -6,6 +6,7 @@ import (
"encoding/json/jsontext"
"errors"
"log/slog"
"slices"
"strings"
"testing"
"time"
@@ -236,6 +237,16 @@ func newApprovalFixture(t *testing.T) *approvalFixture {
return f
}
// reformatted returns raw with the whitespace jsonb puts back on output.
func reformatted(t *testing.T, raw []byte) []byte {
t.Helper()
v := jsontext.Value(slices.Clone(raw))
if err := v.Indent(jsontext.WithIndent(" ")); err != nil {
t.Fatal(err)
}
return v
}
// TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce guards the dispatch-time
// recheck: an approval is discarded, and nothing runs, when the owner has lost
// access, when the target, effect, arguments or approvers changed, when the
@@ -249,6 +260,16 @@ func TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce(t *testing.T) {
wantDiscard string
}{
{name: "an action that still matches runs", wantRuns: 1},
{
// Postgres stores both columns as jsonb and hands them back
// reformatted, with a space after every colon.
name: "an action read back from jsonb still runs",
change: func(f *approvalFixture) {
f.action.Binding = reformatted(t, f.action.Binding)
f.action.Decision = reformatted(t, f.action.Decision)
},
wantRuns: 1,
},
{
name: "the owner's access revoked while pending",
change: func(f *approvalFixture) { f.d.People = fakePeople{alice: person(alice, governance.RoleViewer)} },