Repository navigation
improve automation runner and add breakpoint regression tests - #17598
Conversation
Automation runner ergonomics: - exit 0 (not 143) on a clean `--run-automation` finish. rserver detects the self-sent SIGTERM from `onProcessExit` via a new `server::isShuttingDownForAutomation()` flag and calls `std::exit(0)` instead of re-raising, so external test harnesses can distinguish a clean automation completion from an aborted run. - tee R console output to `/tmp/rstudio-automation/console.log` and `std::cerr` when running under `--run-automation`. R's `cat`/ `writeLines`/`print` normally route to the IDE event queue only, so a headless test runner has no way to see test progress, testthat summaries, or the report-file paths the framework prints on completion. - add `test-automation-smoke.R` for fast harness iteration; pair with `--automation-filter="smoke"` to validate runner changes without a full test suite. Breakpoint regression tests (#9450): - `clicking a top-level breakpoint marker toggles it off` -- exercises `toggleBreakpointAtPosition` and asserts every gutter marker class is gone after the second click. - `Clear All Breakpoints removes every breakpoint marker` -- exercises `BreakpointManager.clearAllBreakpoints` end-to-end through the Yes/No confirmation dialog. - `cleared package breakpoints stay cleared across rebuild` -- mirrors the existing `#15201` package-build setup and asserts no marker reappears after `PackageLoadedEvent` re-runs `updatePackageBreakpoints` on the now-empty breakpoint list.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
onProcessExit now accepts the exit status from ChildProcessTracker and only marks the shutdown as clean (s_shuttingDownForAutomation = true) when the automation host rsession exited with status 0. Non-clean exits (crash, failed startup, signal kill, non-zero testthat status) leave the flag false, so ServerMain falls through to the conventional re-raise path and exits with 128+SIGTERM=143 -- surfacing the failure to external test harnesses rather than masking it as a clean run.
gtritchie
left a comment
There was a problem hiding this comment.
Review notes
Scope: clean exit-status wiring, console tee, and three regression tests for #9450. Below is a triaged set of findings — no blockers.
Important
-
Misleading log when the automation host is killed by a signal —
src/cpp/server/session/ServerSessionManager.cpp:304-308
ChildProcessTrackeronly rewritesstatusviaWEXITSTATUSforWIFEXITED; forWIFSIGNALEDit forwards the raw waitpid status word. The new log prints that verbatim — so a SIGKILL'd host logs"exited with status 9"while a literalexit(9)logs"exited with status 2304". Suggest decoding:if (WIFEXITED(exitStatus)) ... WEXITSTATUS(exitStatus) else if (WIFSIGNALED(exitStatus)) ... WTERMSIG(exitStatus)
The
exitStatus == 0predicate itself is fine —WIFSIGNALEDnever produces 0. -
swallowErrors = TRUEhides build crashes —test-automation-debugger.R(the two "build has completed" / "rebuild has completed" waits)
IfbuildAllcrashes the rsession, the wait silently times out and the subsequentgutterEls[[3]]fails with a confusing subscript error rather than "the build crashed." Worth asserting build success (e.g. absence of an error string, or a build-pane indicator) before proceeding. -
Hardcoded
/tmp/rstudio-automationis not portable —src/cpp/session/SessionMain.cpp(new tee block)
SessionMain.cppcompiles on Windows andrunAutomationisn't POSIX-gated at the call site. On Windows this createstmp\rstudio-automationon the current drive; on systemdPrivateTmp=trueservices it fails opaquely. Either gate the block#ifndef _WIN32or build the path fromcore::system::FilePath::tempFilePath(). Also worth logging whenstream.open()itself fails (currently onlyensureDirectoryerrors are surfaced). -
No test covers the non-clean exit path —
test-automation-smoke.Ronly validates the status-0 case. A future regression making rserver alwaysstd::exit(0)would silently mask test failures from external CI. A failing-smoke variant (e.g.stop()in the test, plus a harness-wrapper assertion of non-zero rserver exit) would close this.
Suggestions
-
Simpler initializer — the double function-local-static in the tee block (
static std::ofstream& = []() -> std::ofstream& { static std::ofstream stream; ...; return stream; }()) has two statics where one suffices.std::ofstreamis movable; the body could bestatic std::ofstream automationLog = []{ std::ofstream s; ...; return s; }();. -
Triplicate comment — the SIGTERM/143 invariant is re-explained at
ServerMain.cpp:539-547,ServerSessionManager.cpp:71-80, and again at:307-313. Patch 2 had to update all three in sync. Consolidating to one anchor at the flag declaration with short pointer-comments at the other two sites would reduce drift risk. -
Fragile fixed-duration waits —
Sys.sleep(1)in thewithr::deferandSys.sleep(0.1)aftereditor$insert(code)in the package-rebuild test. Predicate-based.rs.waitUntilwould be more reliable on slow CI. -
Magic offsets —
-6L(top-level click) vs-4L(function/package click). The latter mirrors#15201; a one-line "why different" comment would prevent future copy-paste confusion. -
s_shuttingDownForAutomationis one-shot — never reset. Correct for the current model (host exits once, rserver dies right after), but a one-line note at the declaration would head off future "should this be reset?" questions.
Verified sound
boost::bind(onProcessExit, username, pid, _2)correctly forwards exit status —ChildProcessTracker::ExitHandlerisboost::function<void(PidType,int)>.exitStatus == 0is a correct clean-exit predicate across all ofWIFEXITED/WIFSIGNALED/WIFSTOPPED.- Memory ordering of
s_shuttingDownForAutomation.store(...)before::kill(...)is fine — the sigwait thread sees the store via the kernel synchronization point. std::exit(0)runs static destructors that the re-raise path skips — that's more cleanup, not less. Fine as-is; callingclearSignalMask()first would be symmetric but isn't required.
Strengths
- Comments consistently explain why (143-vs-0 distinction, the dual-sink rationale for the tee, the offset choices).
- The two-commit split (initial; then patch 2 to preserve non-zero status) caught and closed the one material correctness gap before review.
- Triple-class marker assertion (
ace_breakpoint+ace_pending-breakpoint+ace_inactive-breakpoint) is exactly right for #9450 — catches any state a sticky marker could be stuck in. - Tests assert on visible DOM and go through user-facing commands (
debugClearBreakpoints+ Yes/No dialog) — behavior testing, not implementation coupling. - Atomic flag, self-PID-targeted
kill,std::exit(0)over_exit(0)— all chosen correctly.
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some fit & finish-ish feedback from the LLM.
- decode raw waitpid status in ChildProcessTracker callbacks so the shutdown log distinguishes a normal exit from a signal kill (WIFEXITED / WIFSIGNALED); previously a SIGKILL and exit(N) could log the same bare number - gate the automation stderr tee on isatty(STDERR_FILENO) so the live output stops duplicating into whatever pipe captured stderr (e.g. the host RStudio's Console when an automation run is triggered from inside another RStudio); the log file at /tmp/rstudio-automation always receives the full transcript - gate the tee block with #ifndef _WIN32 and log a warning when the log file fails to open - fail loud in the package-rebuild breakpoint test when buildAll crashes or emits an error, instead of timing out generically and surfacing a confusing subscript error downstream - replace Sys.sleep(0.1) after editor$insert with a content-check predicate; keep the Sys.sleep(1) in the cleanup defer with a comment explaining the defensive pause - add comments explaining why top-level breakpoints use horizontalOffset -6L while package-function breakpoints use -4L - consolidate the triplicate SIGTERM/143 comment to the s_shuttingDownForAutomation declaration; note that the flag is intentionally one-shot
Summary
Two related improvements to the BRAT automation harness, plus regression tests for issue #9450 (sticky breakpoints):
rsessionexits,ServerSessionManagerself-sends SIGTERM to shut downrserver. The signal-wait loop inServerMainpreviously re-raised SIGTERM, terminating with status 143 (128 + SIGTERM) -- indistinguishable to external test harnesses from an aborted run. Now we mark the automation shutdown path viaisShuttingDownForAutomation()andstd::exit(0)instead; externally-delivered SIGTERMs still re-raise as before.rConsoleWrite()now tees R's console output to both the inherited stderr (so a controlling terminal likerserver-devsees it live) and/tmp/rstudio-automation/console.log(for post-run inspection) whenrunAutomation()is set. Without this, the only sink for console output was the IDE event queue, which a headless test runner can't observe.test-automation-debugger.Rcover top-level breakpoint toggle, Clear All Breakpoints, and package-breakpoint persistence across a rebuild. Addstest-automation-smoke.Rfor iterating on the harness itself without running the full debugger suite.Test plan
./rserver-dev --run-automation --automation-filter=automation-smokeexits with status 0 and prints console output to the terminal./rserver-dev --run-automation --automation-filter=automation-debugger-- all three new breakpoint tests passkill <rserver-pid>still exits with status 143 (verify the automation-path check doesn't swallow real SIGTERMs)