Class: Ace::Test::EndToEndRunner::Molecules::ArtifactPruner

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/test/end_to_end_runner/molecules/artifact_pruner.rb

Overview

Prunes stale E2E run artifacts while preserving suite reports and runtime cache.

Constant Summary collapse

ROOT_RELATIVE_PATH =
File.join(".ace-local", "test-e2e")
PRESERVED_DIRECTORY_NAMES =
%w[runtime-cache].freeze
PRESERVED_FILE_PATTERNS =
[
  /-suite-report\.md\z/,
  /-suite-final-report\.md\z/
].freeze

Instance Method Summary collapse

Instance Method Details

#prune(base_dir: Dir.pwd) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ace/test/end_to_end_runner/molecules/artifact_pruner.rb', line 18

def prune(base_dir: Dir.pwd)
  root = File.join(File.expand_path(base_dir), ROOT_RELATIVE_PATH)
  return summary(root, [], []) unless Dir.exist?(root)

  removed_paths = []
  preserved_paths = []

  Dir.children(root).sort.each do |entry|
    path = File.join(root, entry)
    if preserve_entry?(entry, path)
      preserved_paths << path
    else
      FileUtils.rm_rf(path)
      removed_paths << path
    end
  end

  summary(root, removed_paths, preserved_paths)
end