Skip to content

Post-refactor test suite cleanup #18

@davidchris

Description

@davidchris

Follow-up to the packaging refactor (moving api/, web/, static/, main.py under src/fafycat/; introducing src/fafycat/cli.py as the unified entry point; switching AppConfig defaults to platformdirs).

The test suite was hardened ahead of the refactor so it can serve as a safety net. Once the refactor lands, a small set of cleanup tasks flips the suite from "works on both sides" to "post-refactor-native."

Checklist

1. Flip the TOUCHPOINT imports in tests/conftest.py

Change the five right-hand strings in the importlib.import_module(...) block:

  • \"src.fafycat.core.database\"\"fafycat.core.database\"
  • \"src.fafycat.core.config\"\"fafycat.core.config\"
  • \"main\"\"fafycat.app\"
  • \"api.dependencies\"\"fafycat.api.dependencies\"
  • \"api.ml\"\"fafycat.api.ml\"

2. Remove the sys.path bootstrap

  • Delete the sys.path.insert(0, str(_SRC)) / sys.path.insert(0, str(_ROOT)) block at the top of tests/conftest.py (uv sync + editable install makes fafycat importable directly).
  • Remove _SRC / _ROOT references in cli_runner's PYTHONPATH assembly — the subprocess should pick up fafycat from the installed venv.
  • Remove sys.path.insert hacks still present in individual test modules (e.g. tests/test_ml_endpoints_simple.py previously had one; audit with rg 'sys\\.path\\.insert' tests/).

3. Simplify the tmp_data_dir fixture

Once AppConfig derives DB URL, model_dir, and export_dir from FAFYCAT_DATA_DIR, drop the defensive per-leaf env vars:

  • Keep monkeypatch.setenv(\"FAFYCAT_DATA_DIR\", ...) only.
  • Remove FAFYCAT_DB_URL, FAFYCAT_MODEL_DIR, FAFYCAT_EXPORT_DIR sets.
  • Verify tests/test_app_config.py still passes.

4. Simplify _get_cli_module()

  • Delete the try/except fallback in tests/conftest.py; hardcode return \"fafycat\".

5. Add the post-refactor-only AppConfig default test

  • In tests/test_app_config.py, add test_data_dir_defaults_to_platformdirs_when_env_unset: unset every FAFYCAT_* env var via monkeypatch.delenv, instantiate AppConfig, assert str(cfg.data_dir) == platformdirs.user_data_dir(\"fafycat\").

6. Add package entry-point tests

New file tests/test_package_entry_points.py with:

  • test_fafycat_app_importablefrom fafycat.app import app, create_app succeeds.
  • test_fafycat_cli_importablefrom fafycat.cli import main succeeds.
  • test_python_m_fafycat_runscli_runner(\"--help\") exits 0 (the _get_cli_module() shim already resolves to fafycat post-refactor).

7. Follow-up brittleness (not blocking the refactor, but worth addressing while the suite is fresh)

  • Hardcoded year references in tests/test_analytics_api.py (2023/2024 fixtures) and tests/test_api_automation.py (date(2025, 6, 15)) will silently rot as the current year advances. Parameterize or derive from date.today().
  • tests/test_ml_status_ui.py globally patches pathlib.Path.exists. Scope to a specific path to avoid cross-contamination.
  • tests_js/ isn't wired into CI or an npm test script. Either wire it up or remove if unused.

Acceptance

  • uv run pytest stays green with the full refactor + all post-refactor cleanup applied.
  • The refactor's parity tests (tests/test_app_factory.py, tests/test_static_serving.py, tests/test_cli.py, tests/test_app_config.py) still pass.
  • rg 'src\\.fafycat|from main import|from api\\.|from web\\.' tests/ returns zero hits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions