_resolve_test_rel: fix absolute-py regex mis-match on tests/ prefix (fixes #1)

The absolute regex r'/[\w./-]+\.py\b' was matching the '/' inside
'tests/test_<name>.py', capturing '/test_<name>.py' instead of the
correct 'tests/test_<name>.py'.

Fix:
- Move the tests/ relative regex above the absolute .py regex so it
  matches first for any path containing 'tests/'
- Add (?<!\w) boundary guard to all three absolute-path regexes
  (/test|spec, /_test.*, /.*.py) so they only match when the leading
  '/' is at a word boundary (start of string, space, colon, etc.),
  preventing them from snatching a '/' in the middle of a relative path

Applied to running systems: boltzmann and hertz (/usr/local/bin/).
This commit is contained in:
Markus Fritsche
2026-07-25 08:27:50 +00:00
parent d90f0b87ff
commit 95d261e12d
+4 -4
View File
@@ -511,11 +511,11 @@ def _resolve_test_rel(body, repo):
the grind host, but this parser only knew tests/*.py and *_test.go, so every @jsdev ticket
was silently bounced. An absolute match fully specifies the grind — serve() derives the repo
from its directory (2026-07-24)."""
m = (re.search(r"/[\w./-]+\.(?:test|spec)\.(?:js|ts)\b", body or "") # absolute JS/TS spec
or re.search(r"/[\w./-]+_test\.(?:js|ts|go|py)\b", body or "") # absolute *_test.*
or re.search(r"/[\w./-]+\.py\b", body or "") # absolute py
m = (re.search(r"(?<!\w)/[\w./-]+\.(?:test|spec)\.(?:js|ts)\b", body or "") # absolute JS/TS spec (guarded)
or re.search(r"(?<!\w)/[\w./-]+_test\.(?:js|ts|go|py)\b", body or "") # absolute *_test.* (guarded)
or re.search(r"tests/[\w./-]+\.py", body or "") # tests/ relative py
or re.search(r"(?<!\w)/[\w./-]+\.py\b", body or "") # absolute py (guarded)
or re.search(r"[\w./-]*(?:\.test|\.spec|_test)\.(?:js|ts)\b", body or "") # relative JS/TS
or re.search(r"tests/[\w./-]+\.py", body or "")
or re.search(r"[\w./-]+_test\.go", body or ""))
if m:
return m.group(0), None