From 5f69331bfd066d478930fdbff8b50654f6ca6161 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 07:30:23 +0000 Subject: [PATCH] Add edge case test for serve.py record_line Introduces a new unit test, `test_record_line_edge_cases`, inside `tests/test-process.py` to cover parsing failures, incorrect JSON formats, missing keys, and invalid progress values for the `record_line` function in `lib/linux/serve.py`. This explicitly verifies that erroneous edge cases gracefully fail without corrupting the shared global RUN and LOG state. Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com> --- tests/test-process.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test-process.py b/tests/test-process.py index 9b792fb..ec2d057 100644 --- a/tests/test-process.py +++ b/tests/test-process.py @@ -34,6 +34,26 @@ def test_server_counts_completion_not_started_lines(self): server.record_line('@@AUTOOS_PROGRESS {"done":4,"total":3}') self.assertEqual(server.RUN['done'], 1) + def test_record_line_edge_cases(self): + server = load('autoos_serve', 'lib/linux/serve.py') + server.RUN.update(done=0, total=3, current=None) + server.LOG.clear() + + cases = [ + '@@AUTOOS_PROGRESS {broken', # json.JSONDecodeError (ValueError) + '@@AUTOOS_PROGRESS "string"', # TypeError (when int() fails on dict lookup) + '@@AUTOOS_PROGRESS {"done": "x"}', # KeyError (missing total) / ValueError (int("x")) + '@@AUTOOS_PROGRESS {"total": 3}', # KeyError (missing done) + '@@AUTOOS_PROGRESS {"done": -1, "total": 3}', # Out of bounds: done < 0 + '@@AUTOOS_PROGRESS {"done": 4, "total": 3}', # Out of bounds: done > total + '@@AUTOOS_PROGRESS {"done": 1}', # KeyError (missing total) + ] + + for case in cases: + server.record_line(case) + self.assertEqual(server.RUN['done'], 0) + self.assertEqual(len(server.LOG), 0) + def test_unknown_percentage_stays_null(self): runner = load('autoos_process', 'lib/linux/process.py') output = io.StringIO()