browser_review_gate 0.5.3 → 0.5.5

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: 2bca6bbab560800bc0b31754503019313587216fe741889a50f073a5683726ef
4
+ data.tar.gz: 17d1ef5b020bc258a0df17e22bf13cd26dca73efe15243060b09f85e5c49ab1c
5
5
  SHA512:
6
- metadata.gz: 7938e08099e7a40edb047df2957e51fd53d339662aa1ac20f9ba2c6a62ac979e1723986347b76f9646ddaa0364138306b4c72106a52beec40b07650e12203150
7
- data.tar.gz: b4b2284f88a75f1d23accdd782501bc12b3e31ae71e787fa964a5c70bdb974c405d89da262aea8f9c60485be7e26924769bdfedaf9dab735f622e4b63579d505
6
+ metadata.gz: 31d206b2156a6381e78ca6b0cda4cdc2aaef3b8f32df1345265ea2f6561772e3a578e679c23c2966b172332bbb4324e72110144c6ab44afef8cda76f1212a29e
7
+ data.tar.gz: eda6d97f4d0a387a920079a2fa62d3d19dd31a2abf30adf8e734196de3393c981c8e7e5a9ac3fd5472cb7cf8357fa7603223ec2feb7b08dc1c209e9e64abc73c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.5
4
+
5
+ - A draft is gated too. A push to a draft used to skip the workflow, so the new head had no
6
+ `browser-verification` status and review looked open while the old comment still said it was on
7
+ hold. Now the head of a draft stays pending, and a reviewer requested on a draft is taken back. A
8
+ draft is still assessed only when it is marked ready (or dispatched by hand), so no model is
9
+ called on draft pushes. Re-run `browser-review-gate install` to update the workflow.
10
+
11
+ ## 0.5.4
12
+
13
+ - A case that fails and passes on the same commit is marked flaky in the PR comment and counted in
14
+ `stats` (`flaky_cases`). The latest result still decides, so the gate passes and blocks as before;
15
+ the earlier failure is no longer lost when a re-run passes. Reports cannot set the mark themselves.
16
+
3
17
  ## 0.5.3
4
18
 
5
19
  - 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
  ```
@@ -27,8 +27,9 @@ module BrowserReviewGate
27
27
  stats [--days N] [--json] what the gate did on PRs of the last N days (default 30)
28
28
  TEXT
29
29
 
30
- # `github`, `config`, `model` and `shell` are replaced in tests.
31
- def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr, github: nil, config: nil, model: nil, shell: nil)
30
+ # `github`, `config`, `model`, `shell` and `env` are replaced in tests.
31
+ def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr, github: nil, config: nil, model: nil, shell: nil, env: ENV)
32
+ @env = env
32
33
  @shell = shell
33
34
  @argv = argv.dup
34
35
  @github = github
@@ -190,18 +191,26 @@ module BrowserReviewGate
190
191
  return 0
191
192
  end
192
193
 
193
- failed = false
194
- begin
195
- model = @model || (config.local? ? nil : ModelClient.for(config))
196
- Assessor.new(github: github, model: model, config: config, prompts: Prompts.new(root), log: @stdout).assess(number, pull_request: pull_request)
197
- rescue Error => error
198
- failed = true
199
- # Escaped per the workflow-command spec so a message can never start a command of its own.
200
- message = error.message.gsub("%", "%25").gsub("\r", "%0D").gsub("\n", "%0A")
201
- @stdout.puts "::error title=Browser verification assessment failed::#{message}"
194
+ # A draft is assessed when it is marked ready or by hand; until then its head stays on hold.
195
+ if pull_request["draft"] && @env["GITHUB_EVENT_NAME"] != "workflow_dispatch"
196
+ @stdout.puts "PR #{number} is a draft; it is assessed when it is marked ready for review."
197
+ failed = false
198
+ else
199
+ failed = !assessed?(number, pull_request)
202
200
  end
203
201
  Gate.new(github: github, config: config, log: @stdout).enforce(number)
204
202
  failed ? 1 : 0
205
203
  end
204
+
205
+ def assessed?(number, pull_request)
206
+ model = @model || (config.local? ? nil : ModelClient.for(config))
207
+ Assessor.new(github: github, model: model, config: config, prompts: Prompts.new(root), log: @stdout).assess(number, pull_request: pull_request)
208
+ true
209
+ rescue Error => error
210
+ # Escaped per the workflow-command spec so a message can never start a command of its own.
211
+ message = error.message.gsub("%", "%25").gsub("\r", "%0D").gsub("\n", "%0A")
212
+ @stdout.puts "::error title=Browser verification assessment failed::#{message}"
213
+ false
214
+ end
206
215
  end
207
216
  end
@@ -39,6 +39,7 @@ module BrowserReviewGate
39
39
 
40
40
  def verdict(number, pull_request, comments, assessment, waived_by)
41
41
  return [ :open, "Browser verification waived by #{waived_by}." ] if waived_by
42
+ return [ :closed, "Draft: browser testing is assessed when it is marked ready for review." ] if !assessment && pull_request["draft"]
42
43
  return [ :closed, "The browser-testing assessment for this commit is not available." ] unless assessment
43
44
  return [ :open, "Browser verification is not needed." ] unless assessment.required?
44
45
  return [ :open, "Required browser cases are verified." ] if verified?(number, pull_request, comments, assessment)
@@ -91,7 +92,7 @@ module BrowserReviewGate
91
92
  @github.remove_reviewers(number, reviewers: reviewers, team_reviewers: teams)
92
93
  waiting = paused(comments)
93
94
  waiting = { "reviewers" => waiting["reviewers"] | reviewers, "teams" => waiting["teams"] | teams }
94
- write_notice(number, comments, "#{author(pull_request)}#{notice(number, assessment, comments)}\n\n#{names(waiting)} will be " \
95
+ write_notice(number, comments, "#{author(pull_request)}#{notice(number, pull_request, assessment, comments)}\n\n#{names(waiting)} will be " \
95
96
  "asked again automatically once the run is published.", waiting)
96
97
  @log.puts "Took back reviewer requests until browser verification is available."
97
98
  end
@@ -158,7 +159,8 @@ module BrowserReviewGate
158
159
  (waiting["reviewers"] + waiting["teams"]).map { |name| Markdown.escape(name) }.join(", ")
159
160
  end
160
161
 
161
- def notice(number, assessment, comments)
162
+ def notice(number, pull_request, assessment, comments)
163
+ return "Review request paused. This PR is a draft: browser testing is assessed when it is marked ready for review." if !assessment && pull_request["draft"]
162
164
  return "Review request paused. The browser-testing assessment for this commit is not available. Request review again to retry it." unless assessment
163
165
 
164
166
  report = Report.latest(comments, config: @config)
@@ -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
@@ -38,10 +38,9 @@ concurrency:
38
38
 
39
39
  jobs:
40
40
  gate:
41
- # A draft is assessed when it is marked ready, or when someone asks by hand (workflow_dispatch).
41
+ # A draft runs too, so a push keeps its head on hold; it is assessed once marked ready or by hand.
42
42
  # Of all labels, only the two that open the gate matter, added or removed: a published run and a waiver.
43
43
  if: >-
44
- (github.event_name == 'workflow_dispatch' || !github.event.pull_request.draft) &&
45
44
  (!contains(fromJSON('["labeled","unlabeled"]'), github.event.action) ||
46
45
  contains(fromJSON('<%= JSON.generate(gate_labels) %>'), github.event.label.name))
47
46
  runs-on: ubuntu-latest
@@ -1,3 +1,3 @@
1
1
  module BrowserReviewGate
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.5"
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Gagiev