feat(agent): post-deploy verify command
This commit is contained in:
@@ -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())
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user