20cfdf62f2
Reshapes the launcher integration around two ideas:
1. ONE global Prism PreLaunch/PostExit hook is enough for all
instances. Wire it once at Settings > Default > Custom commands:
python /opt/cloud-sync.pyz pull --pack-folder=$INST_MC_DIR
python /opt/cloud-sync.pyz push --pack-folder=$INST_MC_DIR
Instances WITHOUT .cloud-sync/sync.json are silent no-ops (rc=0,
no UI, no banner). The opt-in probe runs BEFORE the UI factory
so Prism's launch log stays clean for non-sync instances.
2. Per-instance opt-in via 'setup' / 'init' subcommands that mint a
fresh ULID-style instance_id + write sync.json (mode 644) and
token (mode 600). 'disable' removes sync.json; cloud data
untouched.
Restic URL gains an /<instance_id>/ subpath under the user's
namespace, so two Prism instances of the same Discord user no longer
share a snapshot timeline. --private-repos still gates on the first
path segment (the username); deeper segments are user-controlled,
so this works without server-side coordination. First-push-on-a-new-
instance probes via 'restic cat config' and 'init's the per-instance
repo if absent.
UI label resolution is runtime-only (NEVER stored in sync.json) so
the user renaming the Prism instance just propagates through on
next launch:
--instance-label > $INST_NAME > $INST_ID > instance_id[:8]
Schema bumps:
state.json schema: 1 -> 2, adds instance_id field. Schema-1 files
are treated as missing (existing test1 user re-pulls fresh).
sync.json schema: 1 (new file).
CLI rework:
pull / push no --url; load everything from sync.json
setup interactive: Qt login dialog for token; URL prompt
if --url omitted; falls back to stdin when headless
init non-interactive setup; for scripted callers
disable rm sync.json
Args dataclass: drops 'url', adds 'instance_label'. cli.parse() now
returns (cmd, Namespace); a separate args_from(ns) builds the Args
so each subcommand can pluck the bits it needs from the Namespace
without forcing a 'one Args fits all subcommands' shape.
73 tests green; pyz 75 KB.
Smoke-verified locally:
- pull/push on a folder without sync.json: silent rc=0, no banner
- init writes sync.json (644) + token (600) with correct contents
- disable removes sync.json, keeps token
- mint produces unique 26-char base32 instance_ids
- label resolution chain (flag > INST_NAME > INST_ID > prefix)
110 lines
3.0 KiB
Python
110 lines
3.0 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_missing_subcommand_exits() -> None:
|
|
with pytest.raises(SystemExit):
|
|
parse([])
|
|
|
|
|
|
def test_unknown_subcommand_exits() -> None:
|
|
with pytest.raises(SystemExit):
|
|
parse(["bogus"])
|