From 8ccdca794672a25f6a5433572601d42e2ee1b367 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 7 Jun 2026 18:17:44 +0200 Subject: [PATCH] fix: restore validation suite --- src/template_finder.py | 14 +++++++++++++- test/tools/test_new_route.py | 4 ++-- tools/_codemod.py | 15 ++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/template_finder.py b/src/template_finder.py index 0f73a4d..3076761 100644 --- a/src/template_finder.py +++ b/src/template_finder.py @@ -172,7 +172,19 @@ def search( match.valid = match.score >= threshold return match - # Multiple templates — parallel search + # Multiple templates default to first valid match in input order. + if not best_match: + best = TemplateMatch() + for template in templates: + match = _single_template_match(template, inp_img, roi, color_match, use_grayscale) + match.valid = match.score >= threshold + if match.score > best.score: + best = match + if match.valid: + return match + return best + + # Multiple templates with best_match=True return the highest score. matches = [] with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: futures = [ diff --git a/test/tools/test_new_route.py b/test/tools/test_new_route.py index 1b5e540..ab0599d 100644 --- a/test/tools/test_new_route.py +++ b/test/tools/test_new_route.py @@ -22,7 +22,7 @@ def _git_restore(): def _run(args, expect_rc=0): - r = subprocess.run(["python3", CLI] + args, cwd=PROJECT, + r = subprocess.run([sys.executable, CLI] + args, cwd=PROJECT, capture_output=True, text=True) if expect_rc != 0 and r.returncode == 0: raise AssertionError(f"Expected failure but got success: {r.stdout}") @@ -32,7 +32,7 @@ def _run(args, expect_rc=0): def _compile_ok(): - r = subprocess.run(["python3", "-m", "py_compile", "src/bot.py"], + r = subprocess.run([sys.executable, "-m", "py_compile", "src/bot.py"], cwd=PROJECT, capture_output=True, text=True) if r.returncode != 0: raise AssertionError(f"py_compile failed: {r.stderr}") diff --git a/tools/_codemod.py b/tools/_codemod.py index 9204cd8..ff58ce9 100644 --- a/tools/_codemod.py +++ b/tools/_codemod.py @@ -247,8 +247,7 @@ def insert_handler(bot_path, name, display): text = _read(bot_path) if "def on_run_" + name in text: return False - short = display[:3] if display else name[:3] - pat = r'( def on_run_[a-z_]+\(self\):.*?_ending_run_helper\(res\))' + pat = r'( def on_run_[a-z_]+\(self\):\n(?: [^\n]*\n)+)' matches = list(re.finditer(pat, text, re.DOTALL)) if not matches: raise ValueError("Cannot find existing handler pattern") @@ -256,14 +255,8 @@ def insert_handler(bot_path, name, display): h = [ "", " def on_run_" + name + "(self):", - " res = False", - " self._do_runs[" + Q2 + "run_" + name + Q2 + "] = False", - " self._game_stats.update_location(" + Q2 + short + Q2 + ")", - " self._curr_loc = self._" + name + ".approach(self._curr_loc)", - " if self._curr_loc:", - " set_pause_state(False)", - " res = self._" + name + ".battle(not self._pre_buffed)", - " self._ending_run_helper(res)", + " self._game_stats.update_location(" + Q2 + display + Q2 + ")", + " self._run_wrapper(" + Q2 + "run_" + name + Q2 + ", self._" + name + ", (), (not self._pre_buffed,))", ] handler = NL.join(h) + NL result = text[:last.end()] + handler + text[last.end():] @@ -274,7 +267,7 @@ def insert_handler(bot_path, name, display): def undo_handler(bot_path, name): text = _read(bot_path) pat = re.compile( - r'\n\s*def on_run_' + re.escape(name) + r'\(self\):.*?_ending_run_helper\(res\)\n', + r'\n\s*def on_run_' + re.escape(name) + r'\(self\):\n(?: [^\n]*\n)+', re.DOTALL ) t = pat.sub("", text)