Files
archie/internal/infrastructure/readiness/probes_test.go
T
sam 5c922038f9 fix(access): check the policy version before each decision
archied, archie-ui and the tool gateway re-read the stored policies on a 30s
ticker, so a forbid written seconds earlier did not stop a run. One
instance-wide revision now moves inside the transaction of every policy write,
and a decision reads it first and rebuilds the engine only when it moved.

A version read that fails, or a policy list that fails after a bump, refuses
with ErrChainUnavailable instead of standing on the last chain, so three call
sites now treat unavailable as availability rather than denial: dispatch leaves
the capture for the next cycle, a task start parks transient, and the tool
gateway reports the tool as unavailable.
2026-10-25 16:21:01 +11:00

40 lines
1.2 KiB
Go

package readiness
import (
"context"
"errors"
"log/slog"
"testing"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/health"
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
)
// TestProblemProbeFollowsTheChain pins that the access_policies probe reads
// the chain on every check: degraded while the policies have not loaded, ok
// once they do, without rebuilding the probe.
func TestProblemProbeFollowsTheChain(t *testing.T) {
up := false
chain := infraaccess.NewPending(t.Context(), func(context.Context) (int64, error) {
return 1, nil
}, func(context.Context) ([]access.Policy, error) {
if !up {
return nil, errors.New("store down")
}
return nil, nil
}, slog.New(slog.DiscardHandler))
probe := NewProblemProbe("access_policies", chain)
if got := probe.Check(t.Context()); got.Status != health.StatusDegraded {
t.Fatalf("before load = %+v, want degraded", got)
}
up = true
if err := chain.Reload(t.Context()); err != nil {
t.Fatal(err)
}
if got := probe.Check(t.Context()); got.Status != health.StatusOK {
t.Fatalf("after load = %+v, want ok", got)
}
}