Read the records at their configured paths in the review header, replay, chunk-pr, score-outcomes, reading-cost and metric-bench
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
usage: reading-cost [--reset] [record]
|
||||
|
||||
Run it inside a project checkout or one of its worktrees. record defaults to docs/reading-cost.md
|
||||
there, created when missing. It reads loop-claude's archive of the project,
|
||||
Run it inside a project checkout or one of its worktrees. record defaults to the
|
||||
docs/reading-cost.md the project's config names, created when missing. It reads loop-claude's archive of the project,
|
||||
$LOOP_CLAUDE_TRANSCRIPTS/<key> (default ~/.claude/loop-claude-transcripts), <key> being the
|
||||
checkout's path relative to ~/code, or to / outside it. For each finished chunk the record does not
|
||||
yet hold, it measures what the worker and its subagents read before the worker's first commit: their
|
||||
@@ -30,9 +30,10 @@ import time
|
||||
|
||||
from reading_cost.measure import Checkout, measure, Reading
|
||||
from failure import Failure
|
||||
from reading_cost.figures import figure, merged, readings_of, RECORD, RESET, trend, unheld
|
||||
from reading_cost.figures import figure, merged, readings_of, RESET, trend, unheld
|
||||
from transcript_archive.read import finished_chunks, read_threads
|
||||
from git_cli.git_repo import git
|
||||
from project_config.main import project
|
||||
from transcript_archive.location import project_archive
|
||||
from records.file_writes import replace_file
|
||||
from records.utc_stamp import utc
|
||||
@@ -57,7 +58,10 @@ def main(argv: list[str]) -> int:
|
||||
return failed(checkout)
|
||||
home = pathlib.Path.home()
|
||||
archive = project_archive(checkout.main_root, home, os.environ)
|
||||
record = pathlib.Path(given[0]) if given else pathlib.Path(checkout.current_root, RECORD)
|
||||
config = project()
|
||||
if not given and isinstance(config, Failure):
|
||||
return failed(config)
|
||||
record = pathlib.Path(given[0]) if given or isinstance(config, Failure) else config.paths["reading-cost"]
|
||||
updated = update(record, archive, checkout, str(home), utc(time.time()) if reset else None)
|
||||
if isinstance(updated, Failure):
|
||||
return failed(updated)
|
||||
|
||||
@@ -22,6 +22,7 @@ from test_env import isolated_env
|
||||
from transcript_archive import outcomes
|
||||
from transcript_archive.location import project_archive
|
||||
from reading_cost.shell_reads import Reads, shell_reads
|
||||
from project_config.test_project_config import write_config
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "reading-cost"
|
||||
|
||||
@@ -129,6 +130,7 @@ class ReadingCostTool(unittest.TestCase):
|
||||
self.git("add", "a.py")
|
||||
self.git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-m", "x")
|
||||
self.archive = project_archive(str(self.checkout), self.home, {})
|
||||
write_config(self.home, self.checkout)
|
||||
|
||||
def git(self, *args):
|
||||
subprocess.run(["git", *args], cwd=self.checkout, check=True, env=self.env)
|
||||
@@ -145,6 +147,21 @@ class ReadingCostTool(unittest.TestCase):
|
||||
def run_tool(self, cwd, *args):
|
||||
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=cwd, env=self.env, text=True)
|
||||
|
||||
def test_writes_the_record_where_the_config_puts_it_and_fails_without_a_config(self):
|
||||
config = self.home / ".claude-projects" / "proj" / "config.toml"
|
||||
config.write_text(config.read_text().replace('"checkout:docs/reading-cost.md"', '"folder:docs/reading-cost.md"'))
|
||||
record = config.parent / "docs" / "reading-cost.md"
|
||||
record.parent.mkdir()
|
||||
ran = self.run_tool(self.checkout, "--reset")
|
||||
self.assertEqual((ran.returncode, ran.stderr), (0, ""))
|
||||
self.assertIn(f"to {record}.", ran.stdout)
|
||||
self.assertTrue(record.is_file())
|
||||
self.assertFalse((self.checkout / "docs").exists())
|
||||
config.unlink()
|
||||
ran = self.run_tool(self.checkout)
|
||||
self.assertEqual((ran.returncode, ran.stdout), (1, ""))
|
||||
self.assertIn("no config names the checkout", ran.stderr)
|
||||
|
||||
def test_appends_each_finished_chunk_once_in_the_order_they_finished_from_a_worktree(self):
|
||||
self.archive_chunk(1790000200)
|
||||
self.archive_chunk(1790000100)
|
||||
|
||||
Reference in New Issue
Block a user