feat(handler): 暴露健康档案 upsert 接口(T-204)

This commit is contained in:
ila
2026-07-16 02:00:56 +08:00
parent 3a30ebdc45
commit 48263d8b9a
16 changed files with 852 additions and 44 deletions
+8 -5
View File
@@ -22,8 +22,8 @@ func TestHealthRecordUpsertCreatesWhenQueryIsEmpty(t *testing.T) {
if err != nil || outcome.Status != StatusDone || outcome.Action != ActionCreate {
t.Fatalf("outcome=%#v err=%v", outcome, err)
}
if client.findCalls != 1 || client.createCalls != 1 || client.updateCalls != 0 || !store.marked {
t.Fatalf("calls find=%d create=%d update=%d marked=%v", client.findCalls, client.createCalls, client.updateCalls, store.marked)
if client.findCalls != 1 || client.createCalls != 1 || client.updateCalls != 0 || !store.marked || !store.completeHasDeadline {
t.Fatalf("calls find=%d create=%d update=%d marked=%v deadline=%v", client.findCalls, client.createCalls, client.updateCalls, store.marked, store.completeHasDeadline)
}
assertNotifications(t, reports, statuses, StatusDone, ActionCreate)
}
@@ -86,7 +86,7 @@ func TestHealthRecordUpsertNeverCreatesAfterQueryFailure(t *testing.T) {
if retryable {
want = StatusRetry
}
if err != nil || outcome.Status != want || client.createCalls != 0 || client.updateCalls != 0 || !store.released {
if err != nil || outcome.Status != want || client.createCalls != 0 || client.updateCalls != 0 || !store.released || !store.releaseHasDeadline {
t.Fatalf("retryable=%v outcome=%#v err=%v", retryable, outcome, err)
}
}
@@ -247,6 +247,7 @@ func (f *fakeHealthRecordClient) UpdateHealthRecord(_ context.Context, req contr
type fakeIdempotencyStore struct {
completed, inProgress, marked, released bool
completeHasDeadline, releaseHasDeadline bool
completeErr error
}
@@ -259,14 +260,16 @@ func (f *fakeIdempotencyStore) Acquire(context.Context, string) (IdempotencyLeas
}
return IdempotencyLease{State: IdempotencyAcquired, Token: "lease-1"}, nil
}
func (f *fakeIdempotencyStore) Complete(_ context.Context, _, token string) error {
func (f *fakeIdempotencyStore) Complete(ctx context.Context, _, token string) error {
_, f.completeHasDeadline = ctx.Deadline()
if token != "lease-1" {
return errors.New("stale lease")
}
f.marked = true
return f.completeErr
}
func (f *fakeIdempotencyStore) Release(_ context.Context, _, token string) error {
func (f *fakeIdempotencyStore) Release(ctx context.Context, _, token string) error {
_, f.releaseHasDeadline = ctx.Deadline()
if token != "lease-1" {
return errors.New("stale lease")
}