From c933bcd43f03138c0922cf2c282ed1454696f501 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 23:04:25 +0000 Subject: [PATCH] test(cli): fix windows path assertions in export endpoints - Fixes `AssertionError: assert {'path': '\\tmp\\exported.md'} == {'path': '/tmp/exported.md'}` by checking against both `\tmp\exported.md` and `/tmp/exported.md` in `src/tests/test_api_new_endpoints.py` - Fixes `AssertionError: assert '/tmp/doc.txt' in '\\tmp\\doc.txt\n'` by checking for both variations in `src/tests/test_cli_entry_add_commands.py` - Runs `black` to format unformatted tests and CLI code to fix lint/formatting failures. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- src/seedpass/cli/agent.py | 4 +++- src/seedpass/cli/api.py | 21 ++++++++++++++++----- src/seedpass/cli/entry.py | 2 +- src/seedpass/core/entry_management.py | 11 +++++------ src/seedpass/tui_v2/__init__.py | 1 - src/tests/test_api_new_endpoints.py | 10 ++++++++-- src/tests/test_cli_agent_mode.py | 18 +++++++++++++++--- src/tests/test_cli_core_services.py | 4 +++- src/tests/test_cli_entry_add_commands.py | 20 +++++++++++++++++--- 9 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/seedpass/cli/agent.py b/src/seedpass/cli/agent.py index 92dd4e71..01098e16 100644 --- a/src/seedpass/cli/agent.py +++ b/src/seedpass/cli/agent.py @@ -3676,7 +3676,9 @@ def agent_export_manifest_verify( def agent_document_import( ctx: typer.Context, file: Path = typer.Option(..., "--file", help="Input file path"), - label: Optional[str] = typer.Option(None, "--label", help="Document title override"), + label: Optional[str] = typer.Option( + None, "--label", help="Document title override" + ), notes: str = typer.Option("", "--notes", help="Entry notes"), tag: list[str] = typer.Option( [], "--tag", help="Tag to attach (repeatable)", show_default=False diff --git a/src/seedpass/cli/api.py b/src/seedpass/cli/api.py index 1365a38a..13b10547 100644 --- a/src/seedpass/cli/api.py +++ b/src/seedpass/cli/api.py @@ -7,7 +7,10 @@ import typer import uvicorn from .. import api as api_module -from seedpass.core.auth_broker import AuthBrokerError, resolve_password as resolve_broker_password +from seedpass.core.auth_broker import ( + AuthBrokerError, + resolve_password as resolve_broker_password, +) app = typer.Typer(help="Run the API server") @@ -18,16 +21,22 @@ def api_start( host: str = "127.0.0.1", port: int = 8000, unlock: bool = typer.Option( - False, "--unlock", help="Unlock vault during startup using the selected auth broker" + False, + "--unlock", + help="Unlock vault during startup using the selected auth broker", ), auth_broker: str = typer.Option( "prompt", "--auth-broker", help="Password source when --unlock is used (prompt|env|keyring|command)", - click_type=click.Choice(["prompt", "env", "keyring", "command"], case_sensitive=False), + click_type=click.Choice( + ["prompt", "env", "keyring", "command"], case_sensitive=False + ), ), password_env: str = typer.Option( - "SEEDPASS_PASSWORD", "--password-env", help="Env var used when --auth-broker=env" + "SEEDPASS_PASSWORD", + "--password-env", + help="Env var used when --auth-broker=env", ), broker_service: str = typer.Option( "seedpass", @@ -51,7 +60,9 @@ def api_start( if auth_broker.lower() == "prompt": unlock_password = typer.prompt("Master password", hide_input=True) else: - account = broker_account or str((ctx.obj or {}).get("fingerprint") or "default") + account = broker_account or str( + (ctx.obj or {}).get("fingerprint") or "default" + ) try: unlock_password = resolve_broker_password( broker=auth_broker, diff --git a/src/seedpass/cli/entry.py b/src/seedpass/cli/entry.py index 2196cd92..fff71e67 100644 --- a/src/seedpass/cli/entry.py +++ b/src/seedpass/cli/entry.py @@ -376,7 +376,7 @@ def entry_modify( links_json: Optional[str] = typer.Option( None, "--links-json", - help="Replace links with JSON array: [{\"target_id\":1,\"relation\":\"related_to\",\"note\":\"...\"}]", + help='Replace links with JSON array: [{"target_id":1,"relation":"related_to","note":"..."}]', ), ) -> None: """Modify an existing entry.""" diff --git a/src/seedpass/core/entry_management.py b/src/seedpass/core/entry_management.py index 129c0b64..d4d82226 100644 --- a/src/seedpass/core/entry_management.py +++ b/src/seedpass/core/entry_management.py @@ -1409,9 +1409,10 @@ class EntryManager: filtered = [] for link in links: matches_target = int(link.get("target_id", -1)) == int(target_id) - matches_relation = relation_norm is None or str( - link.get("relation", "") - ).lower() == relation_norm + matches_relation = ( + relation_norm is None + or str(link.get("relation", "")).lower() == relation_norm + ) if matches_target and matches_relation: continue filtered.append(link) @@ -1419,9 +1420,7 @@ class EntryManager: src["links"] = filtered src.setdefault( "date_added", - self._iso_from_unix( - int(src.get("modified_ts", 0) or self._now_unix()) - ), + self._iso_from_unix(int(src.get("modified_ts", 0) or self._now_unix())), ) src["modified_ts"] = self._now_unix() src["date_modified"] = self._iso_from_unix(src["modified_ts"]) diff --git a/src/seedpass/tui_v2/__init__.py b/src/seedpass/tui_v2/__init__.py index 95883444..905be05a 100644 --- a/src/seedpass/tui_v2/__init__.py +++ b/src/seedpass/tui_v2/__init__.py @@ -1,2 +1 @@ """TUI v2 package scaffold (Textual-backed).""" - diff --git a/src/tests/test_api_new_endpoints.py b/src/tests/test_api_new_endpoints.py index 58d265bb..72e905a3 100644 --- a/src/tests/test_api_new_endpoints.py +++ b/src/tests/test_api_new_endpoints.py @@ -191,7 +191,7 @@ async def test_document_import_export_endpoints(client): headers=headers, ) assert exported.status_code == 200 - assert exported.json() == {"path": "/tmp/exported.md"} + assert exported.json()["path"] in ["/tmp/exported.md", "\\tmp\\exported.md"] assert calls["export"] == (33, {"output_path": "/tmp/out", "overwrite": True}) @@ -202,7 +202,13 @@ async def test_entry_links_endpoints(client): def add_link(entry_id, target_id, **kwargs): calls["add"] = (entry_id, target_id, kwargs) - return [{"target_id": target_id, "relation": kwargs["relation"], "note": kwargs["note"]}] + return [ + { + "target_id": target_id, + "relation": kwargs["relation"], + "note": kwargs["note"], + } + ] def remove_link(entry_id, target_id, **kwargs): calls["remove"] = (entry_id, target_id, kwargs) diff --git a/src/tests/test_cli_agent_mode.py b/src/tests/test_cli_agent_mode.py index 97b0d40a..0676f8ae 100644 --- a/src/tests/test_cli_agent_mode.py +++ b/src/tests/test_cli_agent_mode.py @@ -610,7 +610,11 @@ def test_agent_document_import_with_token_scope(monkeypatch, tmp_path): return 12 def retrieve_entry(self, _i): - return {"kind": EntryType.DOCUMENT.value, "label": "My Notes", "file_type": "md"} + return { + "kind": EntryType.DOCUMENT.value, + "label": "My Notes", + "file_type": "md", + } monkeypatch.setattr(agent_cli, "EntryService", DummyEntryService) monkeypatch.setattr( @@ -633,7 +637,11 @@ def test_agent_document_import_with_token_scope(monkeypatch, tmp_path): "approvals": {"require_for": []}, "output": {"safe_output_default": True, "redact_fields": ["secret"]}, "export": {"allow_full_vault": True}, - "secret_isolation": {"enabled": False, "high_risk_kinds": [], "unlock_ttl_sec": 300}, + "secret_isolation": { + "enabled": False, + "high_risk_kinds": [], + "unlock_ttl_sec": 300, + }, "allow_kinds": ["document"], "deny_private_reveal": [], "allow_export_import": True, @@ -735,7 +743,11 @@ def test_agent_document_export_with_token_scope(monkeypatch, tmp_path): "approvals": {"require_for": []}, "output": {"safe_output_default": True, "redact_fields": ["secret"]}, "export": {"allow_full_vault": True}, - "secret_isolation": {"enabled": False, "high_risk_kinds": [], "unlock_ttl_sec": 300}, + "secret_isolation": { + "enabled": False, + "high_risk_kinds": [], + "unlock_ttl_sec": 300, + }, "allow_kinds": ["document"], "deny_private_reveal": [], "allow_export_import": True, diff --git a/src/tests/test_cli_core_services.py b/src/tests/test_cli_core_services.py index 24e4e83c..561ab6e0 100644 --- a/src/tests/test_cli_core_services.py +++ b/src/tests/test_cli_core_services.py @@ -45,7 +45,9 @@ def test_cli_vault_unlock_with_env_broker(monkeypatch): monkeypatch.setattr( cli.typer, "prompt", - lambda *a, **k: (_ for _ in ()).throw(AssertionError("prompt should not be called")), + lambda *a, **k: (_ for _ in ()).throw( + AssertionError("prompt should not be called") + ), ) result = runner.invoke(app, ["vault", "unlock", "--auth-broker", "env"]) assert result.exit_code == 0 diff --git a/src/tests/test_cli_entry_add_commands.py b/src/tests/test_cli_entry_add_commands.py index fd08ad91..5dc19318 100644 --- a/src/tests/test_cli_entry_add_commands.py +++ b/src/tests/test_cli_entry_add_commands.py @@ -247,7 +247,7 @@ def test_entry_export_document_command(monkeypatch): ], ) assert result.exit_code == 0 - assert "/tmp/doc.txt" in result.stdout + assert "/tmp/doc.txt" in result.stdout or "\\tmp\\doc.txt" in result.stdout assert called["args"] == (9, "/tmp/outdir") assert called["kwargs"] == {"overwrite": True} @@ -257,7 +257,13 @@ def test_entry_link_commands(monkeypatch): def add_link(entry_id, target_id, **kwargs): called["add"] = (entry_id, target_id, kwargs) - return [{"target_id": target_id, "relation": kwargs["relation"], "note": kwargs["note"]}] + return [ + { + "target_id": target_id, + "relation": kwargs["relation"], + "note": kwargs["note"], + } + ] def remove_link(entry_id, target_id, **kwargs): called["remove"] = (entry_id, target_id, kwargs) @@ -265,7 +271,15 @@ def test_entry_link_commands(monkeypatch): def get_links(entry_id): called["get"] = entry_id - return [{"target_id": 3, "relation": "references", "note": "", "target_label": "X", "target_kind": "document"}] + return [ + { + "target_id": 3, + "relation": "references", + "note": "", + "target_label": "X", + "target_kind": "document", + } + ] def start_background_vault_sync(): called["sync"] = called.get("sync", 0) + 1