Files
archie/modules/approvals/approvals_test.go
T
sam 0238f247e5 feat(approvals): a held action is asked of a person, and the run waits for the answer (archie #1985, #1999)
An action judgement holds at propose and wait is no longer a dead end. The
new approvals module owns the request: it binds to the decision and the
action's digest, so an answer covers the action the person was shown and
nothing else, and it settles once. The answer wakes the run, which judges the
action again and runs it only as the approval allows: a refusal still refuses,
an altered input runs nothing, and a judgement that came back worse runs
nothing on that approval.

The composer carries the request as a message with the request id and its
deadline, and its answer is a message too, so the trail shows what was asked
and what was answered. A request nobody answers inside its deadline is settled
as expired and nothing runs.

How long a request waits is an organisation setting, edited in the dashboard
and stored in milliseconds, because a Postgres interval scans as text. A run
pins the deadline it started with, like its model.

An agent that proposes the same action twice is asked about it once, and the
notification says when the investigation proposed nothing at all.
2026-11-16 02:21:06 +11:00

39 lines
1.5 KiB
Go

package approvals
import (
"errors"
"testing"
"time"
"github.com/samcharles93/archie-core/modules/approvals/internal/store"
)
// TestSettleableRefusesASecondAnswerOrALateOne guards the rule that makes an
// approval one decision: the first answer settles a request, so a replaying
// answer or one that arrives after the deadline wakes no run and runs nothing.
func TestSettleableRefusesASecondAnswerOrALateOne(t *testing.T) {
deadline := time.Date(2026, 11, 16, 12, 0, 0, 0, time.UTC)
request := func(state string) store.Request {
return store.Request{State: state, Deadline: deadline}
}
tests := []struct {
name string
row store.Request
now time.Time
wantErr error
}{
{name: "a pending request settles inside its deadline", row: request(StatePending), now: deadline.Add(-time.Minute)},
{name: "a pending request is too late after its deadline", row: request(StatePending), now: deadline, wantErr: ErrExpired},
{name: "an approved request doesn't settle again", row: request(StateApproved), now: deadline.Add(-time.Minute), wantErr: ErrAnswered},
{name: "a denied request doesn't settle again", row: request(StateDenied), now: deadline.Add(-time.Minute), wantErr: ErrAnswered},
{name: "an expired request doesn't settle", row: request(StateExpired), now: deadline.Add(-time.Minute), wantErr: ErrAnswered},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := settleable(tt.row, tt.now); !errors.Is(err, tt.wantErr) {
t.Fatalf("err = %v, want %v", err, tt.wantErr)
}
})
}
}