Merge remote-tracking branch 'origin/main' into item-581
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
# Conflicts: # CHANGELOG.md # README.md
This commit is contained in:
@@ -124,7 +124,7 @@ class TheLauncher(unittest.TestCase):
|
||||
ran = subprocess.run([str(launcher), "--help"], capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual((ran.returncode, ran.stdout.split(" ", 2)[2]), (0, main.HELP + "\n"))
|
||||
tracked = subprocess.run(["git", "ls-files", "--error-unmatch", launcher.name], capture_output=True, cwd=launcher.parent)
|
||||
self.assertEqual(tracked.returncode, 0, "bin/build-epic is not in the repo; .gitignore lists what it keeps")
|
||||
self.assertEqual(tracked.returncode, 0, "bin/build-epic is not in the repo")
|
||||
|
||||
|
||||
class TheCommand(BuildEpicTest):
|
||||
|
||||
+18
-14
@@ -17,7 +17,9 @@ from text_files.file_writes import replace_file
|
||||
LINKED = ("CLAUDE.md", "agents", "bin", "principles", "rules", "skills")
|
||||
# Stands for the clone's folder in the clone's settings.json. Every value that holds it is a shell command, such as a hook's.
|
||||
CLONE = "{clone}"
|
||||
# The file in the home that names the clone and the commit the home was built from.
|
||||
# Stands for the reports folder, which holds every chunk's review folder, in the clone's settings.json. Every value that holds it is a path, so unlike CLONE it isn't shell-quoted.
|
||||
REPORTS = "{reports}"
|
||||
# The file in the home that names the clone, its commit and the reports folder the home was built from.
|
||||
BUILT_FROM = "built-from"
|
||||
|
||||
# Runs `claude` with these arguments in the home.
|
||||
@@ -28,10 +30,10 @@ class Git(typing.Protocol):
|
||||
def __call__(self, *args: str, cwd: str | None = None) -> str | Failure: ...
|
||||
|
||||
|
||||
def unready(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -> str | None:
|
||||
"""Builds the home from clone, or refreshes it where the clone's commit changed since. Then why a claude cannot run in the home yet, said for the person to act on; None where one can."""
|
||||
def unready(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path, claude: Claude, git: Git) -> str | None:
|
||||
"""Builds the home from clone, or refreshes it where the clone's commit or the reports folder changed since. Then why a claude cannot run in the home yet, said for the person to act on; None where one can."""
|
||||
try:
|
||||
built = refreshed(home, clone, claude, git)
|
||||
built = refreshed(home, clone, reports, claude, git)
|
||||
if isinstance(built, Failure):
|
||||
return f"could not build the loop's Claude home, {home}: {built.reason}"
|
||||
status = claude(["auth", "status"])
|
||||
@@ -61,11 +63,11 @@ def printed(done: subprocess.CompletedProcess[str]) -> str:
|
||||
return " ".join((done.stderr or done.stdout).split()) or f"it printed nothing and exited {done.returncode}"
|
||||
|
||||
|
||||
def refreshed(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -> Failure | None:
|
||||
def refreshed(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path, claude: Claude, git: Git) -> Failure | None:
|
||||
commit = git("rev-parse", "HEAD", cwd=str(clone))
|
||||
if isinstance(commit, Failure):
|
||||
return commit
|
||||
built_from = f"{clone} at {commit.strip()}\n"
|
||||
built_from = f"{clone} at {commit.strip()}, reports in {reports}\n"
|
||||
home.mkdir(parents=True, exist_ok=True)
|
||||
# Several loops start at once after an update: one refreshes the home, and the others wait and find it done.
|
||||
with open(home / ".refresh-lock", "w", encoding="utf-8") as lock:
|
||||
@@ -74,7 +76,7 @@ def refreshed(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git)
|
||||
if stamp.is_file() and stamp.read_text(encoding="utf-8") == built_from:
|
||||
return None
|
||||
# The stamp is written last, so a refresh that failed halfway runs again.
|
||||
return linked(home, clone) or settings_written(home, clone) or plugins_installed(clone, claude) or replace_file(stamp, built_from.encode())
|
||||
return linked(home, clone) or settings_written(home, clone, reports) or plugins_installed(clone, claude) or replace_file(stamp, built_from.encode())
|
||||
|
||||
|
||||
def linked(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
|
||||
@@ -87,9 +89,9 @@ def linked(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
|
||||
return None
|
||||
|
||||
|
||||
def settings_written(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
|
||||
"""Writes the home's settings.json: the clone's, with the clone's folder in place of CLONE, and the model the home's file holds."""
|
||||
settings = placed(json.loads((clone / "settings.json").read_text(encoding="utf-8")), shlex.quote(str(clone)))
|
||||
def settings_written(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path) -> Failure | None:
|
||||
"""Writes the home's settings.json: the clone's, with the clone's folder in place of CLONE and the reports folder in place of REPORTS, and the model the home's file holds."""
|
||||
settings = placed(json.loads((clone / "settings.json").read_text(encoding="utf-8")), {CLONE: shlex.quote(str(clone)), REPORTS: str(reports)})
|
||||
generated = home / "settings.json"
|
||||
try:
|
||||
old = json.loads(generated.read_text(encoding="utf-8")) if generated.is_file() else {}
|
||||
@@ -103,13 +105,15 @@ def settings_written(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
|
||||
return replace_file(generated, (json.dumps(settings, indent=2, sort_keys=True) + "\n").encode())
|
||||
|
||||
|
||||
def placed(value: typing.Any, clone: str) -> typing.Any:
|
||||
def placed(value: typing.Any, stand_for: dict[str, str]) -> typing.Any:
|
||||
if isinstance(value, str):
|
||||
return value.replace(CLONE, clone)
|
||||
for name, replacement in stand_for.items():
|
||||
value = value.replace(name, replacement)
|
||||
return value
|
||||
if isinstance(value, list):
|
||||
return [placed(each, clone) for each in value]
|
||||
return [placed(each, stand_for) for each in value]
|
||||
if isinstance(value, dict):
|
||||
return {key: placed(each, clone) for key, each in value.items()}
|
||||
return {key: placed(each, stand_for) for key, each in value.items()}
|
||||
return value
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ SETTINGS = {
|
||||
"enabledPlugins": {"code-review@official": True, "frontend-design@official": False, "lsp@other": True},
|
||||
"extraKnownMarketplaces": {"official": {"source": {"repo": "anthropics/official", "source": "github"}}, "other": {"source": {"repo": "someone/other", "source": "github"}}, "unused": {"source": {"repo": "someone/unused", "source": "github"}}},
|
||||
"hooks": {"PreToolUse": [{"hooks": [{"command": "{clone}/bin/rule-hook", "type": "command"}]}]},
|
||||
"permissions": {"additionalDirectories": ["{reports}", "~/code"], "defaultMode": "bypassPermissions"},
|
||||
"tui": "fullscreen",
|
||||
}
|
||||
SIGNED_IN = json.dumps({"loggedIn": True, "authMethod": "claude.ai"})
|
||||
@@ -31,6 +32,7 @@ class Home(unittest.TestCase):
|
||||
(self.clone / "settings.json").write_text(json.dumps(SETTINGS), encoding="utf-8")
|
||||
self.home = self.temp / "share" / "claude-home"
|
||||
self.commit: str | Failure = "1a2b3c\n"
|
||||
self.reports = self.temp / "state" / "build-release" / "larv-review"
|
||||
self.status = SIGNED_IN
|
||||
# The exit code of each `claude plugin` command, by its last argument; 0 for one not named.
|
||||
self.exits: dict[str, int] = {}
|
||||
@@ -43,7 +45,7 @@ class Home(unittest.TestCase):
|
||||
return subprocess.CompletedProcess(args, self.exits.get(args[-1], 0), "", f"no {args[-1]}\nin the marketplace\n")
|
||||
|
||||
def unready(self) -> str | None:
|
||||
return unready(self.home, self.clone, self.claude, lambda *args, cwd=None: self.commit if (args, cwd) == (("rev-parse", "HEAD"), str(self.clone)) else Failure(f"unexpected git {args} in {cwd}"))
|
||||
return unready(self.home, self.clone, self.reports, self.claude, lambda *args, cwd=None: self.commit if (args, cwd) == (("rev-parse", "HEAD"), str(self.clone)) else Failure(f"unexpected git {args} in {cwd}"))
|
||||
|
||||
def settings(self) -> dict[str, object]:
|
||||
read: dict[str, object] = json.loads((self.home / "settings.json").read_text(encoding="utf-8"))
|
||||
@@ -64,6 +66,19 @@ class Home(unittest.TestCase):
|
||||
self.assertEqual(self.settings()["tui"], "fullscreen")
|
||||
self.assertEqual(json.loads((self.clone / "settings.json").read_text(encoding="utf-8")), SETTINGS)
|
||||
|
||||
def test_the_generated_settings_let_a_session_write_the_reports_folder_wherever_the_state_folder_is(self) -> None:
|
||||
self.unready()
|
||||
|
||||
self.assertEqual(self.settings()["permissions"], {"additionalDirectories": [str(self.reports), "~/code"], "defaultMode": "bypassPermissions"})
|
||||
|
||||
def test_a_moved_reports_folder_refreshes_the_home(self) -> None:
|
||||
self.unready()
|
||||
self.reports = self.temp / "elsewhere" / "build-release" / "larv-review"
|
||||
|
||||
self.assertIsNone(self.unready())
|
||||
|
||||
self.assertEqual(self.settings()["permissions"]["additionalDirectories"][0], str(self.reports)) # type: ignore[index]
|
||||
|
||||
def test_it_adds_each_enabled_plugins_marketplace_then_installs_each_enabled_plugin(self) -> None:
|
||||
self.unready()
|
||||
|
||||
@@ -133,7 +148,7 @@ class Home(unittest.TestCase):
|
||||
def claude(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.CompletedProcess(args, 1, stdout, stderr) if args == ["auth", "status"] else subprocess.CompletedProcess(args, 0, "", "")
|
||||
|
||||
reason = unready(self.home, self.clone, claude, lambda *args, cwd=None: "1a2b3c\n")
|
||||
reason = unready(self.home, self.clone, self.reports, claude, lambda *args, cwd=None: "1a2b3c\n")
|
||||
|
||||
self.assertEqual(reason, f"could not ask claude who is signed in to the loop's Claude home, {self.home}: {said}")
|
||||
|
||||
@@ -174,7 +189,7 @@ class Home(unittest.TestCase):
|
||||
def missing(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
raise FileNotFoundError(2, "No such file or directory", "claude")
|
||||
|
||||
reason = unready(self.home, self.clone, missing, lambda *args, cwd=None: "1a2b3c\n")
|
||||
reason = unready(self.home, self.clone, self.reports, missing, lambda *args, cwd=None: "1a2b3c\n")
|
||||
|
||||
self.assertEqual(reason, f"could not build the loop's Claude home, {self.home}: [Errno 2] No such file or directory: 'claude'")
|
||||
|
||||
@@ -182,7 +197,7 @@ class Home(unittest.TestCase):
|
||||
def stalled(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
raise subprocess.TimeoutExpired(["claude", *args], 600)
|
||||
|
||||
reason = unready(self.home, self.clone, stalled, lambda *args, cwd=None: "1a2b3c\n")
|
||||
reason = unready(self.home, self.clone, self.reports, stalled, lambda *args, cwd=None: "1a2b3c\n")
|
||||
|
||||
self.assertEqual(reason, f"could not build the loop's Claude home, {self.home}: Command '['claude', 'plugin', 'marketplace', 'add', 'anthropics/official']' timed out after 600 seconds")
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ from git_cli import git_repo
|
||||
from machine_load.memory import Memory, read_memory
|
||||
from project_config.settings import Notifier
|
||||
from text_files.file_writes import replace_file
|
||||
from review_rules.review_folder import reports_folder
|
||||
from forge.commands import Run, runner
|
||||
from machine_load.slots import slot_folder
|
||||
from claude_home.home import unready
|
||||
@@ -127,7 +128,7 @@ def system_effects(home: pathlib.Path, env: typing.Mapping[str, str], backends:
|
||||
"""
|
||||
return Effects(
|
||||
claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, env=claude_environment(env, home), input=stdin, text=True),
|
||||
claude_home=lambda: unready(claude_home(env, home), RELEASE_ROOT, lambda args: subprocess.run(["claude", *args], capture_output=True, env=claude_environment(env, home), stdin=subprocess.DEVNULL, text=True, timeout=home_timeout), git_repo.git),
|
||||
claude_home=lambda: unready(claude_home(env, home), RELEASE_ROOT, reports_folder(home, env), lambda args: subprocess.run(["claude", *args], capture_output=True, env=claude_environment(env, home), stdin=subprocess.DEVNULL, text=True, timeout=home_timeout), git_repo.git),
|
||||
claude_on_terminal=claude_on_terminal,
|
||||
discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH),
|
||||
dm=lambda text, directory: notify(text, directory, home, env, backends),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import signal
|
||||
@@ -153,6 +154,20 @@ class ClaudeHomeEffect(unittest.TestCase):
|
||||
self.assertEqual(ran[-1], f"{built} auth status")
|
||||
self.assertIn(f"{built} plugin install code-review@claude-plugins-official", ran)
|
||||
|
||||
def test_lets_a_session_write_the_reports_folder_under_the_state_folder_it_is_given(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
claude = pathlib.Path(folder, "claude")
|
||||
claude.write_text('#!/bin/sh\necho \'{"loggedIn": true}\'\n')
|
||||
claude.chmod(0o755)
|
||||
home = pathlib.Path(folder, "home")
|
||||
state = pathlib.Path(folder, "moved state")
|
||||
|
||||
reason = system_effects(home, without_xdg_folders(os.environ) | {"PATH": f"{folder}:{os.environ['PATH']}", "XDG_STATE_HOME": str(state)}).claude_home()
|
||||
|
||||
self.assertIsNone(reason)
|
||||
written = json.loads((home / ".local" / "share" / "build-release" / "claude-home" / "settings.json").read_text())
|
||||
self.assertIn(str(state / "build-release" / "larv-review"), written["permissions"]["additionalDirectories"])
|
||||
|
||||
def test_a_plugin_that_does_not_install_stops_naming_the_command_and_what_claude_said(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
claude = pathlib.Path(folder, "claude")
|
||||
|
||||
@@ -7,27 +7,14 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from repo_checks import ROOT
|
||||
|
||||
PRIVATE = [
|
||||
".claude/settings.local.json",
|
||||
".credentials.json",
|
||||
"auto-mode-transcripts/a.jsonl",
|
||||
"backups/.claude.json.backup.1",
|
||||
"daemon-auth-status.json",
|
||||
"daemon.log",
|
||||
"daemon/control.key",
|
||||
"debug/a.txt",
|
||||
"file-history/a/b.md",
|
||||
"history.jsonl",
|
||||
"jobs/a/b.json",
|
||||
"memory/MEMORY.md",
|
||||
"paste-cache/a.txt",
|
||||
"projects/-home-a/a.jsonl",
|
||||
"projects/-home-a/memory/MEMORY.md",
|
||||
"projects/-home-a/memory/a.md",
|
||||
"session-env/a/b.sh",
|
||||
"sessions/a.json",
|
||||
"shell-snapshots/a.sh",
|
||||
"tasks/a/b.json",
|
||||
GENERATED = [
|
||||
"bin/__pycache__/a.cpython-313.pyc",
|
||||
"bin/agent_cycle/__pycache__/a.cpython-313.pyc",
|
||||
"presentation/build-release-explained.pdf",
|
||||
"reviewer-merge-trials/agents-wave3.json",
|
||||
"reviewer-merge-trials/clones/rm-a/b.py",
|
||||
"reviewer-merge-trials/results/a/b.json",
|
||||
"reviewer-merge-trials/runs.pkl",
|
||||
"workflow-bench/a-1-1.md",
|
||||
"workflow-bench/a-1-1/README.md",
|
||||
"workflow-bench/compare/a/A1/fixes.diff",
|
||||
@@ -44,6 +31,7 @@ class Gitignore(unittest.TestCase):
|
||||
ignored = subprocess.run(["git", "ls-files", "-oi", "--exclude-standard", "--", "bin/*.py", "bin/**/*.py"], capture_output=True, check=True, cwd=ROOT, text=True).stdout
|
||||
self.assertEqual(ignored, "")
|
||||
|
||||
def test_ignores_every_private_file(self):
|
||||
ignored = subprocess.run(["git", "check-ignore", "--no-index", "--stdin"], capture_output=True, cwd=ROOT, input="\n".join(PRIVATE), text=True).stdout
|
||||
self.assertEqual(ignored.splitlines(), PRIVATE)
|
||||
def test_ignores_every_generated_file(self):
|
||||
ignored = subprocess.run(["git", "check-ignore", "--no-index", "--stdin"], capture_output=True, cwd=ROOT, input="\n".join(GENERATED), text=True).stdout
|
||||
self.assertEqual(ignored.splitlines(), GENERATED)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user