fix(dashboard): pass backup output with -o

fix/verification-admin-route-recovery
墨綠BG 2026-06-30 01:30:40 +08:00 committed by Teknium
parent 7e84d2b5a4
commit bdb1c87247
3 changed files with 60 additions and 5 deletions

View File

@ -11915,8 +11915,9 @@ def _new_dashboard_backup_path() -> Path:
async def run_backup(body: BackupRequest):
args = ["backup"]
archive: Optional[Path] = None
if body.output:
args.append(body.output.strip())
output = (body.output or "").strip()
if output:
args.extend(["-o", output])
else:
archive = _new_dashboard_backup_path()
try:
@ -11926,7 +11927,7 @@ async def run_backup(body: BackupRequest):
status_code=500,
detail=f"Could not create backup directory: {exc}",
)
args.append(str(archive))
args.extend(["-o", str(archive)])
try:
proc = _spawn_hermes_action(args, "backup")
except Exception as exc:

View File

@ -338,6 +338,60 @@ class TestOpsEndpoints:
def _setup(self, _isolate_hermes_home):
self.client, _ = _client()
def test_backup_output_uses_output_flag(self, monkeypatch):
import hermes_cli.web_server as ws
captured = {}
class FakeProc:
pid = 12345
def fake_spawn_action(subcommand, name):
captured["subcommand"] = subcommand
captured["name"] = name
return FakeProc()
monkeypatch.setattr(ws, "_spawn_hermes_action", fake_spawn_action)
r = self.client.post(
"/api/ops/backup",
json={"output": " /tmp/hermes-test.zip "},
)
assert r.status_code == 200
assert captured == {
"subcommand": ["backup", "-o", "/tmp/hermes-test.zip"],
"name": "backup",
}
def test_backup_blank_output_uses_default_archive(self, monkeypatch):
from pathlib import Path
import hermes_cli.web_server as ws
from hermes_cli.config import get_hermes_home
captured = {}
class FakeProc:
pid = 12345
def fake_spawn_action(subcommand, name):
captured["subcommand"] = subcommand
captured["name"] = name
return FakeProc()
monkeypatch.setattr(ws, "_spawn_hermes_action", fake_spawn_action)
r = self.client.post("/api/ops/backup", json={"output": " "})
assert r.status_code == 200
archive = Path(r.json()["archive"])
assert captured == {
"subcommand": ["backup", "-o", str(archive)],
"name": "backup",
}
assert archive.parent == get_hermes_home() / "backups"
def test_hooks_list_reads_config(self):
from hermes_cli.config import load_config, save_config

View File

@ -2385,7 +2385,7 @@ class TestWebServerEndpoints:
assert data["name"] == "backup"
assert captured["name"] == "backup"
assert captured["args"] == ["backup", str(archive)]
assert captured["args"] == ["backup", "-o", str(archive)]
assert archive.parent == get_hermes_home() / "backups"
assert archive.name.startswith("hermes-backup-")
assert archive.suffix == ".zip"
@ -2412,7 +2412,7 @@ class TestWebServerEndpoints:
archive = Path(resp.json()["archive"])
assert archive.parent == hosted_home / "backups"
assert captured["args"] == ["backup", str(archive)]
assert captured["args"] == ["backup", "-o", str(archive)]
assert archive.parent.is_dir()
def test_ops_backup_download_streams_dashboard_backup(self, tmp_path):