Coverage for retraining/vault_commands.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""Pure Aether-Vault (`av`) command builder (Phase V2-17). 

2 

3Builds argv lists only - no subprocess execution here, see 

4retraining/vault_client.py for that. Aether-Vault is a separate sibling 

5tool, invoked purely as an external `av` CLI subprocess. Commit, push and 

6restore ask for its versioned JSON envelope (docs/for-agents.md in that repo), 

7so results are read from a contract rather than from human text. 

8""" 

9 

10from __future__ import annotations 

11 

12from typing import Any 

13 

14 

15def build_av_add_command(paths: list[str], av_binary: str = "av") -> list[str]: 

16 """The `av add` command for the given paths.""" 

17 return [av_binary, "add", *paths] 

18 

19 

20def build_av_commit_command( 

21 message: str, 

22 tag: str, 

23 metrics: dict[str, float], 

24 av_binary: str = "av", 

25 *, 

26 no_upload: bool = False, 

27) -> list[str]: 

28 """The `av commit` command for a model version, with its message, tag and metrics.""" 

29 cmd = [av_binary, "--output", "json", "commit", "-m", message] 

30 if tag: 

31 cmd += ["--tag", tag] 

32 for key, value in metrics.items(): 

33 cmd += ["--metric", f"{key}={value}"] 

34 if no_upload: 

35 cmd.append("--no-upload") 

36 return cmd 

37 

38 

39def build_av_push_command(av_binary: str = "av") -> list[str]: 

40 """The `av push` command (JSON output).""" 

41 return [av_binary, "--output", "json", "push"] 

42 

43 

44def build_av_status_command(av_binary: str = "av") -> list[str]: 

45 """The `av status` command (JSON output).""" 

46 return [av_binary, "--output", "json", "status"] 

47 

48 

49def build_av_head_command(av_binary: str = "av") -> list[str]: 

50 """The `av log --limit 1` command (JSON output): the vault's head.""" 

51 return [av_binary, "--output", "json", "log", "--limit", "1"] 

52 

53 

54def build_av_restore_command(commit_hash: str, paths: list[str], av_binary: str = "av") -> list[str]: 

55 """Restores only `paths`: HEAD and every other file stay as they are.""" 

56 return [av_binary, "--output", "json", "restore", "--source", commit_hash, *paths] 

57 

58 

59def build_commit_plan(version_id: str, add_paths: list[str], metrics: dict[str, float], config: dict[str, Any]) -> dict[str, Any]: 

60 """Assembles the full add -> commit -> push argv plan for one candidate. 

61 

62 config = phase_v2.retraining.vault block. `push` defaults to True per 

63 that config's own default; set config["push"]=False to skip the push 

64 step (e.g. commit-only, offline dev), which also keeps the commit itself 

65 from attempting an upload. 

66 """ 

67 av_binary = config.get("av_binary", "av") 

68 message_template = config.get("commit_message_template", "candidate model {version_id}") 

69 tag = config.get("tag", "candidate") 

70 push = config.get("push", True) 

71 paths = [*add_paths, *config.get("extra_add_paths", [])] 

72 

73 plan = { 

74 "add": build_av_add_command(paths, av_binary=av_binary), 

75 "commit": build_av_commit_command( 

76 message_template.format(version_id=version_id), tag, metrics, av_binary=av_binary, no_upload=not push 

77 ), 

78 "push": build_av_push_command(av_binary=av_binary) if push else None, 

79 } 

80 return plan