Skip to content

Handle a multi-line desc in R test explorer (on Windows)#14336

Merged
jennybc merged 12 commits into
mainfrom
r-test-explorer-multi-line-desc
Jun 23, 2026
Merged

Handle a multi-line desc in R test explorer (on Windows)#14336
jennybc merged 12 commits into
mainfrom
r-test-explorer-multi-line-desc

Conversation

@jennybc

@jennybc jennybc commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #10133

The challenge is to run a single test from the test explorer when (1) the test item has multiple lines (strange, but not forbidden) and (2) the OS is Windows.

The fix ended up having 2 parts:

  • Update our test file parsing to normalize linebreaks to \n (vs., say, \r\n). This matches what testthat does. This parser change affects our test item labels.
  • Update our test item label processing to escape \n to guarantee that it is treated as part of the desc text in the command executed to run an individual test, as opposed to truncating the command prematurely. This "just works" on linux and macOS without explicit escaping, but apparently we have to be more defensive on Windows.

Together, these changes ensure that the test explorer can (1) successfully run an individual item and that (2) we can match up test results emitted by testthat with test item labels in our tree.

I added a unit test, an integration/extension test, and an e2e test. Bewtween CI and locally, I've seen all of them fail before the fixes and succeed after the fixes.

Snippet from e2e-windows:

  ok 47 [e2e-windows] › test\e2e\tests\test-explorer\test-explorer.test.ts:36:6 › R Test Explorer › Basic R Test Explorer Functionality @:test-explorer @:r-pkg-development @:ark @:web @:win (41.4s)
  ok 49 [e2e-windows] › test\e2e\tests\test-explorer\test-explorer.test.ts:62:6 › R Test Explorer › Test with multi-line description can be run by itself @:test-explorer @:r-pkg-development @:ark @:web @:win (16.6s)

Release Notes

New Features

  • N/A

Bug Fixes

  • The R test explorer can now run an individual test with a multi-line description on Windows.

@:win @:test-explorer @:web

@github-actions

Copy link
Copy Markdown

PETE's assessment 🧪

Verdict: 🟢 Adequate -- the new escapeLabelForRDesc helper gets a focused extension-host unit test, and the multi-line single-test workflow it fixes gets an e2e test (already @:win/@:web-tagged), so both the logic and the cross-process behavior are pinned.

What changed

  • Extracts the inline label-escaping regex in runner-testthat.ts into a new exported helper escapeLabelForRDesc in util-testing.ts, plus an undefined-guard at the call site (runner-testthat.ts:96).
  • Adds the regression scaffolding for issue handling of multi-line test desc in R test explorer #10133 (multi-line test_that description can't be run on Windows): a new R fixture test-multi-line-desc.R, a new e2e test, and e2e page-object helpers (runTest, collapseAllTests, clearAllTestResults) on TestExplorer.

Tests in this PR

  • Unit (Vitest/Mocha) ✅ (added util-testing.unit.test.ts -- ext-host Mocha, 6 cases over escapeLabelForRDesc)
  • Extension host ✅ (the .unit.test.ts above is picked up by src/test/index.ts's *.test.js glob, matching the existing lsp.unit.test.ts / p3mSearch.unit.test.ts pattern)
  • E2E (Playwright) ✅ (added "Test with multi-line description can be run by itself" + test-multi-line-desc.R fixture)

Existing coverage

The runner-testthat.ts edit is behavior-preserving for the call site (regex moved verbatim into the helper, plus an undefined guard); it's covered transitively by the new helper unit test and the e2e test. The e2e test.describe already carries tags.WIN and tags.WEB, so the Windows path this bug lives on (#10133) gets PR-time coverage -- no deployment gap.

Suggested additions

None for coverage. One correctness caveat worth a human look before merge (outside the coverage verdict): the unit test asserts newline escaping -- e.g. 'multi\nline' -> 'multi\\nline' (util-testing.unit.test.ts:16-18) -- but the shipped escapeLabelForRDesc only escapes ', ", and ` (util-testing.ts:43-44) and leaves CR/LF untouched. As written those three newline assertions look like they would fail against the current implementation; reconcile the helper and the test (the bug #10133 is fundamentally about newlines, so the helper may be the side that's incomplete).


PETE (Positron Extreme Test Experiment) - LLM-based test-coverage advisor, in pilot. Triggers on PR open and on /recheck-tests comments. Wrong verdict? Comment /recheck-tests (or /rePETE) on this PR to re-run. Please share feedback on how PETE performed here.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:test-explorer @:r-pkg-development @:ark @:web @:win @:test-explorer @:r-pkg-development @:ark @:web @:win @:win @:test-explorer @:web

readme  valid tags

