browser_review_gate 0.5.3 → 0.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa41c3531805de8375cd86b4251457ed78e065eec4ca8e5a02f6adb2196d6dc2
4
- data.tar.gz: d8459a362a7b71375a0c2d9ea12e7fb5a50b30883de73ddacb69c96825a761d9
3
+ metadata.gz: 8e9447ba105f1d9b90e465a8b887beaac6cca90280ada8608081aeec2d1c2c0b
4
+ data.tar.gz: 67f52f8dfeb88d014f0ea761cd333d0708d99ffaae0732ce5bb11aaf2312242a
5
5
  SHA512:
6
- metadata.gz: 7938e08099e7a40edb047df2957e51fd53d339662aa1ac20f9ba2c6a62ac979e1723986347b76f9646ddaa0364138306b4c72106a52beec40b07650e12203150
7
- data.tar.gz: b4b2284f88a75f1d23accdd782501bc12b3e31ae71e787fa964a5c70bdb974c405d89da262aea8f9c60485be7e26924769bdfedaf9dab735f622e4b63579d505
6
+ metadata.gz: f4f2a351ab14b56951ba803368a30f4ae6f46c611d77634a9c0144fa440a63f3702242b7d5f570aae954a8eabb0eacc4241296329cd9d95db88fbae2ffbaa19c
7
+ data.tar.gz: 2f83d3dc9647b12132183b5b62734b7bf82f729441e1e7a704df711de482fb8909328f0fe20201e74693640efb074930670d9d37de38b7b553ee24ed2ddf99a9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.4
4
+
5
+ - A case that fails and passes on the same commit is marked flaky in the PR comment and counted in
6
+ `stats` (`flaky_cases`). The latest result still decides, so the gate passes and blocks as before;
7
+ the earlier failure is no longer lost when a re-run passes. Reports cannot set the mark themselves.
8
+
3
9
  ## 0.5.3
4
10
 
5
11
  - Every comment the gem writes opens with one line saying `browser_review_gate` wrote it: the
data/README.md CHANGED
@@ -158,6 +158,8 @@ A report is JSON in the shape the playbook describes (`schema_version: 2`): the
158
158
 
159
159
  The PR comment shows every scenario as passed, failed, blocked, skipped, missing or stale, the environment and tool, the tested commit of each case, and the evidence. It says plainly that observations are the agent's account.
160
160
 
161
+ A case whose results differ on the same commit, a fail and a pass, is marked flaky in the PR and counted in `stats`. The latest result still decides: a failure followed by a passing re-run counts as passed, and a pass followed by a failure still blocks. Only the gem sets the mark; a submitted report that sets it is refused.
162
+
161
163
  ## Commands
162
164
 
