Skip to content

Conversation

@TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Nov 13, 2025

TL;DR

Added .gitattributes file to enforce LF line endings for .stderr test files.

What changed?

Created a new .gitattributes file that specifies .stderr files should always use LF line endings regardless of the operating system.

How to test?

  1. Clone the repository on a Windows machine
  2. Create or modify a .stderr file
  3. Verify that Git maintains LF line endings for the file regardless of your Git configuration

Why make this change?

This ensures consistent line endings for .stderr test files across different operating systems, which prevents test failures that might occur due to line ending differences between platforms (particularly Windows vs Unix-based systems).

@changeset-bot
Copy link

changeset-bot bot commented Nov 13, 2025

⚠️ No Changeset found

Latest commit: 2feeb6f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Nov 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 13, 2025 9:08am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 13, 2025 9:08am
example-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workbench-hono-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workbench-nitro-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workbench-vite-workflow Ready Ready Preview Comment Nov 13, 2025 9:08am
workflow-docs Ready Ready Preview Comment Nov 13, 2025 9:08am

Copy link
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines +26 to +50
if let Ok(entries) = fs::read_dir(&test_dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
// Look for .stderr files in subdirectories
if let Ok(sub_entries) = fs::read_dir(&path) {
for sub_entry in sub_entries.flatten() {
let sub_path = sub_entry.path();
if sub_path.extension().and_then(|s| s.to_str()) == Some("stderr") {
if let Ok(mut content) = fs::read_to_string(&sub_path) {
// On Windows, normalize line endings to LF
// SWC's error handler outputs LF even on Windows
// but Git may check out files with CRLF due to autocrlf
content = content
.replace("\r\n", "\n") // Normalize CRLF to LF
.replace("\r", "\n"); // Handle old Mac-style CR
// Write back with LF line endings
let _ = fs::write(&sub_path, content);
}
}
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The normalize_stderr_files() function only normalizes .stderr files one level deep under tests/errors/, but the fixture pattern allows input files at arbitrary nesting depths (e.g., tests/errors/**/input.js). This means .stderr files in deeply nested directories won't be normalized on Windows, causing test failures.

View Details
📝 Patch Details
diff --git a/packages/swc-plugin-workflow/transform/tests/errors.rs b/packages/swc-plugin-workflow/transform/tests/errors.rs
index 01c42d5..016f186 100644
--- a/packages/swc-plugin-workflow/transform/tests/errors.rs
+++ b/packages/swc-plugin-workflow/transform/tests/errors.rs
@@ -23,31 +23,31 @@ fn normalize_stderr_files() {
             // This ensures we have the correct path regardless of where the test runs from
             let manifest_dir = env!("CARGO_MANIFEST_DIR");
             let test_dir = PathBuf::from(manifest_dir).join("tests/errors");
-            if let Ok(entries) = fs::read_dir(&test_dir) {
-                for entry in entries.flatten() {
-                    let path = entry.path();
-                    if path.is_dir() {
-                        // Look for .stderr files in subdirectories
-                        if let Ok(sub_entries) = fs::read_dir(&path) {
-                            for sub_entry in sub_entries.flatten() {
-                                let sub_path = sub_entry.path();
-                                if sub_path.extension().and_then(|s| s.to_str()) == Some("stderr") {
-                                    if let Ok(mut content) = fs::read_to_string(&sub_path) {
-                                        // On Windows, normalize line endings to LF
-                                        // SWC's error handler outputs LF even on Windows
-                                        // but Git may check out files with CRLF due to autocrlf
-                                        content = content
-                                            .replace("\r\n", "\n") // Normalize CRLF to LF
-                                            .replace("\r", "\n"); // Handle old Mac-style CR
-                                        // Write back with LF line endings
-                                        let _ = fs::write(&sub_path, content);
-                                    }
-                                }
+            
+            fn normalize_dir_recursive(dir: &PathBuf) {
+                if let Ok(entries) = fs::read_dir(dir) {
+                    for entry in entries.flatten() {
+                        let path = entry.path();
+                        if path.is_dir() {
+                            // Recursively process subdirectories to handle arbitrary nesting depths
+                            normalize_dir_recursive(&path);
+                        } else if path.extension().and_then(|s| s.to_str()) == Some("stderr") {
+                            if let Ok(mut content) = fs::read_to_string(&path) {
+                                // On Windows, normalize line endings to LF
+                                // SWC's error handler outputs LF even on Windows
+                                // but Git may check out files with CRLF due to autocrlf
+                                content = content
+                                    .replace("\r\n", "\n") // Normalize CRLF to LF
+                                    .replace("\r", "\n"); // Handle old Mac-style CR
+                                // Write back with LF line endings
+                                let _ = fs::write(&path, content);
                             }
                         }
                     }
                 }
             }
+            
+            normalize_dir_recursive(&test_dir);
         });
     }
 }

Analysis

Recursive .stderr file normalization for Windows test compatibility

What fails: The normalize_stderr_files() function in packages/swc-plugin-workflow/transform/tests/errors.rs uses non-recursive directory traversal and only finds .stderr files one level deep (e.g., tests/errors/<category>/*.stderr), while the fixture pattern tests/errors/**/input.js allows test files at arbitrary nesting depths. This causes deeply nested .stderr files to be missed during normalization.

How to reproduce:

  1. Create a deeply nested test structure:

    tests/errors/
      category/
        subcategory/
          input.js
          output-step.stderr
    
  2. On Windows with Git's core.autocrlf=true, the .stderr file is checked out with CRLF line endings (\r\n)

  3. Run the tests - the comparison will fail

Result: The unnormalized CRLF line endings in the deeply nested .stderr file don't match SWC's LF output, causing test failures: actual output (LF) != expected file (CRLF). Tests pass on Unix systems because both have LF.

Expected: The normalize_stderr_files() function should recursively traverse all subdirectories under tests/errors/ to normalize line endings in .stderr files at any nesting depth, matching the behavior of the **/ fixture pattern. This ensures consistent test behavior across Windows and Unix systems regardless of Git's core.autocrlf setting.

Fix applied: Refactored normalize_stderr_files() to use a nested recursive helper function normalize_dir_recursive() that walks the entire directory tree instead of stopping after one level. The fix maintains all existing functionality while handling nested test structures.

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