Skip to content

fix windows .lnk shortcut tests on ci: short-path home defeats home aliasing - #18336

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/windows-shortcut-home-aliasing
Jul 23, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/windows-shortcut-home-aliasing

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Problem

The scheduled Windows Desktop e2e workflow has failed on every run since #18275 merged (first failure: run 29611045439, most recent: run 29955359944). The three failing tests are the file-shortcut cases in files_shortcuts.test.ts.

Root cause: the e2e sandbox derives HOME from os.tmpdir(), which on the GitHub Windows runners contains an 8.3 short-name component (C:\Users\RUNNER~1\...). fs.realpathSync does not expand short names (only fs.realpathSync.native does), so rsession runs with a short-form HOME. The shell canonicalizes .lnk targets to long form, so IShellLink::GetPath reports C:/Users/runneradmin/... and createAliasedPath's literal prefix match against home fails. The trace shows the direct consequence: following the shortcut opens the target as a second, path-distinct document (absolute path) alongside the ~/-aliased one, so waitForActiveDocument('~/...') times out and the columns dedupe test sees 3 source panels instead of 2.

Fixes

  • e2e harness: canonicalize the sandbox root with fs.realpathSync.native, expanding 8.3 short names on Windows (identical behavior on macOS/Linux, verified). This also fixes the spurious [sandbox] R workdir ... is not under PW_SANDBOX teardown warnings, which were the same path-form mismatch.
  • rsession: resolveWindowsShortcut now normalizes local targets with GetLongPathName, so home aliasing and the client's duplicate-document detection are robust to short-form (or case-mismatched) stored targets regardless of environment. UNC/remote targets are skipped to keep the existing no-network-I/O contract, and a failed lookup (e.g. deleted target) keeps the stored path, preserving the broken-shortcut behavior covered by ResolveReturnsStoredPathWhenTargetDeleted.

Includes a new WindowsShortcutTest.ResolvesStoredShortPathToLongForm gtest (skips when 8.3 names are disabled on the volume).

Verification

  • tsc --noEmit passes for the e2e change; fs.realpathSync.native verified equivalent to fs.realpathSync on macOS.
  • The C++ change is Windows-only and needs the Windows CI build; the new gtest and the next scheduled Windows e2e run are the end-to-end verification.

… sandbox home

The scheduled Windows e2e runs have failed on files_shortcuts.test.ts
since PR #18275 merged: the sandbox HOME is derived from os.tmpdir(),
which on the CI runners contains an 8.3 short-name component
(C:\Users\RUNNER~1\...), while the shell stores and reports .lnk
targets in long form. createAliasedPath's literal prefix match then
fails, so a followed shortcut opens the target as a second,
path-distinct document instead of ~/-aliased one.

Two fixes:

- e2e: canonicalize the sandbox path with fs.realpathSync.native, which
  (unlike the JS realpath) expands 8.3 short names on Windows. This also
  fixes the spurious "workdir is not under PW_SANDBOX" teardown warning.

- rsession: normalize resolved shortcut targets with GetLongPathName
  (local paths only, keeping the no-network-I/O contract), so aliasing
  and duplicate-document detection are robust to short-form or
  case-mismatched stored targets regardless of environment.
@kevinushey kevinushey added this to the 2026.08 (Yellow Yarrow) milestone Jul 22, 2026
@posit-snyk-bot

posit-snyk-bot commented Jul 22, 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.

@kevinushey

Copy link
Copy Markdown
Collaborator Author

Verified on the Windows CI runner via a branch dispatch of the e2e workflow (build from source + test_selector=files_shortcuts.test.ts): https://github.com/rstudio/rstudio/actions/runs/29962582280 — all shortcut tests pass (5 passed, 0 failed, 0 flaky), including the three that failed on every scheduled run since #18275. The source build also compile-verifies the Win32 rsession change.

@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
1878 1 357 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ desktop-linux 469 0 88 1
✅ desktop-macos 473 0 85 1
✅ desktop-windows 474 0 90 0
❌ server-linux 454 1 94 0
✅ setup 8 0 0 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 8a11177c669eb69b7774b79580dfb4e009bb1bbf - Run #315

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review.

