Class: Ace::Test::EndToEndRunner::Atoms::ArtifactContractValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/test/end_to_end_runner/atoms/artifact_contract_validator.rb

Overview

Validates that verifier-visible artifact paths are explicitly declared by runner instructions or scenario setup, and normalizes grouped capture shorthand such as foo.stdout, .stderr, .exit.

Defined Under Namespace

Classes: Reference

Constant Summary collapse

FULL_PATH_PATTERN =
/
  (?:`|"|')?
  (results\/tc\/\d{2}\/[^\s`)"']+|results\/tc\/\d{2}\/)
  (?:`|"|')?
  (\s*\(optional\))?
/ix
SUFFIX_PATTERN =
/,\s*(?:`|"|')?(\.[A-Za-z0-9*._-]+)(?:`|"|')?(\s*\(optional\))?/i
WILDCARD_PATTERN =
/[*?\[]/.freeze

Class Method Summary collapse

Class Method Details

.extract(markdown, source:) ⇒ Object



23
24
25
26
27
# File 'lib/ace/test/end_to_end_runner/atoms/artifact_contract_validator.rb', line 23

def extract(markdown, source:)
  markdown.to_s.each_line.with_index(1).flat_map do |line, line_number|
    extract_from_line(line, source: source, line_number: line_number)
  end
end

.references_from_paths(paths, source:) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ace/test/end_to_end_runner/atoms/artifact_contract_validator.rb', line 29

def references_from_paths(paths, source:)
  Array(paths).filter_map do |path|
    normalized = normalize(path)
    next if normalized.nil?

    Reference.new(path: normalized, optional: false, source: source, line: nil)
  end
end

.validate!(tc_id:, scenario_dir:, runner_references:, verifier_references:, scenario_references:) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ace/test/end_to_end_runner/atoms/artifact_contract_validator.rb', line 38

def validate!(tc_id:, scenario_dir:, runner_references:, verifier_references:, scenario_references:)
  invalid_wildcards = (runner_references + verifier_references + scenario_references).select do |reference|
    wildcard?(reference.path)
  end
  unless invalid_wildcards.empty?
    raise ArgumentError,
      "Wildcard artifact path(s) are not supported for #{tc_id} in #{scenario_dir}: " \
      "#{format_references(invalid_wildcards)}"
  end

  declared_paths = normalized_paths(scenario_references + runner_references)
  undeclared = verifier_references.reject do |reference|
    declared_paths.include?(normalize(reference.path))
  end
  return if undeclared.empty?

  raise ArgumentError,
    "Verifier references undeclared artifact(s) for #{tc_id} in #{scenario_dir}: " \
    "#{format_references(undeclared)}. " \
    "Declare exact artifact paths in the runner file or scenario.yml sandbox-layout."
end