Bench rebuilding a feature the project shipped #708
@@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- `task-bench --tasks shipped-features` benches rebuilding features the project shipped: it takes each one's change out of the code, tells Haiku the tagline of its plan item, and checks the build with the tests that change holds. `--shipped <n>` sets how many it takes, and a feature whose branch landed by fast-forward is passed over.
|
||||
- `task-bench` plants a Python mutant in a file whose lines end in CRLF, which it could not re-apply before, and a Go mutant there keeps applying.
|
||||
- This repo documents its own `task-bench` command in the README → Test, with `task-bench-image/Dockerfile`, an image that holds pytest, git and tmux, so each scoring run in `larv-review` benches claude-config and records its figures.
|
||||
- The stability reviewer now checks a lookup key built by joining path segments, or matched by prefix, for two inputs that give one key, such as a column named like its own table or the namespaces `ns` and `ns.sub`.
|
||||
|
||||
@@ -228,7 +228,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter.
|
||||
- `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it.
|
||||
- `subagent-rung [--plan] <model> <L>` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model on the project's routing ladder, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule.
|
||||
- `task-bench --image <image> --test <shell text> [<options>]` plants bugs that the tests catch, in the Go and Python files that hold the places the comprehension seats found hardest, has Haiku fix each at the base and at the head, and prints how often the fix passes and what it took. It needs docker and a token from `claude setup-token`; `task-bench --help` says how it plants, runs and checks. It leaves a digest of why runs failed. With `--tasks features` it has Haiku build each feature in the folder the config names as `bench-tasks` instead, from its spec, and checks the build with acceptance tests Haiku never sees. With `--tasks data-sources` it has Haiku add each data source there: a folder that also holds `generate-register`, the seeded script whose made-up register Haiku imports. With `--record-figures`, a bench that finishes appends its figures over every task to the comprehension history. A scoring run starts the bench that way where the project's README documents its `task-bench` command. `task-bench gather` starts a claude on the project's rung, which files a plan item for each place the digest shows to be hard; then gather removes the bench's folder, digest and streams.
|
||||
- `task-bench --image <image> --test <shell text> [<options>]` plants bugs that the tests catch, in the Go and Python files that hold the places the comprehension seats found hardest, has Haiku fix each at the base and at the head, and prints how often the fix passes and what it took. It needs docker and a token from `claude setup-token`; `task-bench --help` says how it plants, runs and checks. It leaves a digest of why runs failed. With `--tasks features` it has Haiku build each feature in the folder the config names as `bench-tasks` instead, from its spec, and checks the build with acceptance tests Haiku never sees. With `--tasks data-sources` it has Haiku add each data source there: a folder that also holds `generate-register`, the seeded script whose made-up register Haiku imports. With `--tasks shipped-features` it has Haiku rebuild features the project shipped: it takes each one's change out of the code, tells Haiku the tagline of the plan item, and checks the build with the tests that change holds. It passes over a feature whose branch landed by fast-forward. With `--record-figures`, a bench that finishes appends its figures over every task to the comprehension history. A scoring run starts the bench that way where the project's README documents its `task-bench` command. `task-bench gather` starts a claude on the project's rung, which files a plan item for each place the digest shows to be hard; then gather removes the bench's folder, digest and streams.
|
||||
- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show <ID>` one item's row and detail; `add …` files an item under the next free ID, `edit <ID> …` sets an item's cells or detail, and `move <ID> --release <version>` sets an item's release; `finish <ID>` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`, except for a plan kept in Jira. Each change ranks a markdown plan. `todo-item --help` states the flags.
|
||||
- `touch-predictions record <ID>...` appends what a chunk's items were predicted to touch, under `Touches:` in their details, beside the files and parts its branch touched, to the record the config names as `touch-predictions`; `touch-predictions --help` shows the spelling and how a part is named. `chunk-preflight` reads the same predictions to name the items that may start chunks at once.
|
||||
- `wait-for <file> [<pattern>] [--timeout <seconds>]` waits until a file a background job writes holds a line matching the pattern, and prints it.
|
||||
@@ -240,7 +240,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `adf_codec/` converts markdown to ADF, the rich text of Jira Cloud and Confluence, and back, in a throwaway container running a pinned `@larvit/adf-codec`. It builds the container's image inside a heavy slot.
|
||||
- `agent_cycle/` runs one cycle (`run.py`): a headless claude worker, then the judge of its transcript. It also holds the interrupt, the tmux window and the routing of the worker's rung. The entry point that runs the cycles supplies the prompts and file names of its own workflow (`worker_prompts.py`), and reads which items a worker took in. `loop_claude` and `do_epic` drive it; `agent_cycle` doesn't import either.
|
||||
- `atlassian/` holds what the Jira and Confluence backends share (`client.py`): one Atlassian account's credentials, the request both backends send, and each service's error messages. `jira.py` holds what every reader of Jira shares: a search read page by page, the key, fields, links and property of each issue it finds, checked for their shape, and the transition that finishes an issue, for `plan_store` and `do_epic`.
|
||||
- `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path.
|
||||
- `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes`, `routing_figures` and `task_bench`. It imports `reading_cost`'s record path.
|
||||
- `chunk_driver/` holds what the entry points share. An entry point is a tool that drives chunks through `agent_cycle`: `loop_claude` and `do_epic` are the two. They share how a cycle starts (`cycle_start.py`) and closes (`chunk_run.py`), the claim on a checkout before a chunk starts in it (`claims.py`), the prompts every worker gets (`prompts.py`), and a checkout's premises, records and saved models (`project/`). It imports neither entry point, and `repo_checks` fails any package that imports one of the two. `agent_cycle` is the layer below it, and `repo_checks` fails `agent_cycle` where it imports `chunk_driver`, tests included.
|
||||
- `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`.
|
||||
- `deploy_release` imports `release_plan`'s `release_standing`.
|
||||
@@ -278,7 +278,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `review_rules/` holds the larv-review rules that several tools apply: its passes, its review folder, its round commit titles and the comprehension history's format.
|
||||
- `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls.
|
||||
- `rung_replay/` holds what `judge_replay` and `review_replay` share: the parallel replay runner, the argument reader, the candidate rungs and the exits, and `judge_replay`'s rung search. It reads `agent_cycle`'s retry count and `chunk_driver`'s models file, and finds that file through `loop_state`'s paths. Its `archive.py` keeps each replay's runs and its report in a `replays/` folder of loop-claude's archive.
|
||||
- `task_bench/` holds `task-bench`, which plants bugs in a project's Go and Python files, or takes the project's bench features or data sources, and has Haiku fix, build or add them in containers.
|
||||
- `task_bench/` holds `task-bench`, which plants bugs in a project's Go and Python files, or takes the project's bench features, its data sources or the features its history shipped, and has Haiku fix, build or add them in containers.
|
||||
- `test_env.py` serves the tests.
|
||||
- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, reads the text piped into a command, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards.
|
||||
- `transcript_archive/` stores loop-claude's transcripts. Its `project_key.py` names each project's archive folder, loop-claude session and models-file entry.
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import pathlib
|
||||
|
||||
from branch_chunks.fixes import blamed, fixing_changes, FixingChange, removed_work, Traced, with_fixes
|
||||
from branch_chunks.cut import BranchChunk, cut_branch, LOG, NOT_WORK, plan_revisions, shipped_by
|
||||
from branch_chunks.cut import Branch, BranchChunk, cut_branch, LOG, NOT_WORK, plan_revisions, shipped_by
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import git, Git, text_at
|
||||
from plan.todo_table import Item
|
||||
from project_config.main import located
|
||||
from project_config.settings import ProjectConfig
|
||||
from record_store.stores import store
|
||||
@@ -37,6 +38,16 @@ def branch_chunks(default: str, run: Git, titles: templates.Titles) -> list[Bran
|
||||
"""Each chunk on the default branch's first-parent line, newest first, with the todo.md items it shipped and the later chunks that fixed code it shipped.
|
||||
|
||||
titles holds the project's title templates, which each commit's title is read through. run must run git in the checkout's top: the diff names each path from the top, while blame and a pathspec read a path from the current directory."""
|
||||
cut = cut_with_shipped(default, run, titles)
|
||||
if isinstance(cut, Failure):
|
||||
return cut
|
||||
branch, shipped = cut
|
||||
traced = traces(fixing_changes(branch, shipped), run)
|
||||
return traced if isinstance(traced, Failure) else with_fixes(branch, shipped, traced)
|
||||
|
||||
|
||||
def cut_with_shipped(default: str, run: Git, titles: templates.Titles) -> tuple[Branch, list[tuple[Item, ...]]] | Failure:
|
||||
"""The first-parent line of default, a branch or a commit, cut into chunks, and the todo.md items each chunk shipped, in the order of the branch's chunks, newest first. run and titles are branch_chunks' own."""
|
||||
# The -- keeps a file named like the branch from making it ambiguous.
|
||||
log = run(*LOG, default, "--")
|
||||
if isinstance(log, Failure):
|
||||
@@ -45,11 +56,7 @@ def branch_chunks(default: str, run: Git, titles: templates.Titles) -> list[Bran
|
||||
if isinstance(branch, Failure):
|
||||
return branch
|
||||
plans = plans_at(plan_revisions(branch), run)
|
||||
if isinstance(plans, Failure):
|
||||
return plans
|
||||
shipped = shipped_by(branch, plans)
|
||||
traced = traces(fixing_changes(branch, shipped), run)
|
||||
return traced if isinstance(traced, Failure) else with_fixes(branch, shipped, traced)
|
||||
return plans if isinstance(plans, Failure) else (branch, shipped_by(branch, plans))
|
||||
|
||||
|
||||
def plans_at(revisions: list[str], run: Git) -> dict[str, str] | Failure:
|
||||
|
||||
@@ -46,7 +46,9 @@ def digest(sides: dict[Side, str], table: list[str], tasks: list[TaskRuns], is_f
|
||||
"""The digest of a bench of the commits sides names: where each side's code is, the table of its figures, then each task,
|
||||
which the digest calls by noun. is_file says whether a path in the project names a file."""
|
||||
line = " A bug's name gives its line at the base." if noun == "bug" else ""
|
||||
code = f"Base {sides['base']}, head {sides['head']}.{line} Each side's code without the {noun}s is in `trees/base` and `trees/head` in the bench's folder."
|
||||
# `trees` holds every shipped feature built; each one's task starts in trees of its own, which lack it.
|
||||
where = "shipped feature <n> is in `shipped-features/<n>/base` and `shipped-features/<n>/head`" if noun == "shipped feature" else f"the {noun}s is in `trees/base` and `trees/head`"
|
||||
code = f"Base {sides['base']}, head {sides['head']}.{line} Each side's code without {where} in the bench's folder."
|
||||
return "\n".join(["# task-bench digest", "", code, "", *table, *(line for task in tasks for line in ["", *told(task, is_file, noun)])]) + "\n"
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ Where the digest's headings read `## Feature`, the bench had Haiku build feature
|
||||
|
||||
Where the digest's headings read `## Data source`, the bench had Haiku add data sources instead. Each data source is a spec, which the digest quotes, and a register: a made-up dataset as a publisher would release it. Haiku wrote the importer, the data and whatever else the spec asks. Read every data source as a feature, with two differences. Its runs are named as `data-source-1-base-2`. And the tree Haiku started in, register included, is `data-sources/<name>/base` or `data-sources/<name>/head` in the bench's folder, `<name>` being the name in the heading; `trees/base` and `trees/head` lack the register.
|
||||
|
||||
Where the digest's headings read `## Shipped feature`, the bench had Haiku rebuild features the project had shipped instead. Each shipped feature is the tagline of its plan item, which the digest quotes, and a rebuild of it passed where the tests its change touched, which Haiku never saw, passed over that rebuild. Read every shipped feature as a feature, with two differences. Its runs are named as `shipped-feature-1-base-2`. And the tree Haiku started in, without the feature, is `shipped-features/<n>/base` or `shipped-features/<n>/head` in the bench's folder, `<n>` being the number in the heading; `trees/base` and `trees/head` hold the feature built.
|
||||
|
||||
Each run's whole stream is in the `runs` folder of the bench's folder, named below, as `<run id>.jsonl`. Open one only where the digest leaves a question open, and read it in parts: a stream is large. The folder is removed when you end, so an item must say everything it needs.
|
||||
|
||||
What to do:
|
||||
|
||||
+61
-23
@@ -1,9 +1,11 @@
|
||||
r"""Measure how hard a project's code is to fix a bug in, or to build a feature in, at a base commit and at a head: plant bugs its
|
||||
tests catch, have Haiku fix each several times at both, and print how often the fix passes and what it took. With --tasks features,
|
||||
Haiku builds the project's bench features instead, and with --tasks data-sources it adds made-up data sources.
|
||||
Haiku builds the project's bench features instead, with --tasks data-sources it adds made-up data sources, and with --tasks
|
||||
shipped-features it rebuilds features the project shipped.
|
||||
|
||||
usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures]
|
||||
task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures]
|
||||
task-bench --tasks shipped-features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--shipped <n>] [--runs <n>] [--record-figures]
|
||||
task-bench gather
|
||||
|
||||
Run it in a checkout, under ~/.claude/bin/run-heavy, with a long-lived token in CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token`
|
||||
@@ -78,6 +80,27 @@ with the committed data. A task counts, and a run passes, as for a feature; the
|
||||
Haiku left it. Name the made-up publisher's country by a code no real data could carry: one ISO 3166-1 leaves to its users,
|
||||
such as QZ, and never XK, which is Kosovo's in practice. The table has a row per data source and side.
|
||||
|
||||
--tasks shipped-features benches rebuilding features the project shipped, so nobody writes a task. A shipped feature is a chunk
|
||||
on the base's first-parent history that took an item out of `todo.md`. A chunk is a merge commit with what it merged, or the
|
||||
commits a rebase landed together, which share a commit time. A chunk with a commit whose title opens `Drop item <ID>:` took
|
||||
that item out unbuilt, so it didn't ship it. The bench goes through the shipped features newest first, until --shipped of
|
||||
them, 5 by default, count. For each:
|
||||
- it takes the chunk's change out of a copy of each side's tree, as `git apply -R` does. The plan and the project's records stay
|
||||
as the side holds them, since later chunks added to them. The records are the changelog, the comprehension history, the
|
||||
decisions, the reading cost and the score anchors. So Haiku can read there what the changelog says of the feature;
|
||||
- Haiku is told the tagline of the item, or of each item the chunk shipped;
|
||||
- the acceptance tests are the test files the change touched, and its files under a `testdata` folder, each as the head holds it;
|
||||
- the reference patch is the change itself.
|
||||
With those, a shipped feature counts, and a build passes, as for a feature. The bench also passes over three kinds:
|
||||
- one whose branch landed by fast-forward. Its commits keep a commit time each, so the history doesn't say which of them
|
||||
built it;
|
||||
- one whose change doesn't come out of both trees cleanly, as where a later chunk rewrote its lines;
|
||||
- one whose change touched no test the head still holds.
|
||||
The report says which and why. The table has a row per shipped feature and side, named by its items, as `item 7`.
|
||||
The project's config must name the checkout, with the plan at `todo.md`, the comprehension history at
|
||||
`docs/comprehension-history.md` and the reading cost at `docs/reading-cost.md`. --seed, --bugs and --prefix don't go with
|
||||
--tasks shipped-features, and --shipped goes with no other kind.
|
||||
|
||||
It prints the base and the head, then a table: a row per bug and side with how many fixes passed and the medians, over the runs
|
||||
that finished, of the input, cache-write, cache-read and output tokens, the turns, the wall time, and the reads and searches before
|
||||
the run first opened the file the bug is in. The median of the reads leaves out a run that never opened that file. Then come a row
|
||||
@@ -100,8 +123,8 @@ passed, so the pass rate's noise is unmeasured.
|
||||
With --record-figures, a bench that finishes appends its figures to the project's comprehension history: an entry with the
|
||||
table's header and its three All rows. The entry's heading gives the current UTC time, then `task-bench of <branch>: head
|
||||
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. For a bench of
|
||||
features the heading reads `task-bench features of <branch>: ...` instead, and for one of data sources `task-bench data-sources
|
||||
of <branch>: ...`. No tool reads the entry as a ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
|
||||
features the heading reads `task-bench features of <branch>: ...` instead, for one of data sources `task-bench data-sources
|
||||
of <branch>: ...`, and for one of shipped features `task-bench shipped-features of <branch>: ...`. No tool reads the entry as a ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
|
||||
|
||||
`task-bench gather`, run in the same checkout, turns the digest into plan items. It starts a claude on the project's rung, the
|
||||
cheapest rung of the model loop-claude runs the project on, with the digest and the prompt in gather-prompt.md beside this file.
|
||||
@@ -112,12 +135,16 @@ Each bench empties its own folder first, and removes the folder every earlier be
|
||||
not, unless a bench or a gather is using it. So gather a bench before the next one starts.
|
||||
|
||||
Exit 1, saying why, on an unknown or repeated argument, a missing --image or --test, a --seed, --bugs or --runs that is no whole
|
||||
number from 1, a --tasks that is none of bugs, features and data-sources, or no token; and where git, docker or a mutation tool
|
||||
number from 1, a --tasks that is none of bugs, features, data-sources and shipped-features, or no token; and where git, docker or a mutation tool
|
||||
fails, the seats' places don't name any Go or Python file, the tests fail at a side without a bug, or no mutant becomes a bug. With --tasks
|
||||
features or data-sources it exits 1 on a --seed, --bugs or --prefix; where no config names the checkout or its config sets no
|
||||
`bench-tasks`, or the folder holds no task of that kind, one that lacks a part, or a `generate-register` that is no executable
|
||||
file, each before docker runs; and where the tests fail at a side without the acceptance tests, or no task counts. Where the
|
||||
API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished.
|
||||
file, each before docker runs; and where the tests fail at a side without the acceptance tests, or no task counts.
|
||||
With --tasks shipped-features it exits 1 on a --seed, --bugs or --prefix, and on a --shipped that is no whole number from 1;
|
||||
where no config names the checkout, its config keeps the plan, the comprehension history or the reading cost at another path
|
||||
than the one above, or the base's history shipped no item, each before docker runs; and where the tests fail at a side with every feature in, or no shipped feature
|
||||
counts. A --shipped with another kind of task exits 1 too.
|
||||
Where the API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished.
|
||||
With --record-figures it also exits 1, saying why: before it plants a bug, where no config names the checkout or the history
|
||||
cannot be read; and after the bench, where the history already holds that branch's bench of those two commits or cannot be
|
||||
written. The folder then still holds the bench's results.
|
||||
@@ -137,7 +164,7 @@ import time
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, SHIPPED, Task, tests_in_copy
|
||||
from task_bench.planted_mutant import bug_at_sides, Mutant
|
||||
from claude_code.reply import Claude
|
||||
from task_bench.bench_folder import clear_left, held
|
||||
@@ -155,20 +182,23 @@ from task_bench.figures import figures, Result, Side, SIDES, 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.shipped_features import read_shipped, shipped_tasks, ShippedFeatures
|
||||
from task_bench.record_figures import recorded_bench
|
||||
from run_heavy.capped_docker import SHARE_VARIABLE
|
||||
|
||||
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench gather"
|
||||
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench --tasks shipped-features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--shipped <n>] [--runs <n>] [--record-figures], or task-bench gather"
|
||||
# A panel of three readers, seated as the README's audience, picked these options on 2026-11-21, each 3 to 0.
|
||||
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--tasks", "--test")
|
||||
# Such a panel picked --shipped on 2026-11-24, first for two of its three and second for the third, who would spell it out as
|
||||
# --shipped-features: it names its kind as --bugs does, where --features would read as counting the bench features.
|
||||
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--shipped", "--tasks", "--test")
|
||||
# The one option that takes no value.
|
||||
RECORD = "--record-figures"
|
||||
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
|
||||
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1", "--shipped": "5"}
|
||||
TASKS = "--tasks"
|
||||
# Opens the report's last line, which names the bench's folder.
|
||||
KEPT = "The digest, and each run's result and stream, until `task-bench gather` files plan items from them or the next bench starts: "
|
||||
# The options only a bench of bugs takes: two choose the bugs to plant, and --prefix runs the mutation tool.
|
||||
OF_BUGS = ("--seed", "--bugs", "--prefix")
|
||||
# The options only a bench of one kind takes. For bugs, two choose the bugs to plant, and --prefix runs the mutation tool.
|
||||
ONLY_FOR = {"--seed": BUG, "--bugs": BUG, "--prefix": BUG, "--shipped": SHIPPED}
|
||||
|
||||
|
||||
class Fixes(typing.NamedTuple):
|
||||
@@ -221,12 +251,12 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
|
||||
return Failure(f"{name} is missing")
|
||||
if given.setdefault(TASKS, "bugs") not in KINDS:
|
||||
return Failure(f"{TASKS} takes {', '.join(list(KINDS)[:-1])} or {list(KINDS)[-1]}, not {given[TASKS]}")
|
||||
of_features = KINDS[given[TASKS]] is not BUG
|
||||
for name in OF_BUGS:
|
||||
if of_features and name in given:
|
||||
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} {given[TASKS]}")
|
||||
kind = KINDS[given[TASKS]]
|
||||
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]}")
|
||||
for name, default in COUNTS.items():
|
||||
if of_features and name in OF_BUGS:
|
||||
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]}")
|
||||
@@ -243,9 +273,11 @@ def progress(line: str) -> None:
|
||||
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. Each kind reads what it makes its tasks from before anything is copied or built,
|
||||
# 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.
|
||||
tasks_from = read(home) if KINDS[given[TASKS]] is BUG else read_features(home, KINDS[given[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
|
||||
git = functools.partial(git_repo.git, env=env)
|
||||
@@ -255,6 +287,10 @@ 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
|
||||
progress(f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}.")
|
||||
review = made_review_folder(checkout, home)
|
||||
if isinstance(review, Failure):
|
||||
@@ -267,10 +303,10 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
|
||||
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, 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. The bench plants bugs at
|
||||
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features, or add the data
|
||||
sources, it holds otherwise."""
|
||||
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()}")
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
trees: dict[Side, str] = {}
|
||||
@@ -282,6 +318,8 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
|
||||
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"])
|
||||
if isinstance(planned, Failure):
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
"""The features task-bench has Haiku rebuild: those the project shipped, read from its history. A shipped feature is a chunk on
|
||||
the base's first-parent line that took an item out of the plan, as branch_chunks cuts that line. Once its change is out of each
|
||||
side's tree, it is a feature as task_bench.feature_tasks has it. `task-bench --help` says what Haiku is told and how a rebuild
|
||||
is checked."""
|
||||
import functools
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import typing
|
||||
|
||||
from task_bench.feature_tasks import ACCEPTANCE, Feature, PATCH, why_passed_over
|
||||
from task_bench.tasks import Bench, committed, on_disk, Planned, Task
|
||||
from branch_chunks.read import cut_with_shipped, unsupported
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import Git
|
||||
from plan.todo_table import Item, tagline_text
|
||||
from branch_chunks.cut import Landing
|
||||
from project_config.main import located
|
||||
from task_bench.runs import of_tests
|
||||
from project_config.settings import RECORDS
|
||||
from task_bench.figures import Side, SIDES
|
||||
|
||||
# Why a feature whose chunk landed by fast-forward is passed over. Each of its commits is a chunk of its own to branch_chunks,
|
||||
# so the chunk that took the item out holds the branch's last commit alone.
|
||||
FAST_FORWARDED = "its branch landed by fast-forward, so the history doesn't say which commits built it"
|
||||
|
||||
# The options that keep the checkout's diff config out of a patch. --no-renames writes a renamed file as one file removed and
|
||||
# one added, so `git apply` doesn't have to detect the rename again.
|
||||
PLAIN_DIFF = ("--no-color", "--no-ext-diff", "--no-textconv", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/")
|
||||
|
||||
|
||||
class Shipped(typing.NamedTuple):
|
||||
"""A feature the project shipped: the name the report gives it, such as `item 7`, the tagline of each item its chunk took out
|
||||
of the plan, a paragraph each, the commits its chunk's change runs between, and how the chunk landed."""
|
||||
|
||||
name: str
|
||||
told: str
|
||||
before: str
|
||||
tip: str
|
||||
landing: Landing
|
||||
|
||||
|
||||
class ShippedFeatures(typing.NamedTuple):
|
||||
"""The features a project shipped, newest first, and the paths of its plan and its records, each from the checkout's top. A
|
||||
chunk's change to those paths is no part of its feature."""
|
||||
|
||||
found: list[Shipped]
|
||||
records: list[str]
|
||||
|
||||
|
||||
def read_shipped(home: pathlib.Path, checkout: str, base: str, git: Git) -> ShippedFeatures | Failure:
|
||||
"""The features that the project in checkout shipped on the first-parent line of the commit base. A Failure where no config
|
||||
names the checkout, where its config puts the plan or a record at a path branch_chunks doesn't read, where git fails, and
|
||||
where that line shipped no item."""
|
||||
in_checkout = functools.partial(git, cwd=checkout)
|
||||
config = located(checkout, home, in_checkout)
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
if why := unsupported(checkout, home, in_checkout):
|
||||
return Failure(f"task-bench cannot tell what the project shipped: {why}")
|
||||
cut = cut_with_shipped(base, in_checkout, config.titles)
|
||||
if isinstance(cut, Failure):
|
||||
return cut
|
||||
branch, shipped = cut
|
||||
found = [
|
||||
Shipped(named(items), "\n\n".join(tagline_text(item.tagline) for item in items), chunk.before, chunk.tip, chunk.landing)
|
||||
for chunk, items in zip(branch.chunks, shipped)
|
||||
if items and chunk.before
|
||||
]
|
||||
if not found:
|
||||
return Failure("No chunk on the base's history took an item out of todo.md, so that history holds no shipped feature to rebuild.")
|
||||
return ShippedFeatures(found, [path for path in map(config.tracked, ("plan", *RECORDS)) if path])
|
||||
|
||||
|
||||
def named(items: tuple[Item, ...]) -> str:
|
||||
"""What the report calls the feature that shipped items: `item 7`, or `items 7, 8`."""
|
||||
return f"item{'s' * (len(items) > 1)} {', '.join(str(item.id) for item in items)}"
|
||||
|
||||
|
||||
def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned | Failure:
|
||||
"""The task of rebuilding each feature of shipped that counts at the bench's commits, newest first, until there are count
|
||||
tasks. The tasks are numbered from 1, and a line says why each feature on the way was passed over. A Failure where none
|
||||
counts."""
|
||||
noun = bench.asked.kind.noun
|
||||
tasks: list[Task] = []
|
||||
passed_over: list[str] = []
|
||||
for feature in shipped.found:
|
||||
if len(tasks) == count:
|
||||
break
|
||||
# A feature passed over leaves no folder, so the next one tried takes the same number.
|
||||
folder = bench.folder / "shipped-features" / str(len(tasks) + 1)
|
||||
taken_out = FAST_FORWARDED if feature.landing == "push" else on_disk(f"take {feature.name} out of the trees in {folder}", lambda: without(bench, feature, shipped.records, folder))
|
||||
why = taken_out if not isinstance(taken_out, TakenOut) else why_passed_over(bench, taken_out.trees, taken_out.feature)
|
||||
if isinstance(why, Failure):
|
||||
return why
|
||||
if isinstance(taken_out, TakenOut) and why is None:
|
||||
tasks.append(Task(len(tasks) + 1, feature.name, taken_out.trees, dict.fromkeys(SIDES, feature.told), acceptance=taken_out.feature.acceptance))
|
||||
continue
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
passed_over.append(f"the {noun} {feature.name}: {why}.")
|
||||
bench.say(f"task-bench: passed over {passed_over[-1]}")
|
||||
if not tasks:
|
||||
return Failure(f"No {noun} on the base's history counts; the lines above say why.")
|
||||
return Planned(tasks, [f"Passed over {line}" for line in passed_over], {})
|
||||
|
||||
|
||||
def held(path: str) -> bool:
|
||||
"""Whether path is a file or a link, which copies as a test does; a folder doesn't."""
|
||||
return os.path.islink(path) or os.path.isfile(path)
|
||||
|
||||
|
||||
class TakenOut(typing.NamedTuple):
|
||||
"""A shipped feature taken out of the bench's trees: each side's tree without it, committed once, and the feature that
|
||||
builds it there again."""
|
||||
|
||||
trees: dict[Side, str]
|
||||
feature: Feature
|
||||
|
||||
|
||||
def without(bench: Bench, shipped: Shipped, records: list[str], folder: pathlib.Path) -> TakenOut | str | Failure:
|
||||
"""shipped taken out of a copy of each side's tree, under folder, where its patch and its acceptance tests go too; or why it
|
||||
cannot be, which ends a sentence that opens with its name. A Failure where git fails.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
change = (shipped.before, shipped.tip, "--", ".", *(f":(exclude,literal){path}" for path in records))
|
||||
# A name that is not UTF-8 is read with U+FFFD in it. The head's tree holds no file of that name, so the file is left out.
|
||||
names = bench.git("diff", "--name-only", "-z", *change, cwd=bench.checkout, errors="replace")
|
||||
if isinstance(names, Failure):
|
||||
return names
|
||||
tests = [path for path in names.split("\x00") if path and of_tests(path) and held(os.path.join(bench.trees["head"], path))]
|
||||
if not tests:
|
||||
return "its change holds no test that the head holds"
|
||||
patch, acceptance = folder / PATCH, folder / ACCEPTANCE
|
||||
for path in tests:
|
||||
os.makedirs(os.path.dirname(acceptance / path), exist_ok=True)
|
||||
shutil.copy2(os.path.join(bench.trees["head"], path), acceptance / path, follow_symlinks=False)
|
||||
# --binary writes a binary file's bytes, which `git apply` needs. --output has git write them to the file, since bench.git
|
||||
# would read them from its output as text.
|
||||
diffed = bench.git("diff", "--binary", f"--output={patch}", *PLAIN_DIFF, *change, cwd=bench.checkout)
|
||||
if isinstance(diffed, Failure):
|
||||
return diffed
|
||||
trees: dict[Side, str] = {}
|
||||
for side in SIDES:
|
||||
tree = str(folder / side)
|
||||
shutil.copytree(bench.trees[side], tree, symlinks=True)
|
||||
# In a repository of its own, the tree is where `git apply` reads the patch's paths from, whatever repository holds the
|
||||
# bench's folder. git has run in this bench already, so a failure of the second command is the patch's.
|
||||
if isinstance(made := bench.git("init", "--quiet", cwd=tree), Failure):
|
||||
return made
|
||||
if isinstance(bench.git("apply", "-R", str(patch), cwd=tree), Failure):
|
||||
return f"its revert doesn't apply at the {side}"
|
||||
if failure := committed(bench.git, tree):
|
||||
return failure
|
||||
trees[side] = tree
|
||||
return TakenOut(trees, Feature(shipped.name, shipped.told, str(patch), str(acceptance)))
|
||||
@@ -1,4 +1,4 @@
|
||||
"""What task-bench's three kinds of task share: a planted bug, a feature to build and a data source to add. They share the task itself, the bench it runs in, and the
|
||||
"""What task-bench's four kinds of task share: a planted bug, a feature to build, a data source to add and a shipped feature to rebuild. They share the task itself, the bench it runs in, and the
|
||||
steps that commit a task's tree and run the tests over a copy of one."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
@@ -32,11 +32,14 @@ class Kind(typing.NamedTuple):
|
||||
BUG = Kind("bug", "A test of this project fails with the message below. Find the bug in the code and fix it. Change no test.\n\n{told}", "a planted bug")
|
||||
FEATURE = Kind("feature", "Build the feature below in this project.\n\n{told}", "a feature's acceptance tests")
|
||||
DATA_SOURCE = Kind("data source", "Add the data source below to this project.\n\n{told}", "a data source's acceptance tests")
|
||||
# What Haiku is asked is a feature's prompt: the feature is new to the tree Haiku gets.
|
||||
SHIPPED = Kind("shipped feature", FEATURE.prompt, "a shipped feature taken out")
|
||||
# By the value --tasks takes. A panel of three readers, seated as the README's audience, picked `--tasks features` on 2026-11-23,
|
||||
# 3 to 0, over a bare `--features` and a `features` subcommand: it names what the bench runs, and the bugs as its other value.
|
||||
# Such a panel picked `data-sources` the same day, 3 to 0, over `sources` and `imports`, which read as source code and as import
|
||||
# statements.
|
||||
KINDS = {"bugs": BUG, "features": FEATURE, "data-sources": DATA_SOURCE}
|
||||
# statements. Such a panel picked `shipped-features` on 2026-11-24, 3 to 0, over `shipped`, `rebuilds`, `reverts` and `history`:
|
||||
# it says what was shipped, and stands apart from the features someone wrote for the bench.
|
||||
KINDS = {"bugs": BUG, "features": FEATURE, "data-sources": DATA_SOURCE, "shipped-features": SHIPPED}
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
|
||||
@@ -288,7 +288,7 @@ class OptionsTest(unittest.TestCase):
|
||||
def test_tasks_names_the_kind_of_task_and_bugs_is_the_default(self):
|
||||
self.assertEqual(self.options()["--tasks"], "bugs")
|
||||
self.assertEqual(self.options("--tasks", "features")["--tasks"], "features")
|
||||
self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs, features or data-sources, not chores")
|
||||
self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs, features, data-sources or shipped-features, not chores")
|
||||
|
||||
def test_features_run_5_times_at_each_side_by_default(self):
|
||||
self.assertEqual(self.options("--tasks", "features")["--runs"], "5")
|
||||
|
||||
@@ -218,7 +218,7 @@ class OptionsTest(unittest.TestCase):
|
||||
|
||||
def test_data_sources_is_a_kind_of_task_that_runs_5_times_at_each_side_by_default(self):
|
||||
self.assertEqual(self.options("--tasks", "data-sources")["--runs"], "5")
|
||||
self.assertEqual(self.options("--tasks", "sources").reason, "--tasks takes bugs, features or data-sources, not sources")
|
||||
self.assertEqual(self.options("--tasks", "sources").reason, "--tasks takes bugs, features, data-sources or shipped-features, not sources")
|
||||
self.assertIn(", or task-bench --tasks features|data-sources --image <image>", main.USAGE)
|
||||
|
||||
def test_the_options_that_choose_bugs_are_refused_with_data_sources(self):
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
"""`task-bench --tasks shipped-features` from its command line down: a whole bench of the features a project's history shipped,
|
||||
with docker and claude faked, and the histories it passes over."""
|
||||
import contextlib
|
||||
import functools
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from task_bench.test_feature_tasks import ACCEPTANCE, BenchOfTasksCase
|
||||
from task_bench.test_task_bench import BASE_CODE, HEAD_CODE
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import git
|
||||
from task_bench import main
|
||||
from branch_chunks.read import READ_AT
|
||||
from task_bench.shipped_features import read_shipped
|
||||
|
||||
HEADER = "| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves |\n|---|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
ROWS = {
|
||||
7: "| 7 | 0.1.0 | | | **Add `Halve`, which halves a whole number.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
8: "| 8 | 0.1.0 | | | **Multiply in `Twice`.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
9: "| 9 | 0.1.0 | | | **Say in the README what Calc is.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
10: "| 10 | 0.1.0 | | | **Keep `Twice` whole, as `a \\| b` is.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
11: "| 11 | 0.1.0 | | | **Add `Third`.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
}
|
||||
HALVE = "package calc\n\nfunc Halve(a int) int {\n\treturn a / 2\n}\n"
|
||||
|
||||
|
||||
class ShippedFeaturesCase(BenchOfTasksCase):
|
||||
"""BenchOfTasksCase's checkout, whose default branch then shipped four items, each in a chunk rebased onto it. Oldest first:
|
||||
|
||||
- item 8 wrote the line of Twice that the head rewrites;
|
||||
- item 7 added Halve, with a binary file, a file whose name is not UTF-8, a test, and a link to that test;
|
||||
- item 9 changed the README alone;
|
||||
- item 10 added only a test, which passes without it.
|
||||
|
||||
The head branches off after them. The checkout's config writes a diff without the `a/` and `b/` that `git apply` strips."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.given.update({"--tasks": "shipped-features", "--shipped": "5"})
|
||||
# branch_chunks reads the plan and two records at these paths alone.
|
||||
self.config.write_text(re.sub(r'"checkout:(plan|comprehension-history|reading-cost)\.md"', lambda found: f'"checkout:{READ_AT[found[1]]}"', self.config.read_text()))
|
||||
self.git("checkout", "--quiet", "main")
|
||||
self.git("config", "diff.noprefix", "true")
|
||||
self.git("rm", "--quiet", "-r", "bench-tasks")
|
||||
(self.repo / "calc.go").write_text(BASE_CODE.replace("a * 2", "a + a"))
|
||||
self.plan(7, 8, 9, 10)
|
||||
self.landed(1, "Plan four items")
|
||||
(self.repo / "calc.go").write_text(BASE_CODE)
|
||||
(self.repo / "twice_test.go").write_text("grep -q 'a \\* 2\\|2 \\* a' calc.go\n")
|
||||
self.plan(7, 9, 10)
|
||||
self.landed(2, "Multiply in Twice", "Finish item 8 in the plan")
|
||||
(self.repo / "halve_test.go").write_text(ACCEPTANCE)
|
||||
self.landed(3, "Test Halve")
|
||||
(self.repo / "halve.go").write_text(HALVE)
|
||||
(self.repo / "halve.bin").write_bytes(b"\x00\xff")
|
||||
(self.repo / os.fsdecode(b"halv\xe9.txt")).write_text("A name that is not UTF-8.\n")
|
||||
os.symlink("halve_test.go", self.repo / "linked_test.go")
|
||||
self.plan(9, 10)
|
||||
self.landed(3, "Add Halve", "Finish item 7 in the plan")
|
||||
(self.repo / "README.md").write_text("# Calc\n\nIt adds.\n")
|
||||
self.plan(10)
|
||||
self.landed(4, "Say what Calc is")
|
||||
(self.repo / "whole_test.go").write_text("exit 0\n")
|
||||
self.plan()
|
||||
self.landed(5, "Keep Twice whole", "Finish item 10 in the plan")
|
||||
self.base = self.git("rev-parse", "HEAD")
|
||||
self.git("checkout", "--quiet", "-B", "item-1")
|
||||
(self.repo / "calc.go").write_text(HEAD_CODE)
|
||||
self.head = self.commit("Head")
|
||||
|
||||
def plan(self, *ids: int) -> None:
|
||||
"""Writes a plan that holds the items ids."""
|
||||
(self.repo / "todo.md").write_text("# Plan\n\n" + HEADER + "".join(ROWS[id_] for id_ in ids))
|
||||
|
||||
def landed(self, hour: int, *titles: str, written_then: bool = False) -> None:
|
||||
"""Commits what the checkout holds under the first of titles, and an empty commit under each other one, all at the commit
|
||||
time a rebase at that hour would give them: branch_chunks reads the commits that share a commit time as one chunk.
|
||||
With written_then the commits were written at that time too, as a fast-forward leaves them."""
|
||||
times = {"GIT_COMMITTER_DATE": f"2026-11-01T0{hour}:00:00+00:00"}
|
||||
self.env.update(times | {"GIT_AUTHOR_DATE": times["GIT_COMMITTER_DATE"]} if written_then else times)
|
||||
self.git("add", "--all")
|
||||
for title in titles:
|
||||
self.git("commit", "--quiet", "--allow-empty", "--message", title)
|
||||
for name in ("GIT_COMMITTER_DATE", "GIT_AUTHOR_DATE"):
|
||||
self.env.pop(name, None)
|
||||
|
||||
|
||||
class ShippedFeatureBenchTest(ShippedFeaturesCase):
|
||||
def test_has_haiku_rebuild_each_shipped_feature_from_its_tagline_and_checks_it_with_the_tests_its_change_added(self):
|
||||
report = self.bench()
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
folder = pathlib.Path(report[-1].removeprefix(main.KEPT))
|
||||
self.assertEqual(report[:-1], [
|
||||
f"task-bench: base {self.base[:12]}, head {self.head[:12]}. 1 shipped feature, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.",
|
||||
"Passed over the shipped feature item 10: its acceptance tests pass at the base before it is built.",
|
||||
"Passed over the shipped feature item 9: its change holds no test that the head holds.",
|
||||
"Passed over the shipped feature item 8: its revert doesn't apply at the head.",
|
||||
"",
|
||||
"| Shipped feature | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |",
|
||||
"|---|---|---|---|---|---|---|---|---|---|",
|
||||
"| 1: item 7 | base | 0/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||
"| 1: item 7 | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||
"| All | base | 0/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||
"| All | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||
"| All | change | +2 | 0 % | 0 % | 0 % | 0 % | 0 | 0 % | - |",
|
||||
"",
|
||||
])
|
||||
handed = json.loads(pathlib.Path(f"{self.log}.claude").read_text())
|
||||
self.assertEqual(handed["prompt"], "Build the feature below in this project.\n\nAdd `Halve`, which halves a whole number.")
|
||||
# Haiku's copy holds the tree without Halve, its binary file and its tests; the plan and the later items' files stay as the side holds them.
|
||||
self.assertEqual(handed["handed"], [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go", "whole_test.go"])
|
||||
results = json.loads((folder / "results.json").read_text())
|
||||
self.assertEqual((results["shipped-features"], len(results["runs"])), ({"1": "item 7"}, 4))
|
||||
self.assertEqual(sorted(path.name for path in (folder / "runs").iterdir() if path.suffix == ".jsonl"), [f"shipped-feature-1-{side}-{run}.jsonl" for side in ("base", "head") for run in (1, 2)])
|
||||
|
||||
def test_stops_looking_once_as_many_features_count_as_shipped_asks_for(self):
|
||||
report = self.bench(**{"--shipped": "1"})
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
# Item 8 shipped before item 7, which filled the bench, so nothing is said of it.
|
||||
self.assertEqual(report[1:4], [
|
||||
"Passed over the shipped feature item 10: its acceptance tests pass at the base before it is built.",
|
||||
"Passed over the shipped feature item 9: its change holds no test that the head holds.",
|
||||
"",
|
||||
])
|
||||
|
||||
def test_gives_haiku_a_tree_whose_one_commit_holds_it_without_the_feature(self):
|
||||
report = self.bench()
|
||||
tree = pathlib.Path(report[-1].removeprefix(main.KEPT)) / "shipped-features" / "1" / "head"
|
||||
self.assertEqual(sorted(path.name for path in tree.iterdir()), [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go", "whole_test.go"])
|
||||
self.assertEqual(subprocess.run(["git", "log", "--format=%s"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "Import\n")
|
||||
self.assertEqual(subprocess.run(["git", "status", "--porcelain"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "")
|
||||
|
||||
def test_writes_a_digest_that_says_where_the_tree_without_each_feature_is(self):
|
||||
report = self.bench()
|
||||
digest = (pathlib.Path(report[-1].removeprefix(main.KEPT)) / "digest.md").read_text().splitlines()
|
||||
self.assertEqual(digest[2], f"Base {self.base}, head {self.head}. Each side's code without shipped feature <n> is in `shipped-features/<n>/base` and `shipped-features/<n>/head` in the bench's folder.")
|
||||
self.assertIn("## Shipped feature 1: item 7", digest)
|
||||
|
||||
def test_keeps_a_test_that_is_a_link_as_a_link(self):
|
||||
report = self.bench()
|
||||
acceptance = pathlib.Path(report[-1].removeprefix(main.KEPT)) / "shipped-features" / "1" / "acceptance"
|
||||
self.assertEqual(sorted(path.name for path in acceptance.iterdir()), ["halve_test.go", "linked_test.go"])
|
||||
self.assertEqual(os.readlink(acceptance / "linked_test.go"), "halve_test.go")
|
||||
|
||||
def test_benches_the_whole_checkout_from_a_folder_inside_it(self):
|
||||
(self.repo / "inside").mkdir()
|
||||
self.enterContext(contextlib.chdir(self.repo / "inside"))
|
||||
report = self.bench()
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
self.assertIn("| 1: item 7 | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |", report)
|
||||
|
||||
def test_passes_over_a_feature_whose_tests_the_head_removed_or_made_a_folder(self):
|
||||
# The checkout the process runs in still holds both tests.
|
||||
self.git("checkout", "--quiet", "-b", "without-test")
|
||||
self.git("rm", "--quiet", "halve_test.go", "linked_test.go")
|
||||
(self.repo / "halve_test.go").mkdir()
|
||||
(self.repo / "halve_test.go" / "notes").write_text("Halve's test was here.\n")
|
||||
self.commit("Remove Halve's tests")
|
||||
self.git("checkout", "--quiet", "item-1")
|
||||
report = self.bench(**{"--head": "without-test"})
|
||||
self.assertEqual(report.reason, "No shipped feature on the base's history counts; the lines above say why.")
|
||||
self.assertIn("task-bench: passed over the shipped feature item 7: its change holds no test that the head holds.", self.progress.getvalue().splitlines())
|
||||
|
||||
def test_fails_where_no_shipped_feature_counts(self):
|
||||
# The default branch as it was when item 8 had shipped and no other; the head rewrites the line item 8 wrote.
|
||||
self.git("branch", "--quiet", "--force", "main", "main~6")
|
||||
report = self.bench()
|
||||
self.assertEqual(report.reason, "No shipped feature on the base's history counts; the lines above say why.")
|
||||
self.assertIn("task-bench: passed over the shipped feature item 8: its revert doesn't apply at the head.", self.progress.getvalue().splitlines())
|
||||
|
||||
def test_passes_over_a_feature_whose_branch_landed_by_fast_forward(self):
|
||||
# Each commit keeps the time it was written at, so the commit that takes the item out is a chunk of its own.
|
||||
self.git("checkout", "--quiet", "main")
|
||||
self.plan(11)
|
||||
self.landed(6, "Plan an item")
|
||||
(self.repo / "third.go").write_text("package calc\n")
|
||||
(self.repo / "third_test.go").write_text("test -e third.go\n")
|
||||
self.landed(7, "Add Third", written_then=True)
|
||||
self.plan()
|
||||
self.landed(8, "Finish item 11 in the plan", written_then=True)
|
||||
# The bench's base is where the head left the default branch, so the head leaves it after item 11.
|
||||
self.git("checkout", "--quiet", "-B", "item-1")
|
||||
(self.repo / "calc.go").write_text(HEAD_CODE)
|
||||
self.commit("Head")
|
||||
report = self.bench(**{"--shipped": "1"})
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
self.assertEqual(report[1], "Passed over the shipped feature item 11: its branch landed by fast-forward, so the history doesn't say which commits built it.")
|
||||
|
||||
def test_fails_before_docker_runs_where_the_history_shipped_no_item(self):
|
||||
self.git("branch", "--quiet", "--force", "main", "main~8")
|
||||
report = self.bench()
|
||||
self.assertEqual(report.reason, "No chunk on the base's history took an item out of todo.md, so that history holds no shipped feature to rebuild.")
|
||||
self.assertFalse(self.log.exists(), "docker ran")
|
||||
|
||||
def test_fails_before_docker_runs_where_the_plan_is_kept_outside_the_checkout(self):
|
||||
self.config.write_text(self.config.read_text().replace('plan = "checkout:todo.md"', 'plan = "folder:todo.md"'))
|
||||
report = self.bench()
|
||||
self.assertEqual(report.reason, f"task-bench cannot tell what the project shipped: the project's config puts {self.config.parent / 'todo.md'} elsewhere than todo.md, docs/comprehension-history.md, docs/reading-cost.md in the checkout, the only paths whose commits are read so far")
|
||||
self.assertFalse(self.log.exists(), "docker ran")
|
||||
|
||||
|
||||
class ReadShippedTest(ShippedFeaturesCase):
|
||||
def read(self, run=git):
|
||||
return read_shipped(self.home, str(self.repo), "main", functools.partial(run, env=self.env))
|
||||
|
||||
def test_reads_the_features_newest_first_with_the_paths_a_revert_leaves_alone(self):
|
||||
shipped = self.read()
|
||||
self.assertEqual([(feature.name, feature.told) for feature in shipped.found], [
|
||||
# The table writes a | as \\|.
|
||||
("item 10", "Keep `Twice` whole, as `a | b` is."),
|
||||
("item 9", "Say in the README what Calc is."),
|
||||
("item 7", "Add `Halve`, which halves a whole number."),
|
||||
("item 8", "Multiply in `Twice`."),
|
||||
])
|
||||
self.assertEqual(shipped.records, ["todo.md", "decisions.md", "score-anchors.md", "docs/comprehension-history.md", "docs/reading-cost.md", "changelog.md"])
|
||||
|
||||
def test_a_chunk_that_shipped_two_items_is_one_feature_told_by_both_taglines(self):
|
||||
self.git("checkout", "--quiet", "main")
|
||||
self.plan(7, 8)
|
||||
self.landed(5, "Plan two items again")
|
||||
self.plan()
|
||||
self.landed(6, "Build both", "Finish item 7 in the plan", "Finish item 8 in the plan")
|
||||
newest = self.read().found[0]
|
||||
self.assertEqual((newest.name, newest.told), ("items 7, 8", "Add `Halve`, which halves a whole number.\n\nMultiply in `Twice`."))
|
||||
self.assertEqual((newest.before, newest.tip), (self.git("rev-parse", "main~3"), self.git("rev-parse", "main")))
|
||||
|
||||
def test_an_item_a_commit_title_drops_is_not_shipped(self):
|
||||
self.git("checkout", "--quiet", "main")
|
||||
self.plan(8)
|
||||
self.landed(5, "Plan an item again")
|
||||
self.plan()
|
||||
self.landed(6, "Drop item 8: nobody asked for it")
|
||||
self.assertEqual(self.read().found[0].name, "item 10")
|
||||
|
||||
def test_reads_the_checkout_it_is_given_wherever_the_process_runs(self):
|
||||
self.enterContext(contextlib.chdir(self.root))
|
||||
self.assertEqual(len(self.read().found), 4)
|
||||
|
||||
def test_refuses_a_plan_outside_the_checkout_wherever_the_process_runs(self):
|
||||
self.config.write_text(self.config.read_text().replace('plan = "checkout:todo.md"', 'plan = "folder:todo.md"'))
|
||||
self.enterContext(contextlib.chdir(self.root))
|
||||
self.assertTrue(self.read().reason.startswith("task-bench cannot tell what the project shipped: "))
|
||||
|
||||
def test_fails_where_git_cannot_read_a_plan(self):
|
||||
def run(*args, **named):
|
||||
return Failure("git broke") if "show" in args[:1] or "cat-file" in args[:1] else git(*args, **named)
|
||||
|
||||
self.assertEqual(self.read(run).reason, "git broke")
|
||||
|
||||
|
||||
class OptionsTest(unittest.TestCase):
|
||||
def options(self, *argv: str):
|
||||
return main.options(["--image", "golang:1.27.4", "--test", "go test ./...", *argv], {"CLAUDE_CODE_OAUTH_TOKEN": "sk-secret-token"})
|
||||
|
||||
def test_shipped_says_how_many_shipped_features_to_take_and_is_5_by_default(self):
|
||||
self.assertEqual(self.options("--tasks", "shipped-features")["--shipped"], "5")
|
||||
self.assertEqual(self.options("--tasks", "shipped-features", "--shipped", "2")["--shipped"], "2")
|
||||
self.assertEqual(self.options("--tasks", "shipped-features", "--shipped", "0").reason, "--shipped takes a whole number from 1, not 0")
|
||||
|
||||
def test_shipped_goes_with_no_other_kind_of_task(self):
|
||||
for tasks in ("bugs", "features", "data-sources"):
|
||||
with self.subTest(tasks=tasks):
|
||||
self.assertEqual(self.options("--tasks", tasks, "--shipped", "2").reason, f"--shipped is for a bench of shipped features, so it doesn't go with --tasks {tasks}")
|
||||
self.assertNotIn("--shipped", self.options())
|
||||
|
||||
def test_a_bench_of_shipped_features_takes_no_option_of_a_bench_of_bugs(self):
|
||||
self.assertEqual(self.options("--tasks", "shipped-features", "--seed", "2").reason, "--seed is for a bench of bugs, so it doesn't go with --tasks shipped-features")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -3521,3 +3521,40 @@ Read most (opens and searches):
|
||||
- `bin/task_bench/main.py` 2
|
||||
- `CHANGELOG.md` 1
|
||||
- `todo.md` 1
|
||||
|
||||
## Reading cost, chunk 5590d64e8135, finished 2026-11-23T22:28:19Z
|
||||
|
||||
40082 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `skills/larv-review/SKILL.md` 6
|
||||
- `agents/stability-reviewer.md` 2
|
||||
|
||||
## Reading cost, chunk b369f321ce4d, finished 2026-11-23T22:40:55Z
|
||||
|
||||
45216 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `README.md` 2
|
||||
- `bin/repo_checks/test_types.py` 1
|
||||
- `bin/run_tests/main.py` 1
|
||||
- `bin/task_bench/runs.py` 1
|
||||
- `ci.sh` 1
|
||||
- `docs/decisions.md` 1
|
||||
- `skills/larv-review/SKILL.md` 1
|
||||
|
||||
## Reading cost, chunk dc3c9bb92e0e, finished 2026-11-23T23:17:20Z
|
||||
|
||||
65012 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `bin/task_bench/test_python_bugs.py` 5
|
||||
- `bin/mutate_changes/mutmut_tool.py` 4
|
||||
- `bin/task_bench/planted_mutant.py` 2
|
||||
- `CHANGELOG.md` 1
|
||||
- `README.md` 1
|
||||
- `bin/task_bench/python_bugs.py` 1
|
||||
- `bin/task_bench/test_planted_mutant.py` 1
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
`Bar = 0.1`
|
||||
|
||||
`Next ID = 531`
|
||||
`Next ID = 532`
|
||||
|
||||
## Renamed
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|
||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| 507 | 0.16.0 | | owner | **Bench rebuilding a feature the project shipped: revert its commit at the head, hand Haiku its item tagline, and check with the tests that commit added.** | 3 | 2 | 1 | 4 | 5 | 1.1 by 3 | 0.7 |
|
||||
| 531 | 0.16.0 | | | **Bench the shipped features of a branch that landed by fast-forward: take as the feature the commits from the one after the item finished before it, up to the commit that took its item out of the plan.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 | 1.1 |
|
||||
| 524 | 0.16.0 | | owner | **Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names.** | 3 | 2 | 1 | 4 | 6 | 1.1 by 3 | 0.5 |
|
||||
| 526 | 0.16.0 | | owner | **Plant bugs for `task-bench` in Rust, from the mutants cargo-mutants kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 |
|
||||
| 527 | 0.16.0 | | owner | **Plant bugs for `task-bench` in TypeScript, from the mutants Stryker kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 |
|
||||
@@ -112,9 +112,18 @@
|
||||
|
||||
## Details
|
||||
|
||||
### 507. Bench rebuilding a feature the project shipped: revert its commit at the head, hand Haiku its item tagline, and check with the tests that commit added.
|
||||
### 531. Bench the shipped features of a branch that landed by fast-forward: take as the feature the commits from the one after the item finished before it, up to the commit that took its item out of the plan.
|
||||
|
||||
Such tasks cost nothing to write and are realistic. A commit whose revert doesn't apply cleanly at both the base and the head is skipped.
|
||||
Today `task-bench --tasks shipped-features` passes such a feature over. A fast-forwarded branch's commits keep a commit time each, so `branch_chunks` cuts each commit into a chunk of its own, and the chunk that took the item out of the plan holds only the feature's last commit. This project landed 114 of its 260 shipped features that way, and none of those can be benched. A squash-merged feature whose one commit was authored and committed at the same time would be passed over too; whether a forge writes such commits is not checked.
|
||||
|
||||
The tagline's rule is a recommendation, not yet checked on a real history: a commit between two chunks that belongs to neither, such as a direct push, would join the later feature. The acceptance check still guards that: a feature counts only where its tests fail after the revert and pass with the reference patch.
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/task_bench/shipped_features.py`: `read_shipped`, `shipped_tasks` (small), `FAST_FORWARDED`
|
||||
- `bin/task_bench/test_shipped_features.py`
|
||||
- `bin/task_bench/main.py`: `(module)` (small)
|
||||
- `README.md`: `## Tools` (small)
|
||||
|
||||
### 524. Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user