Class: Lemans::Patch
- Inherits:
-
Object
- Object
- Lemans::Patch
- Defined in:
- lib/lemans/patch.rb
Overview
The agent's work as one git patch, diffed against a baseline sealed before its first turn
Constant Summary collapse
- LOCAL_PATH =
"agent.patch"- REMOTE_PATCH =
"/tmp/lemans-agent.patch"- REMOTE_INDEX =
"/tmp/lemans-patch.idx"- TIMEOUT =
300
Instance Method Summary collapse
-
#collect! ⇒ Object
Must run before the verifier restores the graded surfaces: a patch taken after would not show what the agent did to them.
-
#initialize(environment, bench:, dir:) ⇒ Patch
constructor
A new instance of Patch.
- #seal! ⇒ Object
Constructor Details
#initialize(environment, bench:, dir:) ⇒ Patch
Returns a new instance of Patch.
16 17 18 19 20 21 |
# File 'lib/lemans/patch.rb', line 16 def initialize(environment, bench:, dir:) @environment = environment @workdir = bench.environment.workdir @path = Pathname(dir).join(LOCAL_PATH) @baseline = nil end |
Instance Method Details
#collect! ⇒ Object
Must run before the verifier restores the graded surfaces: a patch taken after would not show what the agent did to them
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lemans/patch.rb', line 29 def collect! return unless baseline after = write_tree return unless after result = environment.exec("#{git} diff --binary #{baseline} #{after} > #{REMOTE_PATCH}", timeout: TIMEOUT) return unless result.success? path.dirname.mkpath environment.download(REMOTE_PATCH, path) environment.exec("rm -f #{REMOTE_PATCH} #{REMOTE_INDEX}", timeout: TIMEOUT) path rescue InfrastructureError => e warn "lemans: could not collect the agent patch for #{path.dirname.basename}: #{e.}" nil end |
#seal! ⇒ Object
23 24 25 |
# File 'lib/lemans/patch.rb', line 23 def seal! @baseline = write_tree end |