Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(cli): fail backup create when no store paths are configured (#1957)

John Costab5e380a4b982
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8bdc686..0ac44596 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- **`semantica backup create` reported success for an archive with no store data** (fixes #1820) by @costajohnt
+ - With no file-based `graph_db` / `vector_store` / `triplet_store` path in the config, `backup create` wrote a manifest with `"files": []` and exited 0. It now fails with an error that points to `semantica backup info`, before asking for a passphrase or confirmation and before writing anything.
+
- **`calculate_pagerank` rebuilt the adjacency once per node for a plain graph dictionary** (fixes #1842)
- `_get_filtered_neighbors` called `build_adjacency(graph, directed=True)` for every node, making neighbour resolution O(N * (N + E)). `calculate_pagerank` now builds it once before the node loop and passes it in through a new optional `adjacency` argument; scores are unchanged. New `tests/kg/test_centrality_pagerank_adjacency_reuse.py`
diff --git a/semantica/cli.py b/semantica/cli.py
index 9d4af98c..dc3b610a 100644
--- a/semantica/cli.py
+++ b/semantica/cli.py
@@ -5255,13 +5255,29 @@ def backup_create(
passphrase = kp.read_text(encoding="utf-8").strip()
if not passphrase:
raise click.ClickException(f"Keyfile {keyfile} is empty; cannot derive encryption key.")
- elif encrypt:
- passphrase = click.prompt("Backup passphrase", hide_input=True,
- confirmation_prompt=True)
else:
passphrase = None
cfg = cli_ctx.config.to_dict()
+ sources = _collect_backup_sources(cfg, cli_ctx.config_path, include, strip_config)
+ # Fail before any prompt instead of writing an archive with no
+ # store data in it (#1820).
+ if include in ("graph", "vector", "triplet", "all") and not any(
+ arcname.startswith(("graph/", "vector/", "triplet/"))
+ for arcname, _ in sources
+ ):
+ stores = "graph, vector and triplet stores" if include == "all" else f"{include} store"
+ raise click.ClickException(
+ f"No store data to back up: found no local files for the {stores}. "
+ "backup create only copies file-based stores (a graph_db / vector_store / "
+ "triplet_store path that exists on disk); run `semantica backup info` "
+ "to see how to back up other backends."
+ )
+
+ if encrypt and passphrase is None:
+ passphrase = click.prompt("Backup passphrase", hide_input=True,
+ confirmation_prompt=True)
+
if not strip_config and not encrypt and passphrase is None:
if not quiet:
console.print(
@@ -5274,7 +5290,6 @@ def backup_create(
dest.parent.mkdir(parents=True, exist_ok=True)
import tarfile, tempfile, shutil
- sources = _collect_backup_sources(cfg, cli_ctx.config_path, include, strip_config)
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
manifest: Dict[str, Any] = {
diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py
index 9fe59216..b12c1da3 100644
--- a/tests/test_cli_commands.py
+++ b/tests/test_cli_commands.py
@@ -18,6 +18,7 @@ import os
import time
import re
import stat
+import tarfile
import types
from typing import Any
from unittest.mock import MagicMock, patch
@@ -3115,6 +3116,40 @@ class TestBackup:
)
assert "Traceback" not in result.output
+ @pytest.mark.parametrize("extra", [["--strip-config"], [], ["--encrypt"]])
+ def test_create_without_stores_fails(self, runner, monkeypatch, tmp_path, extra):
+ # Regression for #1820: no store paths used to write an archive
+ # with "files": [] and exit 0. It must also fail before asking for
+ # a passphrase or confirmation.
+ monkeypatch.setattr(cli_module.Path, "home", staticmethod(lambda: tmp_path))
+ with runner.isolated_filesystem():
+ result = runner.invoke(
+ cli_module.main,
+ ["backup", "create", "out.tar.gz", "--quiet", *extra],
+ )
+ assert result.exit_code != 0
+ assert "No store data to back up" in result.output
+ assert "passphrase" not in result.output
+ assert "Continue without encryption" not in result.output
+ assert not os.path.exists("out.tar.gz")
+
+ def test_create_with_local_store_writes_its_files(self, runner):
+ with runner.isolated_filesystem():
+ os.makedirs("kg")
+ with open("kg/graph.db", "w") as f:
+ f.write("data")
+ with open("cfg.yaml", "w") as f:
+ f.write("graph_db:\n backend: sqlite\n path: kg\n")
+ result = runner.invoke(
+ cli_module.main,
+ ["--config", "cfg.yaml", "backup", "create", "out.tar.gz",
+ "--strip-config", "--quiet"],
+ )
+ _ok(result)
+ with tarfile.open("out.tar.gz") as tar:
+ names = tar.getnames()
+ assert "semantica-backup/graph/graph.db" in names
+
def test_create_dry_run_json(self, runner):
# backup create has no per-command --json; use global --json
result = runner.invoke(cli_module.main, ["--json", "backup", "create", "backup.tar.gz",