Skip to content

Modernize asprom: tests, logging, Python 3 refactor, Alembic migrations - #2

Draft
daimoniac wants to merge 12 commits into
masterfrom
cursor/asprom-modernization-404b
Draft

Modernize asprom: tests, logging, Python 3 refactor, Alembic migrations#2
daimoniac wants to merge 12 commits into
masterfrom
cursor/asprom-modernization-404b

Conversation

@daimoniac

@daimoniac daimoniac commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the asprom modernization plan: dev tooling, a full characterization test suite, structured logging, Python 3 cleanup, parameterized SQL, bug fixes, and Alembic migrations.

Key changes

Phase 0 — Tooling

  • pyproject.toml, pytest.ini, scripts/check.sh (ruff + pytest + mypy + coverage gate)
  • GitHub Actions CI with MySQL 8.0 service container
  • Removed dead __init__.py pymysql shim

Phase 1 — Regression test suite

  • tests/conftest.py with MySQL fixtures (ASPROM_TEST_DB_* env vars; testcontainers optional via ASPROM_USE_TESTCONTAINERS=1)
  • 41 tests covering domain model, SQL views, scan (mocked nmap), Nagios exit codes, schedule parsing
  • inc/db.pyget_db() / set_db() decouples Bottle request.db from CLI/tests

Phase 2 — Structured logging

  • inc/logging.py with structlog (JSON via ASPROM_LOG_FORMAT=json)
  • Replaced print() in all entry points and inc/asprom.py

Phase 3 — Python 3 refactor

  • Modern class syntax, type hints, parameterized SQL throughout Service/Machine/Model/scan
  • mypy inc/ enforced in CI

Phase 4 — Bug fixes

  • Nagios check: removed erroneous start_http_server(5000) call
  • Machine.delete(): fixed exposure log logic, cascade-deletes child records, removes machine row
  • getScannedRanges(): implemented on AspromScheduleModel

Phase 5 — Alembic migrations

  • Baseline no-op revision 001, rename unique keys 002
  • ASPROM_RUN_MIGRATIONS=1 runs alembic upgrade head in Docker start script
  • db/ddl.sql unchanged for Docker first-boot

Phase 6 — Coverage

  • 72% coverage on inc/ (gate: 70%)
  • Gap-fill tests for metrics, controller rescans, schedule job mocks, changelog HTML

CI fix

  • tests/test_migrations.py used hardcoded cwd="/workspace" which fails on GitHub Actions (/home/runner/work/asprom/asprom). Now uses repo root via Path(__file__).

Pre-commit workflow

ASPROM_COV_FAIL_UNDER=70 ./scripts/check.sh

Test plan

  • ASPROM_COV_FAIL_UNDER=70 ASPROM_RUN_MYPY=1 ./scripts/check.sh — 41 passed
  • Integration tests against local MySQL (127.0.0.1:3306/asprom_test)
  • CI run on GitHub Actions (MySQL service container)
Open in Web Open in Cursor 

cursoragent and others added 12 commits June 29, 2026 13:30
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
- Discover MySQL service via kubectl (internal1/asprom by default)
- Port-forward to localhost and run aspromGUI with generated config
- Support ASPROM_CFG override in Cfg for non-default config paths

Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
- Document venv + apt packages for mysqlclient build (PEP 668)
- Bump mysqlclient to 2.2.8 for Python 3.14 support
- dev-prod.sh prefers ./venv/bin/python3 when present

Co-authored-by: Stefan Knott <daimoniac@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants