Repository navigation
feat: introduce new --timings flag to read test duration hints - #68
Conversation
The new `--timings` flag for the `flakiness-playwright-shard` binary allows reading duration hints from a previous Flakiness Report, if necessary.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2db02a5ae0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const maxDuration = test.attempts.reduce((acc, attempt) => Math.max(acc, attempt.duration ?? 0), 0); | ||
| // We never accept that a test can be executed "for free": we assign at least | ||
| const predictedDuration = Math.max(envDuration ?? maxDuration, 1); |
There was a problem hiding this comment.
Preserve default weight for missing duration hints
When the durations report/timings file contains a matching test but no usable attempt.duration (for example, the Durations API has no history for that test/env, or all attempts are skipped/missing durations), maxDuration is 0 and this stores a 1ms prediction. That bypasses the DEFAULT_DURATION fallback in sharding.ts, so partial timing data treats unknown tests as effectively free instead of using the default weight, which can heavily skew mixed known/unknown shards.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 931367b5d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // and otherwise use an average duration. | ||
| const envDuration = test.attempts.find(attempt => durationsReport.environments[attempt.environmentIdx ?? 0]?.name === envName)?.duration; | ||
| // We fallback to the max of the test durations across environments. | ||
| const maxDuration = test.attempts.reduce((acc, attempt) => Math.max(acc, attempt.duration ?? 0), 0); |
There was a problem hiding this comment.
Keep other projects off unmatched timings
When a timings file has a duration for this test only in a different current environment, such as a file produced with --project=slow and then reused while sharding fast or all projects, envDuration is undefined for the fast test case but this fallback still takes the slow attempt. That records a prediction for the fast project instead of leaving it absent for the default weight, so partial per-project timings can make one environment inherit another environment's duration and skew the balanced split.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43d1144f0f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // For each test case, we want to find the best timing approximation. | ||
| // We either try to find the environment with the same name (these should be unique), | ||
| // and otherwise use an average duration. | ||
| const envDuration = test.attempts.find(attempt => durationsReport.environments[attempt.environmentIdx ?? 0]?.name === envName)?.duration; |
There was a problem hiding this comment.
Aggregate same-env attempts from timings files
When --timings points at a normal report that contains retries for a test, there can be multiple attempts for the same environment, but this find uses only the first one and ignores the rest. If the first attempt was a quick failure and the retry was the slow run (or vice versa), the generated shard gets a misleading duration even though the timings file has the actual retry data; aggregate matching attempts (for example max or sum) before setting the prediction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e10f94f2e9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // and otherwise use a max duration. | ||
| const envDuration = envName ? durationsPerEnv.get(envName) : undefined; | ||
| // We fallback to the max of the test durations across environments. | ||
| durationPredictions.set(testCase, envDuration ?? maxDuration); |
There was a problem hiding this comment.
Avoid multiplying repeated timing attempts per test case
When a timings file comes from a suite using repeatEach, the report can contain multiple attempts for the same FK test/environment while the current list run also maps that FK id to multiple TestCases. Because the code sums all attempts per environment and then assigns that summed value to every mapped test case here, two 1s repeats are weighted as 4s instead of the 2s historical total, and larger repeat counts can make that test group dominate otherwise balanced shards.
Useful? React with 👍 / 👎.
The new
--timingsflag for theflakiness-playwright-shardbinaryallows reading duration hints from a previous Flakiness Report, if
necessary.