Skip to content

Commit f8151c9

Browse files
committed
refactor: remove three functions only tests called
- `git_ops.commit_all`, `schema.schemas_as_provider_tools` and `process.process_identity` go with the three tests that existed for `commit_all` alone; the tests that used them as fixtures do the plain operation instead, and the one-caller `_commit` helper is inlined into `commit_paths`.
1 parent dcdf840 commit f8151c9

9 files changed

Lines changed: 49 additions & 153 deletions

File tree

‎src/agent6/sessions/process.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,6 @@ def _read_pid_record(session_dir: pathlib.Path) -> tuple[int, str] | None:
296296
type ProcessIdentity = tuple[int, str]
297297

298298

299-
def process_identity(pid: int) -> ProcessIdentity:
300-
"""Return a pid with the start time that distinguishes it from later reuse.
301-
302-
Args:
303-
pid: The pid.
304-
305-
Returns:
306-
The identity.
307-
"""
308-
return pid, _proc_start_time(pid)
309-
310-
311299
def process_is_alive(identity: ProcessIdentity) -> bool:
312300
"""Return whether an identity still names its live process.
313301

‎src/agent6/tools/schema.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,3 @@ def wire_schema(cls: type[_ToolInput]) -> dict[str, Any]:
742742
model.pop("description", None)
743743
schema.setdefault("type", "object")
744744
return schema
745-
746-
747-
def schemas_as_provider_tools() -> list[dict[str, Any]]:
748-
"""Return ALL_TOOLS as Anthropic-shape tool descriptors, dict-typed to avoid an import cycle."""
749-
return [
750-
{
751-
"name": cls.TOOL_NAME,
752-
"description": cls.TOOL_DESCRIPTION,
753-
"input_schema": wire_schema(cls),
754-
}
755-
for cls in ALL_TOOLS
756-
]

‎src/agent6/vcs/git_ops.py‎

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -284,29 +284,6 @@ def clone_repo(origin: pathlib.Path, dest: pathlib.Path) -> None:
284284
git_command.run(pathlib.Path("/"), "clone", str(origin.absolute()), str(dest.absolute()))
285285

286286

287-
def commit_all(
288-
path: pathlib.Path,
289-
message: str,
290-
*,
291-
trailers: dict[str, str] | None = None,
292-
identity: git_read.CommitIdentity | None = None,
293-
) -> str:
294-
"""Stage everything and commit.
295-
296-
Args:
297-
path: The repository.
298-
message: The commit message.
299-
trailers: Trailer lines appended to the message.
300-
identity: The author and committer overrides; None uses the repo's config,
301-
validated at startup by `git_read.verify_git_identity`.
302-
303-
Returns:
304-
The new HEAD sha.
305-
"""
306-
git_command.run(path, "add", "-A")
307-
return _commit(path, message, trailers=trailers, identity=identity)
308-
309-
310287
def commit_paths(
311288
path: pathlib.Path,
312289
message: str,
@@ -336,7 +313,10 @@ def commit_paths(
336313
if not paths:
337314
raise errors.GitError("commit_paths requires at least one path")
338315
git_command.run(path, "add", "--", *paths, env_extra=git_read.LITERAL_PATHSPECS)
339-
return _commit(path, message, trailers=trailers, identity=identity, only_paths=paths)
316+
env_extra = {**(_identity_env(identity) or {}), **git_read.LITERAL_PATHSPECS}
317+
full_message = _full_message(message, trailers, identity)
318+
git_command.run(path, "commit", "-m", full_message, "--", *paths, env_extra=env_extra)
319+
return git_command.run(path, "rev-parse", "HEAD").stdout.strip()
340320

341321

342322
def _identity_env(identity: git_read.CommitIdentity | None) -> dict[str, str] | None:
@@ -611,35 +591,6 @@ def tree_with_paths_from(path: pathlib.Path, tree: str, rev: str, paths: Sequenc
611591
shutil.rmtree(tmp, ignore_errors=True)
612592

613593

614-
def _commit(
615-
path: pathlib.Path,
616-
message: str,
617-
*,
618-
trailers: dict[str, str] | None,
619-
identity: git_read.CommitIdentity | None,
620-
only_paths: tuple[str, ...] | None = None,
621-
) -> str:
622-
"""Commit the index, or only the given paths from the worktree.
623-
624-
Args:
625-
path: The repository.
626-
message: The commit message.
627-
trailers: Trailer lines appended to the message.
628-
identity: The author and committer overrides; None uses the repo's config.
629-
only_paths: The repo-relative paths; None commits the index.
630-
631-
Returns:
632-
The new HEAD sha.
633-
"""
634-
env_extra = {**(_identity_env(identity) or {}), **git_read.LITERAL_PATHSPECS}
635-
full_message = _full_message(message, trailers, identity)
636-
argv = ["commit", "-m", full_message]
637-
if only_paths is not None:
638-
argv.extend(["--", *only_paths])
639-
git_command.run(path, *argv, env_extra=env_extra)
640-
return git_command.run(path, "rev-parse", "HEAD").stdout.strip()
641-
642-
643594
@dataclasses.dataclass(frozen=True, slots=True)
644595
class MergeResult:
645596
"""The outcome of landing a run branch on a target.

