From 28049bd2907b196173b752b1de70ffa788e195fa Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 6 Oct 2026 09:10:31 +0800 Subject: [PATCH] =?UTF-8?q?gateway=20tests:=20the=20rewind=20tests=20wait?= =?UTF-8?q?=20for=20the=20rewind=20to=20be=20asked=20before=20the=20resend?= =?UTF-8?q?=20=E2=80=94=20letGo=20runs=20on=20its=20own=20after=20the=20re?= =?UTF-8?q?quest=20given=20up=20on=20returns,=20and=20keeps=20the=20run=20?= =?UTF-8?q?for=20the=20resend=20just=20before=20it=20tells=20Claude=20Code?= =?UTF-8?q?=20to=20rewind;=20the=20tests=20sent=20the=20resend=20at=20once?= =?UTF-8?q?,=20so=20under=20load=20it=20found=20no=20run=20kept=20and=20st?= =?UTF-8?q?arted=20a=20new=20one=20(TestClaudeTurnGivenUpOnIsRewound:=20"t?= =?UTF-8?q?he=20resend=20went=20to=20another=20Claude=20Code";=20NotRewoun?= =?UTF-8?q?d/refuse:=20"2=20runs"),=20and=20the=20refuse=20case's=20rewind?= =?UTF-8?q?=20still=20read=20rewindLongest=20as=20the=20silent=20case=20se?= =?UTF-8?q?t=20it=20(the=20data=20race=20in=20CI=20run=2037395880309=20on?= =?UTF-8?q?=202bd49cc5).=20rewindAsked=20waits=20for=20the=20rewind=5Fconv?= =?UTF-8?q?ersation=20line=20in=20the=20stand-in's=20log;=20the=20resend?= =?UTF-8?q?=20then=20waits=20on=20the=20rewind=20as=20a=20real=20one=20doe?= =?UTF-8?q?s.=20Test-only:=20a=20user=20rewording=20a=20message=20is=20nev?= =?UTF-8?q?er=20that=20quick.=20Before,=20go=20test=20-race=20-count=3D30?= =?UTF-8?q?=20-cpu=201,2=20of=20the=20four=20rewind=20tests=20failed=20IsR?= =?UTF-8?q?ewound=20once;=20with=20this,=20-count=3D40=20-cpu=201,2=20pass?= =?UTF-8?q?es.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/claude_subscription_rewind_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/gateway/claude_subscription_rewind_test.go b/internal/gateway/claude_subscription_rewind_test.go index 8bd91e97..482c6b8b 100644 --- a/internal/gateway/claude_subscription_rewind_test.go +++ b/internal/gateway/claude_subscription_rewind_test.go @@ -121,6 +121,22 @@ func (h *rewindHarness) giveUp(msgs string) { } } +// rewindAsked waits for the run given up on to be told to rewind. letGo +// runs on its own once the request has returned, and keeps the run for the +// resend just before it asks: a resend sent before that finds no run kept +// and starts a new one, and a rewind still under way reads rewindLongest +// as the next case sets it. A user rewording a message is never that quick. +func (h *rewindHarness) rewindAsked() { + h.t.Helper() + deadline := time.Now().Add(10 * time.Second) + for !strings.Contains(h.read(), "rewind_conversation") { + if time.Now().After(deadline) { + h.t.Fatalf("Claude Code was never told to rewind:\n%s", h.read()) + } + time.Sleep(10 * time.Millisecond) + } +} + func (h *rewindHarness) read() string { b, _ := os.ReadFile(h.log) return string(b) @@ -168,6 +184,7 @@ func TestClaudeTurnGivenUpOnIsRewound(t *testing.T) { } conv += `,` + rmsg("assistant", second) h.giveUp(`[` + conv + `,` + rmsg("user", "SLOW, go on") + `]`) + h.rewindAsked() again := h.ask(`[` + conv + `,` + rmsg("user", "go on instead") + `]`) if again != "pid "+pid+" turn 4" { t.Fatalf("the resend went to another Claude Code: %q (first %q)\n%s", again, first, h.read()) @@ -220,6 +237,7 @@ func TestClaudeTurnGivenUpOnNotRewound(t *testing.T) { second := h.ask(`[` + conv + `]`) conv += `,` + rmsg("assistant", second) h.giveUp(`[` + conv + `,` + rmsg("user", "SLOW, go on") + `]`) + h.rewindAsked() again := h.ask(`[` + conv + `,` + rmsg("user", "go on instead") + `]`) if pidOf(t, again) == pid || !strings.HasSuffix(again, " turn 1") { t.Fatalf("the resend: %q, first %q", again, first)