From 01a9eef06ce8490b79acdf14760db53b45a305d3 Mon Sep 17 00:00:00 2001 From: Jacob Nelson Date: Sun, 23 Aug 2026 17:18:01 -0500 Subject: [PATCH] feat(agent): post-deploy verify command --- agent/src/agent/verify.py | 42 ++++++++++++++++++++++++++++++++++++++ agent/tests/test_verify.py | 28 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 agent/src/agent/verify.py create mode 100644 agent/tests/test_verify.py diff --git a/agent/src/agent/verify.py b/agent/src/agent/verify.py new file mode 100644 index 0000000..0b7a97f --- /dev/null +++ b/agent/src/agent/verify.py @@ -0,0 +1,42 @@ +"""Post-deploy verification: `python -m agent.verify`.""" + +from __future__ import annotations + +from agent.config import AgentConfig, load_config +from agent.db import connect +from agent.firefly import FireflyClient + + +def verify(cfg: AgentConfig, client: FireflyClient | None = None) -> list[str]: + lines: list[str] = [] + + with connect(cfg) as conn: + migrations = conn.execute("SELECT count(*) FROM schema_migrations").fetchone()[0] + runs = conn.execute( + "SELECT connector, status, finished_at" + " FROM sync_runs ORDER BY id DESC LIMIT 3" + ).fetchall() + lines.append(f"agentdb: OK ({migrations} migration(s) applied)") + for connector, status, finished_at in runs: + lines.append(f" last run: {connector} {status} at {finished_at}") + + if client is None: + client = FireflyClient(cfg.firefly_url, cfg.firefly_token) + info = client.about() + lines.append(f"firefly: OK (version {info.get('version', 'unknown')})") + + accounts = client.accounts() + lines.append(f"firefly: {len(accounts)} asset account(s):") + for account in accounts: + lines.append(f" - {account['attributes']['name']}") + return lines + + +def main() -> int: + for line in verify(load_config()): + print(line) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/agent/tests/test_verify.py b/agent/tests/test_verify.py new file mode 100644 index 0000000..69d5316 --- /dev/null +++ b/agent/tests/test_verify.py @@ -0,0 +1,28 @@ +from agent.db import ensure_database, run_migrations +from agent.jobs.heartbeat import run_heartbeat +from agent.verify import verify + + +class FakeFirefly: + def about(self) -> dict: + return {"version": "6.1.1"} + + def accounts(self, type: str = "asset") -> list[dict]: + return [ + {"id": "1", "attributes": {"name": "NFCU Checking"}}, + {"id": "2", "attributes": {"name": "Venmo"}}, + ] + + +def test_verify_reports_db_firefly_and_accounts(cfg): + ensure_database(cfg) + run_migrations(cfg) + run_heartbeat(cfg, client=FakeFirefly()) + + report = "\n".join(verify(cfg, client=FakeFirefly())) + + assert "1 migration(s) applied" in report + assert "heartbeat ok" in report + assert "firefly: OK (version 6.1.1)" in report + assert "2 asset account(s)" in report + assert "NFCU Checking" in report