-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: stabilize test #6793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schiller-manuel
wants to merge
1
commit into
main
Choose a base branch
from
stabilize-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
chore: stabilize test #6793
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,54 @@ import { chromium } from '@playwright/test' | |
| import { getTestServerPort } from '@tanstack/router-e2e-utils' | ||
| import packageJson from '../package.json' with { type: 'json' } | ||
|
|
||
| import { extractViolationsFromLog } from './violations.utils' | ||
| import { extractViolationsFromLog, stripAnsi } from './violations.utils' | ||
| import type { FullConfig } from '@playwright/test' | ||
| import type { Violation } from './violations.utils' | ||
|
|
||
| const VIOLATION_MARKER = '[import-protection] Import denied in' | ||
|
|
||
| /** | ||
| * Counts the number of violation markers currently present in the log chunks. | ||
| */ | ||
| function countViolations(logChunks: Array<string>): number { | ||
| let count = 0 | ||
| for (const chunk of logChunks) { | ||
| const cleaned = stripAnsi(chunk) | ||
| let idx = 0 | ||
| while ((idx = cleaned.indexOf(VIOLATION_MARKER, idx)) !== -1) { | ||
| count++ | ||
| idx += VIOLATION_MARKER.length | ||
| } | ||
| } | ||
| return count | ||
| } | ||
|
|
||
| /** | ||
| * Polls the log output and waits until the violation count stops changing | ||
| * for `stableMs` milliseconds, or until `hardTimeoutMs` is reached. | ||
| * This avoids fixed-delay race conditions in slow CI environments where | ||
| * deferred violation processing may take longer than expected. | ||
| */ | ||
| async function waitForViolationStabilization( | ||
| logChunks: Array<string>, | ||
| { stableMs = 2_000, hardTimeoutMs = 30_000, pollMs = 250 } = {}, | ||
| ): Promise<void> { | ||
| const start = Date.now() | ||
| let lastCount = countViolations(logChunks) | ||
| let lastChangeAt = Date.now() | ||
|
|
||
| while (Date.now() - start < hardTimeoutMs) { | ||
| await new Promise((r) => setTimeout(r, pollMs)) | ||
| const currentCount = countViolations(logChunks) | ||
| if (currentCount !== lastCount) { | ||
| lastCount = currentCount | ||
| lastChangeAt = Date.now() | ||
| } else if (Date.now() - lastChangeAt >= stableMs) { | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+36
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stabilization can return too early and hard-timeout currently fails open. The loop can return after 🔧 Proposed fix async function waitForViolationStabilization(
logChunks: Array<string>,
{ stableMs = 2_000, hardTimeoutMs = 30_000, pollMs = 250 } = {},
): Promise<void> {
const start = Date.now()
let lastCount = countViolations(logChunks)
- let lastChangeAt = Date.now()
+ let lastChangeAt = start
+ let hasObservedViolation = lastCount > 0
while (Date.now() - start < hardTimeoutMs) {
await new Promise((r) => setTimeout(r, pollMs))
const currentCount = countViolations(logChunks)
if (currentCount !== lastCount) {
lastCount = currentCount
lastChangeAt = Date.now()
- } else if (Date.now() - lastChangeAt >= stableMs) {
+ if (currentCount > 0) hasObservedViolation = true
+ } else if (hasObservedViolation && Date.now() - lastChangeAt >= stableMs) {
return
}
}
+
+ throw new Error(
+ `Timed out waiting for violation log stabilization after ${hardTimeoutMs}ms (lastCount=${lastCount})`,
+ )
}🤖 Prompt for AI Agents |
||
|
|
||
| async function waitForHttpOk(url: string, timeoutMs: number): Promise<void> { | ||
| const start = Date.now() | ||
|
|
||
|
|
@@ -154,7 +198,9 @@ async function runDevPass( | |
| await browser.close() | ||
| } | ||
|
|
||
| await new Promise((r) => setTimeout(r, 750)) | ||
| // Wait until the violation count in the server log stabilizes. | ||
| // This replaces a fixed delay and is more robust in slow CI. | ||
| await waitForViolationStabilization(logChunks) | ||
| } finally { | ||
| await killChild(child) | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cat -n e2e/react-start/import-protection/tests/violations.setup.ts | head -60Repository: TanStack/router
Length of output: 2473
🏁 Script executed:
Repository: TanStack/router
Length of output: 122
🏁 Script executed:
Repository: TanStack/router
Length of output: 260
🏁 Script executed:
Repository: TanStack/router
Length of output: 1560
🏁 Script executed:
Repository: TanStack/router
Length of output: 2304
🏁 Script executed:
Repository: TanStack/router
Length of output: 3020
Fix marker counting to handle split markers across stream chunks.
Stream chunks have arbitrary boundaries. The current chunk-by-chunk approach misses markers split across chunks, which causes
countViolationsto return an incorrect count. This can result in premature stabilization detection, causing the test to proceed before all violations are logged.The demonstration confirms the issue: when a marker is split across two chunks, the current implementation counts 0 while the corrected implementation counts 1.
🔧 Proposed fix
function countViolations(logChunks: Array<string>): number { + const cleanedLog = stripAnsi(logChunks.join('')) let count = 0 - for (const chunk of logChunks) { - const cleaned = stripAnsi(chunk) - let idx = 0 - while ((idx = cleaned.indexOf(VIOLATION_MARKER, idx)) !== -1) { - count++ - idx += VIOLATION_MARKER.length - } + let idx = 0 + while ((idx = cleanedLog.indexOf(VIOLATION_MARKER, idx)) !== -1) { + count++ + idx += VIOLATION_MARKER.length } return count }📝 Committable suggestion
🤖 Prompt for AI Agents