From 2892dff95dcc48104de02ee99bf66e781f9f0e32 Mon Sep 17 00:00:00 2001 From: Rodin Date: Fri, 15 May 2026 01:51:19 -0700 Subject: [PATCH] refactor(#154): use flag-name lookup in InvalidRepo and InvalidPRNumber tests Make the override code robust against base-arg order changes: search for the flag name ('--repo', '--pr') and replace the following value, rather than searching for the value string itself. This prevents a subtle bug if the same value appeared elsewhere in the base args before the target flag. --- cmd/review-bot/main_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/review-bot/main_test.go b/cmd/review-bot/main_test.go index f52099b..4492239 100644 --- a/cmd/review-bot/main_test.go +++ b/cmd/review-bot/main_test.go @@ -902,10 +902,10 @@ func TestMainSubprocess_InvalidRepo(t *testing.T) { if os.Getenv("TEST_SUBPROCESS_MAIN") == "1" { flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) args := baseSubprocessArgs() - // Replace the canonical --repo with an invalid one. + // Replace the canonical --repo value with an invalid one. for i, a := range args { - if a == "owner/repo" { - args[i] = "invalidrepo" + if a == "--repo" && i+1 < len(args) { + args[i+1] = "invalidrepo" break } } @@ -931,8 +931,8 @@ func TestMainSubprocess_InvalidPRNumber(t *testing.T) { args := baseSubprocessArgs() // Replace the canonical --pr value with a non-numeric string. for i, a := range args { - if a == "1" { - args[i] = "notanumber" + if a == "--pr" && i+1 < len(args) { + args[i+1] = "notanumber" break } }