Fix async forEach bug in test framework preventing error catching #28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix async forEach bug in test framework that prevented error catching
Problem
The test framework in
packages/deparser/test-utils/index.tshad a critical async/await bug at line 100 wheretree.stmts.forEach(async (stmt: any) => {was used. This prevented proper error catching becauseforEachdoesn't wait for async operations - errors thrown inside the async callback were "fire-and-forget" and never bubbled up to fail tests.Root Cause
This meant that even when the deparser generated invalid SQL that failed to reparse, the test framework couldn't catch these failures and tests would incorrectly pass.
Solution
Fixed the async forEach bug by converting to a proper for-of loop:
Also fixed a TypeScript error with the diff function by adding null handling.
Verification
The fix is verified by running the test that was previously passing incorrectly:
Before fix: Test passed silently even with deparser generating invalid SQL
After fix: Test now properly fails with detailed error output:
The detailed logging now appears in test output, proving that async operations are properly awaited and errors are caught.
Impact
This fix enables the test framework to properly catch deparser bugs where invalid SQL is generated. Previously, such bugs would go undetected because the async forEach prevented error propagation.
Link to Devin run: https://app.devin.ai/sessions/53c6e39590e9403ab99a25afe0dd5e99
Requested by: Dan Lynch ([email protected])