163
165
  ```
@@ -18,7 +18,7 @@ module BrowserReviewGate
18
18
  URL_PATTERN = %r{\A(?:https?://|/)\S*\z}
19
19
  TOP_KEYS = %w[schema_version tested_sha verified_by environment tool started_at finished_at coverage_complete
20
20
  cases excluded runs failed_runs not_required].freeze
21
- CASE_KEYS = %w[id name result url details reason evidence tested_sha verified_by environment tool].freeze
21
+ CASE_KEYS = %w[id name result url details reason evidence tested_sha verified_by environment tool flaky].freeze
22
22
  EVIDENCE_KEYS = %w[files console_errors network_errors links trace_check].freeze
23
23
  FILE_KEYS = %w[kind name media_type bytes sha256].freeze
24
24
 
@@ -46,17 +46,28 @@ module BrowserReviewGate
46
46
 
47
47
  # Later results replace earlier ones case by case; cases that were not run again are kept. The
48
48
  # merged report counts the runs published on the PR and how many of them had a failing case.
49
+ # A case whose results differed on the same commit is marked flaky; the latest result still counts.
49
50
  def self.merge(previous_data, latest_data, config: Config.new)
50
51
  previous = new(previous_data, config: config)
51
52
  latest = new(latest_data, config: config)
52
53
  return latest unless latest.valid?
53
54
 
54
55
  combined = previous.valid? ? previous.cases.to_h { |test_case| [ test_case["id"], test_case ] } : {}
55
- latest.cases.each { |test_case| combined[test_case["id"]] = test_case }
56
+ latest.cases.each { |test_case| combined[test_case["id"]] = with_flaky_mark(combined[test_case["id"]], test_case) }
56
57
  failed = latest.cases.any? { |test_case| test_case["result"] == "fail" } ? 1 : 0
57
58
  new(latest.to_h.merge("cases" => combined.values, "runs" => previous.runs + 1, "failed_runs" => previous.failed_runs + failed), config: config)
58
59
  end
59
60
 
61
+ # The same code passed once and failed once, so the outcome does not depend on the change alone.
62
+ # The mark stays for as long as the case is run on that commit.
63
+ def self.with_flaky_mark(earlier, test_case)
64
+ return test_case unless earlier && earlier["tested_sha"] == test_case["tested_sha"]
65
+ return test_case unless earlier["flaky"] == true || [ earlier["result"], test_case["result"] ].sort == %w[fail pass]
66
+
67
+ test_case.merge("flaky" => true)
68
+ end
69
+ private_class_method :with_flaky_mark
70
+
60
71
  def initialize(data, config: Config.new)
61
72
  @config = config
62
73
  @errors = []
@@ -120,6 +131,8 @@ module BrowserReviewGate
120
131
  missing_evidence(test_case, evidence) || trace_problem(evidence)
121
132
  end
122
133
 
134
+ def flaky?(id) = cases.any? { |test_case| test_case["id"] == id && test_case["flaky"] == true }
135
+
123
136
  def failed? = cases.any? { |test_case| status_of(test_case["id"]) == "failed" }
124
137
 
125
138
  # Complete, and nothing failed when failures block review.
@@ -144,6 +157,7 @@ module BrowserReviewGate
144
157
  found << "case #{position} is #{test_case["result"]} and needs a reason" unless text?(test_case["reason"], 300)
145
158
  end
146
159
  found << "case #{position} details must say what was observed" unless text?(test_case["details"], 500)
160
+ found << "case #{position} flaky is set by the gem from earlier runs, not by the report" if test_case.key?("flaky")
147
161
  evidence = test_case["evidence"].is_a?(Hash) ? test_case["evidence"] : {}
148
162
  problem = test_case["result"] == "pass" ? (missing_evidence(test_case, evidence) || trace_problem(evidence)) : nil
149
163
  found << "case #{position} #{problem}" if problem
@@ -320,6 +334,7 @@ module BrowserReviewGate
320
334
  errors << "case #{position} details must be a string of at most 500 characters" unless test_case["details"].nil? || text?(test_case["details"], 500)
321
335
  errors << "case #{position} reason must be a string of at most 300 characters" unless test_case["reason"].nil? || text?(test_case["reason"], 300)
322
336
  errors << "case #{position} tool must name the browser tool" unless test_case["tool"].is_a?(Hash) && text?(test_case["tool"]["name"], 60)
337
+ errors << "case #{position} flaky must be true when present" unless test_case["flaky"].nil? || test_case["flaky"] == true
323
338
  validate_evidence(test_case["evidence"], position) unless test_case["evidence"].nil?
324
339
  end
325
340
 
@@ -378,6 +393,7 @@ module BrowserReviewGate
378
393
  def markdown_case(test_case, commits)
379
394
  status = status_of(test_case["id"], commits: commits)
380
395
  problem = test_case["result"] == "pass" && status == "failed" ? " (#{policy_problem(test_case)})" : ""
396
+ problem += " (flaky: results differed on this commit)" if test_case["flaky"] == true
381
397
  page = test_case["url"].to_s.empty? ? "" : Markdown.escape(test_case["url"])
382
398
  "| `#{test_case["id"]}` #{Markdown.escape(test_case["name"])} | #{status.upcase}#{Markdown.escape(problem)} | #{page} | " \
383
399
  "`#{test_case["tested_sha"][0, 7]}` | #{markdown_evidence(test_case["evidence"])} |"
@@ -5,7 +5,7 @@ module BrowserReviewGate
5
5
  # the comments record is counted: each PR keeps its latest assessment and its merged report, so
6
6
  # earlier assessments of the same PR and their token usage are not visible any more.
7
7
  class Stats
8
- COUNTS = %w[pull_requests assessed required verified waived owed found_a_failure runs failed_runs].freeze
8
+ COUNTS = %w[pull_requests assessed required verified waived owed found_a_failure runs failed_runs flaky_cases].freeze
9
9
 
10
10
  def initialize(github:, config: Config.new)
11
11
  @github = github
@@ -35,7 +35,8 @@ module BrowserReviewGate
35
35
  " waived: #{result["waived"]}",
36
36
  " open and still owing a run: #{result["owed"]}",
37
37
  " a run found a failing case: #{result["found_a_failure"]}",
38
- " browser runs published: #{result["runs"]} (#{result["failed_runs"]} with a failing case)" ]
38
+ " browser runs published: #{result["runs"]} (#{result["failed_runs"]} with a failing case)",
39
+ " flaky cases: #{result["flaky_cases"]} (results differed on one commit)" ]
39
40
  if (time = result["hours_to_verification"])
40
41
  lines << " PR opened to verified run: median #{time["median"]} h over #{time["measured"]} PRs"
41
42
  end
@@ -77,6 +78,7 @@ module BrowserReviewGate
77
78
  counts["runs"] += report.runs
78
79
  counts["failed_runs"] += report.failed_runs
79
80
  counts["found_a_failure"] += 1 if report.failed_runs.positive?
81
+ counts["flaky_cases"] += report.cases.count { |test_case| test_case["flaky"] == true }
80
82
  report.cases.each { |test_case| failing[test_case["id"]] += 1 if report.status_of(test_case["id"]) == "failed" }
81
83
  measure(pull_request, comments, labels, hours)
82
84
  end
@@ -1,3 +1,3 @@
1
1
  module BrowserReviewGate
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_review_gate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Gagiev