Skip to content

Persist test tracking even if a document is closed#5883

Merged
DanTup merged 8 commits intomasterfrom
persist-test-trackers
Jan 21, 2026
Merged

Persist test tracking even if a document is closed#5883
DanTup merged 8 commits intomasterfrom
persist-test-trackers

Conversation

@DanTup
Copy link
Member

@DanTup DanTup commented Jan 20, 2026

Otherwise closing and re-opening a file will stop it from updating.

There is a chance that a file is modified while it was closed, but I don't think there's a way to handle this (since we don't get proper edits).

Fixes #5878

@DanTup DanTup added this to the v3.128.0 milestone Jan 20, 2026
@DanTup DanTup added is bug fix in testing Relates to test execution of Dart/Flutter tests for end users labels Jan 20, 2026
@DanTup DanTup requested a review from Copilot January 20, 2026 13:44
@DanTup
Copy link
Member Author

DanTup commented Jan 20, 2026

@codex review
/gemini review

@gemini-code-assist
Copy link

It looks like you tried to invoke @codex review, which is not a recognized command. If you intended to request a code review, please use /gemini review. I will proceed with the /gemini review command now.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e176d6fb91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request modifies the document position and range trackers to persist tracking when documents are closed and reopened, fixing an issue where closing and reopening a file would stop position/range updates.

Changes:

  • Replaced onDidCloseTextDocument handler with onDidOpenTextDocument handler to validate trackers when documents reopen
  • Added validation logic to dispose trackers if file content changed externally while closed
  • Updated tests to verify tracking persists across document close/reopen cycles

Reviewed changes

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

File Description
src/shared/vscode/trackers.ts Replaced document close handler with document open handler that validates and cleans up invalid trackers instead of disposing all trackers on close
src/test/dart/editing/position_trackers.test.ts Changed tests from expecting undefined on close to expecting continued tracking after close/reopen, using file-based documents instead of in-memory ones

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

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.38%. Comparing base (b40eed6) to head (2017fa2).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5883      +/-   ##
==========================================
+ Coverage   67.36%   67.38%   +0.02%     
==========================================
  Files         168      168              
  Lines       12899    12907       +8     
  Branches     2556     2557       +1     
==========================================
+ Hits         8689     8697       +8     
  Misses       3756     3756              
  Partials      454      454              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Otherwise closing and re-opening a file will stop it from updating.

There is a chance that a file is modified while it was closed, but I don't think there's a way to handle this (since we don't get proper edits).

Fixes #5878
When a document is closed, isClosed is set to true and re-opening can return a new `TextDocument` instance.

Although no tests failed with the previous code, I suspect that's because VS Code only cleans up closed TextDocuments periodically and we don't have a way to force it 😔
@DanTup DanTup force-pushed the persist-test-trackers branch from 5f6c3c4 to 01bdd60 Compare January 20, 2026 18:45
@DanTup DanTup requested a review from Copilot January 20, 2026 19:02
@DanTup
Copy link
Member Author

DanTup commented Jan 20, 2026

@codex review

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of position tracking being lost when a document is closed and re-opened. By changing the trackers map to use document.uri.toString() as a key and switching from onDidCloseTextDocument to onDidOpenTextDocument, the system can now persist tracking information across document lifecycle events. The new handleDocumentOpen logic correctly identifies and invalidates trackers if a document has been externally modified in a way that makes existing offsets invalid. The added tests thoroughly cover these new behaviors, including scenarios where tracking is retained, invalidated due to external modification, or invalidated if any part of a range becomes invalid. The changes are well-implemented and improve the robustness of position tracking.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d28c350843

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

These were effectively the same now we're clearing all positions if any becomes invalid.
When we are setting a test up, if there are no open files, or only the one we are going to open, we can skip this (rather slow) work.
@DanTup DanTup merged commit 378bbd3 into master Jan 21, 2026
21 checks passed
@DanTup DanTup deleted the persist-test-trackers branch January 21, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in testing Relates to test execution of Dart/Flutter tests for end users is bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go to Test doesn't work on some failing tests

2 participants