okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9adf4e01a
main
1<|im_start|>system 2You are a coding agent working in the user's repository. You can call tools to read files, search the code and run commands. Keep changes small and explain what you did.<|im_end|> 3<|im_start|>user 4The test `test_parse_duration` fails since yesterday's merge. Can you find out why and fix it?<|im_end|> 5<|im_start|>assistant 6<think> 7I should run the failing test first to see the actual error message, then look at the function it tests. 8</think> 9 10<tool_call> 11{"name": "run_command", "arguments": {"command": "python -m pytest tests/test_time_utils.py -k test_parse_duration -q"}} 12</tool_call><|im_end|> 13<|im_start|>user 14<tool_response> 15F [100%] 16=================================== FAILURES =================================== 17_____________________________ test_parse_duration ______________________________ 18 19 def test_parse_duration(): 20 assert parse_duration("90s") == 90 21 assert parse_duration("5m") == 300 22> assert parse_duration("1h30m") == 5400 23E ValueError: invalid duration: '1h30m' 24 25tests/test_time_utils.py:14: ValueError 261 failed, 11 deselected in 0.21s 27</tool_response><|im_end|> 28<|im_start|>assistant 29<think> 30Single units work but a combined value fails. Let me read the parser. 31</think> 32 33<tool_call> 34{"name": "read_file", "arguments": {"path": "src/time_utils.py", "start_line": 1, "end_line": 40}} 35</tool_call><|im_end|> 36<|im_start|>user 37<tool_response> 38import re 39 40_UNITS = {"s": 1, "m": 60, "h": 3600, "d": 86400} 41_PART = re.compile(r"^(\d+)([smhd])$") 42 43 44def parse_duration(text: str) -> int: 45 """Parse a duration like '90s', '5m' or '1h30m' into seconds.""" 46 text = text.strip().lower() 47 if not text: 48 raise ValueError("empty duration") 49 m = _PART.match(text) 50 if m is None: 51 raise ValueError(f"invalid duration: {text!r}") 52 return int(m.group(1)) * _UNITS[m.group(2)] 53</tool_response><|im_end|> 54<|im_start|>assistant 55<think> 56The regex is anchored at both ends and matches exactly one number-unit pair, so "1h30m" can never match. The docstring promises combined values. Let me check git history to see what the merge changed. 57</think> 58 59<tool_call> 60{"name": "run_command", "arguments": {"command": "git log -p -n 1 -- src/time_utils.py | head -40"}} 61</tool_call><|im_end|> 62<|im_start|>user 63<tool_response> 64commit 4e1b9c2f7a0d (Merge branch 'cleanup-regex') 65 Simplify duration parsing 66 67-_PART = re.compile(r"(\d+)([smhd])") 68+_PART = re.compile(r"^(\d+)([smhd])$") 69@@ def parse_duration(text: str) -> int: 70- total = 0 71- pos = 0 72- for m in _PART.finditer(text): 73- if m.start() != pos: 74- raise ValueError(f"invalid duration: {text!r}") 75- total += int(m.group(1)) * _UNITS[m.group(2)] 76- pos = m.end() 77- if pos != len(text): 78- raise ValueError(f"invalid duration: {text!r}") 79- return total 80+ m = _PART.match(text) 81+ if m is None: 82+ raise ValueError(f"invalid duration: {text!r}") 83+ return int(m.group(1)) * _UNITS[m.group(2)] 84</tool_response><|im_end|> 85<|im_start|>assistant 86The cleanup merge replaced the loop over all number-unit pairs with a single anchored match, so only one unit per string is accepted now. I will restore the loop, which also rejects garbage between the parts. 87 88<tool_call> 89{"name": "edit_file", "arguments": {"path": "src/time_utils.py", "old": "_PART = re.compile(r\"^(\\d+)([smhd])$\")", "new": "_PART = re.compile(r\"(\\d+)([smhd])\")"}} 90</tool_call><|im_end|> 91<|im_start|>user 92<tool_response> 93OK: 1 replacement in src/time_utils.py 94</tool_response><|im_end|> 95<|im_start|>assistant 96<tool_call> 97{"name": "edit_file", "arguments": {"path": "src/time_utils.py", "old": " m = _PART.match(text)\n if m is None:\n raise ValueError(f\"invalid duration: {text!r}\")\n return int(m.group(1)) * _UNITS[m.group(2)]", "new": " total = 0\n pos = 0\n for m in _PART.finditer(text):\n if m.start() != pos:\n raise ValueError(f\"invalid duration: {text!r}\")\n total += int(m.group(1)) * _UNITS[m.group(2)]\n pos = m.end()\n if pos != len(text):\n raise ValueError(f\"invalid duration: {text!r}\")\n return total"}} 98</tool_call><|im_end|> 99<|im_start|>user 100<tool_response> 101OK: 1 replacement in src/time_utils.py 102</tool_response><|im_end|> 103<|im_start|>assistant 104<tool_call> 105{"name": "run_command", "arguments": {"command": "python -m pytest tests/test_time_utils.py -q"}} 106</tool_call><|im_end|> 107<|im_start|>user 108<tool_response> 109............ [100%] 11012 passed in 0.19s 111</tool_response><|im_end|> 112<|im_start|>assistant 113All 12 tests in `tests/test_time_utils.py` pass again. The cause was the `cleanup-regex` merge: it anchored the pattern with `^...$` and replaced the loop with one `match`, so a duration with several parts such as `1h30m` was rejected. I restored the previous loop, which sums every number-unit pair and still raises `ValueError` for text between or after the parts (for example `1h x30m`). You may want to add a test for that rejection case so the next simplification does not drop it.<|im_end|>