Files
gaokao-volunteer-system/data/cli_compat_backup.py
Hermes a57522b11e
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled
feat(cli): delegate channel/delivery/retention/backup to gaokao-cli (phase 3 batch 3)
Round 3 of the unified gaokao-cli rollout. Adds four more passthrough
markers so the unified entry point can drive the remaining ops scripts
without bringing new data models into data/.

- data/cli_compat_delivery_dispatch.py: runpy shim for
  scripts/gaokao-delivery-dispatch.py (DispatchDeliveryEvents).
- data/cli_compat_delivery_watchdog.py: runpy shim for
  scripts/gaokao-delivery-watchdog.py (WatchdogDeliveryEvents).
- data/cli_compat_retention_cleanup.py: runpy shim for
  scripts/gaokao-retention-cleanup.py (OrderRetentionCleanup).
- data/cli_compat_channel_fallback.py: forwarder for
  data.channel_sync.monitor.main (CheckChannelHealth /
  ManualTemplate).
- data/cli_compat_backup.py: subprocess wrapper that dispatches
  scripts/backup_snapshot.sh and scripts/backup_verify.sh.
- data/rules/cli.py main(): routes gaokao-cli {channel, delivery
  {dispatch,watchdog}, retention, backup {snapshot,verify}} to the
  shims; rejects unknown subcommands with a structured error.
- docs/CLI_API_MAPPING.md §2.1: now lists 12 top-level commands with
  their real subcommands and fallback paths.
- tests/test_cli_doctor_phase3.py: +6 tests covering channel
  delegation, delivery dispatch / unknown-subcommand, retention
  routing, backup shell routing, and backup unknown-subcommand
  rejection.

Verification:
- focused: 12 passed
- dev-verify full gate: all checks passed (ruff / mypy / coverage /
  pytest / benchmark)
2026-06-17 22:18:57 +08:00

32 lines
956 B
Python

"""Thin import shim for the `scripts/backup_snapshot.sh` / `backup_verify.sh` shells."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
_SCRIPTS_DIR = Path(__file__).resolve().parent.parent / "scripts"
_SHELL_TARGETS = {
"snapshot": _SCRIPTS_DIR / "backup_snapshot.sh",
"verify": _SCRIPTS_DIR / "backup_verify.sh",
}
def main(argv: list[str] | None = None) -> int:
if argv is None:
argv = sys.argv[1:]
if not argv or argv[0] not in _SHELL_TARGETS:
valid = ", ".join(sorted(_SHELL_TARGETS))
raise SystemExit(f"gaokao-cli backup expects one of [{valid}]; got: {argv!r}")
subcommand = argv[0]
target = _SHELL_TARGETS[subcommand]
if not target.is_file():
raise FileNotFoundError(f"backup script not found at {target}")
completed = subprocess.run(
["bash", str(target), *argv[1:]],
check=False,
)
return completed.returncode