Skip to content

Strip project scope prefix from IDs copied by "Copy test ID" - #26153

Open
Eduardo Villalpando Mello (edvilme) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-copy-test-id-issue-26092
Open

Eduardo Villalpando Mello (edvilme) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-copy-test-id-issue-26092

Conversation

Copilot AI commented Sep 16, 2026

Copy link
Copy Markdown

Fixes #26092

"Copy test ID" copied the raw TestItem.id, which since project scoping is {projectId}@@vsc@@{testId}, so users pasted file:///path/to/workspace@@vsc@@/path/to/workspace/tests/unit/test_foo.py::test_bar instead of the test ID.

Changes

  • src/client/testing/utils.ts: writeTestIdToClipboard now normalizes the ID with the existing parseVsId helper before unittest detection/conversion, the pytest clipboard write, and logging.
    • TestItem.id is not mutated and discovery/execution scoping is untouched — only the clipboard-facing value is normalized.
    • parseVsId returns [undefined, vsId] for unscoped IDs, so legacy behavior and the module.class.method unittest formatting are preserved.
-        if (testItem.id.includes('\\') && testItem.id.indexOf('::') === -1) {
+        const [, testId] = parseVsId(testItem.id);
+        if (testId.includes('\\') && testId.indexOf('::') === -1) {
  • src/test/testing/utils.unit.test.ts: this file was a top-level IIFE with try/catch-swallowed assertions that mocha never registered as tests (and its idToModuleClassMethod inputs had lost their backslash separators). Converted to a suite/test file asserting the real clipboard contents via the MockClipboard from src/test/vscode-mock.ts, with cases for project-scoped pytest IDs, parameterized IDs (test_pipe_single[False] preserved verbatim), Windows-style paths, legacy unscoped IDs, and project-scoped unittest IDs.

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix copy test ID to remove 'file://' prefix Strip project scope prefix from IDs copied by "Copy test ID" Sep 16, 2026
@edvilme
Eduardo Villalpando Mello (edvilme) marked this pull request as ready for review September 17, 2026 16:39
@bschnurr

Bill Schnurr (bschnurr) commented Sep 17, 2026

Copy link
Copy Markdown
Member

🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR.

if (testItem && typeof testItem.id === 'string') {
if (testItem.id.includes('\\') && testItem.id.indexOf('::') === -1) {
// Strip the project scope prefix (if any) so only the test id is copied.
const [, testId] = parseVsId(testItem.id);

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.

Warning · Non-blocking recommendation

Could an unscoped pytest parameter ID contain @@vsc@@ (for example, tests/test_foo.py::test_value[value@@vsc@@suffix])? If so, parseVsId would treat it as project-scoped and copy only suffix]. Please ensure the scope prefix is validated before stripping it, and cover this parameterized-ID case.

@bschnurr Bill Schnurr (bschnurr) 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.

Approved via Review Center.

@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Copy test ID" includes file:// gunk

3 participants