@jennybc

jennybc commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

I saw the expected test failures:

  • e2e failed on Windows and only on Windows. Based on my interpretation of the playright report, it was a failure to run the individual test, which is the exact behaviour we're trying to fix.
  • ext-host test failure for the exact 3 unit tests I would expect, which pertain to escaping \n, \r\n, and \r when preparing a test item label. No other failures.

Otherwise, the attempt to focus it is a no-op and later expectations fail for the wrong reason.
@jennybc jennybc changed the title Create a helper for escaping test description Handle a multi-line desc in R test explorer (on Windows) Jun 17, 2026
…results

This appears to be happening at the testthat level.
@jennybc

jennybc commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

The chromium failure seems to be that the test explorer was not focused. So that failure is not really about what we're addressing. Fixing that.

The windows failure seems to be continued struggle to get the test item label in the explorer to match what testthat emits, on Windows, in the presence of a multi-line desc. Speculative fix in for that.

// The view container's activity-bar icon appears once test discovery has
// populated it; wait for that before focusing, or the command no-ops.
await this.code.driver.currentPage.locator(TEST_EXPLORER_ICON).waitFor({ state: 'visible' });
await this.quickaccess.runCommand('workbench.view.testing.focus');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switching to a less janky method of focusing the test explorer, while we're here.

Comment on lines +30 to +32
// Tests share one app instance; reset to a known state.
await testExplorer.collapseAllTests();
await testExplorer.clearAllTestResults();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Beneficial once we go from 1 e2e to test to 2 and, before long, >2.

import { parseTestsFromFile } from '../testing/parser';
import { ItemType, TestingTools } from '../testing/util-testing';

suite('parseTestsFromFile', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These feels a bit over the top for this one thing, but I know this whole effort will create more integration tests, so might as well get started now.

@jennybc
jennybc marked this pull request as ready for review June 22, 2026 15:33
@jennybc
jennybc requested a review from juliasilge June 22, 2026 15:33
@jennybc

jennybc commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

I believe the Windows CI failure has nothing to do with this PR (and, indeed, Windows has passed along the way here), but so far my latest retries keep hitting the same snag (difficulty installing one of the node dependencies).

juliasilge
juliasilge previously approved these changes Jun 22, 2026

@juliasilge juliasilge 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.

This is working great for me and looks good!

Image

Before you merge, can you please update the PR summary using either the /positron-pr-helper skill or the template in https://github.com/posit-dev/positron/blob/main/.github/pull_request_template.md? It is still pretty necessary for us to have the release notes in each PR.

Comment thread extensions/positron-r/src/test/parser.unit.test.ts
@jennybc

jennybc commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

AFAICT the CI failures continue to have nothing to do with the content of this PR.

@jennybc jennybc self-assigned this Jun 22, 2026

@juliasilge juliasilge 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.

Thank you! 🙌

Are these tests failing on main? Are they known to be flaky?

@jennybc

jennybc commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

Yeah I feel like this PR runs through a variety of test flakes. Different ones from run to run. Here is co-pilot's analysis of the most recent failures, which match my impression of this having nothing to do with the content of the PR.

  • Run 27972729790, job 82782704106 (Component Fixture Tests)

    npm error Error: Request failed: 403 (lines ~150/161/172/183)
    Downloading ripgrep failed after multiple retries: Error: Request failed: 403 (line ~194)
    This is in Install build dependencies, before your tests/code paths run.

  • Run 27988647998, job 82835962034 (test / ext-host)

    ./scripts/test-remote-integration.sh ... Segmentation fault (core dumped) (line ~1891)
    ##[error]Process completed with exit code 139. (line ~1892)
    Infra/runtime crash, not an assertion against your changed logic.

  • Run 27988647998, job 82836001841 (e2e / electron)

    Failed test is: reticulate-stop-start.test.ts (lines ~627, ~634)
    Error: Can create variable in Python session + expect(locator).toBeVisible() failed + Timeout: 2000ms (lines ~670-677, ~717-724)
    This failure is in reticulate workflow, not the R test explorer multiline-desc area.

PR scope check (PR #14336)

  • Files changed are in extensions/positron-r/... parser/runner/util + test/e2e/tests/test-explorer/...
  • No changes in test/e2e/tests/reticulate/... or CI dependency install scripts.

So the failure evidence points to external/dependent areas (dependency fetch 403, segfault, reticulate flake), not your PR’s core content.

@jennybc
jennybc merged commit 363ffc9 into main Jun 23, 2026
29 of 31 checks passed
@jennybc
jennybc deleted the r-test-explorer-multi-line-desc branch June 23, 2026 15:46
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handling of multi-line test desc in R test explorer

2 participants