‎tests/unit/test_git_ops.py‎

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def test_path_limited_stash_keeps_staged_deletions_and_renames(
7272
"""A selected staged deletion or rename stashes without taking unrelated run edits."""
7373
_init_repo(tmp_path)
7474
(tmp_path / "run [work].py").write_text("x = 1\n", encoding="utf-8")
75-
git_ops.commit_all(tmp_path, "track run file")
75+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
76+
subprocess.run(["git", "-C", str(tmp_path), "commit", "-q", "-m", "track run file"], check=True)
7677
(tmp_path / "run [work].py").write_text("x = 5\n", encoding="utf-8")
7778
(tmp_path / "notes.txt").write_text("operator notes\n", encoding="utf-8")
7879
selected = {"README.md"}
@@ -168,7 +169,8 @@ def test_git_ops_neutralizes_repo_fsmonitor(tmp_path: pathlib.Path) -> None:
168169
(tmp_path / "new.txt").write_text("x\n", encoding="utf-8")
169170
# Index-refreshing op through agent6's hardened command runner.
170171
git_read.status(tmp_path)
171-
git_ops.commit_all(tmp_path, "msg")
172+
git_command.run(tmp_path, "add", "-A")
173+
git_command.run(tmp_path, "commit", "-m", "msg")
172174
assert not marker.exists(), "repo core.fsmonitor command executed on the host"
173175

174176

@@ -193,7 +195,8 @@ def test_git_ops_skips_repo_hooks_by_default(tmp_path: pathlib.Path) -> None:
193195
marker = tmp_path / "HOOK_FIRED"
194196
_add_pre_commit_hook(tmp_path, marker)
195197
(tmp_path / "n.txt").write_text("x\n", encoding="utf-8")
196-
git_ops.commit_all(tmp_path, "c") # no set_repo_hook_policy call: the default governs
198+
git_command.run(tmp_path, "add", "-A")
199+
git_command.run(tmp_path, "commit", "-m", "c") # no set_repo_hook_policy: the default governs
197200
assert not marker.exists()
198201

199202

@@ -204,7 +207,8 @@ def test_git_ops_runs_repo_hooks_when_enabled(tmp_path: pathlib.Path) -> None:
204207
(tmp_path / "n.txt").write_text("x\n", encoding="utf-8")
205208
try:
206209
git_policy.set_repo_hook_policy(True) # git.run_repo_hooks = true
207-
git_ops.commit_all(tmp_path, "c")
210+
git_command.run(tmp_path, "add", "-A")
211+
git_command.run(tmp_path, "commit", "-m", "c")
208212
assert marker.exists()
209213
finally:
210214
git_policy.set_repo_hook_policy(False) # reset process-wide policy for other tests
@@ -271,7 +275,9 @@ def test_commit_diff_survives_poisoned_diff_external(tmp_path: pathlib.Path) ->
271275
check=True,
272276
)
273277
(tmp_path / "README.md").write_text("changed\n", encoding="utf-8")
274-
sha = git_ops.commit_all(tmp_path, "change readme")
278+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
279+
subprocess.run(["git", "-C", str(tmp_path), "commit", "-q", "-m", "change readme"], check=True)
280+
sha = _rev(tmp_path, "HEAD")
275281
out = git_read.commit_diff(tmp_path, sha)
276282
assert not marker.exists(), "repo diff.external command executed on the host"
277283
assert "README.md" in out, "git show honored the external diff and lost the patch"
@@ -303,7 +309,9 @@ def test_commit_diff_survives_poisoned_textconv(tmp_path: pathlib.Path) -> None:
303309
marker = tmp_path / "PWNED_TEXTCONV_SHOW"
304310
_poison_textconv(tmp_path, marker)
305311
(tmp_path / "README.md").write_text("changed\n", encoding="utf-8")
306-
sha = git_ops.commit_all(tmp_path, "change readme")
312+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
313+
subprocess.run(["git", "-C", str(tmp_path), "commit", "-q", "-m", "change readme"], check=True)
314+
sha = _rev(tmp_path, "HEAD")
307315
out = git_read.commit_diff(tmp_path, sha)
308316
assert not marker.exists(), "git show ran the repo textconv driver on the host"
309317
assert "README.md" in out, "git show lost the patch under --no-textconv"
@@ -322,7 +330,8 @@ def test_git_ops_neutralizes_repo_gpg_signing(tmp_path: pathlib.Path) -> None:
322330
check=True,
323331
)
324332
(tmp_path / "n.txt").write_text("x\n", encoding="utf-8")
325-
git_ops.commit_all(tmp_path, "c") # must not raise or fire the signing program
333+
git_command.run(tmp_path, "add", "-A")
334+
git_command.run(tmp_path, "commit", "-m", "c") # must not raise or fire the signing program
326335
assert not marker.exists(), "repo gpg.program executed on the host during commit"
327336

