| index 95b4b2ac..355071ab 100644 |
| --- a/internal/headless/scenarios_test.go |
| +++ b/internal/headless/scenarios_test.go |
| @@ -329,20 +329,47 @@ func scenarioStreamResume(t *testing.T, env *Env) { |
| if s.conv.Applied == before { |
| t.Fatal("no events replayed from the cursor") |
| } |
| - // The same events again from the old cursor change nothing. |
| + // The same events again from the old cursor change nothing. Only the |
| + // replay counts, up to where the conversation stood: the live stream |
| + // closes first, and nothing after that point is a repeat. The |
| + // conversation goes on after a reply (on staging a runner's hello |
| + // stores a connection's fresh headroom at any moment), and an event |
| + // newer than the conversation's cursor is news, not a replay. |
| + s.close() |
| + top := s.conv.Cursor |
| + applied := s.conv.Applied |
| again, err := env.Client.Open(s.ctx, cursor) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - applied := s.conv.Applied |
| - timeout := time.After(2 * time.Second) |
| + if env.duringReplay != nil { |
| + env.duringReplay(t, s) |
| + } |
| + timeout := time.After(30 * time.Second) |
| + last := cursor |
| replay: |
| for { |
| select { |
| - case e := <-again.Events: |
| + case e, ok := <-again.Events: |
| + if !ok { |
| + // The edge can drop a stream (a 502 on staging): resume the |
| + // replay from what it brought, as a client would. |
| + again.Close() |
| + if again, err = env.Client.Open(s.ctx, last); err != nil { |
| + t.Fatalf("reopen the replay: %v", err) |
| + } |
| + continue |
| + } |
| + if e.Cursor > top { |
| + t.Fatalf("the replay passed cursor %d without it (at %d)", top, e.Cursor) |
| + } |
| s.conv.Apply(e) |
| + last = max(last, e.Cursor) |
| + if e.Cursor == top { |
| + break replay |
| + } |
| case <-timeout: |
| - break replay |
| + t.Fatalf("the replay did not reach cursor %d (at %d)", top, last) |
| } |
| } |
| again.Close() |
| @@ -574,6 +601,22 @@ func TestHeadless(t *testing.T) { |
| report(t) |
| } |
| |
| +// TestHeadlessStreamResumeWhileLive is scenario 7 while something new |
| +// reaches the conversation as it reads the replay: on staging a runner's |
| +// hello stores a connection's fresh headroom at any moment after a reply. |
| +// Only the replay must change nothing; what is new still applies. |
| +func TestHeadlessStreamResumeWhileLive(t *testing.T) { |
| + env, _, r := localEnv(t) |
| + r.opts.NoMoveIn = true |
| + r.start(t) |
| + env.duringReplay = func(t *testing.T, s *session) { |
| + if _, err := env.Client.Connect(s.ctx, wire.Connect{Provider: "codex"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + scenarioStreamResume(t, env) |
| +} |
| + |
| // TestStaging runs the same scenarios against staging with the real CLI. |
| // The gate script sets the origin, the device bearer and the controls. |
| func TestStaging(t *testing.T) { |