Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+7 -7
View File
@@ -63,12 +63,12 @@ class ArchiveChunks:
unread: tuple[str, ...] = ()
def measure_archive(root: pathlib.Path, home: str, since: str, git: Git) -> ArchiveChunks | Failure:
def measure_archive(root: pathlib.Path, home: str, env: typing.Mapping[str, str], since: str, git: Git) -> ArchiveChunks | Failure:
"""The figures of each chunk that finished after since, measured one chunk at a time because the archive outgrows memory. Only an archive that cannot be listed fails."""
listed = archived_outcomes(root)
if isinstance(listed, Failure):
return listed
projects = [measure_project(root, project, home, since, git) for project in sorted({root / key for key, _ in listed})]
projects = [measure_project(root, project, home, env, since, git) for project in sorted({root / key for key, _ in listed})]
return ArchiveChunks(
[chunk for project in projects for chunk in project.chunks],
tuple(skipped for project in projects for skipped in project.skipped),
@@ -76,7 +76,7 @@ def measure_archive(root: pathlib.Path, home: str, since: str, git: Git) -> Arch
)
def measure_project(root: pathlib.Path, project: pathlib.Path, home: str, since: str, git: Git) -> ArchiveChunks:
def measure_project(root: pathlib.Path, project: pathlib.Path, home: str, env: typing.Mapping[str, str], since: str, git: Git) -> ArchiveChunks:
"""The figures of each of one project's chunks that finished after since, as measure_archive measures them."""
key = str(project.relative_to(root))
listed = finished_chunks(project)
@@ -86,11 +86,11 @@ def measure_project(root: pathlib.Path, project: pathlib.Path, home: str, since:
if not chunks:
return ArchiveChunks([], ())
checkout = checkout_of(key, pathlib.Path(home))
titles = title_templates(checkout, pathlib.Path(home), functools.partial(git, timeout=GIT_TIMEOUT, guarded=True))
titles = title_templates(checkout, pathlib.Path(home), env, functools.partial(git, timeout=GIT_TIMEOUT, guarded=True))
if isinstance(titles, Failure):
# Read bare, a templated project's round titles would count as no round.
return ArchiveChunks([], (), (f"{key}: none of its chunks is measured: {titles.reason}",))
history = branch_history(checkout, pathlib.Path(home), titles, git)
history = branch_history(checkout, pathlib.Path(home), env, titles, git)
found = []
skipped = []
for chunk in chunks:
@@ -106,10 +106,10 @@ def measure_project(root: pathlib.Path, project: pathlib.Path, home: str, since:
return ArchiveChunks(found, tuple(skipped), (f"{key}: {history.reason}",) if isinstance(history, Failure) else ())
def branch_history(checkout: str, home: pathlib.Path, titles: Titles, git: Git) -> list[BranchChunk] | Failure:
def branch_history(checkout: str, home: pathlib.Path, env: typing.Mapping[str, str], titles: Titles, git: Git) -> list[BranchChunk] | Failure:
"""The chunks on the checkout's default branch as last fetched, each title read through titles, the project's title templates; read guarded, since the checkout's config may name a program. A Failure where the project's config under home puts the plan or a record where branch_chunks reads no commits."""
guarded = functools.partial(git, cwd=checkout, timeout=GIT_TIMEOUT, guarded=True)
if why := unsupported(checkout, home, guarded):
if why := unsupported(checkout, home, env, guarded):
return Failure(f"its chunks' items and later fixes are not counted: {why}")
ref = default_ref(checkout, GIT_TIMEOUT, guarded=True, run=git)
return ref if isinstance(ref, Failure) else branch_chunks(ref, guarded, titles)
+13 -13
View File
@@ -320,7 +320,7 @@ class BranchHistory(unittest.TestCase):
folder = configured(self, checkout)
config = folder / "config.toml"
config.write_text(config.read_text().replace('"checkout:todo.md"', '"folder:todo.md"'))
found = archive.branch_history(str(checkout), folder.parents[1], BARE, functools.partial(git_repo.git, env=isolated_env()))
found = archive.branch_history(str(checkout), folder.parents[2], {}, BARE, functools.partial(git_repo.git, env=isolated_env()))
assert isinstance(found, Failure), found
self.assertEqual(found.reason, f"its chunks' items and later fixes are not counted: the project's config puts {folder}/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")
@@ -349,16 +349,16 @@ class Archive(unittest.TestCase):
def test_measures_each_finished_chunk_keyed_by_its_project(self):
self.chunk("home/x", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z", call("Agent", "a1", subagent_type="Explore"))], ({"agentType": "Explore", "toolUseId": "a1"}, [message("s1", "2026-10-14T09:00:01Z")]))
self.chunk("log", "c2", stamped("2026-10-14T10:00:00Z", outcomes.unfinished(LOW_ROUTE, "e", "j", "")), [message("m1", "2026-10-14T09:00:00Z")])
found = archive.measure_archive(self.root, "/h", "", no_checkout)
found = archive.measure_archive(self.root, "/h", {}, "", no_checkout)
self.assertEqual([chunk.dollars["project"] for chunk in found.chunks], [{"home/x": 4.0}])
self.assertEqual(found.chunks[0].dollars["subagent type"], {"worker": 2.0, "Explore": 2.0})
self.assertEqual(archive.measure_archive(self.root, "/h", "2026-10-14T10:00:00Z", no_checkout), archive.ArchiveChunks([], ()))
self.assertEqual(archive.measure_archive(self.root, "/h", {}, "2026-10-14T10:00:00Z", no_checkout), archive.ArchiveChunks([], ()))
def test_measures_a_chunk_whose_transcripts_are_compressed(self):
self.chunk("home/x", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z", call("Agent", "a1", subagent_type="Explore"))], ({"agentType": "Explore", "toolUseId": "a1"}, [message("s1", "2026-10-14T09:00:01Z")]))
for copy in self.root.rglob("*.jsonl"):
self.assertIsNone(compress(copy))
found = archive.measure_archive(self.root, "/h", "", no_checkout)
found = archive.measure_archive(self.root, "/h", {}, "", no_checkout)
self.assertEqual(found.chunks[0].dollars["subagent type"], {"worker": 2.0, "Explore": 2.0})
def test_counts_each_chunks_later_fixes_from_its_projects_checkout(self):
@@ -366,7 +366,7 @@ class Archive(unittest.TestCase):
env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(home)}
self.ship_then_fix(home / "code" / "log", env)
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
found = archive.measure_archive(self.root, str(home), "", functools.partial(git_repo.git, env=env))
found = archive.measure_archive(self.root, str(home), {}, "", functools.partial(git_repo.git, env=env))
self.assertEqual([(chunk.dollars["project"].keys(), chunk.fixed_later) for chunk in found.chunks], [({"log": 0}.keys(), 1)])
def test_reads_a_projects_round_titles_and_its_branchs_history_through_its_configs_templates(self):
@@ -377,9 +377,9 @@ class Archive(unittest.TestCase):
config = write_config(home, home / "code" / "log") / "config.toml"
worker = [message(f"m{n}", "2026-10-14T09:00:00Z", call("Bash", command=f"git commit -m '{round_title.format(n)}'")) for n in (1, 2)]
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), worker)
bare = archive.measure_archive(self.root, str(home), "", functools.partial(git_repo.git, env=env))
bare = archive.measure_archive(self.root, str(home), {}, "", functools.partial(git_repo.git, env=env))
config.write_text(config.read_text() + 'commit-title = "PAY-{id} - {summary}"\n')
templated = archive.measure_archive(self.root, str(home), "", functools.partial(git_repo.git, env=env))
templated = archive.measure_archive(self.root, str(home), {}, "", functools.partial(git_repo.git, env=env))
self.assertEqual([(chunk.rounds_past_first, chunk.fixed_later) for chunk in bare.chunks], [(0, 0)])
self.assertEqual([(chunk.rounds_past_first, chunk.fixed_later) for chunk in templated.chunks], [(1, 1)])
@@ -390,7 +390,7 @@ class Archive(unittest.TestCase):
config = write_config(home, home / "code" / "log") / "config.toml"
config.write_text(config.read_text() + 'commit-title = "PAY-{id}"\n')
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
found = archive.measure_archive(self.root, str(home), "", functools.partial(git_repo.git, env=env))
found = archive.measure_archive(self.root, str(home), {}, "", functools.partial(git_repo.git, env=env))
self.assertEqual(found.chunks, [])
self.assertEqual(len(found.unread), 1)
self.assertRegex(found.unread[0], r"^log: none of its chunks is measured: .*`commit-title` is 'PAY-\{id\}'")
@@ -405,7 +405,7 @@ class Archive(unittest.TestCase):
def recording(*args, **options):
made.append((args[0], options))
return git_repo.git(*args, **options, env=env)
archive.measure_archive(self.root, str(home), "", recording)
archive.measure_archive(self.root, str(home), {}, "", recording)
self.assertTrue(all(options.get("guarded") is True for _, options in made))
read = [options.get("timeout") for command, options in made if command in ("log", "ls-tree", "show", "diff", "blame")]
self.assertEqual(set(read), {archive.GIT_TIMEOUT})
@@ -417,12 +417,12 @@ class Archive(unittest.TestCase):
(home / "code" / "log").mkdir(parents=True)
subprocess.run(["git", "init", "-q"], cwd=home / "code" / "log", check=True, env=env, capture_output=True)
self.chunk("log", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
found = archive.measure_archive(self.root, str(home), "", functools.partial(git_repo.git, env=env))
found = archive.measure_archive(self.root, str(home), {}, "", functools.partial(git_repo.git, env=env))
self.assertEqual(found.unread, ("log: no origin remote, and no main or master branch to take as the default branch",))
def test_names_each_project_whose_history_it_cannot_read(self):
self.chunk("gone", "c1", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
found = archive.measure_archive(self.root, "/h", "", no_checkout)
found = archive.measure_archive(self.root, "/h", {}, "", no_checkout)
self.assertEqual(([chunk.fixed_later for chunk in found.chunks], found.unread), ([None], ("gone: no checkout",)))
def ship_then_fix(self, checkout, env, fix_title="Fix six", ships_fix=True):
@@ -457,7 +457,7 @@ class Archive(unittest.TestCase):
self.assertIsNone(write.archive(kept / "log", str(transcript), "t", outcomes.unfinished(LOW_ROUTE, "e", "j", ""), 1790000000, replace=replace_file))
transcript.write_text(json.dumps(first) + "\n" + json.dumps(message("m2", "2099-01-01T00:00:00Z")) + "\n")
self.assertIsNone(write.archive(kept / "log", str(transcript), "t", outcomes.finished(Route(HIGH).worker_line(), "m", "j"), 4070908800, replace=replace_file))
(found,) = archive.measure_archive(kept, "/h", "", no_checkout).chunks
(found,) = archive.measure_archive(kept, "/h", {}, "", no_checkout).chunks
self.assertEqual((found.start, found.unfinished), (LOW, 1))
self.assertEqual(found.dollars["rung"], {str(LOW): 2.0, str(HIGH): 2.0})
@@ -467,7 +467,7 @@ class Archive(unittest.TestCase):
self.chunk("other", "c2", stamped("2026-10-14T10:00:00Z", outcomes.finished(LOW_ROUTE, "m", "j")), [message("m1", "2026-10-14T09:00:00Z")])
self.chunk("broken", "c3", "", [])
(self.root / "broken" / "c3" / "copy.outcomes.md").write_bytes(b"\xff")
found = archive.measure_archive(self.root, "/h", "", no_checkout)
found = archive.measure_archive(self.root, "/h", {}, "", no_checkout)
self.assertEqual((len(found.chunks), found.skipped), (1, ("broken", "log/c1")))
self.assertIn("## Chunks skipped, unreadable\n\n- log/c1\n", render(LADDER, totals([], ("log/c1",)), [], "2026-10-15T00:00:00Z", 20, ""))