package runner import ( "amadan.net/oficina/equipo/internal/runnerproto" "context" "encoding/json" "testing" ) func TestDirectUploadUsesEventIdentity(t *testing.T) { s, r, _, _ := cleanupFixture(t) e := Event{Version: 2, ID: "stale-A", AssignmentID: "attempt-A", Scope: r.Claim.Scope, Handle: r.Claim.Handle} e.Handle.Attempt++ e.Handle.Fence++ s.api = apiFuncR3(func(_ context.Context, _ string, q runnerproto.RunnerRequest, _ any) error { var saved Event mustJournal(t, json.Unmarshal(q.Event, &saved)) if q.AssignmentID != saved.AssignmentID || q.Scope != saved.Scope || q.Handle != saved.Handle { return runnerproto.ErrInvalid } return nil }) mustJournal(t, s.uploadDirectEvent(context.Background(), r, e)) } func TestDirectCloseDrainsFinalEvents(t *testing.T) { done := make(chan error, 1) pending, uploaded := 0, 0 err := finishDirectStream(context.Background(), func() error { pending++; done <- nil; return nil }, done, func(context.Context) error { uploaded += pending; pending = 0; return nil }) mustJournal(t, err) if uploaded != 1 || pending != 0 { t.Fatal("close event not drained") } }