Class: CleoQualityReview::RunArtifacts

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/run_artifacts.rb,
lib/cleo_quality_review/run_artifacts/raw_check_outputs.rb

Overview

Manages artifacts produced during a quality review run

Defined Under Namespace

Classes: RawCheckOutputs

Constant Summary collapse

ROOT =
"tmp/quality_checks"
RawCheckOutput =
RawCheckOutputs::Record

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(review_id:, changes_diff: nil, **_run_metadata) ⇒ RunArtifacts

Returns a new instance of RunArtifacts.

Parameters:

  • review_id (String)

    deterministic identifier for the reviewed diff

  • timestamp (Integer)

    epoch milliseconds for the run

  • target_files (Array<String>)

    file paths being analyzed

  • changes_diff (String) (defaults to: nil)

    captured git diff content



22
23
24
25
26
# File 'lib/cleo_quality_review/run_artifacts.rb', line 22

def initialize(review_id:, changes_diff: nil, **)
  @review_id = review_id.to_s
  @changes_diff_content = changes_diff
  @path = File.join(ROOT, @review_id)
end

Class Method Details

.load(review_id:) ⇒ RunArtifacts

Load artifacts by review ID

Parameters:

  • review_id (String)

    deterministic identifier for the reviewed diff

Returns:



32
33
34
# File 'lib/cleo_quality_review/run_artifacts.rb', line 32

def self.load(review_id:)
  new(review_id: review_id)
end

Instance Method Details

#changes_diffString

Read the captured git diff for changes

Returns:

  • (String)


96
97
98
# File 'lib/cleo_quality_review/run_artifacts.rb', line 96

def changes_diff
  File.read(artifact_path("changes.diff"))
end

#complete?Boolean

Returns whether this artifact directory contains a complete analysis.

Returns:

  • (Boolean)

    whether this artifact directory contains a complete analysis



47
48
49
# File 'lib/cleo_quality_review/run_artifacts.rb', line 47

def complete?
  File.file?(artifact_path("complete.json"))
end

#prepare!self

Prepare the artifact directory and capture initial data

Returns:

  • (self)


39
40
41
42
43
# File 'lib/cleo_quality_review/run_artifacts.rb', line 39

def prepare!
  FileUtils.mkdir_p(@path)
  write_changes_diff
  self
end

#raw_check_output_recordsArray<RawCheckOutputs::Record>

Read all raw check outputs with metadata from the artifact directory

Returns:



110
111
112
# File 'lib/cleo_quality_review/run_artifacts.rb', line 110

def raw_check_output_records
  raw_check_output_store.records
end

#raw_check_outputsHash{String => String}

Read all raw check outputs from the artifact directory

Returns:

  • (Hash{String => String})

    check name to output content mapping



103
104
105
# File 'lib/cleo_quality_review/run_artifacts.rb', line 103

def raw_check_outputs
  raw_check_output_store.to_h
end

#to_run(format:, log: false) ⇒ Run

Reconstruct a run from persisted artifacts

Parameters:

  • format (String)

    output format to render

  • log (Boolean) (defaults to: false)

    whether LLM logging should be enabled

Returns:

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cleo_quality_review/run_artifacts.rb', line 74

def to_run(format:, log: false)
  raise ArgumentError, "No completed quality review artifacts found for review ID #{@review_id}" unless complete?

  manifest = read_manifest
  target_files = manifest.fetch("target_files", [])
  Run.new(
    timestamp: manifest.fetch("timestamp"),
    review_id: manifest.fetch("review_id"),
    format: format,
    checks: manifest.fetch("checks", []),
    target_files: target_files,
    ruby_files: manifest.fetch("ruby_files", target_files),
    run_directory: @path,
    results: read_results,
    artifacts: self,
    log: log,
  )
end

#to_sString

Returns path to the artifacts directory.

Returns:

  • (String)

    path to the artifacts directory



116
117
118
# File 'lib/cleo_quality_review/run_artifacts.rb', line 116

def to_s
  @path
end

#write_check_output(check_output) ⇒ void

This method returns an undefined value.

Write raw check output to a file

Parameters:



55
56
57
# File 'lib/cleo_quality_review/run_artifacts.rb', line 55

def write_check_output(check_output)
  raw_check_output_store.write(check_output)
end

#write_run(run) ⇒ void

This method returns an undefined value.

Persist run metadata for later render/publish commands

Parameters:

  • run (Run)

    completed run



63
64
65
66
67
# File 'lib/cleo_quality_review/run_artifacts.rb', line 63

def write_run(run)
  File.write(artifact_path("results.json"), JSON.pretty_generate(Array(run.results).map(&:to_h)))
  File.write(artifact_path("manifest.json"), JSON.pretty_generate(run.manifest_data))
  File.write(artifact_path("complete.json"), JSON.pretty_generate({ review_id: @review_id, completed: true }))
end