Class: Homebrew::DevCmd::AdvisoryMatch Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/advisory-match.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/advisory_match.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args, CountEmitter, DirEmitter, Emitter, JsonEmitter

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::DevCmd::AdvisoryMatch::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/advisory_match.rbi', line 10

def args; end

#build_emitter(formula_names: nil) ⇒ Emitter

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • formula_names (Array<String>, nil) (defaults to: nil)

Returns:



1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
# File 'dev-cmd/advisory-match.rb', line 1346

def build_emitter(formula_names: nil)
  if (dir = args.output)
    DirEmitter.new(dir, verbose: args.verbose?, close_open_ranges: !args.no_history?,
                   reconcile_history: args.reconcile_history?, formula_names:)
  elsif args.json?
    JsonEmitter.new
  else
    CountEmitter.new
  end
end

#each_formula(formula_names: nil) ⇒ T::Enumerator[Formula]

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • formula_names (Array<String>, nil) (defaults to: nil)

Returns:

Raises:



530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'dev-cmd/advisory-match.rb', line 530

def each_formula(formula_names: nil)
  return args.named.to_resolved_formulae.each if !args.all? && !args.formula_list

  raise UsageError, "`--all` does not take named arguments" if args.named.any?

  tap = CoreTap.instance
  raise TapUnavailableError, tap.name unless tap.installed?

  names = tap.formula_names
  if formula_names
    (formula_names - names).each do |name|
      opoo "#{name}: no longer in homebrew/core; leaving its records unchanged"
    end
    names &= formula_names
  end

  Enumerator.new do |y|
    names.each do |name|
      y << Formulary.factory(name)
    rescue => e
      onoe "Error loading formula '#{name}': #{e}"
    end
  end
end

#emit_index(matcher) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

Raises:



1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
# File 'dev-cmd/advisory-match.rb', line 1358

def emit_index(matcher)
  tap = CoreTap.instance
  raise TapUnavailableError, tap.name unless tap.installed?

  index = tap.formula_names.each_with_object({}) do |name, h|
    identity = matcher.identify(Formulary.factory(name))
    next unless identity.identifiable?

    h[name] = {
      git_repo:          identity.git_repo,
      git_tag:           identity.git_tag,
      primary_package:   identity.primary_package&.to_h,
      resource_packages: identity.resource_packages.transform_values(&:to_h),
      distro_packages:   identity.distro_packages,
    }.compact
  rescue => e
    onoe "Error loading formula '#{name}': #{e}"
  end
  puts JSON.pretty_generate(index)
end

#hold_upstream_formula(formula, error, emitter) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



508
509
510
511
# File 'dev-cmd/advisory-match.rb', line 508

def hold_upstream_formula(formula, error, emitter)
  emitter.record_upstream_unavailable(formula.name) if emitter.is_a?(DirEmitter)
  opoo "#{formula.name}: upstream unavailable; leaving its records unchanged: #{error.message}"
end

#local_overrides ⇒ Homebrew::Vulns::AdvisoryOverrides?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



523
524
525
526
527
# File 'dev-cmd/advisory-match.rb', line 523

def local_overrides
  return unless (path = args.overrides)

  Homebrew::Vulns::AdvisoryOverrides.from_file(Pathname(path))
end

#local_repology ⇒ Homebrew::Vulns::Repology?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

