Skip to content

Commit d346922

Browse files
Michael Glassclaude
andcommitted
Make only the first rebuild wait in the newest-change test
The test gated the slow rebuild on `written.length === 0`, but the first rebuild is suspended at that await, so the second rebuild saw a length of 0 too and waited on the same promise. Both then resolved in call order and the assertion held even with no serialization at all — the test could not fail. Count rebuilds instead, and wait for the first one to have actually started before submitting the second change. Verified both directions against a non-serialized queue: the old shape passed, the new one produces ['newer-change', 'older-change'] and fails. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lcj4iQ3fBxMwAu2rf4zLbC
1 parent 2b9a5c4 commit d346922

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/@tailwindcss-cli/src/commands/build/index.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,20 @@ it('writes the newest change last when an earlier rebuild is slower', async () =
8383
// batches tests pin the scheduling on its own; this pins the outcome through
8484
// the watcher wiring, which is the shape the bug was reported in.
8585
let written: string[] = []
86+
let rebuildCount = 0
87+
let startFirstRebuild!: () => void
88+
let firstRebuildStarted = new Promise<void>((resolve) => (startFirstRebuild = resolve))
8689
let releaseSlowRebuild!: () => void
8790
let slowRebuildCanFinish = new Promise<void>((resolve) => (releaseSlowRebuild = resolve))
8891

8992
let queue = serializeBatches<string>(async (files) => {
90-
// Make the *first* rebuild the slow one. Without serialization the second
91-
// rebuild finishes first and this stale result lands on top of it.
92-
if (written.length === 0) await slowRebuildCanFinish
93+
// Only the *first* rebuild is slow. Counting rebuilds rather than writes
94+
// matters: the first rebuild is suspended below, so a write-count check
95+
// would also suspend the second one and the test would pass unserialized.
96+
if (rebuildCount++ === 0) {
97+
startFirstRebuild()
98+
await slowRebuildCanFinish
99+
}
93100
written.push(files.at(-1)!)
94101
})
95102
let fake = fakeWatcher()
@@ -105,7 +112,7 @@ it('writes the newest change last when an earlier rebuild is slower', async () =
105112
)
106113

107114
await fake.callbacks[0](null, [{ type: 'update', path: 'older-change' }])
108-
await nextTask()
115+
await firstRebuildStarted
109116
await fake.callbacks[0](null, [{ type: 'update', path: 'newer-change' }])
110117
await nextTask()
111118

0 commit comments

Comments
 (0)