From 938b2cb71451d48b6b107f19e6180db2077c29e1 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 13 Jul 2026 08:21:49 +0530 Subject: [PATCH] test(runner): cover weight-suffixed echo and stripWeightSuffix --- internal/runner/llm_source_test.go | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/runner/llm_source_test.go b/internal/runner/llm_source_test.go index 2c9c9a2..057f583 100644 --- a/internal/runner/llm_source_test.go +++ b/internal/runner/llm_source_test.go @@ -12,6 +12,7 @@ import ( "net/http" "net/http/httptest" "slices" + "strconv" "strings" "testing" @@ -338,6 +339,43 @@ func TestLLMSourceSkipsOnOutOfRangeChoice(t *testing.T) { } } +func TestLLMSourceAcceptsEchoWithWeightSuffix(t *testing.T) { + // Real models copy the whole numbered line, including its trailing "(w34)" + // weight annotation. That must still count as a match, not a strict skip. + fake := newFakeOpenRouter(t) + source, verifierInstance := newLLMSource(t, fake) + pushLLMSnapshot(t, verifierInstance) + candidates := verifierInstance.Candidates() + + tap := candidateByKind(t, candidates, verifier.ActionKindTap) + fake.choice = tap.Index + fake.chosenAction = tap.Description + " (w" + strconv.Itoa(tap.Weight) + ")" + action, err := source.NextAction(context.Background()) + if err != nil { + t.Fatalf("NextAction: %v", err) + } + if action.Kind != verifier.ActionKindTap { + t.Errorf("action = %+v, want Tap; the weight-suffixed echo was wrongly rejected", action) + } + if source.lastSource != "llm" { + t.Error("weight-suffixed echo should be accepted, not strict-skipped") + } +} + +func TestStripWeightSuffix(t *testing.T) { + cases := map[string]string{ + `Tap "+ Add account" (w34)`: `Tap "+ Add account"`, + `Tap "Sign in"`: `Tap "Sign in"`, + `Scroll down (w7)`: `Scroll down`, + ` Tap "x" (w1) `: `Tap "x"`, + } + for in, want := range cases { + if got := stripWeightSuffix(in); got != want { + t.Errorf("stripWeightSuffix(%q) = %q, want %q", in, got, want) + } + } +} + func TestLLMSourceStrictSkipsOnEchoMismatch(t *testing.T) { fake := newFakeOpenRouter(t) source, verifierInstance := newLLMSource(t, fake)