Class: Lemans::TaskDefinition
- Inherits:
-
Object
- Object
- Lemans::TaskDefinition
- Defined in:
- lib/lemans/task_definition.rb
Overview
A single task definition: an instruction, an environment, tests, a solution —
plus the task's projection of the bench config (setup and verifier sections
with per-task overrides applied). Anything lemans does not understand
belongs under metadata, copied untouched.
Constant Summary collapse
- INSTRUCTION =
"instruction.md"- ENVIRONMENT_DIR =
"environment"- TESTS_DIR =
"tests"- SOLUTION_DIR =
"solution"- FLAT_TEST =
"verification_test.rb"- FLAT_SOLUTION =
"solution.patch"- FLAT_SEED =
"environment.patch"- FRONTMATTER =
/\A---\n(.*?)\n---\n/m
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#description ⇒ Object
Returns the value of attribute description.
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
- #environment ⇒ Object
- #environment_dockerfile ⇒ Object
- #environment_image ⇒ Object
-
#initialize(config, name, dir: nil) ⇒ TaskDefinition
constructor
A new instance of TaskDefinition.
-
#instruction ⇒ Object
The story alone: frontmatter is for the harness, never for the agent.
- #seed? ⇒ Boolean
-
#setup ⇒ Object
The task's projection of the config sections: bench-wide values with the task's own overrides applied.
- #setup=(declared) ⇒ Object
- #solution? ⇒ Boolean
- #solution_dir ⇒ Object
- #solution_files ⇒ Object
-
#test_files ⇒ Object
[absolute, remote-relative] pairs.
- #tests_dir ⇒ Object
- #verifier ⇒ Object
Constructor Details
#initialize(config, name, dir: nil) ⇒ TaskDefinition
Returns a new instance of TaskDefinition.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/lemans/task_definition.rb', line 108 def initialize(config, name, dir: nil) @config = config @name = name @difficulty = :easy @tags = [] @description = "" @metadata = {} @dir = dir || config.tasks_dir.join(name) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
104 105 106 |
# File 'lib/lemans/task_definition.rb', line 104 def config @config end |
#description ⇒ Object
Returns the value of attribute description.
106 107 108 |
# File 'lib/lemans/task_definition.rb', line 106 def description @description end |
#difficulty ⇒ Object
Returns the value of attribute difficulty.
106 107 108 |
# File 'lib/lemans/task_definition.rb', line 106 def difficulty @difficulty end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
104 105 106 |
# File 'lib/lemans/task_definition.rb', line 104 def dir @dir end |
#metadata ⇒ Object
Returns the value of attribute metadata.
106 107 108 |
# File 'lib/lemans/task_definition.rb', line 106 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
104 105 106 |
# File 'lib/lemans/task_definition.rb', line 104 def name @name end |
#tags ⇒ Object
Returns the value of attribute tags.
106 107 108 |
# File 'lib/lemans/task_definition.rb', line 106 def @tags end |
Class Method Details
.load_from_directory(config, dir) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lemans/task_definition.rb', line 24 def load_from_directory(config, dir) dir = Pathname(dir) data = frontmatter(dir) task = new(config, data["name"] || dir.basename.to_s, dir:) task.description = data["description"].to_s if data["description"] task.difficulty = data["difficulty"].to_sym if data["difficulty"] task. = Array(data["tags"]).map(&:to_s) if data["tags"] task. = data["metadata"] if data["metadata"] declared_setup = Config::Setup.from_config(data["setup"], root: dir) refuse_config_collisions!(task, declared_setup, config.setup) task.setup = declared_setup task.verifier.restore_paths = Config::Verifier.restore_paths!(data["restore"]) if data.key?("restore") if (declared = Config::Setup.from_config(data.dig("verifier", "setup"), root: dir)) refuse_config_collisions!(task, declared, config.verifier.setup) task.verifier.setup = config.verifier.setup.merge(declared) end validate!(task, data) task end |
Instance Method Details
#digest ⇒ Object
125 126 127 |
# File 'lib/lemans/task_definition.rb', line 125 def digest @digest ||= Config::TreeDigest.call(dir)[0, 16] end |
#environment ⇒ Object
144 |
# File 'lib/lemans/task_definition.rb', line 144 def environment = config.environment |
#environment_dockerfile ⇒ Object
164 |
# File 'lib/lemans/task_definition.rb', line 164 def environment_dockerfile = dir.join(ENVIRONMENT_DIR, "Dockerfile") |
#environment_image ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/lemans/task_definition.rb', line 166 def environment_image if environment_dockerfile.file? Config::ImageSpec.dockerfile(environment_dockerfile, slug: name) elsif environment.image Config::ImageSpec.registry(environment.image) else Config::ImageSpec.dockerfile(environment.dockerfile, slug: "shared") end end |
#instruction ⇒ Object
The story alone: frontmatter is for the harness, never for the agent.
121 122 123 |
# File 'lib/lemans/task_definition.rb', line 121 def instruction @instruction ||= dir.join(INSTRUCTION).read.sub(FRONTMATTER, "") end |
#seed? ⇒ Boolean
146 |
# File 'lib/lemans/task_definition.rb', line 146 def seed? = dir.join(FLAT_SEED).file? |
#setup ⇒ Object
The task's projection of the config sections: bench-wide values with the task's own overrides applied. Phase machinery reads these, never the global config.
132 133 134 |
# File 'lib/lemans/task_definition.rb', line 132 def setup @setup ||= config.setup.merge(own_setup_with_seed) end |
#setup=(declared) ⇒ Object
136 137 138 |
# File 'lib/lemans/task_definition.rb', line 136 def setup=(declared) @declared_setup = declared end |
#solution? ⇒ Boolean
158 |
# File 'lib/lemans/task_definition.rb', line 158 def solution? = solution_files.any? |
#solution_dir ⇒ Object
162 |
# File 'lib/lemans/task_definition.rb', line 162 def solution_dir = dir.join(SOLUTION_DIR) |
#solution_files ⇒ Object
154 155 156 |
# File 'lib/lemans/task_definition.rb', line 154 def solution_files solution_dir.directory? ? (solution_dir) : flat(FLAT_SOLUTION) end |
#test_files ⇒ Object
[absolute, remote-relative] pairs. Tests stay on the harness side while the agent works; uploaded into the sandbox only at verification.
150 151 152 |
# File 'lib/lemans/task_definition.rb', line 150 def test_files tests_dir.directory? ? (tests_dir) : flat(FLAT_TEST) end |
#tests_dir ⇒ Object
160 |
# File 'lib/lemans/task_definition.rb', line 160 def tests_dir = dir.join(TESTS_DIR) |
#verifier ⇒ Object
140 141 142 |
# File 'lib/lemans/task_definition.rb', line 140 def verifier @verifier ||= config.verifier.dup end |