From dabe0b4f7c293776fa4e11a3717bc37773ad1315 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 16 Nov 2026 09:41:39 +1100 Subject: [PATCH] refactor(approvals): judgement's change-request rules route an approval, and without a connector it goes to the channels (#1985) --- modules/approvals/approvals.go | 14 ++++++-------- modules/approvals/escalation.go | 26 +++++--------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/modules/approvals/approvals.go b/modules/approvals/approvals.go index b09c1f05a..2f47884f8 100644 --- a/modules/approvals/approvals.go +++ b/modules/approvals/approvals.go @@ -206,23 +206,21 @@ type Module struct { func NewModule(db *sqlx.DB, log *slog.Logger, orgID string, tell Delivery, wake Signaller, classes Classes, policy Policy, people People) *Module { return &Module{ orgID: orgID, store: store.New(db), tell: tell, wake: wake, classes: classes, policy: policy, people: people, - changes: NoChangeRequests{}, log: log, now: time.Now, + log: log, now: time.Now, } } // Ask records a request for d and puts it to the first step of path. It runs // out for good when the last step does. Asking again for the same run and key -// returns the request that stands, so a replayed step asks once. An action the -// change-request rules pick goes through a change request, and every other one -// through the approvers' channels. +// returns the request that stands, so a replayed step asks once. An action +// judgement's change-request rules pick goes through a change request when a +// change-request connector is installed, and every other one through the +// approvers' channels. func (m *Module) Ask(ctx context.Context, runID uuid.UUID, key string, d judgement.Decision, path []governance.PathStep) (Request, error) { if len(path) == 0 { return Request{}, ErrNoPath } - changeRequest, err := m.changes.Needed(ctx, d) - if err != nil { - return Request{}, fmt.Errorf("route approval: %w", err) - } + changeRequest := d.ChangeRequest && m.changes != nil now := m.now().UTC() var total time.Duration for _, st := range path { diff --git a/modules/approvals/escalation.go b/modules/approvals/escalation.go index 535a1aa27..7eca791f3 100644 --- a/modules/approvals/escalation.go +++ b/modules/approvals/escalation.go @@ -10,16 +10,11 @@ import ( "github.com/samcharles93/archie-core/modules/deliveries" "github.com/samcharles93/archie-core/modules/governance" - "github.com/samcharles93/archie-core/modules/judgement" ) -// ChangeRequests is the seam between approval routing and a change-request -// connector. Routing asks one question of an action, whether it needs a change -// request; every action that doesn't goes to the approvers' channels. The -// rules that answer it are deterministic and run after the guards. +// ChangeRequests is a change-request connector. Judgement's change-request +// rules decide which held actions need one; this opens and withdraws them. type ChangeRequests interface { - // Needed reports whether d goes through a change request. - Needed(ctx context.Context, d judgement.Decision) (bool, error) // Open raises the change request for r. It may be called again for the same // request and must not open a second one. Open(ctx context.Context, r Request) error @@ -27,20 +22,9 @@ type ChangeRequests interface { Withdraw(ctx context.Context, r Request) error } -// NoChangeRequests is the routing while no change-request connector exists: -// no action needs one, so there is nothing to open or withdraw. -type NoChangeRequests struct{} - -// Needed reports false. -func (NoChangeRequests) Needed(context.Context, judgement.Decision) (bool, error) { return false, nil } - -// Open does nothing. -func (NoChangeRequests) Open(context.Context, Request) error { return nil } - -// Withdraw does nothing. -func (NoChangeRequests) Withdraw(context.Context, Request) error { return nil } - -// UseChangeRequests makes the module route approvals through c. +// UseChangeRequests makes the module open the change requests judgement asks +// for through c. Without one, those approvals go to the approvers' channels, +// so a rule never strands a request where nobody can answer it. func (m *Module) UseChangeRequests(c ChangeRequests) { m.changes = c } // Escalate passes a pending request to step n of its path, telling every