From a383e96ad5b44b798bfcbfb10fe1a8022d953ed5 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 16 Nov 2026 18:09:49 +0000 Subject: [PATCH 1/2] fix(repo): refuse a --cache-dir that is not a usable directory with exit 2 (#765) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A `repo` command given a `--cache-dir` that names a regular file (or a path below one) reached `ensure_clone`, whose `mkdir` raised `FileExistsError`; the command printed `✗ [Errno 17] File exists: ''` and exited 1, a failed run in `--json`, without naming the flag. `usable_cache_dir` moves from `commands/novelty_run.py` to the new `commands/cache_dir.py` (still importable from `novelty_run`) with a parameter for the closing words of its message: the novelty text is unchanged, and the repo commands say "pass a directory the repository clones can be cached in". `_cache_dir` in `commands/repo.py` calls it, and `_parse_source` calls it so every command that parses a source refuses a bad value first, also with a local-directory source, which never used the cache. InputError is a ValueError, so the clone handlers of `fetch`, `reach` and `_source_tree`, which were three copies, are one `_open_tree` that reads the flag before its `try`. Signed-off-by: Anton Volkov --- .../20261116_150000_repo-cache-dir-usable.md | 3 + dokimi/dokimi/commands/cache_dir.py | 45 +++++++ dokimi/dokimi/commands/novelty_run.py | 37 +----- dokimi/dokimi/commands/repo.py | 67 +++++------ dokimi/tests/test_repo_cache_dir_usable.py | 110 ++++++++++++++++++ 5 files changed, 185 insertions(+), 77 deletions(-) create mode 100644 dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md create mode 100644 dokimi/dokimi/commands/cache_dir.py create mode 100644 dokimi/tests/test_repo_cache_dir_usable.py diff --git a/dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md b/dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md new file mode 100644 index 000000000..57fa00250 --- /dev/null +++ b/dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md @@ -0,0 +1,3 @@ +### Fixed + +- **`repo` commands refuse a `--cache-dir` that is not a usable directory with exit 2 and a message naming the flag and the path** — a regular file, or a path below one, used to end in `✗ [Errno 17] File exists` and exit 1 (a failed run in `--json`) after the command had started; the value is now checked before any clone, as `skill shorten` and `skill novelty analyze` do. A bad `--cache-dir` next to a local-directory source is refused too, where it used to be ignored. diff --git a/dokimi/dokimi/commands/cache_dir.py b/dokimi/dokimi/commands/cache_dir.py new file mode 100644 index 000000000..c19ca9f8e --- /dev/null +++ b/dokimi/dokimi/commands/cache_dir.py @@ -0,0 +1,45 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +"""The up-front check of a ``--cache-dir`` value, shared by the novelty and repo commands (#701, #765).""" + +from __future__ import annotations + +import os +from pathlib import Path + +RETENTION_USE = "the retention verdicts can be stored in" +CLONE_USE = "the repository clones can be cached in" + + +def usable_cache_dir(raw: str | None, use: str = RETENTION_USE) -> Path | None: + """``--cache-dir`` as a path a cache can store into, or ``None`` when unset. + + A directory that does not exist yet is fine (created on the first store) when an existing, + writable directory is above it; one that exists must be a readable directory, writable or + not (a fully cached run replays from it). Anything else raises ``InputError`` before a paid + call or a clone (#701, #765). ``use`` closes the message: "pass a directory ". + """ + from dokimi.utils import InputError + + if not raw: + return None + path = Path(raw) + probe = path + try: + while not probe.exists() and not probe.is_symlink() and probe != probe.parent: + probe = probe.parent + is_dir = probe.is_dir() + except OSError as exc: + # An ancestor without search permission: exists()/is_dir() raise PermissionError (Python < 3.14). + raise InputError(f"--cache-dir {path}: cannot inspect {probe} ({exc.strerror or type(exc).__name__}); " + f"pass a directory {use}") from exc + if not is_dir: + where = "is not a directory" if probe == path else f"has {probe} above it, which is not a directory" + raise InputError(f"--cache-dir {path} {where}; pass a directory {use}") + # An existing directory only has to be readable: a fully cached run replays from a read-only + # directory and writes nothing. A missing one is created on the first store, so it needs to be writable. + needed, word = (os.R_OK | os.X_OK, "readable") if probe == path else (os.W_OK | os.X_OK, "writable") + if not os.access(probe, needed): + raise InputError(f"--cache-dir {path}: {probe} is not {word}; pass a directory {use}") + return path diff --git a/dokimi/dokimi/commands/novelty_run.py b/dokimi/dokimi/commands/novelty_run.py index 6c3bce99c..f8c55c01d 100644 --- a/dokimi/dokimi/commands/novelty_run.py +++ b/dokimi/dokimi/commands/novelty_run.py @@ -10,9 +10,8 @@ import argparse import functools import math -import os import sys -from pathlib import Path +from dokimi.commands.cache_dir import usable_cache_dir # noqa: F401 - re-exported for the novelty commands def stops_at_cap(command): @@ -30,40 +29,6 @@ def run(args: argparse.Namespace) -> None: return run -def usable_cache_dir(raw: str | None) -> Path | None: - """``--cache-dir`` as a path the retention cache can store into, or ``None`` when unset. - - A directory that does not exist yet is fine (created on the first store) when an existing, - writable directory is above it; one that exists must be a readable directory, writable or - not (the oracle skips a store it cannot make). Anything else raises ``InputError`` before a - paid call (#701). - """ - from dokimi.utils import InputError - - if not raw: - return None - path = Path(raw) - probe = path - try: - while not probe.exists() and not probe.is_symlink() and probe != probe.parent: - probe = probe.parent - is_dir = probe.is_dir() - except OSError as exc: - # An ancestor without search permission: exists()/is_dir() raise PermissionError (Python < 3.14). - raise InputError(f"--cache-dir {path}: cannot inspect {probe} ({exc.strerror or type(exc).__name__}); " - "pass a directory the retention verdicts can be stored in") from exc - if not is_dir: - where = "is not a directory" if probe == path else f"has {probe} above it, which is not a directory" - raise InputError(f"--cache-dir {path} {where}; pass a directory the retention verdicts can be stored in") - # An existing directory only has to be readable: a fully cached run replays from a read-only - # directory and writes nothing. A missing one is created on the first store, so it needs to be writable. - needed, word = (os.R_OK | os.X_OK, "readable") if probe == path else (os.W_OK | os.X_OK, "writable") - if not os.access(probe, needed): - raise InputError(f"--cache-dir {path}: {probe} is not {word}; pass a directory the retention " - "verdicts can be stored in") - return path - - def exit_if_analyze_partial(result, out) -> None: """Save and exit when the cap stopped ``analyze`` (``result.partial``); a finished run returns.""" from dokimi.commands.novelty_budget import save_analyze_partial diff --git a/dokimi/dokimi/commands/repo.py b/dokimi/dokimi/commands/repo.py index 6977aea24..d8f771917 100644 --- a/dokimi/dokimi/commands/repo.py +++ b/dokimi/dokimi/commands/repo.py @@ -44,35 +44,37 @@ def _parse_source(args: argparse.Namespace) -> RepoSource: from dokimi.repos import RepoSource, SourceError try: - return RepoSource.parse(args.source) + source = RepoSource.parse(args.source) except SourceError as exc: raise InputError(str(exc)) from exc except OSError as exc: # Path.is_dir raises PermissionError on Python 3.11-3.13 print(f"✗ {exc}", file=sys.stderr) sys.exit(1) + _cache_dir(args) # a bad --cache-dir is a usage error too, and must not reach a handler of the clone's failures + return source -def _source_tree(args: argparse.Namespace) -> tuple: - """The source (source, tree): a malformed string, unpinned remote or pinned local path that is not the repository root is a usage error (2); a clone, fetch or pin resolution failure is 1.""" +def _open_tree(source: RepoSource, args: argparse.Namespace): + """The source's tree, cloned into ``--cache-dir`` when remote: a bad ``--cache-dir`` or a pinned local path that is not the repository root is a usage error (2); a clone, fetch or pin resolution failure is 1.""" from dokimi.repos import SourceError, open_source from dokimi.repos.source import SourceArgumentError - source = _parse_source(args) - # 2 = malformed source string, unpinned remote, pinned local path inside a repository, manifest/profile errors; 1 = clone/fetch/resolve of a pin - # (incl. pinned local non-git source, pin absent locally, remote pin missing from origin). + cache_dir = _cache_dir(args) # before the handlers below: InputError is a ValueError try: - return source, open_source(source, _cache_dir(args)) - except SourceArgumentError as exc: # a pinned local path that is not the repository root + return open_source(source, cache_dir) + except SourceArgumentError as exc: raise InputError(str(exc)) from exc - except SourceError as exc: - print(f"✗ {exc}", file=sys.stderr) - sys.exit(1) - except (OSError, ValueError) as exc: - # A cache dir that cannot be made, or git output that is not UTF-8: a failed read, not a usage error. + except (SourceError, OSError, ValueError) as exc: # a cache dir that cannot be made, or git output that is not UTF-8 print(f"✗ {exc}", file=sys.stderr) sys.exit(1) +def _source_tree(args: argparse.Namespace) -> tuple: + """The source (source, tree): a malformed string, unpinned remote or pinned local path that is not the repository root is a usage error (2); a clone, fetch or pin resolution failure is 1.""" + source = _parse_source(args) + return source, _open_tree(source, args) + + def _manifest_or_exit(tree, args: argparse.Namespace, *, guidance_default: bool = False, also_usage: tuple = ()) -> Any: """The manifest of the tree. A bad manifest or a manifest path that leaves the tree is a usage error @@ -249,8 +251,8 @@ def cmd_repo_inspect(args: argparse.Namespace) -> None: def cmd_repo_fetch(args: argparse.Namespace) -> None: """Clone (once) and fetch a pinned remote source into the cache; print the SHA.""" - from dokimi.repos import RepoSource, SourceError, open_source - from dokimi.repos.source import GitTree, SourceArgumentError + from dokimi.repos import RepoSource, SourceError + from dokimi.repos.source import GitTree try: # the source as typed: a usage error source = RepoSource.parse(args.source) @@ -258,13 +260,7 @@ def cmd_repo_fetch(args: argparse.Namespace) -> None: raise SourceError("fetch needs a pinned source: @") except SourceError as exc: raise InputError(str(exc)) from exc - try: # the clone and fetch: a runtime failure (network, git, unknown revision) - tree = open_source(source, _cache_dir(args)) - except SourceArgumentError as exc: # a pinned local path that is not the repository root - raise InputError(str(exc)) from exc - except (SourceError, OSError, ValueError) as exc: - print(f"✗ {exc}", file=sys.stderr) - sys.exit(1) + tree = _open_tree(source, args) assert isinstance(tree, GitTree) if args.json: cli_output.emit_leaf("repo fetch", {"sha": tree.sha, "git_dir": str(tree.git_dir)}) @@ -320,23 +316,16 @@ def _saved_reach_inputs(args: argparse.Namespace): def _reach_from_saved(args: argparse.Namespace) -> None: """The matrix or the receipt of a saved reach.json, checked against the source; no harness runs.""" - from dokimi.repos import ManifestError, SourceError, open_source + from dokimi.repos import ManifestError, SourceError from dokimi.repos.harness_profile import ProfileError from dokimi.repos.receipt import check_receipt_provenance, check_saved_guidance, check_saved_reach from dokimi.repos.reach import ReachError, format_matrix - from dokimi.repos.source import SourceArgumentError try: # the arguments and the saved file as typed: a usage error profile, source, reach = _saved_reach_inputs(args) except (SourceError, ProfileError, ReachError, OSError, ValueError) as exc: raise InputError(str(exc)) from exc - try: # the clone and fetch: a runtime failure - tree = open_source(source, _cache_dir(args)) - except SourceArgumentError as exc: # a pinned local path that is not the repository root - raise InputError(str(exc)) from exc - except (SourceError, OSError, ValueError) as exc: - print(f"✗ {exc}", file=sys.stderr) - sys.exit(1) + tree = _open_tree(source, args) try: # the manifest and the file's provenance: a usage error; a failed git read is a fetch failure (1) manifest = _load_manifest(tree, args, guidance_default=True) check_saved_reach(reach, manifest.id, profile.name, getattr(tree, "sha", None)) @@ -426,9 +415,8 @@ def _reach_plan(args: argparse.Namespace, tree, profile, kinds: tuple[str, ...], def cmd_repo_reach(args: argparse.Namespace) -> None: """L1 reach probe: which guidance files one harness/version/model loads.""" - from dokimi.repos import RepoSource, SourceError, open_source + from dokimi.repos import RepoSource, SourceError from dokimi.repos.harness_profile import ProfileError, load_profile - from dokimi.repos.source import SourceArgumentError from dokimi.repos.reach import ReachError, check_flags, check_kinds, check_shadow, run_reach, save_reach kinds = tuple(k.strip() for k in args.scenarios.split(",") if k.strip()) @@ -441,13 +429,7 @@ def cmd_repo_reach(args: argparse.Namespace) -> None: source = RepoSource.parse(args.source) except (SourceError, ProfileError, ReachError) as exc: raise InputError(str(exc)) from exc - try: # the clone and fetch: a runtime failure - tree = open_source(source, _cache_dir(args)) - except SourceArgumentError as exc: # a pinned local path that is not the repository root - raise InputError(str(exc)) from exc - except (SourceError, OSError, ValueError) as exc: - print(f"✗ {exc}", file=sys.stderr) - sys.exit(1) + tree = _open_tree(source, args) manifest, files, planned_count = _reach_plan(args, tree, profile, kinds, only) if not args.dry_run: print(f"{len(files)} guidance files, {planned_count} scenarios, " @@ -621,7 +603,10 @@ def _manifest_id(label: str) -> str: def _cache_dir(args: argparse.Namespace) -> Path | None: - return Path(args.cache_dir) if args.cache_dir else None + """``--cache-dir`` as given, or ``None``; a value no clone can be cached in is a usage error (2) (#765).""" + from dokimi.commands.cache_dir import CLONE_USE, usable_cache_dir + + return usable_cache_dir(args.cache_dir, CLONE_USE) def register(sub, positive_int, eval_sub) -> None: diff --git a/dokimi/tests/test_repo_cache_dir_usable.py b/dokimi/tests/test_repo_cache_dir_usable.py new file mode 100644 index 000000000..f1880e4e7 --- /dev/null +++ b/dokimi/tests/test_repo_cache_dir_usable.py @@ -0,0 +1,110 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +"""`--cache-dir` of the `repo` commands is checked before any clone (#765): a bad value exits 2 naming the flag.""" + +from __future__ import annotations + +import argparse +import json + +import pytest + +from dokimi import cli +from dokimi.commands.repo import _cache_dir +from tests.cli_refusal import refusal + +PIN = "HEAD" + + +def _argv(monkeypatch, *argv): + monkeypatch.setattr("sys.argv", ["dokimi", *argv]) + + +def _source(tmp_path) -> str: + return f"file://{tmp_path}/nothere@{PIN}" + + +def _commands(tmp_path): + return { + "fetch": ["repo", "fetch", _source(tmp_path)], + "scan": ["repo", "scan", _source(tmp_path)], + "reach": ["repo", "reach", _source(tmp_path), "--model", "m"], + } + + +@pytest.mark.parametrize("command", ["fetch", "scan", "reach"]) +def test_repo_command_refuses_a_cache_dir_that_is_a_regular_file(command, tmp_path, monkeypatch, capsys): + cache = tmp_path / "cachefile" + cache.write_text("x", encoding="utf-8") + _argv(monkeypatch, *_commands(tmp_path)[command], "--cache-dir", str(cache)) + with refusal() as exc: + cli.main() + err = capsys.readouterr().err + assert exc.code == 2 + assert f"--cache-dir {cache} is not a directory; pass a directory the repository clones can be cached in" in err + assert "File exists" not in err and cache.read_text(encoding="utf-8") == "x" + + +@pytest.mark.parametrize("kind", ["check", "replay"]) +def test_eval_commands_that_clone_refuse_a_cache_dir_that_is_a_regular_file(kind, tmp_path, monkeypatch, capsys): + threads = tmp_path / "threads.json" + threads.write_text("[]", encoding="utf-8") + cache = tmp_path / "cachefile" + cache.write_text("x", encoding="utf-8") + argv = {"check": ["eval", "check", _source(tmp_path)], + "replay": ["eval", "tasks", "generate", "--from", "replay", _source(tmp_path), "--threads", str(threads), + "--out-dir", str(tmp_path / "out")]}[kind] + _argv(monkeypatch, *argv, "--cache-dir", str(cache)) + with refusal() as exc: + cli.main() + assert exc.code == 2 + assert f"--cache-dir {cache} is not a directory" in capsys.readouterr().err + + +def test_repo_fetch_refuses_a_child_of_a_regular_file_and_makes_nothing(tmp_path, monkeypatch, capsys): + blocker = tmp_path / "file" + blocker.write_text("x", encoding="utf-8") + _argv(monkeypatch, *_commands(tmp_path)["fetch"], "--cache-dir", str(blocker / "cache")) + with refusal() as exc: + cli.main() + err = capsys.readouterr().err + assert exc.code == 2 + assert f"--cache-dir {blocker / 'cache'} has {blocker} above it, which is not a directory" in err + assert sorted(p.name for p in tmp_path.iterdir()) == ["file"] + + +def test_repo_fetch_json_reports_the_bad_flag_as_input_not_a_failed_run(tmp_path, monkeypatch, capsys): + cache = tmp_path / "cachefile" + cache.write_text("x", encoding="utf-8") + _argv(monkeypatch, "repo", "fetch", _source(tmp_path), "--cache-dir", str(cache), "--json") + with refusal() as exc: + cli.main() + document = json.loads(capsys.readouterr().out) + assert exc.code == 2 + assert document["status"] == "failed" + assert f"--cache-dir {cache} is not a directory" in json.dumps(document) + assert "exit 1: see stderr" not in json.dumps(document) + + +def test_repo_scan_of_a_local_directory_also_refuses_a_bad_cache_dir(tmp_path, monkeypatch, capsys): + repo = tmp_path / "repo" + repo.mkdir() + cache = tmp_path / "cachefile" + cache.write_text("x", encoding="utf-8") + _argv(monkeypatch, "repo", "scan", str(repo), "--cache-dir", str(cache)) + with refusal() as exc: + cli.main() + assert exc.code == 2 + assert f"--cache-dir {cache} is not a directory" in capsys.readouterr().err + + +def test_cache_dir_passes_unset_an_existing_directory_and_a_missing_child_unchanged(tmp_path): + def args(value): + return argparse.Namespace(cache_dir=value) + + assert _cache_dir(args(None)) is None + assert _cache_dir(args("")) is None + assert _cache_dir(args(str(tmp_path))) == tmp_path + assert _cache_dir(args(str(tmp_path / "new" / "deeper"))) == tmp_path / "new" / "deeper" + assert not (tmp_path / "new").exists() From e8ac28d99d1f7c98fc109a4777a9cd0655c0f2db Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 16 Nov 2026 23:09:13 +0000 Subject: [PATCH 2/2] fix(repo): document the read-only --cache-dir case, name the fragment by author, pin a usable cache dir Settles the review threads on the PR. An existing read-only --cache-dir stays accepted on purpose (a populated cache replays without writing); the `_cache_dir` docstring and the changelog fragment now say that an empty read-only one fails at the clone with exit 1. The `_parse_source` docstring lists the --cache-dir usage error. The fragment is renamed to carry the author segment, as changelog.d/README.md names it. New test: `repo fetch` of a pinned file:// source under a writable --cache-dir prints the SHA, so `_open_tree` returning no tree fails a test. Signed-off-by: Anton Volkov --- ..._150000_antonwolfy_repo-cache-dir-usable.md} | 2 +- dokimi/dokimi/commands/repo.py | 8 ++++++-- dokimi/tests/test_repo_cache_dir_usable.py | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) rename dokimi/changelog.d/{20261116_150000_repo-cache-dir-usable.md => 20261116_150000_antonwolfy_repo-cache-dir-usable.md} (74%) diff --git a/dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md b/dokimi/changelog.d/20261116_150000_antonwolfy_repo-cache-dir-usable.md similarity index 74% rename from dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md rename to dokimi/changelog.d/20261116_150000_antonwolfy_repo-cache-dir-usable.md index 57fa00250..8bd78bde2 100644 --- a/dokimi/changelog.d/20261116_150000_repo-cache-dir-usable.md +++ b/dokimi/changelog.d/20261116_150000_antonwolfy_repo-cache-dir-usable.md @@ -1,3 +1,3 @@ ### Fixed -- **`repo` commands refuse a `--cache-dir` that is not a usable directory with exit 2 and a message naming the flag and the path** — a regular file, or a path below one, used to end in `✗ [Errno 17] File exists` and exit 1 (a failed run in `--json`) after the command had started; the value is now checked before any clone, as `skill shorten` and `skill novelty analyze` do. A bad `--cache-dir` next to a local-directory source is refused too, where it used to be ignored. +- **`repo` commands refuse a `--cache-dir` that is not a usable directory with exit 2 and a message naming the flag and the path** — a regular file, or a path below one, used to end in `✗ [Errno 17] File exists` and exit 1 (a failed run in `--json`) after the command had started; the value is now checked before any clone, as `skill shorten` and `skill novelty analyze` do. A bad `--cache-dir` next to a local-directory source is refused too, where it used to be ignored. An existing read-only directory still passes, so a populated cache replays; an empty read-only one fails at the clone with exit 1. diff --git a/dokimi/dokimi/commands/repo.py b/dokimi/dokimi/commands/repo.py index d8f771917..eb599ae90 100644 --- a/dokimi/dokimi/commands/repo.py +++ b/dokimi/dokimi/commands/repo.py @@ -40,7 +40,7 @@ def _write_json(path: str, payload: dict) -> None: def _parse_source(args: argparse.Namespace) -> RepoSource: - """The source as typed: a malformed string, an unpinned remote or a local path that is not a directory is a usage error (2); a local path the filesystem refuses to stat (no permission to traverse it) is 1.""" + """The source as typed: a malformed string, an unpinned remote, a local path that is not a directory or a ``--cache-dir`` that is not a usable directory is a usage error (2); a local path the filesystem refuses to stat (no permission to traverse it) is 1.""" from dokimi.repos import RepoSource, SourceError try: @@ -603,7 +603,11 @@ def _manifest_id(label: str) -> str: def _cache_dir(args: argparse.Namespace) -> Path | None: - """``--cache-dir`` as given, or ``None``; a value no clone can be cached in is a usage error (2) (#765).""" + """``--cache-dir`` as given, or ``None``; a value no clone can be cached in is a usage error (2) (#765). + + An existing read-only directory passes on purpose: a populated one replays without writing. An empty one + is not told apart without the clone URL, so its clone fails later with exit 1. + """ from dokimi.commands.cache_dir import CLONE_USE, usable_cache_dir return usable_cache_dir(args.cache_dir, CLONE_USE) diff --git a/dokimi/tests/test_repo_cache_dir_usable.py b/dokimi/tests/test_repo_cache_dir_usable.py index f1880e4e7..438269690 100644 --- a/dokimi/tests/test_repo_cache_dir_usable.py +++ b/dokimi/tests/test_repo_cache_dir_usable.py @@ -7,6 +7,7 @@ import argparse import json +import subprocess import pytest @@ -108,3 +109,19 @@ def args(value): assert _cache_dir(args(str(tmp_path))) == tmp_path assert _cache_dir(args(str(tmp_path / "new" / "deeper"))) == tmp_path / "new" / "deeper" assert not (tmp_path / "new").exists() + + +def test_repo_fetch_prints_the_sha_of_a_pinned_source_in_a_writable_cache_dir(tmp_path, monkeypatch, capsys): + src = tmp_path / "src" + src.mkdir() + (src / "a.txt").write_text("a", encoding="utf-8") + git = ["git", "-C", str(src), "-c", "user.name=t", "-c", "user.email=t@example.com"] + subprocess.run([*git, "init", "-q"], check=True) + subprocess.run([*git, "add", "-A"], check=True) + subprocess.run([*git, "commit", "-qm", "init"], check=True) + sha = subprocess.run([*git, "rev-parse", "HEAD"], check=True, capture_output=True, text=True).stdout.strip() + cache = tmp_path / "cache" + cache.mkdir() + _argv(monkeypatch, "repo", "fetch", f"file://{src}@{sha}", "--cache-dir", str(cache)) + cli.main() + assert capsys.readouterr().out.startswith(f"{sha}\t")