A CI run that has just built the index locally (advisory-database's Ingest) reads it directly instead of fetching the published copy.

Returns:



516
517
518
519
520
# File 'dev-cmd/advisory-match.rb', line 516

def local_repology
  return unless (path = args.repology)

  Homebrew::Vulns::Repology.from_file(Pathname(path))
end

#new_record_histories(matcher, formula, hits, emitter, latest_macos:) ⇒ Hash{String => Homebrew::Vulns::Match::ReconciledHistory}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Query each platform once per formula. Stop visiting platforms for a candidate as soon as its history or provenance requires review.

Parameters:

Returns:



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'dev-cmd/advisory-match.rb', line 311

def new_record_histories(matcher, formula, hits, emitter, latest_macos:)
  independent = Homebrew::Vulns::PlatformIndependence.formula?(formula)
  records = hits.to_h { |hit| [matcher.record_id(formula, hit), matcher.to_brew_record(formula, hit)] }
  outcomes = T.let({}, T::Hash[String, T::Array[Homebrew::Vulns::Match::ReconciledHistory]])
  records.each_key { |id| outcomes[id] = [] }
  [[latest_macos, :arm], [latest_macos, :intel], [:linux, :arm], [:linux, :intel]]
    .each_with_index do |(os, arch), index|
    pending = hits.select do |hit|
      outcomes.fetch(matcher.record_id(formula, hit))
              .all? { |result| [:range, :never_affected].include?(result.state) }
    end
    break if pending.empty?

    Homebrew::SimulateSystem.with(os:, arch:) do
      begin
        view = (index.zero? || independent) ? formula : Formulary.factory(formula.path)
        platform_hits = if index.zero? || independent
          hits
        else
          matcher.dedup_by_aliases(matcher.advisories_for(view))
        end
      rescue Homebrew::Vulns::OSV::Error
        raise
      rescue => e
        pending.each do |hit|
          outcomes.fetch(matcher.record_id(formula, hit)) << Homebrew::Vulns::Match::ReconciledHistory.new(
            state: :unresolved, reasons: [:platform_unavailable],
          )
        end
        opoo "#{formula.name} (#{os}/#{arch}): #{e.message}"
        next
      end
      pending.each do |hit|
        id = matcher.record_id(formula, hit)
        family = platform_hits.select { |other| other.identifiers.intersect?(hit.identifiers) }
        # Missing query results alone never prove absence. A resource-only
        # hit can reuse its upstream constraints when every subject is
        # demonstrably absent; the full walk still checks older builds.
        absent_resources = family.empty? && hit.evidence.present? && hit.evidence.all? do |evidence|
          evidence.resource && !matcher.subject_version_at(view, evidence).first
        end
        if absent_resources
          platform_hit = hit
        elsif platform_provenance_changed?(matcher, emitter, records.fetch(id), view, family)
          outcomes.fetch(id) << Homebrew::Vulns::Match::ReconciledHistory.new(
            state: :unresolved, reasons: [:platform_provenance_changed],
          )
          next
        else
          platform_hit = family.fetch(0)
        end
        emitter.record_history_walk
        outcomes.fetch(id) << matcher.reconcile_history(view, platform_hit, reuse_platforms: true)
      end
    end
  end
  outcomes.transform_values { |results| Homebrew::Vulns::Match::ReconciledHistory.combine(results) }
end

#platform_provenance_changed?(matcher, emitter, record, view, family) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

A platform view must rediscover the record through exactly one hit carrying its stored upstream family with the same matching provenance; anything else means the stored ranges cannot be compared across views.

Parameters:

Returns:

  • (Boolean)


499
500
501
502
503
504
505
# File 'dev-cmd/advisory-match.rb', line 499

def platform_provenance_changed?(matcher, emitter, record, view, family)
  hit = family.first
  return true if !family.one? || hit.nil?
  return true if emitter.range_basis(record) != emitter.range_basis(matcher.to_brew_record(view, hit))

  (record.fetch(:upstream) - hit.identifiers).any?
end

#reconcile_formula(matcher, formula, hits, emitter, latest_macos:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'dev-cmd/advisory-match.rb', line 391

def reconcile_formula(matcher, formula, hits, emitter, latest_macos:)
  return if matcher.skip_formula?(formula.name)

  resource_records = emitter.reconciliation_resource_records(formula.name).reject do |record|
    if hits.any? { |hit| record.upstream.intersect?(hit.identifiers) }
      true
    elsif matcher.preserve_homebrew_ranges?(formula.name, record.upstream)
      emitter.skip_reconciliation(record.id, [:preserved])
      true
    else
      false
    end
  end
  resource_hits = matcher.resource_advisories_for(resource_records)
  hits = matcher.dedup_by_aliases(hits + resource_hits)
  resource_records.each do |record|
    next if hits.any? { |hit| record.upstream.intersect?(hit.identifiers) }

    emitter.skip_reconciliation(record.id, [:resource_not_rediscovered])
  end
  groups = hits.to_h do |hit|
    ids = matcher.record_ids(formula, hit)
    [ids.fetch(0), ids]
  end
  errors = emitter.prepare_aliases(formula.name, groups)
  if errors.any?
    errors.each { |error| onoe error }
    Homebrew.failed = true
    return
  end

  candidates = hits.to_h { |hit| [matcher.record_id(formula, hit), matcher.to_brew_record(formula, hit)] }
  candidates.select! { |_, record| emitter.reconciliation_record(record) }
  return if candidates.empty?

  outcomes = T.let({}, T::Hash[String, T::Array[Homebrew::Vulns::Match::ReconciledHistory]])
  candidates.each_key { |id| outcomes[id] = [] }
  platforms = T.let([[latest_macos, :arm], [latest_macos, :intel], [:linux, :arm], [:linux, :intel]],
                    T::Array[[Symbol, Symbol]])
  platforms.each_with_index do |(os, arch), index|
    pending = candidates.select do |id, _|
      outcomes.fetch(id).all? { |result| [:range, :never_affected].include?(result.state) }
    end
    break if pending.empty?

    Homebrew::SimulateSystem.with(os:, arch:) do
      # Reload under each platform: resources and primary sources can differ.
      begin
        view = index.zero? ? formula : Formulary.factory(formula.path)
        platform_hits = if index.zero?
          hits
        else
          matcher.dedup_by_aliases(
            matcher.advisories_for(view) + resource_hits,
          )
        end
      rescue Homebrew::Vulns::OSV::Error
        raise
      rescue => e
        pending.each_key do |id|
          outcomes.fetch(id) << Homebrew::Vulns::Match::ReconciledHistory.new(
            state: :unresolved, reasons: [:platform_unavailable],
          )
        end
        opoo "#{formula.name} (#{os}/#{arch}): #{e.message}"
        next
      end
      pending.each do |id, record|
        family = platform_hits.select { |hit| hit.identifiers.intersect?(record.fetch(:upstream)) }
        if platform_provenance_changed?(matcher, emitter, record, view, family)
          result = Homebrew::Vulns::Match::ReconciledHistory.new(
            state: :unresolved, reasons: [:platform_provenance_changed],
          )
        else
          hit = family.fetch(0)
          result = if resource_records.any? { |stored| stored.upstream.intersect?(hit.identifiers) }
            matcher.reconcile_history(view, hit, require_resource_presence: true)
          else
            matcher.reconcile_history(view, hit)
          end
          emitter.record_history_walk if result.state != :preserved
        end
        outcomes.fetch(id) << result
      end
    end
  end
  candidates.each do |id, record|
    results = outcomes.fetch(id)
    reasons = results.flat_map(&:reasons)
    reasons << :preserved if results.any? { |result| result.state == :preserved }
    reasons << :platform_unavailable if results.length != platforms.length
    if reasons.any?
      emitter.skip_reconciliation(id, reasons.uniq)
    else
      emitter.reconcile(record, Homebrew::Vulns::Match::ReconciledHistory.combine(results))
    end
  end
rescue Homebrew::Vulns::OSV::Error => e
  hold_upstream_formula(formula, e, emitter)
end

#report(matcher, formula, hits) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'dev-cmd/advisory-match.rb', line 564

def report(matcher, formula, hits)
  ohai "#{formula.name} #{formula.pkg_version}"
  if hits.empty?
    puts "  No advisories matched."
    return
  end
  hits.sort_by { |h| [-h.vulnerability.severity_level, h.canonical_id] }.each do |hit|
    v = hit.vulnerability
    status, = matcher.range_status(hit, formula_name: formula.name)
    state = case status&.state
    when nil       then "uncomparable"
    when :affected then "AFFECTED#{", upstream fix #{status&.fixed_in}" if status&.fixed_in}"
    when :fixed    then "fixed (upstream #{status&.fixed_in || "?"})"
    else "not applicable"
    end
    summary = v.summary&.slice(0, 60)
    puts "  #{hit.canonical_id} [#{hit.strategy}, #{matcher.confidence_for(hit, status)}] " \
         "#{v.severity_display} #{state}" \
         "#{" (resource: #{hit.resource})" if hit.resource}" \
         "#{" — #{summary}" if summary}"
  end
end

#report_history_load_failures(matcher) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'dev-cmd/advisory-match.rb', line 371

def report_history_load_failures(matcher)
  failures = matcher.history_load_failures
  return if failures.empty?

  revisions = failures.map { |failure| [failure.formula, failure.revision, failure.path] }.uniq.length
  formulae = failures.map(&:formula).uniq.length
  puts "  History loads: #{revisions} failed formula revisions across #{formulae} formulae " \
       "(#{failures.length} platform loads)"
  return unless args.verbose?

  failures.each do |failure|
    puts "    #{failure.formula}: #{failure.revision}:#{failure.path} [#{failure.platform}] " \
         "#{failure.error_class}: #{failure.message}"
  end
end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'dev-cmd/advisory-match.rb', line 74

def run
  if args.formula_list && !args.reconcile_history? && !args.new_history?
    raise UsageError, "`--formula-list` requires `--new-history` or `--reconcile-history`"
  end
  if args.reconcile_history? && !args.overrides
    raise UsageError, "`--reconcile-history` requires an explicit `--overrides` file"
  end
  if args.formula_list && args.named.any?
    raise UsageError, "`--formula-list` does not take named arguments"
  end

  formula_names = if (list = args.formula_list)
    File.readlines(list, chomp: true).reject(&:empty?).uniq
  end
  rejected_candidates = if (path = args.rejected_candidates)
    File.readlines(path, chomp: true).filter_map do |line|
      id = line.sub(/#.*/, "").strip
      id unless id.empty?
    end.to_set
  else
    Set.new
  end
  prefiltered = T.let([], T::Array[String])
  Formulary.enable_factory_cache!
  Homebrew::API.with_no_api_env do
    latest_macos = MacOSVersion.new((HOMEBREW_MACOS_NEWEST_UNSUPPORTED.to_i - 1).to_s).to_sym
    Homebrew::SimulateSystem.with(os: latest_macos, arch: :arm) do
      overrides = local_overrides
      matcher = Homebrew::Vulns::Match.new(repology:        local_repology,
                                           overrides:,
                                           bulk:            args.all? || args.index? || !formula_names.nil?,
                                           strict_upstream: args.reconcile_history?)
      next emit_index(matcher) if args.index?

      emitter = build_emitter(formula_names:)
      begin
        on_error = if args.reconcile_history?
          lambda do |formula, error|
            hold_upstream_formula(formula, error, emitter)
          end
        end
        matcher.each_advisory_batch(
          each_formula(formula_names:),
          on_error:,
        ) do |formula, hits|
          if args.reconcile_history? && emitter.is_a?(DirEmitter)
            reconcile_formula(matcher, formula, hits, emitter, latest_macos:)
            next
          end

          report(matcher, formula, hits) if text_mode?
          # A below-introduced hit would otherwise look open to OSV
          # consumers; it must not participate in alias maintenance.
          actionable = hits.filter_map do |hit|
            status, = matcher.range_status(hit, formula_name: formula.name)
            [hit, status] if status&.state != :not_applicable
          end
          record_ids_by_canonical = actionable.to_h do |hit, _status|
            ids = matcher.record_ids(formula, hit)
            [ids.fetch(0), ids]
          end
          alias_errors = emitter.prepare_aliases(formula.name, record_ids_by_canonical)
          if alias_errors.any?
            alias_errors.each { |error| onoe error }
            Homebrew.failed = true
            next
          end

          # Alias preparation must still see every actionable hit. Only
          # absent records can be rejected before their initial history;
          # existing records remain subject to the database's checks.
          if rejected_candidates.any? && !args.no_history? && emitter.is_a?(DirEmitter)
            actionable.reject! do |hit, status|
              next false unless status

              id = matcher.record_id(formula, hit)
              next false unless rejected_candidates.include?(id)
              next false if emitter.alias_protected?(id) || emitter.reviewed_range_state(id)
              next false if emitter.alias_target_paths(id).any? { |target| File.exist?(target) }

              prefiltered << id
              true
            end
          end

          new_histories = T.let({}, T::Hash[String, Homebrew::Vulns::Match::ReconciledHistory])
          actionable.each do |hit, status|
            record_id = matcher.record_id(formula, hit)
            next if emitter.alias_protected?(record_id)

            reviewed_state = emitter.reviewed_range_state(record_id)
            if reviewed_state && !status && matcher.current_prerelease_boundary?(hit)
              opoo "#{record_id}: prerelease_boundary in current version; leaving reviewed record unchanged"
              next
            end
            initial_introduction = false
            initial_introduction = true if !args.no_history? && status && reviewed_state.nil?
            candidate = matcher.to_brew_record(formula, hit)
            basis_changed = emitter.range_basis_changed?(candidate)
            if basis_changed && !initial_introduction && (args.no_history? || !status&.fixed?)
              emitter.emit(candidate)
              next
            end

            override = overrides&.advisory_override(formula.name, hit.identifiers)
            if initial_introduction && override&.state
              upstream_state = matcher.aggregate_state_at(formula, hit)
              if override.state != upstream_state
                emitter.record_history_unavailable(formula.name)
                opoo "#{record_id}: reviewed state override " \
                     "#{upstream_state.nil? ? "cannot be checked against" : "disagrees with"} " \
                     "upstream history; " \
                     "skipping automatic update. Review its ranges and provenance together."
                next
              end
            end

            if initial_introduction
              if new_histories.empty?
                new_hits = actionable.filter_map do |candidate_hit, candidate_status|
                  id = matcher.record_id(formula, candidate_hit)
                  next if !candidate_status || emitter.alias_protected?(id) || emitter.reviewed_range_state(id)

                  candidate_hit
                end
                new_histories = new_record_histories(matcher, formula, new_hits, emitter, latest_macos:)
              end
              history = new_histories.fetch(record_id)
              next if history.state == :never_affected

              if history.state != :range
                emitter.record_history_unavailable(formula.name)
                reason = if history.reasons.include?(:history_unavailable)
                  "formula history is unavailable"
                else
                  "complete history requires review"
                end
                opoo "#{record_id}: #{reason} (#{history.reasons.join(", ")}); skipping automatic update"
                next
              end
              candidate = matcher.to_brew_record(formula, hit, history:)
              revalidated = !history.fixed.nil? && !override&.fixed_in_overridden
              emitter.emit(candidate, revalidated:, initial_introduction: true)
              next
            end

            has_open_range = reviewed_state == :open
            has_terminal_range = reviewed_state == :terminal
            transition = (status&.fixed? && has_open_range) ||
                         (status&.affected? && has_terminal_range)
            if args.no_history? && transition
              opoo "#{record_id}: reviewed range transition needs history; leaving it unchanged"
              next
            end

            walk_history = !args.no_history? && status&.fixed?
            walk_history &&= basis_changed || emitter.history_required?(record_id) if args.new_history?
            emitter.record_history_walk if walk_history
            first_fixed = matcher.first_fixed_version(formula, hit) if walk_history
            fixed_boundary = T.let(nil, T.nilable(String))
            case first_fixed
            when String
              fixed_boundary = first_fixed
            when nil
              # No history walk was required.
            when :never_affected
              next
            when :history_unavailable
              emitter.record_history_unavailable(formula.name)
              opoo "#{record_id}: formula history is unavailable; skipping automatic update"
              next
            when :shared_fixed_version
              emitter.record_history_unavailable(formula.name)
              opoo "#{record_id}: #{formula.pkg_version} also has an affected build; " \
                   "skipping automatic update until a later version"
              next
            else
              raise TypeError, "unexpected fixed-history result: #{first_fixed.inspect}"
            end

            if fixed_boundary && !emitter.fixed_boundary_valid?(record_id, fixed_boundary)
              onoe "#{record_id}: fixed #{fixed_boundary} does not follow its reviewed range"
              Homebrew.failed = true
              next
            end

            first_introduced = T.let(nil, T.nilable(String))
            if status&.affected? && has_terminal_range
              emitter.record_history_walk
              reintroduced = matcher.first_reintroduced_version(formula, hit)
              if reintroduced == :history_unavailable
                emitter.record_history_unavailable(formula.name)
                opoo "#{record_id}: reintroduction history is unavailable; skipping automatic update"
                next
              end
              unless reintroduced.is_a?(String)
                onoe "#{record_id}: could not find a prior non-affected version for its reviewed fixed range"
                Homebrew.failed = true
                next
              end
              unless emitter.reintroduction_boundary_valid?(record_id, reintroduced)
                onoe "#{record_id}: reintroduction #{reintroduced} does not follow its reviewed range"
                Homebrew.failed = true
                next
              end
              first_introduced = reintroduced
            end

            candidate = matcher.to_brew_record(formula, hit, first_fixed: fixed_boundary, first_introduced:)
            # A metadata override does not replace the upstream constraints
            # used by the history walk. Correct its reviewed ranges and
            # provenance together instead of automatically certifying them.
            revalidated = !fixed_boundary.nil? && !override&.fixed_in_overridden
            emitter.emit(candidate, revalidated:, initial_introduction:)
          end
        end
      rescue Homebrew::Vulns::OSV::Error => e
        onoe "OSV query failed: #{e.message}"
        Homebrew.failed = true
      end
      emitter.finish
      if prefiltered.any?
        puts "  #{prefiltered.length} rejected candidates skipped before history"
        prefiltered.sort.each { |id| puts "    #{id}" }
      end
      report_history_load_failures(matcher) if args.reconcile_history?
    end
  end
end

#text_mode? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


556
557
558
# File 'dev-cmd/advisory-match.rb', line 556

def text_mode?
  !args.json? && args.output.nil?
end