Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/export_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,12 @@ def export_cmd(path: str, no_secrets: bool, yes: bool):
use_encryption = not no_secrets and _check_pyrage()

if not no_secrets and not _check_pyrage():
warning("pyrage not installed — exporting without secret encryption.")
warning("Install with: pip install pyrage")
use_encryption = False
error(
"pyrage is not installed — secrets cannot be encrypted.\n"
" Install: pip install pyrage\n"
" Export without secrets: apc export --no-secrets"
)
raise SystemExit(1)

if use_encryption:
public_key, _priv = _load_or_create_identity()
Expand Down
6 changes: 3 additions & 3 deletions src/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def _tool_sync_status(name: str) -> str:
if fp := info_dict.get("link_path"):
recorded_paths.append(fp)

for info_dict in manifest._data.get("memory", {}).values():
if fp := info_dict.get("file_path"):
recorded_paths.append(fp)
# memory is a flat dict {file_path, checksum, ...}, not a dict-of-dicts.
if fp := manifest._data.get("memory", {}).get("file_path"):
recorded_paths.append(fp)

# If nothing was recorded (e.g. only MCP servers were synced), trust the timestamp
if not recorded_paths:
Expand Down
14 changes: 9 additions & 5 deletions src/sync_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ def sync_skills(tool_list: List[str]) -> Tuple[int, int]:
applier = get_applier(tool_name)
manifest = applier.get_manifest()

# Per-tool counts (reset each iteration)
tool_copy = 0
tool_link = 0

# Copy collected skills
if collected_skills:
c = applier.apply_skills(collected_skills, manifest)
total_copy += c
tool_copy = applier.apply_skills(collected_skills, manifest)
total_copy += tool_copy

# Link installed skills
if installed_skills:
lk = applier.link_skills(installed_skills, skills_dir, manifest)
total_link += lk
tool_link = applier.link_skills(installed_skills, skills_dir, manifest)
total_link += tool_link

# Prune orphaned skills (keep MCP names empty — not our concern)
applier.prune(all_skill_names, [], manifest)
manifest.save()

success(f"{tool_name}: {total_copy} copied, {total_link} linked")
success(f"{tool_name}: {tool_copy} copied, {tool_link} linked")
except Exception as e:
error(f"Failed to sync skills to {tool_name}: {e}")

Expand Down
41 changes: 39 additions & 2 deletions tests/test_export_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,43 @@ def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.export_dir = Path(self.tmpdir) / "test-export"

@patch("export_import._check_pyrage", return_value=False)
def test_export_fails_loudly_without_pyrage(self, _mock_pyrage):
"""Without pyrage and --no-secrets unset, export must abort — no silent plaintext."""
from click.testing import CliRunner

runner = CliRunner()
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes"])

# Must NOT succeed — secrets would be plaintext
self.assertNotEqual(result.exit_code, 0)
self.assertFalse(self.export_dir.exists(), "Export dir should not be created on abort")

@patch("export_import._check_pyrage", return_value=False)
@patch("export_import.get_skills_dir")
@patch("export_import.get_config_dir")
@patch("export_import.load_mcp_servers", return_value=[])
@patch(
"export_import.load_local_bundle",
return_value={"skills": [], "mcp_servers": [], "memory": []},
)
def test_export_no_secrets_succeeds_without_pyrage(
self, mock_bundle, mock_mcp, mock_config, mock_skills, _mock_pyrage
):
"""--no-secrets works fine even when pyrage is unavailable."""
config_dir = Path(self.tmpdir) / "config"
config_dir.mkdir()
mock_config.return_value = config_dir
mock_skills.return_value = config_dir / "skills"

from click.testing import CliRunner

runner = CliRunner()
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes", "--no-secrets"])

self.assertEqual(result.exit_code, 0, result.output)
self.assertTrue((self.export_dir / "apc-export.json").exists())

@patch("export_import._check_pyrage", return_value=False)
@patch("export_import.get_skills_dir")
@patch("export_import.get_config_dir")
Expand All @@ -328,7 +365,7 @@ def test_export_creates_structure(
from click.testing import CliRunner

runner = CliRunner()
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes"])
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes", "--no-secrets"])

self.assertEqual(result.exit_code, 0, result.output)
self.assertTrue((self.export_dir / "apc-export.json").exists())
Expand Down Expand Up @@ -363,7 +400,7 @@ def test_export_writes_cache_data(
from click.testing import CliRunner

runner = CliRunner()
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes"])
result = runner.invoke(export_cmd, [str(self.export_dir), "--yes", "--no-secrets"])

self.assertEqual(result.exit_code, 0, result.output)

Expand Down