Files
Agent-System/internal/events/replay_test.go
T
weichenandCursor 1c04f17c8c test(events): reject replay apply without approval ref
ReplayPlan two-person apply already required digest match; this pins the missing ApprovalRef negative so dry-run tickets cannot skip the ticket field.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 13:26:20 +00:00

41 lines
1.2 KiB
Go

package events
import "testing"
func TestAuthorizeReplayDryRunRequiresScope(t *testing.T) {
if err := AuthorizeReplayPlan(ReplayPlan{DryRun: true, Operator: "ops", Reason: "fix", Consumer: ConsumerNotify}); err != ErrReplayScope {
t.Fatalf("%v", err)
}
}
func TestApplyReplayRequiresMatchingDigestAndTwoPerson(t *testing.T) {
p := ReplayPlan{
PlanID: "p1", Operator: "ops", Approver: "sec", Environment: "dev",
ProjectID: 9, Consumer: ConsumerNotify, EventIDs: []string{"e1"},
Reason: "repair", ApprovalRef: "ticket-1", DryRun: true,
}
digest := p.Digest()
p.DryRun = false
if err := ApplyReplay(p, digest); err != nil {
t.Fatal(err)
}
p.Approver = p.Operator
if err := ApplyReplay(p, digest); err == nil {
t.Fatal("same operator/approver must fail")
}
p.Approver = "sec"
if err := ApplyReplay(p, "deadbeef"); err == nil {
t.Fatal("digest mismatch must fail")
}
p.ApprovalRef = ""
if err := ApplyReplay(p, digest); err == nil {
t.Fatal("apply without approval ref must fail")
}
}
func TestLegacyAuthorizeReplayStillDryRunOnly(t *testing.T) {
if err := AuthorizeReplay(ReplayRequest{DryRun: false, Consumer: "x", Operator: "o", Reason: "r"}); err != ErrReplayScope {
t.Fatalf("%v", err)
}
}