Skip to content

Fix file dedupe fourslash flake#3258

Merged
jakebailey merged 4 commits intomainfrom
jabaile/fix-deduping-fourslash-flake
Mar 27, 2026
Merged

Fix file dedupe fourslash flake#3258
jakebailey merged 4 commits intomainfrom
jabaile/fix-deduping-fourslash-flake

Conversation

@jakebailey
Copy link
Copy Markdown
Member

After probably 100k runs, I pinned this one down to two things:

  • UpdateProgram was not fully checking if a file was a part of a cycle. Has to check both maps (Strada did too).
  • When a package.json file is modified, we can't reuse things anymore. It's dubious, but fourslash does actually edit JSON files, and we see them. Maybe this isn't real, but it does matter for the test at least.

Copy link
Copy Markdown
Contributor

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

Fixes an intermittent fourslash flake by forcing full rebuilds in cases that invalidate incremental reuse and by tightening cycle/redirect detection during program updates.

Changes:

  • Force a full rebuild when package.json changes (to avoid incorrect incremental dedupe/reuse).
  • In UpdateProgram, rebuild when the changed file is a redirect target as well as a redirect file.

Reviewed changes

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

File Description
internal/project/projectcollectionbuilder.go Treats package.json edits as rebuild-triggering to prevent incorrect single-file cloning.
internal/compiler/program.go Expands redirect/cycle detection to include redirectTargetsMap to avoid unsafe incremental updates.

Comment on lines +1092 to +1097
// package.json changes can affect module resolution and package
// identity (e.g. dedup decisions), so they must always trigger
// a full rebuild rather than a single-file clone.
if tspath.GetBaseFileName(string(path)) == "package.json" {
dirtyFilePath = ""
break
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The package.json check is case-sensitive, which can miss the file on case-insensitive filesystems if it appears with different casing (e.g. Package.json). Consider using a case-insensitive comparison (e.g. strings.EqualFold on the base name) or normalizing the base filename via existing path-canonicalization utilities before comparing.

Copilot uses AI. Check for mistakes.
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 not quite right; if we're on a case-insensitive file system, that's when path is guaranteed to be lowercase because it's a normalized tspath.Path. Only on a case-sensitive file system would path preserve the original casing, and I think a person on a case-sensitive file system would be having a bad time with a non-standard casing of package.json anyway.

Comment thread internal/compiler/program.go Outdated
Comment thread internal/project/projectcollectionbuilder.go
@jakebailey jakebailey enabled auto-merge March 27, 2026 22:03
@jakebailey jakebailey added this pull request to the merge queue Mar 27, 2026
Merged via the queue into main with commit 9e42514 Mar 27, 2026
21 checks passed
@jakebailey jakebailey deleted the jabaile/fix-deduping-fourslash-flake branch March 27, 2026 22: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