Skip to content

improve automation runner and add breakpoint regression tests - #17598

Merged
kevinushey merged 3 commits into
mainfrom
developer/automation-runner-improvements
May 12, 2026
Merged

kevinushey merged 3 commits into
mainfrom
developer/automation-runner-improvements

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

Two related improvements to the BRAT automation harness, plus regression tests for issue #9450 (sticky breakpoints):

  • Clean exit status for automation runs. When the automation host rsession exits, ServerSessionManager self-sends SIGTERM to shut down rserver. The signal-wait loop in ServerMain previously 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 via isShuttingDownForAutomation() and std::exit(0) instead; externally-delivered SIGTERMs still re-raise as before.
  • Visible console output during automation. rConsoleWrite() now tees R's console output to both the inherited stderr (so a controlling terminal like rserver-dev sees it live) and /tmp/rstudio-automation/console.log (for post-run inspection) when runAutomation() is set. Without this, the only sink for console output was the IDE event queue, which a headless test runner can't observe.
  • Regression tests for breakpoints do not disappear on click #9450. Three new tests in test-automation-debugger.R cover top-level breakpoint toggle, Clear All Breakpoints, and package-breakpoint persistence across a rebuild. Adds test-automation-smoke.R for iterating on the harness itself without running the full debugger suite.

Test plan

  • ./rserver-dev --run-automation --automation-filter=automation-smoke exits with status 0 and prints console output to the terminal
  • ./rserver-dev --run-automation --automation-filter=automation-debugger -- all three new breakpoint tests pass
  • An externally-delivered kill <rserver-pid> still exits with status 143 (verify the automation-path check doesn't swallow real SIGTERMs)

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.
@kevinushey kevinushey added this to the Golden Wattle milestone May 11, 2026
@posit-snyk-bot

posit-snyk-bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 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 gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Misleading log when the automation host is killed by a signal — src/cpp/server/session/ServerSessionManager.cpp:304-308
    ChildProcessTracker only rewrites status via WEXITSTATUS for WIFEXITED; for WIFSIGNALED it forwards the raw waitpid status word. The new log prints that verbatim — so a SIGKILL'd host logs "exited with status 9" while a literal exit(9) logs "exited with status 2304". Suggest decoding:

    if (WIFEXITED(exitStatus)) ... WEXITSTATUS(exitStatus)
    else if (WIFSIGNALED(exitStatus)) ... WTERMSIG(exitStatus)

    The exitStatus == 0 predicate itself is fine — WIFSIGNALED never produces 0.

  2. swallowErrors = TRUE hides build crashes — test-automation-debugger.R (the two "build has completed" / "rebuild has completed" waits)
    If buildAll crashes the rsession, the wait silently times out and the subsequent gutterEls[[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.

  3. Hardcoded /tmp/rstudio-automation is not portable — src/cpp/session/SessionMain.cpp (new tee block)
    SessionMain.cpp compiles on Windows and runAutomation isn't POSIX-gated at the call site. On Windows this creates tmp\rstudio-automation on the current drive; on systemd PrivateTmp=true services it fails opaquely. Either gate the block #ifndef _WIN32 or build the path from core::system::FilePath::tempFilePath(). Also worth logging when stream.open() itself fails (currently only ensureDirectory errors are surfaced).

  4. No test covers the non-clean exit path — test-automation-smoke.R only validates the status-0 case. A future regression making rserver always std::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

  1. 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::ofstream is movable; the body could be static std::ofstream automationLog = []{ std::ofstream s; ...; return s; }();.

  2. 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.

  3. Fragile fixed-duration waits — Sys.sleep(1) in the withr::defer and Sys.sleep(0.1) after editor$insert(code) in the package-rebuild test. Predicate-based .rs.waitUntil would be more reliable on slow CI.

  4. 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.

  5. s_shuttingDownForAutomation is 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::ExitHandler is boost::function<void(PidType,int)>.
  • exitStatus == 0 is a correct clean-exit predicate across all of WIFEXITED/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; calling clearSignalMask() 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 gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@kevinushey
kevinushey merged commit 309a50a into main May 12, 2026
8 checks passed
@kevinushey
kevinushey deleted the developer/automation-runner-improvements branch May 12, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants