mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-07 13:22:26 +00:00
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 <[email protected]>
This commit is contained in:
1 parent
d71e7d6bc9
commit
c933bcd43f
9 files changed
+68
-23
No files matched your search
@@ -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
|
||||
|
||||
+16
-5
@@ -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,
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
"""TUI v2 package scaffold (Textual-backed)."""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user