328337

@@ -364,15 +373,6 @@ def test_status_dirty_repo(tmp_path: pathlib.Path) -> None:
364373
assert st.untracked_count == 1
365374

366375

367-
def test_commit_all_returns_sha_and_log(tmp_path: pathlib.Path) -> None:
368-
_init_repo(tmp_path)
369-
(tmp_path / "f.txt").write_text("y", encoding="utf-8")
370-
sha = git_ops.commit_all(tmp_path, "add f", trailers={"agent6-step": "x"})
371-
assert len(sha) == 40
372-
log = git_read.recent_log(tmp_path, n=5)
373-
assert "add f" in log
374-
375-
376376
def test_create_branch(tmp_path: pathlib.Path) -> None:
377377
_init_repo(tmp_path)
378378
git_ops.create_branch(tmp_path, "agent6/test")
@@ -385,7 +385,8 @@ def test_create_branch_at_is_additive_no_checkout(tmp_path: pathlib.Path) -> Non
385385
base = git_read.status(tmp_path).head_sha
386386
# Advance HEAD so base != current; the fork branch must land on base.
387387
(tmp_path / "b.txt").write_text("b\n", encoding="utf-8")
388-
git_ops.commit_all(tmp_path, "second")
388+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
389+
subprocess.run(["git", "-C", str(tmp_path), "commit", "-q", "-m", "second"], check=True)
389390
git_ops.create_branch_at(tmp_path, "agent6/fork", base)
390391
assert git_read.status(tmp_path).branch == "main", "must not check out the new branch"
391392
forked = subprocess.run(
@@ -407,7 +408,9 @@ def test_create_branch_at_idempotent_and_refuses_move(tmp_path: pathlib.Path) ->
407408
git_ops.create_branch_at(tmp_path, "agent6/fork", base)
408409
git_ops.create_branch_at(tmp_path, "agent6/fork", base) # idempotent: no raise
409410
(tmp_path / "c.txt").write_text("c\n", encoding="utf-8")
410-
other = git_ops.commit_all(tmp_path, "third")
411+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
412+
subprocess.run(["git", "-C", str(tmp_path), "commit", "-q", "-m", "third"], check=True)
413+
other = _rev(tmp_path, "HEAD")
411414
with pytest.raises(errors.GitError):
412415
git_ops.create_branch_at(tmp_path, "agent6/fork", other)
413416

@@ -530,28 +533,6 @@ def test_verify_git_identity_missing_raises(
530533
git_read.verify_git_identity(repo, git_read.CommitIdentity())
531534

532535

533-
def test_commit_all_with_identity_overrides_author(tmp_path: pathlib.Path) -> None:
534-
_init_repo(tmp_path)
535-
(tmp_path / "f.txt").write_text("y", encoding="utf-8")
536-
sha = git_ops.commit_all(
537-
tmp_path,
538-
"add f",
539-
identity=git_read.CommitIdentity(
540-
name="agent6",
541-
email="agent6@example.com",
542-
trailer="Co-authored-by: Alice <alice@example.com>",
543-
),
544-
)
545-
show = subprocess.run(
546-
["git", "-C", str(tmp_path), "show", "--no-patch", "--format=%an|%ae|%B", sha],
547-
check=True,
548-
capture_output=True,
549-
text=True,
550-
).stdout
551-
assert "agent6|agent6@example.com|" in show
552-
assert "Co-authored-by: Alice <alice@example.com>" in show
553-
554-
555536
def test_commit_error_surfaces_stdout_when_stderr_empty(tmp_path: pathlib.Path) -> None:
556537
"""A failed git's error text includes stdout when stderr is empty.
557538
@@ -560,7 +541,7 @@ def test_commit_error_surfaces_stdout_when_stderr_empty(tmp_path: pathlib.Path)
560541
_init_repo(tmp_path)
561542
# `git commit` exits 1 with "nothing to commit, working tree clean" on stdout.
562543
with pytest.raises(errors.GitError) as excinfo:
563-
git_ops.commit_all(tmp_path, "no-op commit on clean repo")
544+
git_command.run(tmp_path, "commit", "-m", "no-op commit on clean repo")
564545
msg = str(excinfo.value)
565546
# The detail (from stdout) must be present so callers can pattern-match.
566547
assert "nothing to commit" in msg.lower()
@@ -588,7 +569,10 @@ def test_restore_stash_conflict_keeps_stash(tmp_path: pathlib.Path) -> None:
588569
git_ops.stash_tracked_changes(tmp_path, "agent6 auto-stash")
589570
# A conflicting commit on the same line means the stash cannot apply cleanly.
590571
(tmp_path / "README.md").write_text("committed change\n", encoding="utf-8")
591-
git_ops.commit_all(tmp_path, "conflicting commit")
572+
subprocess.run(["git", "-C", str(tmp_path), "add", "-A"], check=True)
573+
subprocess.run(
574+
["git", "-C", str(tmp_path), "commit", "-q", "-m", "conflicting commit"], check=True
575+
)
592576
entry = git_read.find_stash(tmp_path, "agent6 auto-stash")
593577
assert entry is not None
594578
assert git_ops.restore_stash(tmp_path, entry) is False
@@ -1335,21 +1319,6 @@ def test_condense_subject_drops_only_a_markdown_heading_mark() -> None:
13351319
)
13361320

13371321

1338-
def test_commit_all_appends_the_identity_trailer_once(tmp_path: pathlib.Path) -> None:
1339-
_init_repo(tmp_path)
1340-
(tmp_path / "f.txt").write_text("x", encoding="utf-8")
1341-
line = "Assisted-by: agent6:m1 (worker)"
1342-
git_ops.commit_all(tmp_path, "add f", identity=git_read.CommitIdentity(trailer=line))
1343-
head_msg = subprocess.run(
1344-
["git", "-C", str(tmp_path), "log", "-1", "--format=%B"],
1345-
capture_output=True,
1346-
text=True,
1347-
check=True,
1348-
).stdout
1349-
assert head_msg.count(line) == 1
1350-
assert head_msg.splitlines()[0] == "add f"
1351-
1352-
13531322
def test_render_commit_trailer_joins_the_code_writers() -> None:
13541323
assert commit_message.render_commit_trailer("", models=("m",)) is None
13551324
got = commit_message.render_commit_trailer("Assisted-by: agent6:{model}", models=("m1",))

‎tests/unit/test_lane_snapshot_spawn.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from agent6.harness import subrun
2020
from agent6.sessions import manifest, process
2121
from agent6.ui.cli import parallel
22-
from agent6.vcs import git_ops
2322
from agent6.viewmodel import session_log
2423

2524

@@ -90,7 +89,8 @@ def test_detached_lane_loads_snapshot_and_records_notes(
9089
monkeypatch.delenv("AGENT6_REASONING_EFFORT", raising=False)
9190
subprocess.run(["git", "init", "-q", "-b", "main", str(short_repo)], check=True)
9291
(short_repo / "README.md").write_text("Local lane smoke.\n")
93-
git_ops.commit_all(short_repo, "init")
92+
subprocess.run(["git", "-C", str(short_repo), "add", "-A"], check=True)
93+
subprocess.run(["git", "-C", str(short_repo), "commit", "-q", "-m", "init"], check=True)
9494
global_path = paths.global_config_path()
9595
global_path.parent.mkdir(parents=True, exist_ok=True)
9696
global_path.write_text(

‎tests/unit/test_parallel_orchestrator.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def __call__(self, spec: subrun.LaneSpec, task: str) -> subrun.LaneResult:
209209
(spec.workdir / f"lane{spec.lane}.txt").write_text(
210210
f"lane {spec.lane}\n", encoding="utf-8"
211211
)
212-
git_ops.commit_all(spec.workdir, f"lane {spec.lane} work")
212+
_git(spec.workdir, "add", "-A")
213+
_git(spec.workdir, "commit", "-q", "-m", f"lane {spec.lane} work")
213214
session_dir = self.state_root / f"lane{spec.lane}" / "sessions" / "runs" / spec.session_id
214215
_write_fake_run(
215216
session_dir,
@@ -3256,7 +3257,8 @@ def test_sweep_keeps_a_clone_holding_unmerged_commits(
32563257
subrun.clone_workspace(origin, unmerged)
32573258
git_ops.create_branch(unmerged, "agent6/fan-a-l1")
32583259
(unmerged / "x.txt").write_text("x\n", encoding="utf-8")
3259-
git_ops.commit_all(unmerged, "lane work")
3260+
_git(unmerged, "add", "-A")
3261+
_git(unmerged, "commit", "-q", "-m", "lane work")
32603262

32613263
merged = scoped / "fan-b" / "lane-1"
32623264
merged.parent.mkdir(parents=True)
@@ -3408,7 +3410,8 @@ def test_sweep_keeps_a_clone_whose_tip_the_origin_cannot_reach(
34083410
subrun.clone_workspace(origin, lane)
34093411
git_ops.create_branch(lane, "agent6/fan-x-l1")
34103412
(lane / "x.txt").write_text("lane work\n", encoding="utf-8")
3411-
git_ops.commit_all(lane, "lane work")
3413+
_git(lane, "add", "-A")
3414+
_git(lane, "commit", "-q", "-m", "lane work")
34123415
tip = subprocess.run(
34133416
["git", "-C", str(lane), "rev-parse", "HEAD"], capture_output=True, text=True, check=True
34143417
).stdout.strip()

‎tests/unit/test_stop_session.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ def policy_for(argv: tuple[str, ...], rw: tuple[pathlib.Path, ...]) -> kinds.Jai
211211

212212
def test_a_gone_shell_pid_is_ignored(tmp_path: pathlib.Path) -> None:
213213
proc = _spawn("import time; time.sleep(60)")
214-
identity = process.process_identity(proc.pid)
214+
pid_start = process.pid_record(proc.pid).partition(" ")[2]
215215
shell = tmp_path / "shells" / "bg1"
216216
shell.mkdir(parents=True)
217217
(shell / "meta.json").write_text(
218-
json.dumps(
219-
{"id": "bg1", "command": "sleep 60", "pid": identity[0], "pid_start": identity[1]}
220-
),
218+
json.dumps({"id": "bg1", "command": "sleep 60", "pid": proc.pid, "pid_start": pid_start}),
221219
encoding="utf-8",
222220
)
223221
proc.terminate()

‎tests/unit/test_subrun.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def test_import_run_lands_branch_and_moves_run_dir(tmp_path: pathlib.Path) -> No
6464
branch = "agent6/lane-1"
6565
git_ops.create_branch(lane_repo, branch)
6666
(lane_repo / "feature.txt").write_text("new stuff\n", encoding="utf-8")
67-
git_ops.commit_all(lane_repo, "lane change")
67+
_git(lane_repo, "add", "-A")
68+
_git(lane_repo, "commit", "-q", "-m", "lane change")
6869

6970
lane_session_dir = tmp_path / "lane-state" / "sessions" / "runs" / "01ABC"
7071
lane_session_dir.mkdir(parents=True)
@@ -130,7 +131,8 @@ def test_import_run_refuses_existing_run_dir(tmp_path: pathlib.Path) -> None:
130131
branch = "agent6/lane-1"
131132
git_ops.create_branch(lane_repo, branch)
132133
(lane_repo / "feature.txt").write_text("new stuff\n", encoding="utf-8")
133-
git_ops.commit_all(lane_repo, "lane change")
134+
_git(lane_repo, "add", "-A")
135+
_git(lane_repo, "commit", "-q", "-m", "lane change")
134136

135137
lane_session_dir = tmp_path / "lane-state" / "sessions" / "runs" / "01ABC"
136138
lane_session_dir.mkdir(parents=True)

0 commit comments

Comments
 (0)