Important

  1. src/cpp/session/SessionModuleContextWin32.cpp:170 — the GetLongPathNameW buffer-too-small case silently reverts to the short form, quietly reintroducing this bug. When the buffer is too small the API returns the required size (>= MAX_PATH) without filling the buffer; the guard if (length > 0 && length < MAX_PATH) correctly avoids the overread but then lumps that case into the same do-nothing fallback as a genuine failure, keeping the short form. This is the case most likely to bite: 8.3 short names exist for paths whose long form exceeds MAX_PATH, so a .lnk can store a short target (which fit the earlier GetPath call) whose long form is >= MAX_PATH, and home aliasing then silently degrades with no diagnostic. Fix: handle the length >= MAX_PATH regime explicitly with a two-phase heap-buffer retry (see the pattern in expandEnvironmentVariables, src/cpp/core/system/Win32System.cpp:839), preserving the intentional length == 0 -> keep-stored-form path.

  2. src/cpp/session/SessionModuleContextTests.cpp:903 — ResolvesStoredShortPathToLongForm can pass with the fix reverted. It builds the .lnk via SetPath(shortForm) + Save, but (as the test's own comment concedes) the shell often canonicalizes to long form at Save time; when it does, GetPath returns long form and EXPECT_EQ(resolved, target) holds even without the GetLongPathNameW block. Nothing asserts the stored form actually remained short, and this is the only dedicated unit guard for the C++ fix. Fix: after Save, read the stored target back and GTEST_SKIP if it already came back long-form, so the assertion only runs when it actually crosses the normalization seam.

Suggestions

  1. src/cpp/session/SessionModuleContextWin32.cpp:161 — the "no-target-I/O contract" comment is misleading. GetLongPathNameW performs local-disk I/O for local targets too (it opens each path component), so the block relaxes the earlier "costs no target I/O" property to no network I/O, not no I/O. Reword, e.g. "Local normalization reads the local filesystem (accepted during listings); UNC/remote targets are skipped because the same lookup would incur network I/O."

  2. src/cpp/session/SessionModuleContextWin32.cpp:163 — the comment "a failed lookup (e.g. a deleted target) keeps the stored form" describes only length == 0, not the length >= MAX_PATH success-but-too-long case (see finding 1). If finding 1 is fixed this largely dissolves; otherwise add "...or a long form exceeding MAX_PATH".

  3. e2e/rstudio/fixtures/sandbox-setup.ts:108 — the fs.realpathSync.native switch has no self-guard, so a reversion surfaces only as a confusing downstream visibility timeout. Optional: throw in setup if the resolved sandbox path still contains an ~N 8.3 component, turning a silent infra regression into an immediate, labeled failure.

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

A few findings worth a peek.

@kevinushey

Copy link
Copy Markdown
Collaborator Author

Thanks -- all five findings addressed in 8a11177:

  1. GetLongPathNameW buffer-too-small: the length >= MAX_PATH regime is now handled explicitly with a heap-buffer retry sized from the returned required length (same two-phase pattern as expandEnvironmentVariables). The length == 0 failure path still keeps the stored form.
  2. ResolvesStoredShortPathToLongForm could pass vacuously: added a readStoredShortcutTarget fixture helper that reads the persisted target back via a raw IShellLink::GetPath (no normalization); the test now GTEST_SKIPs when the shell already canonicalized at Save time, so a pass always means the short-to-long seam was exercised.
  3. "no-target-I/O contract" comment: reworded -- local normalization reads the local filesystem (accepted during listings); UNC/remote targets are skipped to avoid network I/O.
  4. Failed-lookup comment: dissolved by fix 1; the retry path is commented in place.
  5. e2e self-guard: sandbox setup now throws a labeled error on Windows if the resolved sandbox path still contains an 8.3 short-name component, instead of surfacing as a downstream visibility timeout.

@kevinushey
kevinushey merged commit e931b7b into main Jul 23, 2026
27 of 28 checks passed
@kevinushey
kevinushey deleted the bugfix/windows-shortcut-home-aliasing branch July 23, 2026 18:34
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