flake-ledger 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +419 -2
- package/bin/flake-ledger.mjs +385 -0
- package/examples/README.md +102 -0
- package/examples/demo.mjs +155 -0
- package/examples/runs/run-01/results.xml +29 -0
- package/examples/runs/run-02/results.xml +24 -0
- package/examples/runs/run-03/results.xml +25 -0
- package/examples/runs/run-04/results.xml +24 -0
- package/examples/runs/run-05/results.xml +24 -0
- package/lib/index.mjs +24 -0
- package/lib/junit.mjs +346 -0
- package/lib/report.mjs +133 -0
- package/lib/scan.mjs +537 -0
- package/lib/xml.mjs +296 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 WJDdidi-1
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,420 @@
|
|
|
1
|
-
#
|
|
1
|
+
# flake-ledger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/WJDdidi-1/flake-ledger/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/WJDdidi-1/flake-ledger/releases)
|
|
5
|
+
|
|
6
|
+
Ranks flaky tests from JUnit XML across CI runs, including passed-on-retry.
|
|
7
|
+
|
|
8
|
+
Retries turn a red run green, so the same test burns CI time indefinitely; each
|
|
9
|
+
run's JUnit XML is inspected alone and the passed-on-retry evidence is
|
|
10
|
+
discarded. `flake-ledger` reads every JUnit XML under a directory, groups shards
|
|
11
|
+
into CI runs, and keeps each attempt. A test that failed and then passed on
|
|
12
|
+
retry stays a `passed-on-retry` row in the ledger instead of disappearing into a
|
|
13
|
+
green build.
|
|
14
|
+
|
|
15
|
+
## A real session
|
|
16
|
+
|
|
17
|
+
The five runs are checked in at [`examples/runs`](examples/runs), one JUnit
|
|
18
|
+
report per run. From a checkout, `npm run example` (or
|
|
19
|
+
`node examples/demo.mjs`) runs the same CLI commands against those files and
|
|
20
|
+
checks the output:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
examples/runs/
|
|
24
|
+
run-01/results.xml
|
|
25
|
+
run-02/results.xml
|
|
26
|
+
run-03/results.xml
|
|
27
|
+
run-04/results.xml
|
|
28
|
+
run-05/results.xml
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`run-01/results.xml` (other testcases trimmed) carries Surefire's
|
|
32
|
+
passed-on-retry evidence:
|
|
33
|
+
|
|
34
|
+
```xml
|
|
35
|
+
<testsuite name="com.example.CheckoutTest" timestamp="2026-01-05T10:00:00">
|
|
36
|
+
<testcase classname="com.example.CheckoutTest" name="appliesCoupon">
|
|
37
|
+
<flakyFailure message="expected 10% discount, got 0">
|
|
38
|
+
<stackTrace>org.opentest4j.AssertionFailedError: expected 10% discount, got 0
|
|
39
|
+
at CheckoutTest.appliesCoupon(CheckoutTest.java:42)</stackTrace>
|
|
40
|
+
</flakyFailure>
|
|
41
|
+
</testcase>
|
|
42
|
+
<!-- more testcases -->
|
|
43
|
+
</testsuite>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Scan the tree. The table is ranked by a 95% Wilson lower bound on unstable
|
|
47
|
+
rate, so a test with more evidence outranks one with a single bad run:
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
$ flake-ledger scan examples/runs
|
|
51
|
+
TEST ID RUNS ATTEMPTS UNSTABLE PASS-ON-RETRY FAILED RATE SCORE CLASS
|
|
52
|
+
com.example.LoginTest::rejectsExpiredToken 5 5 2 0 2 40.0% 0.118 cross-run flake
|
|
53
|
+
com.example.SearchTest::filtersByPrice 5 5 2 0 2 40.0% 0.118 cross-run flake
|
|
54
|
+
com.example.CheckoutTest::appliesCoupon 5 7 2 2 0 40.0% 0.118 passed-on-retry
|
|
55
|
+
com.example.CartTest::addsItem 5 5 0 0 0 0.0% 0.000 stable
|
|
56
|
+
com.example.ReportTest::exportsCsv 5 5 0 0 0 0.0% 0.000 skipped
|
|
57
|
+
|
|
58
|
+
5 runs, 5 tests, 27 attempts, 5 XML files.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`appliesCoupon` has five runs but seven attempts and two passed-on-retry runs:
|
|
62
|
+
the two red attempts are not lost. `explain` prints the timeline that produced
|
|
63
|
+
the score (it prints absolute paths; they are shown here relative to the
|
|
64
|
+
repository root):
|
|
65
|
+
|
|
66
|
+
```console
|
|
67
|
+
$ flake-ledger explain examples/runs 'com.example.CheckoutTest::appliesCoupon'
|
|
68
|
+
com.example.CheckoutTest::appliesCoupon
|
|
69
|
+
classification: passed-on-retry
|
|
70
|
+
runs: 5 attempts: 7 unstable: 2/5 rate: 40.0% score: 0.118
|
|
71
|
+
|
|
72
|
+
run run-01 passed-on-retry 2 attempts
|
|
73
|
+
examples/runs/run-01
|
|
74
|
+
#1 failed examples/runs/run-01/results.xml
|
|
75
|
+
expected 10% discount, got 0
|
|
76
|
+
#2 passed examples/runs/run-01/results.xml (retried)
|
|
77
|
+
|
|
78
|
+
run run-02 passed 1 attempt
|
|
79
|
+
examples/runs/run-02
|
|
80
|
+
#1 passed examples/runs/run-02/results.xml
|
|
81
|
+
|
|
82
|
+
run run-03 passed-on-retry 2 attempts
|
|
83
|
+
examples/runs/run-03
|
|
84
|
+
#1 failed examples/runs/run-03/results.xml
|
|
85
|
+
expected 10% discount, got 0
|
|
86
|
+
#2 passed examples/runs/run-03/results.xml (retried)
|
|
87
|
+
|
|
88
|
+
run run-04 passed 1 attempt
|
|
89
|
+
examples/runs/run-04
|
|
90
|
+
#1 passed examples/runs/run-04/results.xml
|
|
91
|
+
|
|
92
|
+
run run-05 passed 1 attempt
|
|
93
|
+
examples/runs/run-05
|
|
94
|
+
#1 passed examples/runs/run-05/results.xml
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Use the ledger as a CI gate and write the quarantine list. The table on stdout
|
|
98
|
+
is the same one shown above, so it is omitted here:
|
|
99
|
+
|
|
100
|
+
```console
|
|
101
|
+
$ flake-ledger scan examples/runs --quarantine flaky.txt --fail-on 0.2 --min-runs 5 > /dev/null
|
|
102
|
+
wrote 3 flaky test ids to flaky.txt
|
|
103
|
+
flaky: com.example.LoginTest::rejectsExpiredToken unstable in 2/5 runs (40.0%) >= 20.0%
|
|
104
|
+
flaky: com.example.SearchTest::filtersByPrice unstable in 2/5 runs (40.0%) >= 20.0%
|
|
105
|
+
flaky: com.example.CheckoutTest::appliesCoupon unstable in 2/5 runs (40.0%) >= 20.0%
|
|
106
|
+
flake-ledger: 3 flaky tests crossed --fail-on 0.2
|
|
107
|
+
$ echo $?
|
|
108
|
+
1
|
|
109
|
+
$ cat flaky.txt
|
|
110
|
+
com.example.LoginTest::rejectsExpiredToken
|
|
111
|
+
com.example.SearchTest::filtersByPrice
|
|
112
|
+
com.example.CheckoutTest::appliesCoupon
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`--fail-on` and `--min-runs` are opt-in; without them the command is
|
|
116
|
+
report-only and exits 0.
|
|
117
|
+
|
|
118
|
+
## Measured on real test runners
|
|
119
|
+
|
|
120
|
+
The checked-in example is hand-written. To check the parser against output it
|
|
121
|
+
did not create, the same CLI was run against JUnit XML produced by pytest
|
|
122
|
+
9.2.0 with pytest-rerunfailures 16.7 and by Playwright 1.65.0. Each fixture had
|
|
123
|
+
ten runs, one directory per run; the test files, configs, and commands are in
|
|
124
|
+
[`docs/real-world.md`](https://github.com/WJDdidi-1/flake-ledger/blob/main/docs/real-world.md).
|
|
125
|
+
|
|
126
|
+
pytest-rerunfailures writes one `<testcase>` per attempt, so a test that failed
|
|
127
|
+
once and then passed on retry appears as two passing testcases. From the
|
|
128
|
+
fixture directory, `flake-ledger scan runs` printed:
|
|
129
|
+
|
|
130
|
+
```console
|
|
131
|
+
$ flake-ledger scan runs
|
|
132
|
+
TEST ID RUNS ATTEMPTS UNSTABLE PASS-ON-RETRY FAILED RATE SCORE CLASS
|
|
133
|
+
test_checkout::test_always_failing 10 20 10 0 10 100.0% 0.722 failed-on-retry
|
|
134
|
+
test_checkout::test_applies_coupon 10 20 10 10 0 100.0% 0.722 passed-on-retry
|
|
135
|
+
test_checkout::test_cross_run_flake 10 10 5 0 5 50.0% 0.237 cross-run flake
|
|
136
|
+
test_checkout::test_skipped 10 10 0 0 0 0.0% 0.000 skipped
|
|
137
|
+
test_checkout::test_stable 10 10 0 0 0 0.0% 0.000 stable
|
|
138
|
+
|
|
139
|
+
10 runs, 5 tests, 70 attempts, 10 XML files.
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The recovered test is `passed-on-retry` in all 10 runs, the alternating test is
|
|
143
|
+
`cross-run flake` in 5 of 10, and the stable and skipped tests stay in their
|
|
144
|
+
classes.
|
|
145
|
+
|
|
146
|
+
Playwright's JUnit reporter writes `<flakyError>`/`<rerunError>` only when
|
|
147
|
+
`includeRetries: true` is set. With that option, two projects (chromium and
|
|
148
|
+
firefox) and ten runs produced:
|
|
149
|
+
|
|
150
|
+
```console
|
|
151
|
+
$ flake-ledger scan runs
|
|
152
|
+
TEST ID RUNS ATTEMPTS UNSTABLE PASS-ON-RETRY FAILED RATE SCORE CLASS
|
|
153
|
+
checkout.spec.js::failures › always failing 10 40 10 0 10 100.0% 0.722 always-failing
|
|
154
|
+
checkout.spec.js::checkout › applies coupon 10 40 10 10 0 100.0% 0.722 passed-on-retry
|
|
155
|
+
checkout.spec.js::cross-run flake 10 20 5 0 5 50.0% 0.237 cross-run flake
|
|
156
|
+
checkout.spec.js::skipped 10 20 0 0 0 0.0% 0.000 skipped
|
|
157
|
+
checkout.spec.js::stable 10 20 0 0 0 0.0% 0.000 stable
|
|
158
|
+
|
|
159
|
+
10 runs, 5 tests, 140 attempts, 10 XML files.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The recovered test is `passed-on-retry` in all 10 runs. `stable` has 20 attempts
|
|
163
|
+
because both projects run it, but it is still `stable`: duplicate executions in
|
|
164
|
+
separate Playwright project suites are not retries.
|
|
165
|
+
|
|
166
|
+
**Playwright caveat:** with the default JUnit reporter, Playwright writes only
|
|
167
|
+
the final attempt for each test, so the retry is not in the XML at all. With the
|
|
168
|
+
same ten runs, the row for `checkout.spec.js::checkout › applies coupon` had 20
|
|
169
|
+
attempts, 0 passed-on-retry runs, and class `stable`. `flake-ledger` cannot
|
|
170
|
+
recover that retry from the file; set `includeRetries: true` (or
|
|
171
|
+
`PLAYWRIGHT_JUNIT_INCLUDE_RETRIES=1`) if you want retry evidence in the ledger.
|
|
172
|
+
|
|
173
|
+
## Who it is for
|
|
174
|
+
|
|
175
|
+
Maintainers of multi-runner CI suites (pytest, Playwright, xUnit,
|
|
176
|
+
cargo-nextest, Surefire) whose jobs keep going green only after a retry.
|
|
177
|
+
|
|
178
|
+
## Why not the obvious answer
|
|
179
|
+
|
|
180
|
+
pytest-rerunfailures, Playwright retries, and `--rerun-failed` only mask the
|
|
181
|
+
failure; BuildPulse, Trunk, and Datadog CI Visibility are paid hosted
|
|
182
|
+
dashboards; GitHub's flaky-test detection is confined to Actions. None offers a
|
|
183
|
+
free, offline, cross-runner ledger plus a quarantine file.
|
|
184
|
+
|
|
185
|
+
## Install
|
|
186
|
+
|
|
187
|
+
From a checkout:
|
|
188
|
+
|
|
189
|
+
```sh
|
|
190
|
+
git clone https://github.com/WJDdidi-1/flake-ledger.git
|
|
191
|
+
cd flake-ledger
|
|
192
|
+
npm install --global .
|
|
193
|
+
flake-ledger --version
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The npm package is published by the release workflow when a `v*` tag is
|
|
197
|
+
pushed. The latest release is `v0.1.1`:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
npm install --global flake-ledger@0.1.1
|
|
201
|
+
flake-ledger --version # 0.1.1
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
To try it without a global install, run the checked-in five-run example:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
npm run example
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Requires Node.js 18 or newer. There are no runtime dependencies, and the
|
|
211
|
+
published package contains the runtime (`bin/`, `lib/`), the checked-in example
|
|
212
|
+
(`examples/`), package metadata, `README.md`, and `LICENSE`.
|
|
213
|
+
|
|
214
|
+
## Use
|
|
215
|
+
|
|
216
|
+
Point the scanner at a directory of JUnit XML. It reads recursively:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
flake-ledger scan path/to/runs
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Machine-readable output, top 10 only:
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
flake-ledger scan path/to/runs --json --top 10
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Explain one test's per-run timeline, including XML paths and failure messages:
|
|
229
|
+
|
|
230
|
+
```sh
|
|
231
|
+
flake-ledger explain path/to/runs 'com.example.FooTest::eventuallyGreen'
|
|
232
|
+
flake-ledger explain path/to/runs 'com.example.FooTest::eventuallyGreen' --json
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Write the ids of flaky tests to a quarantine file, and fail CI when a flaky
|
|
236
|
+
test crosses a threshold and has at least five eligible (non-skipped) runs:
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
flake-ledger scan path/to/runs --quarantine flaky.txt --fail-on 0.5 --min-runs 5
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`--fail-on` accepts a fraction (`0.5`), a percentage (`50%`), or a whole
|
|
243
|
+
percentage (`50`). Exit codes:
|
|
244
|
+
|
|
245
|
+
- `0` — report written, or no flaky test crossed `--fail-on`.
|
|
246
|
+
- `1` — a flaky test crossed `--fail-on`, or `explain` matched no test or more
|
|
247
|
+
than one test.
|
|
248
|
+
- `2` — usage error, unreadable runs directory, or a quarantine file that
|
|
249
|
+
could not be written.
|
|
250
|
+
|
|
251
|
+
### Scan options
|
|
252
|
+
|
|
253
|
+
| Option | Meaning |
|
|
254
|
+
| --- | --- |
|
|
255
|
+
| `--json`, `-j` | Print JSON instead of the terminal table. |
|
|
256
|
+
| `--top N` | Show only the N highest-ranked tests (totals still count every test). |
|
|
257
|
+
| `--quarantine <file>` | Write the ids of flaky tests, one per line. |
|
|
258
|
+
| `--fail-on <rate>` | Exit 1 when a flaky test's unstable rate is at or above `<rate>`. |
|
|
259
|
+
| `--min-runs <n>` | With `--fail-on`, ignore tests with fewer than `n` eligible runs. |
|
|
260
|
+
| `--group-by <mode>` | `auto` (default), `file`, or `parent`; controls what counts as one run. |
|
|
261
|
+
|
|
262
|
+
## Input layout
|
|
263
|
+
|
|
264
|
+
The first directory below `<runs-dir>` is one CI run, so every XML file inside
|
|
265
|
+
it is a shard of that run:
|
|
266
|
+
|
|
267
|
+
```text
|
|
268
|
+
runs/
|
|
269
|
+
run-1/results.xml
|
|
270
|
+
run-1/retry-shard/results.xml
|
|
271
|
+
run-2/results.xml
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
XML files placed directly under `<runs-dir>` are separate runs unless their
|
|
275
|
+
names carry a shard marker (`shard-1.xml`, `run-3-part-2.xml`). Top-level
|
|
276
|
+
shard-named run directories (`run-3-shard-1/`, `run-3-shard-2/`) merge into one
|
|
277
|
+
run as well. Use `--group-by file` to make every XML document its own run, or
|
|
278
|
+
`--group-by parent` to group by immediate directory.
|
|
279
|
+
|
|
280
|
+
Supported inputs are Surefire and compatible JUnit XML, including
|
|
281
|
+
`<failure>`, `<error>`, `<skipped>`, `<flakyFailure>`, `<flakyError>`,
|
|
282
|
+
`<rerunFailure>`, `<rerunError>`, `retry`/`retries`/`rerun`/`rerunCount`
|
|
283
|
+
attributes, and repeated `<testcase>` elements for the same test. A malformed
|
|
284
|
+
XML file produces a warning and does not hide healthy files.
|
|
285
|
+
|
|
286
|
+
Real runners differ in how much of that they emit. pytest-rerunfailures
|
|
287
|
+
recovers a test by writing the passing `<testcase>` again, so repeated passing
|
|
288
|
+
testcases in one suite count as retry evidence. Playwright writes
|
|
289
|
+
`<flakyError>`/`<rerunError>` only with `includeRetries: true`; without it its
|
|
290
|
+
JUnit XML contains only the final attempt. The measured output from both
|
|
291
|
+
runners is in [`docs/real-world.md`](https://github.com/WJDdidi-1/flake-ledger/blob/main/docs/real-world.md).
|
|
292
|
+
|
|
293
|
+
## What it reports
|
|
294
|
+
|
|
295
|
+
`scan` collapses all of those attempts into one record per `classname::name`
|
|
296
|
+
and classifies it:
|
|
297
|
+
|
|
298
|
+
| Classification | Meaning |
|
|
299
|
+
| --- | --- |
|
|
300
|
+
| `stable` | Every eligible run passed without retry evidence. |
|
|
301
|
+
| `passed-on-retry` | A run ended green only after a retry. |
|
|
302
|
+
| `cross-run flake` | The test both passed and failed across runs. |
|
|
303
|
+
| `always-failing` | No run passed and at least one run failed. |
|
|
304
|
+
| `failed-on-retry` | A run ended red after at least one retry. |
|
|
305
|
+
| `skipped` | Every run skipped the test. |
|
|
306
|
+
|
|
307
|
+
Flaky classifications are `passed-on-retry`, `cross-run flake`, and
|
|
308
|
+
`failed-on-retry`; those are the records written by `--quarantine` and checked
|
|
309
|
+
by `--fail-on`.
|
|
310
|
+
|
|
311
|
+
The JSON output contains `totals`, `runs`, `warnings`, and one `tests` record
|
|
312
|
+
per test (limited to the first N by `--top`) with its `attempts`,
|
|
313
|
+
`unstableRuns`, `eligibleRuns`, `unstableRate`, Wilson `score`,
|
|
314
|
+
`classification`, and `timeline`.
|
|
315
|
+
|
|
316
|
+
## Use it in CI
|
|
317
|
+
|
|
318
|
+
Collect one directory per CI run (artifact names become run ids), download the
|
|
319
|
+
reports, and gate on the ledger:
|
|
320
|
+
|
|
321
|
+
```yaml
|
|
322
|
+
- uses: actions/download-artifact@v4
|
|
323
|
+
with:
|
|
324
|
+
path: runs
|
|
325
|
+
- run: npm install --global flake-ledger
|
|
326
|
+
- run: flake-ledger scan runs --fail-on 0.3 --min-runs 10 --quarantine flaky.txt
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
The command fails only when a flaky classification crosses the threshold. Keep
|
|
330
|
+
the `flaky.txt` artifact or commit it if your test runner supports reading a
|
|
331
|
+
quarantine list.
|
|
332
|
+
|
|
333
|
+
## FAQ
|
|
334
|
+
|
|
335
|
+
**Do I have to install it globally?**
|
|
336
|
+
No. From a checkout, call the CLI through Node:
|
|
337
|
+
|
|
338
|
+
```sh
|
|
339
|
+
node bin/flake-ledger.mjs scan path/to/runs
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
A global install just makes `flake-ledger` available on your `PATH`.
|
|
343
|
+
|
|
344
|
+
**Does it run or retry my tests?**
|
|
345
|
+
No. `flake-ledger` reads JUnit XML that your test runner already produced; it
|
|
346
|
+
does not execute tests, change retry settings, or modify reports.
|
|
347
|
+
|
|
348
|
+
**Does it upload my reports anywhere?**
|
|
349
|
+
No. `scan` and `explain` read local XML and write to stdout, `--json`, or the
|
|
350
|
+
`--quarantine` file you name. There are no network calls and no runtime
|
|
351
|
+
dependencies.
|
|
352
|
+
|
|
353
|
+
**How do I fail CI only on well-evidenced flakes?**
|
|
354
|
+
Combine both thresholds:
|
|
355
|
+
|
|
356
|
+
```sh
|
|
357
|
+
flake-ledger scan path/to/runs --fail-on 0.3 --min-runs 10
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
On a readable runs directory, this exits 1 only when a flaky classification has
|
|
361
|
+
at least 10 eligible runs and an unstable rate of at least 30%; otherwise it
|
|
362
|
+
exits 0. Without `--fail-on`, `scan` is report-only.
|
|
363
|
+
|
|
364
|
+
**How much history do I need?**
|
|
365
|
+
One run is enough to produce a ledger, and a single run can already show
|
|
366
|
+
`passed-on-retry` evidence; cross-run flakes need at least two runs. The score
|
|
367
|
+
is a 95% Wilson lower bound on the unstable rate, so use `--min-runs` to require
|
|
368
|
+
enough history before `--fail-on` can fail the build.
|
|
369
|
+
|
|
370
|
+
## How we know it works
|
|
371
|
+
|
|
372
|
+
`npm test` builds temporary JUnit fixtures and exercises every feature above
|
|
373
|
+
through the CLI: recursive scanning, shard merging, repeated testcases,
|
|
374
|
+
Surefire `flakyFailure`/`rerunFailure`, retry attributes, all classifications,
|
|
375
|
+
Wilson-bound table ordering, `--json`, `--top`, `--quarantine`, `explain`, and
|
|
376
|
+
`--fail-on`/`--min-runs`.
|
|
377
|
+
|
|
378
|
+
The checked-in fixture under [`examples/runs`](examples/runs) is a second,
|
|
379
|
+
readable path through the same CLI: `npm run example` runs `scan`, `explain`,
|
|
380
|
+
`--quarantine`, and the CI gate against it, and exits nonzero if the table,
|
|
381
|
+
timeline, quarantine list, or exit codes change.
|
|
382
|
+
|
|
383
|
+
The real-runner measurement in [`docs/real-world.md`](https://github.com/WJDdidi-1/flake-ledger/blob/main/docs/real-world.md)
|
|
384
|
+
records the exact commands and output from pytest-rerunfailures and Playwright,
|
|
385
|
+
including the Playwright `includeRetries` caveat.
|
|
386
|
+
|
|
387
|
+
CI runs the suite on Ubuntu, macOS (Intel), and Windows for Node.js 18, 20, 22,
|
|
388
|
+
and 24. Each job also packs the tarball, installs it into a clean directory,
|
|
389
|
+
and runs the installed binary, so the published package is tested rather than
|
|
390
|
+
just the checkout.
|
|
391
|
+
|
|
392
|
+
From a checkout, the same commands run against the local entry point:
|
|
393
|
+
|
|
394
|
+
```sh
|
|
395
|
+
npm test
|
|
396
|
+
node bin/flake-ledger.mjs scan path/to/runs
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Releases
|
|
400
|
+
|
|
401
|
+
Versions are SemVer tags (`vMAJOR.MINOR.PATCH`) and must match `version` in
|
|
402
|
+
`package.json`. Pushing a `v*` tag runs the publish workflow, which tests,
|
|
403
|
+
packs the tarball, installs it into a clean directory, and publishes it to npm
|
|
404
|
+
with provenance. The latest release is `v0.1.1`, matching `version` `0.1.1` in
|
|
405
|
+
`package.json`.
|
|
406
|
+
|
|
407
|
+
The changelog for each version lives in [`CHANGELOG.md`](CHANGELOG.md), the
|
|
408
|
+
per-release GitHub Release bodies are in
|
|
409
|
+
[`docs/releases`](https://github.com/WJDdidi-1/flake-ledger/tree/main/docs/releases),
|
|
410
|
+
and the maintainer steps are in
|
|
411
|
+
[`docs/RELEASING.md`](https://github.com/WJDdidi-1/flake-ledger/blob/main/docs/RELEASING.md).
|
|
412
|
+
|
|
413
|
+
## Status
|
|
414
|
+
|
|
415
|
+
Early MVP. The features above are the scope; anything not listed is not built
|
|
416
|
+
yet.
|
|
417
|
+
|
|
418
|
+
## License
|
|
419
|
+
|
|
420
|
+
Apache-2.0. See [LICENSE](LICENSE).
|