Files
claude-timemachine 9074121898
CI / test (3.10) (push) Successful in 7s
CI / test (3.11) (push) Successful in 7s
CI / test (3.12) (push) Successful in 6s
CI / build-pyz (push) Successful in 4s
CI / release (push) Has been skipped
feat: 'disable' renames to sync.json.disabled; new 'enable' rename-back
Pause/resume sync without losing the instance_id.

  disable  sync.json -> sync.json.disabled
  enable   sync.json.disabled -> sync.json

Re-enabling preserves the original ULID + url so the same restic
repo continues. No new instance_id minted, no orphaned snapshot
history. Tradeoff vs the previous 'disable = delete' semantics:
the on-disk artifact survives, so a truly fresh start now needs
'disable && rm sync.json.disabled' before 'setup'.

Implementation:

  config.disable(pack)  os.rename(sync.json -> sync.json.disabled).
                        False if no sync.json.
  config.enable(pack)   os.rename(sync.json.disabled -> sync.json).
                        Refuses if sync.json already exists
                        (caller must disable first).
  config.delete(pack)   now sweeps BOTH forms (escape hatch / tests).

setup_flow gains a precheck: if sync.json.disabled is present, point
the user at 'enable' instead of silently minting a fresh ULID over
their existing instance.

Opt-in gate (cfgmod.exists) is unchanged — only literal sync.json
counts. The .disabled sibling is invisible to pull/push, so the
silent-no-op behavior for paused instances Just Works.

cli adds 'enable' subcommand alongside 'disable'. _run_disable prints
'already disabled' when called twice; _run_enable refuses to clobber
an active config (exits 2 with the FileExistsError message).

7 new tests for disable/enable behavior + edge cases (idempotency,
nothing-to-X, refuse-clobber). 80 tests total.
2026-06-05 09:58:56 +02:00

116 lines
3.2 KiB
Python

"""CLI parsing tests — argv → (subcommand, Namespace) and → Args."""
from __future__ import annotations
import pytest
from cloud_sync.cli import Args, args_from, parse
# ---- pull / push ----
def test_parses_pull_without_url() -> None:
"""url is sync.json's job now — pull/push don't take --url."""
cmd, ns = parse(["pull"])
assert cmd == "pull"
args = args_from(ns)
assert isinstance(args, Args)
assert args.allow_download is True
assert args.headless is False
assert args.instance_label is None
def test_default_token_file_under_pack_folder() -> None:
_, ns = parse(["pull", "--pack-folder=/tmp/inst"])
args = args_from(ns)
assert args.token_file.as_posix().endswith(".cloud-sync/token")
assert "/tmp/inst" in args.token_file.as_posix()
def test_custom_token_file_overrides_default() -> None:
_, ns = parse([
"pull", "--pack-folder=/tmp/inst", "--token-file=/etc/cloud-creds",
])
args = args_from(ns)
assert args.token_file.as_posix() == "/etc/cloud-creds"
def test_inline_and_space_separated_both_work() -> None:
_, ns1 = parse(["pull", "--pack-folder=/srv"])
_, ns2 = parse(["pull", "--pack-folder", "/srv"])
a1, a2 = args_from(ns1), args_from(ns2)
assert a1.pack_folder == a2.pack_folder
def test_no_gui_flag() -> None:
_, a = parse(["push", "-g"])
assert args_from(a).headless is True
_, b = parse(["push", "--no-gui"])
assert args_from(b).headless is True
def test_no_download_flag() -> None:
_, ns = parse(["push", "--no-download"])
assert args_from(ns).allow_download is False
def test_restic_binary_override() -> None:
_, ns = parse(["push", "--restic-binary=/opt/restic"])
a = args_from(ns)
assert a.restic_binary is not None
assert a.restic_binary.as_posix() == "/opt/restic"
def test_instance_label_override() -> None:
_, ns = parse(["pull", "--instance-label=Frazaserver 1.21.4"])
assert args_from(ns).instance_label == "Frazaserver 1.21.4"
def test_pack_folder_is_resolved_to_absolute() -> None:
_, ns = parse(["pull", "--pack-folder=."])
assert args_from(ns).pack_folder.is_absolute()
# ---- setup / init / disable ----
def test_setup_subcommand_accepts_optional_url() -> None:
cmd, ns = parse(["setup", "--url=https://x"])
assert cmd == "setup"
assert ns.url == "https://x"
def test_init_requires_url() -> None:
with pytest.raises(SystemExit):
parse(["init"])
def test_init_accepts_url_and_token() -> None:
cmd, ns = parse(["init", "--url=https://x", "--token=42:secret"])
assert cmd == "init"
assert ns.url == "https://x"
assert ns.token == "42:secret"
def test_disable_subcommand_parses() -> None:
cmd, ns = parse(["disable", "--pack-folder=/tmp/x"])
assert cmd == "disable"
assert str(ns.pack_folder) == "/tmp/x"
def test_enable_subcommand_parses() -> None:
cmd, ns = parse(["enable", "--pack-folder=/tmp/x"])
assert cmd == "enable"
assert str(ns.pack_folder) == "/tmp/x"
def test_missing_subcommand_exits() -> None:
with pytest.raises(SystemExit):
parse([])
def test_unknown_subcommand_exits() -> None:
with pytest.raises(SystemExit):
parse(["bogus"])