feat: make proposal responses durable

This commit is contained in:
Josh Creek
2026-09-01 07:52:52 +01:00
parent 30b4560bd5
commit eef7cf28da
6 changed files with 228 additions and 16 deletions
+27 -2
View File
@@ -22,8 +22,18 @@ type queueBackendSpy struct{ createCalls, heartbeatCalls, cancelCalls, getCalls
type sessionBackendSpy struct{ calls int }
type proposalBackendSpy struct {
proposal domain.Proposal
calls int
proposal domain.Proposal
calls int
mutations int
}
func (b *proposalBackendSpy) Respond(_ context.Context, playerID, _ string, key string, accept bool, revision uint64, now time.Time) (domain.Proposal, error) {
b.mutations++
updated, err := b.proposal.Respond(playerID, key, accept, revision, now)
if err == nil {
b.proposal = updated
}
return updated, err
}
func (b *proposalBackendSpy) Get(_ context.Context, playerID, _ string, _ time.Time) (domain.Proposal, error) {
@@ -389,6 +399,21 @@ func TestProposalRecoveryUsesDurableBackendAndRemainsParticipantScoped(t *testin
if status := get(participantSession, participantToken); status != http.StatusOK {
t.Fatalf("participant recovery status = %d", status)
}
respond, err := http.NewRequest(http.MethodPost, server.URL+"/v1/proposals/"+proposal.ProposalID+"/accept", nil)
if err != nil {
t.Fatal(err)
}
respond.Header.Set("Authorization", "Bearer "+participantSession.SessionID+":"+participantToken)
respond.Header.Set("Idempotency-Key", "proposal-durable-response-123456")
respond.Header.Set("If-Match-Revision", "0")
response, err := server.Client().Do(respond)
if err != nil {
t.Fatal(err)
}
_ = response.Body.Close()
if response.StatusCode != http.StatusOK || backend.mutations != 1 {
t.Fatalf("durable response status = %d, mutations = %d", response.StatusCode, backend.mutations)
}
if status := get(outsiderSession, outsiderToken); status != http.StatusNotFound {
t.Fatalf("outsider recovery status = %d", status)
}