test(amber-python): add unit tests for Udon debugger#4510
Merged
Yicong-Huang merged 6 commits intoApr 26, 2026
Conversation
Adds two pytest modules covering the previously-untested Python runtime of the Udon UDF debugger: - test_debug_manager.py: command/event pipe state, prompt initialization, flushed-output round-trip, pipe independence. - test_debug_command_handler.py: translate_debug_command rewrites b/break with module:lineno, preserves condition arg, passes other commands through, and strips whitespace. Closes apache#4509
Added 9 more cases on top of the initial 13: - DebugManager: Pdb is wired to debug_in/debug_out (round-trip via the debugger's stdin/stdout), event pipe supports successive round-trips, Pdb is constructed with nosigint=True. - WorkerDebugCommandHandler.translate_debug_command: internal whitespace is collapsed, break-with-only-lineno emits no trailing space. - WorkerDebugCommandHandler.debug_command (async): translates then forwards to debug_manager, resumes USER/EXCEPTION/DEBUG pause types in order, returns EmptyReturn, passes non-break commands through. Driven via asyncio.run to avoid pulling in pytest-asyncio. Refs apache#4509
Adds 12 more cases pinning the debugger's behavior on inputs the frontend isn't expected to send today, so that future changes to either side surface as test failures rather than silent regressions: - DebugManager: empty command, repeated put without consume (silent overwrite), embedded-newline command passed verbatim, event pipe overwrite-on-second-flush. - translate_debug_command: empty/whitespace-only raise ValueError, case-sensitive `b`/`break` match, function-name and explicit filename:line args are still module-prefixed, None module_name renders as the string "None". - debug_command async: empty cmd propagates the ValueError; on a translation failure neither put_debug_command nor resume runs. Refs apache#4509
CI's `ruff format --check` step rejected the previous commits' line wrapping. Reformatted with the project's pinned ruff 0.14.7. No test behavior changes.
2 tasks
This was referenced Apr 26, 2026
Yicong-Huang
added a commit
that referenced
this pull request
Apr 27, 2026
…input (#4512) ### What changes were proposed in this PR? Fixes four correctness gaps in `WorkerDebugCommandHandler.translate_debug_command` that were pinned as quirks by the unit tests added in #4510: | Input | Before | After | | --- | --- | --- | | `""` / `" "` | `ValueError: not enough values to unpack` | `ValueError("debug command cannot be empty")` | | `b foo.py:5` | `b my_udf:foo.py:5` (rejected by pdb) | `b foo.py:5` (passed through) | | `b my_func` | `b my_udf:my_func` (rejected by pdb — filename prefix requires lineno) | `b my_func` (passed through; pdb resolves the symbol) | | `b 5` with `operator_module_name = None` | `b None:5` (no such module) | `ValueError("executor module not initialized; cannot set breakpoint")` | The rule is now: **only prepend `module:` when the target is a numeric line in the operator's own UDF module.** Function-name and explicit `filename:lineno` forms — both of which pdb already accepts — pass through unchanged. ### Any related issues, documentation, discussions? Closes #4511. Follow-up to #4510 (which introduced the tests that exposed these gaps). ### How was this PR tested? - Updated the four pinning tests from #4510 (`test_break_with_function_name_*`, `test_break_with_explicit_filename_*`, `test_module_name_none_*`, `test_empty_command_*`) to assert the new intentional behaviors. - Added one new test for the function-name fallback when the executor module isn't initialized yet. - Local: `python -m pytest core/architecture/managers/test_debug_manager.py core/architecture/handlers/control/test_debug_command_handler.py` — 35 passed. - Local: `ruff format --check .` and `ruff check .` — clean. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
Yicong-Huang
added a commit
that referenced
this pull request
Apr 27, 2026
…current-tuple handlers (#4520) ### What changes were proposed in this PR? Adds unit tests for the two debugger-adjacent worker RPC handlers that had no Python coverage: - **`test_evaluate_expression_handler.py`** (4 cases) — covers `EvaluateExpressionHandler.evaluate_python_expression`, which backs the frontend's "watch variable" feature. Verifies the evaluator's return is passed through unchanged, the runtime context exposes the executor as `self` / current tuple as `tuple_` / current port id as `input_`, the context is read fresh on each call (not snapshot at handler construction), and the handler tolerates `None` tuple/port (worker before any input has arrived). - **`test_replay_current_tuple_handler.py`** (6 cases) — covers `RetryCurrentTupleHandler.retry_current_tuple` (used by debugger "step over an exception" flows). Verifies it chains the current tuple onto the front of the input iterator, resumes `USER_PAUSE` + `EXCEPTION_PAUSE` in order, **does not** resume `DEBUG_PAUSE` (so an active debugging session is not silently dropped), no-ops when the worker is `COMPLETED`, and still chains correctly when the remaining iterator is empty. No production code is touched. Async handlers are driven via `asyncio.run` to avoid pulling in `pytest-asyncio`, matching the pattern from #4510 / #4512. ### Any related issues, documentation, discussions? Closes #4516. Same gap pattern as #4509. ### How was this PR tested? ``` $ python -m pytest core/architecture/handlers/control/test_evaluate_expression_handler.py \ core/architecture/handlers/control/test_replay_current_tuple_handler.py -v ======================== 10 passed in 1.14s ======================== ``` `ruff format --check .` and `ruff check .` clean locally. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Adds the first Python-side unit tests for the Udon UDF debugger:
test_debug_manager.py(6 cases) — coversDebugManager's init state, command/event pipe checks,prompt == "", flushed-output round-trip viaPdb.stdout, and independence of the command vs event pipes.test_debug_command_handler.py(7 cases) — coversWorkerDebugCommandHandler.translate_debug_command:b/breakwith lineno prependsmodule:, condition arg is preserved, no-argbfalls through, non-break commands pass through, and whitespace is stripped.No production code is touched.
Any related issues, documentation, discussions?
Closes #4509
How was this PR tested?
Ran the new tests locally with the project's shared venv:
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.7)