Answer principles round 1: 0 🔴, 1 🟡 (0 misread); bound and stream a patch cut's ci.sh, keep a trace of each deploy-release run, fail on file errors and a missing Unreleased heading, read the plan once per cut, one home for the review title, inject task-bench's container names, one spelling of its task kind
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
@@ -121,7 +121,7 @@ class BenchOfTasksCase(unittest.TestCase):
|
||||
|
||||
def bench(self, **given: str):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
||||
return main.bench({**self.given, **given}, self.env, lambda home: "", self.home)
|
||||
return main.bench({**self.given, **given}, self.env, lambda home: "", self.home, "task-bench-0123456789ab", "1234:5678")
|
||||
|
||||
|
||||
class FeatureBenchTest(BenchOfTasksCase):
|
||||
|
||||
+145
-66
@@ -196,7 +196,7 @@ import time
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, SHIPPED, Side, SIDES, Task, tests_in_copy
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, DATA_SOURCE, FEATURE, Kind, KINDS, on_disk, Planned, SHIPPED, Side, SIDES, Task, tests_in_copy
|
||||
from task_bench.bugs.planted_mutant import bug_at_sides, Mutant
|
||||
from claude_code.reply import Claude
|
||||
from task_bench.bench_folder import clear_left, held
|
||||
@@ -206,15 +206,15 @@ from machine_load.slots import CPUS_PER_SLOT
|
||||
from git_cli.git_repo import default_ref, Git, top
|
||||
from task_bench.figures.gather import DIGEST, gather, run_claude
|
||||
from task_bench.bugs.plant import drawn, killed_mutants, place_files, task_text
|
||||
from claude_code.entries import entry_from, json_objects
|
||||
from claude_code.entries import Entry, entry_from, json_objects
|
||||
from mutate_changes.tool_process import failed, Ran, run_tool
|
||||
from failure import Failure
|
||||
from task_bench.features.feature_tasks import feature_tasks, Features, read_features
|
||||
from task_bench.figures.run_figures import figures, Result, table
|
||||
from task_bench.figures.run_figures import Figures, figures, Result, table
|
||||
from git_cli import git_repo
|
||||
from review_rules.review_folder import made_review_folder, REPORTS
|
||||
from larv_review.history_commands import read_places
|
||||
from task_bench.features.shipped_features import read_shipped, shipped_tasks, ShippedFeatures
|
||||
from task_bench.features.shipped_features import read_shipped, shipped_tasks
|
||||
from task_bench.figures.record_figures import recorded_bench
|
||||
from run_heavy.capped_docker import SHARE_VARIABLE
|
||||
from task_bench.rust_test_modules import tells_apart
|
||||
@@ -234,15 +234,43 @@ KEPT = "The digest, and each run's result and stream, until `task-bench gather`
|
||||
ONLY_FOR = {"--seed": BUG, "--bugs": BUG, "--prefix": BUG, "--shipped": SHIPPED}
|
||||
|
||||
|
||||
# What plans a bench's tasks, once the bench has opened its containers.
|
||||
Planner = typing.Callable[[Bench], Planned | Failure]
|
||||
# What makes a kind's planner from each side's tree, once the trees stand.
|
||||
Planning = typing.Callable[[dict[Side, str]], Planner | Failure]
|
||||
# What reads a kind's tasks once the bench knows its checkout and its sides' commits, with git to read them by.
|
||||
Source = typing.Callable[[str, dict[Side, str], Git], Planning | Failure]
|
||||
|
||||
|
||||
class Fixes(typing.NamedTuple):
|
||||
"""The runs that finished, in the order they ran, and the failure that stopped the bench before the rest, if one did."""
|
||||
results: list[Result]
|
||||
stopped: Failure | None
|
||||
|
||||
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure] = read_places, claude: Claude = run_claude) -> int:
|
||||
class Call(typing.NamedTuple):
|
||||
"""What a bench was called with: its options, the environment its tools run in, what reads what `larv-review places` prints,
|
||||
and the home folder."""
|
||||
given: dict[str, str]
|
||||
env: typing.Mapping[str, str]
|
||||
read: typing.Callable[[pathlib.Path], str | Failure]
|
||||
home: pathlib.Path
|
||||
|
||||
|
||||
def new_name() -> str:
|
||||
"""A name no other bench's containers have."""
|
||||
return f"task-bench-{uuid.uuid4().hex[:12]}"
|
||||
|
||||
|
||||
def host_user() -> str:
|
||||
"""The user and group this process runs as, as docker's --user takes them."""
|
||||
return f"{os.getuid()}:{os.getgid()}"
|
||||
|
||||
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure] = read_places, claude: Claude = run_claude, name: typing.Callable[[], str] = new_name, user: typing.Callable[[], str] = host_user) -> int:
|
||||
"""Runs task-bench with the arguments argv; git, docker and the mutation tool run in the environment env, `read` reads what
|
||||
`larv-review places` prints for the checkout, and `claude` runs the claude that gathers."""
|
||||
`larv-review places` prints for the checkout, and `claude` runs the claude that gathers. `name` names a bench's containers,
|
||||
and `user` is the user they run as."""
|
||||
if argv in (["-h"], ["--help"]):
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
@@ -254,7 +282,7 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
|
||||
if isinstance(given, Failure):
|
||||
print(f"{given.reason}; {USAGE}", file=sys.stderr)
|
||||
return 1
|
||||
report = bench(given, env, read, home)
|
||||
report = bench(given, env, read, home, name(), user())
|
||||
if isinstance(report, Failure):
|
||||
print(report.reason, file=sys.stderr)
|
||||
return 1
|
||||
@@ -263,6 +291,13 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
|
||||
|
||||
|
||||
def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] | Failure:
|
||||
"""The options argv gives, with each default filled in; a Failure where argv cannot be read, or asks what no bench does."""
|
||||
given = parsed(argv)
|
||||
return given if isinstance(given, Failure) else checked(given, env)
|
||||
|
||||
|
||||
def parsed(argv: list[str]) -> dict[str, str] | Failure:
|
||||
"""Each option argv names, with its value, given as `--name value` or `--name=value`."""
|
||||
given: dict[str, str] = {}
|
||||
rest = list(argv)
|
||||
while rest:
|
||||
@@ -279,6 +314,11 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
|
||||
if not equals and not rest:
|
||||
return Failure(f"{name} needs a value")
|
||||
given[name] = value if equals else rest.pop(0)
|
||||
return given
|
||||
|
||||
|
||||
def checked(given: dict[str, str], env: typing.Mapping[str, str]) -> dict[str, str] | Failure:
|
||||
"""given with each default filled in, where it holds what a bench of its kind needs and env holds the token."""
|
||||
for name in ("--image", "--test"):
|
||||
if not given.get(name):
|
||||
return Failure(f"{name} is missing")
|
||||
@@ -288,14 +328,17 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
|
||||
for name, only in ONLY_FOR.items():
|
||||
if only is not kind and name in given:
|
||||
return Failure(f"{name} is for a bench of {only.noun}s, so it doesn't go with {TASKS} {given[TASKS]}")
|
||||
return counts_failure(given, kind) or (given if env.get(TOKEN) else Failure(f"{TOKEN} holds no token"))
|
||||
|
||||
|
||||
def counts_failure(given: dict[str, str], kind: Kind) -> Failure | None:
|
||||
"""Fills in the default of each count a bench of kind takes; a Failure where one given is no whole number from 1."""
|
||||
for name, default in COUNTS.items():
|
||||
if ONLY_FOR.get(name, kind) is not kind:
|
||||
continue
|
||||
if not given.setdefault(name, default).isdecimal() or int(given[name]) < 1:
|
||||
return Failure(f"{name} takes a whole number from 1, not {given[name]}")
|
||||
if not env.get(TOKEN):
|
||||
return Failure(f"{TOKEN} holds no token")
|
||||
return given
|
||||
return None
|
||||
|
||||
|
||||
def progress(line: str) -> None:
|
||||
@@ -303,16 +346,15 @@ def progress(line: str) -> None:
|
||||
print(line, file=sys.stderr)
|
||||
|
||||
|
||||
def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure], home: pathlib.Path) -> list[str] | Failure:
|
||||
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. It tells
|
||||
its progress on stderr."""
|
||||
# Only bugs are planted at the seats' places; features and data sources come from the project's folder, and shipped features from its history. Each kind reads what it makes its tasks from before anything is copied or built,
|
||||
# so a fault there stops the bench at once.
|
||||
def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure], home: pathlib.Path, name: str, user: str) -> list[str] | Failure:
|
||||
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. Its
|
||||
containers are named name and run as user. It tells its progress on stderr."""
|
||||
# The one place that resolves the bench's kind from its options: SOURCES holds what reads each kind's tasks.
|
||||
kind = KINDS[given[TASKS]]
|
||||
# Shipped features are read from the base's history, once the base is known.
|
||||
tasks_from: str | Features | ShippedFeatures | Failure | None = None if kind is SHIPPED else read(home) if kind is BUG else read_features(home, kind)
|
||||
if isinstance(tasks_from, Failure):
|
||||
return tasks_from
|
||||
# Each kind reads what it makes its tasks from before anything is copied or built, so a fault there stops the bench at once.
|
||||
source = SOURCES[kind](Call(given, env, read, home), kind)
|
||||
if isinstance(source, Failure):
|
||||
return source
|
||||
git = functools.partial(git_repo.git, env=env)
|
||||
checkout = top(git)
|
||||
if isinstance(checkout, Failure):
|
||||
@@ -320,10 +362,9 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
|
||||
sides = commits(given, checkout, git)
|
||||
if isinstance(sides, Failure):
|
||||
return sides
|
||||
if tasks_from is None:
|
||||
tasks_from = read_shipped(home, checkout, sides["base"], git)
|
||||
if isinstance(tasks_from, Failure):
|
||||
return tasks_from
|
||||
planning = source(checkout, sides, git)
|
||||
if isinstance(planning, Failure):
|
||||
return planning
|
||||
progress(f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}.")
|
||||
review = made_review_folder(checkout, home)
|
||||
if isinstance(review, Failure):
|
||||
@@ -332,15 +373,14 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
|
||||
if isinstance(folder, Failure):
|
||||
return folder
|
||||
clear_left(home / REPORTS)
|
||||
run = functools.partial(bench_in, folder, given, env, tasks_from, checkout, sides, git)
|
||||
containers = Containers(docker_cli(env), name, given["--test"], int(env.get(SHARE_VARIABLE) or MEMORY_MIB), user)
|
||||
run = functools.partial(bench_in, folder, given["--image"], containers, Asked(kind, int(given["--runs"])), planning, checkout, sides, git)
|
||||
return recorded_bench(run, folder, git, home, time.time) if RECORD in given else run()
|
||||
|
||||
|
||||
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], tasks_from: str | Features | ShippedFeatures, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. Where tasks_from is what
|
||||
`larv-review places` prints, the bench plants bugs at the places it names. Where tasks_from holds features, data sources or
|
||||
shipped features, the bench has Haiku build, add or rebuild them."""
|
||||
containers = Containers(docker_cli(env), f"task-bench-{uuid.uuid4().hex[:12]}", given["--test"], int(env.get(SHARE_VARIABLE) or MEMORY_MIB), f"{os.getuid()}:{os.getgid()}")
|
||||
def bench_in(folder: pathlib.Path, image: str, containers: Containers, asked: Asked, planning: Planning, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, in containers of image, which empties folder and keeps its runs there.
|
||||
planning makes what plans the tasks of the kind asked."""
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
trees: dict[Side, str] = {}
|
||||
for side, commit in sides.items():
|
||||
@@ -348,23 +388,47 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
|
||||
if isinstance(tree, Failure):
|
||||
return tree
|
||||
trees[side] = tree
|
||||
planned: typing.Callable[[Bench], Planned | Failure] | Failure
|
||||
if isinstance(tasks_from, Features):
|
||||
asked, planned = Asked(KINDS[given[TASKS]], int(given["--runs"])), features_planner(tasks_from, checkout, trees)
|
||||
elif isinstance(tasks_from, ShippedFeatures):
|
||||
asked, planned = Asked(SHIPPED, int(given["--runs"])), functools.partial(shipped_tasks, shipped=tasks_from, count=int(given["--shipped"]))
|
||||
else:
|
||||
asked, planned = Asked(BUG, int(given["--runs"])), bugs_planner(given, env, tasks_from, trees["base"])
|
||||
planned = planning(trees)
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
try:
|
||||
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, asked, containers, folder, git, progress), planned)
|
||||
found = opened(containers, image) or benched(Bench(checkout, sides, trees, asked, containers, folder, git, progress), planned)
|
||||
finally:
|
||||
closed(containers)
|
||||
return found if isinstance(found, Failure) else [*found, f"{KEPT}{folder}"]
|
||||
|
||||
|
||||
def features_planner(features: Features, checkout: str, trees: dict[Side, str]) -> typing.Callable[[Bench], Planned | Failure]:
|
||||
def bugs_source(call: Call, kind: Kind) -> Source | Failure:
|
||||
"""Reads the seats' places, where alone bugs are planted."""
|
||||
places = call.read(call.home)
|
||||
if isinstance(places, Failure):
|
||||
return places
|
||||
return lambda checkout, sides, git: functools.partial(bugs_planner, call.given, call.env, places)
|
||||
|
||||
|
||||
def features_source(call: Call, kind: Kind) -> Source | Failure:
|
||||
"""Reads the features, or the data sources where kind is DATA_SOURCE, from the project's folder."""
|
||||
features = read_features(call.home, kind)
|
||||
if isinstance(features, Failure):
|
||||
return features
|
||||
return lambda checkout, sides, git: functools.partial(features_planner, features, checkout)
|
||||
|
||||
|
||||
def shipped_source(call: Call, kind: Kind) -> Source:
|
||||
"""Shipped features are read from the base's history, so only once the base is known."""
|
||||
def source(checkout: str, sides: dict[Side, str], git: Git) -> Planning | Failure:
|
||||
shipped = read_shipped(call.home, checkout, sides["base"], git)
|
||||
if isinstance(shipped, Failure):
|
||||
return shipped
|
||||
return lambda trees: functools.partial(shipped_tasks, shipped=shipped, count=int(call.given["--shipped"]))
|
||||
return source
|
||||
|
||||
|
||||
# What reads each kind's tasks. A kind without an entry stops the bench before it reads anything.
|
||||
SOURCES: dict[Kind, typing.Callable[[Call, Kind], Source | Failure]] = {BUG: bugs_source, FEATURE: features_source, DATA_SOURCE: features_source, SHIPPED: shipped_source}
|
||||
|
||||
|
||||
def features_planner(features: Features, checkout: str, trees: dict[Side, str]) -> Planner:
|
||||
"""What plans a bench of features in trees, each side's. It takes the features' folder, with its acceptance tests and
|
||||
reference patches, out of trees first, so Haiku's copy leaves it out."""
|
||||
if features.folder.is_relative_to(checkout):
|
||||
@@ -374,10 +438,11 @@ def features_planner(features: Features, checkout: str, trees: dict[Side, str])
|
||||
return functools.partial(feature_tasks, found=features.found, folder=features.folder)
|
||||
|
||||
|
||||
def bugs_planner(given: dict[str, str], env: typing.Mapping[str, str], places: str, base: str) -> typing.Callable[[Bench], Planned | Failure] | Failure:
|
||||
"""What plans a bench of bugs. The bugs' files are those of the tree at base that hold a place in places and are in a language
|
||||
of plant's LANGUAGES. Of the mutants the tests kill in those files, the ones --seed draws first become bugs, until --bugs of
|
||||
them have."""
|
||||
def bugs_planner(given: dict[str, str], env: typing.Mapping[str, str], places: str, trees: dict[Side, str]) -> Planner | Failure:
|
||||
"""What plans a bench of bugs. The bugs' files are those of the base's tree in trees that hold a place in places and are in a
|
||||
language of plant's LANGUAGES. Of the mutants the tests kill in those files, the ones --seed draws first become bugs, until
|
||||
--bugs of them have."""
|
||||
base = trees["base"]
|
||||
files = [path for path in place_files(places) if pathlib.Path(base, path).is_file()]
|
||||
if not files:
|
||||
return Failure("The places the seats found hard don't name any file at the base in a language the bench plants bugs in, so there is nowhere to plant a bug.")
|
||||
@@ -417,7 +482,7 @@ def archived(commit: str, into: pathlib.Path, checkout: str, git: Git) -> str |
|
||||
return removed if isinstance(removed, Failure) else str(into)
|
||||
|
||||
|
||||
def benched(bench: Bench, planned: typing.Callable[[Bench], Planned | Failure]) -> list[str] | Failure:
|
||||
def benched(bench: Bench, planned: Planner) -> list[str] | Failure:
|
||||
"""Makes the tasks that planned plans, runs each, writes the results into the bench's folder and returns the report."""
|
||||
if failure := baseline_failure(bench):
|
||||
return failure
|
||||
@@ -557,34 +622,48 @@ def fixed(task: Task, side: Side, number: int, containers: Containers, folder: p
|
||||
stream = stream_of(Result(task.number, side, number, False, None), folder, kind.key)
|
||||
copy, check = folder / "copy", folder / "check"
|
||||
try:
|
||||
try:
|
||||
stream.parent.mkdir(exist_ok=True)
|
||||
shutil.copytree(task.trees[side], copy, symlinks=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not copy {kind.noun} {task.number}'s tree at the {side}: {failure}")
|
||||
attempted = fix_attempted(containers, str(copy), kind.prompt.format(told=task.told[side]), stream)
|
||||
if isinstance(attempted, Failure):
|
||||
return attempted
|
||||
raw = on_disk(f"read {stream}", stream.read_bytes)
|
||||
if isinstance(raw, Failure):
|
||||
return raw
|
||||
events = json_objects(raw)
|
||||
entries = [entry_from(event) for event in events]
|
||||
found = figures(events, task.file and os.path.join(WORK, task.file))
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
checked = on_disk(f"make the tree that checks {kind.noun} {task.number}'s fix at the {side}", lambda: check_made(task.trees[side], str(copy), str(check), task.acceptance))
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
ran = ran_tests(containers, str(check))
|
||||
if isinstance(ran, Failure) and not isinstance(ran, TimedOut):
|
||||
return ran
|
||||
return Result(task.number, side, number, isinstance(ran, Ran) and ran.code == 0, found, tuple(entries))
|
||||
worked = attempt(task, side, containers, copy, stream, kind)
|
||||
if isinstance(worked, Failure):
|
||||
return worked
|
||||
passed = verdict(task, side, containers, copy, check, kind)
|
||||
if isinstance(passed, Failure):
|
||||
return passed
|
||||
return Result(task.number, side, number, passed, *worked)
|
||||
finally:
|
||||
shutil.rmtree(copy, ignore_errors=True)
|
||||
shutil.rmtree(check, ignore_errors=True)
|
||||
|
||||
|
||||
def attempt(task: Task, side: Side, containers: Containers, copy: pathlib.Path, stream: pathlib.Path, kind: Kind) -> tuple[Figures | None, tuple[Entry, ...]] | Failure:
|
||||
"""Haiku's work on task in copy, made a copy of the side's tree: the figures of its run, None where it didn't finish, and
|
||||
the entries of its stream, which it writes to the file stream."""
|
||||
try:
|
||||
stream.parent.mkdir(exist_ok=True)
|
||||
shutil.copytree(task.trees[side], copy, symlinks=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not copy {kind.noun} {task.number}'s tree at the {side}: {failure}")
|
||||
attempted = fix_attempted(containers, str(copy), kind.prompt.format(told=task.told[side]), stream)
|
||||
if isinstance(attempted, Failure):
|
||||
return attempted
|
||||
raw = on_disk(f"read {stream}", stream.read_bytes)
|
||||
if isinstance(raw, Failure):
|
||||
return raw
|
||||
events = json_objects(raw)
|
||||
found = figures(events, task.file and os.path.join(WORK, task.file))
|
||||
return found if isinstance(found, Failure) else (found, tuple(entry_from(event) for event in events))
|
||||
|
||||
|
||||
def verdict(task: Task, side: Side, containers: Containers, copy: pathlib.Path, check: pathlib.Path, kind: Kind) -> bool | Failure:
|
||||
"""Whether the tests pass over check, made the side's tree with what Haiku changed in copy. Tests that run out of time don't."""
|
||||
checked = on_disk(f"make the tree that checks {kind.noun} {task.number}'s fix at the {side}", lambda: check_made(task.trees[side], str(copy), str(check), task.acceptance))
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
ran = ran_tests(containers, str(check))
|
||||
if isinstance(ran, Failure) and not isinstance(ran, TimedOut):
|
||||
return ran
|
||||
return isinstance(ran, Ran) and ran.code == 0
|
||||
|
||||
|
||||
def stream_of(result: Result, folder: pathlib.Path, key: str) -> pathlib.Path:
|
||||
"""The file that holds the stream of the run result names, of a task whose kind has that key. Its name without the suffix is
|
||||
the run's id in the digest."""
|
||||
|
||||
@@ -90,6 +90,8 @@ CLAUDE = textwrap.dedent("""\
|
||||
usage = {"input_tokens": 40, "cache_creation_input_tokens": 9000, "cache_read_input_tokens": 52000, "output_tokens": 800}
|
||||
print(json.dumps({"type": "result", "subtype": "success", "is_error": False, "num_turns": 3, "duration_ms": 61500, "usage": usage, "result": "Fixed."}))
|
||||
""")
|
||||
# The name of a bench's containers and the user they run as, where a test fixes them.
|
||||
NAME, USER = "task-bench-0123456789ab", "1234:5678"
|
||||
PLACES = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\nJunior A, hardest first:\n\n- `calc.go:3` `Add`: long\n- `gone.go:1` `Gone`: removed since\n- `README.md:1` `Calc`: thin\n"
|
||||
|
||||
|
||||
@@ -131,7 +133,7 @@ class BenchTest(unittest.TestCase):
|
||||
|
||||
def bench(self, **given: str):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
||||
return main.bench({**self.given, "--base": "main", **given}, self.env, lambda home: PLACES, self.home)
|
||||
return main.bench({**self.given, "--base": "main", **given}, self.env, lambda home: PLACES, self.home, NAME, USER)
|
||||
|
||||
def calls(self) -> list[list[str]]:
|
||||
return [json.loads(line) for line in self.log.read_text().splitlines()]
|
||||
@@ -223,6 +225,20 @@ class BenchTest(unittest.TestCase):
|
||||
self.assertTrue((reports / "crashed/task-bench.lock").exists())
|
||||
self.assertTrue((reports / "running/task-bench/trees/task-bench").exists())
|
||||
|
||||
def test_the_command_line_names_its_containers_afresh_and_runs_them_as_the_hosts_user(self):
|
||||
self.assertRegex(main.new_name(), r"^task-bench-[0-9a-f]{12}$")
|
||||
self.assertNotEqual(main.new_name(), main.new_name())
|
||||
self.assertEqual(main.host_user(), f"{os.getuid()}:{os.getgid()}")
|
||||
argv = [part for name, value in {**self.given, "--runs": "1"}.items() for part in (name, value)]
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertEqual(main.main(argv, self.env, lambda home: PLACES, name=lambda: "task-bench-other", user=lambda: "7:8"), 0)
|
||||
calls = self.calls()
|
||||
self.assertEqual(calls[1], ["network", "create", "--internal", "task-bench-other"])
|
||||
self.assertIn(["--user", "7:8"], [call[at:at + 2] for call in calls if "claude" in call for at in range(len(call))])
|
||||
|
||||
def test_each_kind_of_task_has_what_reads_its_tasks(self):
|
||||
self.assertEqual(set(main.SOURCES), set(main.KINDS.values()))
|
||||
|
||||
def test_the_command_line_runs_the_bench_on_the_seats_places_and_prints_its_report(self):
|
||||
argv = [part for name, value in self.given.items() for part in (name, value)]
|
||||
homes = []
|
||||
@@ -282,11 +298,11 @@ class BenchTest(unittest.TestCase):
|
||||
fixes = [call for call in calls if "claude" in call]
|
||||
self.assertEqual(len(fixes), 2)
|
||||
name = fixes[0][fixes[0].index("--network") + 1]
|
||||
self.assertRegex(name, r"^task-bench-[0-9a-f]{12}$")
|
||||
self.assertEqual(name, NAME)
|
||||
image = fixes[0].index(f"{name}:throwaway")
|
||||
self.assertEqual(fixes[0][image + 1:], ["claude", "-p", "--strict-mcp-config", "--disable-slash-commands", "--no-session-persistence", "--model", "claude-haiku-5-5", "--effort", "low", "--output-format", "stream-json", "--verbose", "--permission-mode", "bypassPermissions", "A test of this project fails with the message below. Find the bug in the code and fix it. Change no test.\n\nAdd(1, 2) = -1, want 3"])
|
||||
options = fixes[0][:image]
|
||||
for expected in (["--memory", "2048m"], ["--memory-swap", "2048m"], ["--user", f"{os.getuid()}:{os.getgid()}"], ["--env", "HOME=/tmp"], ["--env", "CLAUDE_CODE_OAUTH_TOKEN"], ["--env", f"HTTPS_PROXY=http://{name}-proxy:8080"], ["--workdir", "/work"]):
|
||||
for expected in (["--memory", "2048m"], ["--memory-swap", "2048m"], ["--user", USER], ["--env", "HOME=/tmp"], ["--env", "CLAUDE_CODE_OAUTH_TOKEN"], ["--env", f"HTTPS_PROXY=http://{name}-proxy:8080"], ["--workdir", "/work"]):
|
||||
self.assertIn(expected, [options[at:at + 2] for at in range(len(options))])
|
||||
self.assertNotIn("sk-secret-token", self.log.read_text())
|
||||
self.assertEqual(calls[0][:1] + calls[0][-3:], ["build", "--tag", f"{name}:throwaway", "-"])
|
||||
@@ -308,7 +324,7 @@ class BenchTest(unittest.TestCase):
|
||||
|
||||
def test_fails_where_the_places_name_no_file_of_the_base_in_a_language_the_bench_plants_in(self):
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
found = main.bench({**self.given, "--base": "main"}, self.env, lambda home: "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home)
|
||||
found = main.bench({**self.given, "--base": "main"}, self.env, lambda home: "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home, NAME, USER)
|
||||
self.assertEqual(found, Failure("The places the seats found hard don't name any file at the base in a language the bench plants bugs in, so there is nowhere to plant a bug."))
|
||||
self.assertFalse(self.log.exists())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user