Class: Bulldogger::Run
- Inherits:
-
Object
- Object
- Bulldogger::Run
- Defined in:
- lib/bulldogger/run.rb
Overview
Owns the on-disk run directory: its lazy creation, evidence file sequence numbers, and the index.json/latest written at the end.
The directory is created lazily, on first use, not at construction. A fully green test suite must never touch the filesystem -- that is what "costs nothing while tests are green" means in practice -- so nothing here may mkdir until a caller actually asks for a path to write to.
Instance Method Summary collapse
-
#dir ⇒ Object
Returns nil when the switch is off.
- #finish ⇒ Object
-
#initialize(config:) ⇒ Run
constructor
A new instance of Run.
- #next_path(slug) ⇒ Object
- #record(path, test:, exception_summary:) ⇒ Object
Constructor Details
#initialize(config:) ⇒ Run
Returns a new instance of Run.
16 17 18 19 20 21 22 23 |
# File 'lib/bulldogger/run.rb', line 16 def initialize(config:) @config = config @dir = nil @sequence = 0 @failures = [] @finished = false @mutex = Mutex.new end |
Instance Method Details
#dir ⇒ Object
Returns nil when the switch is off. A kill switch earns its name only if every public path honours it, so this one refuses even though record_failure and finish already refuse on their own: a caller who reads the API and asks for the run directory directly must not be the one hole that still writes to disk.
30 31 32 33 34 |
# File 'lib/bulldogger/run.rb', line 30 def dir return nil unless @config.enabled @mutex.synchronize { ensure_dir } end |
#finish ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bulldogger/run.rb', line 54 def finish @mutex.synchronize do return if @finished @finished = true # A disabled switch must produce nothing, even if some other # caller reached run_dir directly and already created @dir -- # this guard does not depend on record_failure's own refusal # to touch @dir being the only path here. return unless @config.enabled # No @dir means record was never called: a green run. Writing # an index for zero failures would create the very directory # the zero-cost-when-green claim says must not exist. return unless @dir write_index write_latest_symlink end end |
#next_path(slug) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/bulldogger/run.rb', line 36 def next_path(slug) @mutex.synchronize do ensure_dir @sequence += 1 File.join(@dir, format("%03d-%s.json", @sequence, slug)) end end |
#record(path, test:, exception_summary:) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/bulldogger/run.rb', line 44 def record(path, test:, exception_summary:) @mutex.synchronize do @failures << { "path" => File.basename(path), "test" => test, "exception" => exception_summary } end end |