39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLocalRefusedExecutionClosesOnceWithoutAgentAttempt(t *testing.T) {
|
|
st, _ := readyLocalOrigination(t)
|
|
at := time.Date(2026, 9, 21, 2, 0, 0, 0, time.UTC)
|
|
if err := st.RefuseLocalOrigination("d-1", "execution-a", "policy_denied", at); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ids, err := st.ListLocalRefusedWithoutTerminal("d-1", 0, 256)
|
|
if err != nil || len(ids) != 1 || ids[0] != "execution-a" {
|
|
t.Fatalf("refused decision unavailable to recover: ids=%v err=%v", ids, err)
|
|
}
|
|
candidate, decidedAt, reason, err := st.LoadLocalRefusedOrigination("d-1", "execution-a")
|
|
if err != nil || candidate.ExecutionID != "execution-a" || reason != "policy_denied" || !decidedAt.Equal(at) {
|
|
t.Fatalf("persisted refusal lost: candidate=%+v at=%v reason=%q err=%v", candidate, decidedAt, reason, err)
|
|
}
|
|
fact := LocalCallTerminal{
|
|
ExecutionID: "execution-a", CallID: "execution-a", Source: "dispatcher_refusal",
|
|
StartedAt: at, EndedAt: at, Outcome: "failed", ReasonCode: reason,
|
|
}
|
|
event := localFinalEventFixture()
|
|
if err := st.RecordLocalCallTerminal(fact, &event); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assertLocalTerminalQuota(t, st, 0, 0, "released")
|
|
if err := st.RecordLocalCallTerminal(fact, &event); err != nil {
|
|
t.Fatalf("refusal replay changed terminal fact: %v", err)
|
|
}
|
|
ids, err = st.ListLocalRefusedWithoutTerminal("d-1", 0, 256)
|
|
if err != nil || len(ids) != 0 {
|
|
t.Fatalf("closed refusal scheduled twice: ids=%v err=%v", ids, err)
|
|
}
|
|
}
|