Skip to content

fix(workbench): escape embedded newline before typing job script into console#536

Closed
ianpittwood wants to merge 1 commit into
mainfrom
fix/job-write-script-truncation
Closed

fix(workbench): escape embedded newline before typing job script into console#536
ianpittwood wants to merge 1 commit into
mainfrom
fix/job-write-script-truncation

Conversation

@ianpittwood

Copy link
Copy Markdown
Contributor

Fixes #535

Summary

  • _JOB_SCRIPT_CONTENT embeds a real newline between its two R statements. write_test_script only escaped quotes before typing the writeLines() call into the console, so that raw newline reached Playwright's type(), which aliases embedded \n/\r to the Enter key — submitting the command early and splitting it into two invalid R statements. The script file was never created, which the file.exists() check added in fix(workbench): harden Workbench Job flow against write/chooser races #528 now catches loudly as VIP_JOB_SCRIPT_CHECK: FALSE.
  • Added _escape_for_r_string_literal(), which escapes quotes and newlines/carriage-returns, used at the writeLines() call site.
  • _run_console_command() now asserts no raw \n/\r reaches type(), enforcing its documented "single-line" contract for any future caller.

Test plan

  • ruff check / ruff format --check clean
  • mypy clean
  • New selftest (selftests/test_job_script_escaping.py) passes
  • Live verification against a real Workbench deployment (not run — no deployment available in this environment)

🤖 Generated with Claude Code

… console

_JOB_SCRIPT_CONTENT embeds a real newline between its two R statements.
write_test_script only escaped quotes before typing the writeLines() call
into the console, so the raw newline reached Playwright's type(), which
aliases embedded \n/\r to the Enter key — submitting the command early and
splitting it into two invalid R statements. The script file was never
created, which the file.exists() check added in #528 now catches loudly as
"VIP_JOB_SCRIPT_CHECK: FALSE".

Escape the newline into the R string literal (like the quotes already are)
so the console receives one line. Also assert in _run_console_command that
no raw newline reaches type(), since its contract is a single-line command.
Copilot AI review requested due to automatic review settings July 24, 2026 20:04
@samcofer

Copy link
Copy Markdown
Contributor

Lol, I literally just fixed this! Sorry about that! The GHA is running now and should be resolved soon for the newest release!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes the Workbench Jobs tests’ console script-writing regression where an embedded newline in _JOB_SCRIPT_CONTENT was being typed into the RStudio console as an Enter keypress (via Playwright type()), splitting the writeLines() command and preventing the script file from being created.

Changes:

  • Added _escape_for_r_string_literal() to escape quotes and newline/CR characters before embedding content in a one-line R string literal.
  • Hardened _run_console_command() with a contract check to prevent raw \n/\r from reaching Playwright typing.
  • Added a selftest to validate escaping removes raw newline and carriage-return characters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vip_tests/workbench/test_jobs.py Adds newline/CR guard to console typing and introduces/uses an R string-literal escaping helper for the job script write step.
selftests/test_job_script_escaping.py Adds a regression selftest validating the escaping helper removes raw newline/CR characters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +218 to +221
assert "\n" not in r_cmd and "\r" not in r_cmd, (
f"r_cmd contains a raw newline, which Playwright's type() would submit as "
f"a premature Enter keypress: {r_cmd!r}"
)
Comment on lines +1 to +8
"""Guard against a raw newline reaching the console as a premature Enter keypress.

``_run_console_command`` types R commands via Playwright's ``type()``, which
aliases embedded "\n"/"\r" characters to the Enter key — a raw newline in the
command submits it early, splitting it into two invalid R statements (see the
regression where ``write_test_script``'s ``writeLines()`` call never created
the test job script).
"""
@samcofer

Copy link
Copy Markdown
Contributor

You should be able to use version 58.7, which won't just skip and should work on version 2026.06 and 2026.07

@samcofer

Copy link
Copy Markdown
Contributor
samcofer@SamsWorkLaptop2:aws-sol-arch-demo/vip$ uv tool install posit-vip --upgrade
Resolved 36 packages in 274ms
Prepared 1 package in 109ms
Uninstalled 1 package in 2ms
Installed 1 package in 7ms
 - posit-vip==0.58.6
 + posit-vip==0.58.7
Installed 1 executable: vip
samcofer@SamsWorkLaptop2:aws-sol-arch-demo/vip$ vip verify --config vip.toml --interactive-auth --filter workbench_job -- -n 0
>>> Reusing cached auth session from /home/samcofer/.vip-auth-cache.json
============================================================================================================================= test session starts =============================================================================================================================
collected 142 items / 141 deselected / 1 skipped / 1 selected

workbench/test_jobs.py::test_workbench_job[chromium]
workbench/test_jobs.py::test_workbench_job[chromium] PASSED                                                                                                                                                                                                             [100%]

================================================================================================================ 1 passed, 1 skipped, 141 deselected in 51.91s ================================================================================================================
samcofer@SamsWorkLaptop2:aws-sol-arch-demo/vip$

@ianpittwood

Copy link
Copy Markdown
Contributor Author

Hahaha thanks @samcofer!

@github-actions

Copy link
Copy Markdown

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.

test_jobs.py: embedded raw newline in _JOB_SCRIPT_CONTENT breaks writeLines() console write

3 participants