Skip to content

API refactor and front-end tests#95

Merged
shaddi merged 8 commits into
mainfrom
api-refactor-and-tests
Jun 6, 2026
Merged

API refactor and front-end tests#95
shaddi merged 8 commits into
mainfrom
api-refactor-and-tests

Conversation

@shaddi

@shaddi shaddi commented Jun 6, 2026

Copy link
Copy Markdown
Member

Big refactor of the main API router into blueprints to avoid one giant routes file. Adds a synthetic end-to-end test and fake data fixture. Adds first front-end tests and standardizes front-end response format (previously, these varied by API endpoint).

shaddi added 8 commits June 5, 2026 20:25
Add a committable, anonymized test dataset (real coverage/fiber geometry
affine-transformed onto a synthetic fabric footprint) plus an end-to-end test
that runs the coverage pipeline over it and pins the resulting served-location
counts. Mount the fixture into the test container so the e2e runs in CI.
Break the single large routes.py into a routes/ package of Flask blueprints
grouped by domain (auth, users, organizations, filings, files, edit, tiles,
export, wireless, tasks, challenge, admin), with shared email helpers in
routes/_email.py. routes/__init__.py registers the blueprints on the app and
re-exposes `app` so `gunicorn routes:app` is unchanged; `python -m routes` runs
the dev server. All endpoint paths are unchanged.
Add get_session() backed by a scoped_session and a teardown_appcontext that
rolls it back and closes it at the end of each request, replacing the
per-handler Session() + try/finally/close boilerplate in the route handlers.

Also fix fabric_ops.write_to_db, which acquired and closed the scoped session:
harmless across processes, but under eager task execution it runs on the web
request's thread and would detach that request's in-flight ORM objects. It now
uses its own Session().
Add indexes on the columns behind the heaviest queries: kml_data and
fabric_data (file_id, location_id), celerytaskinfo (organization_id), and a
composite index on vector_tiles (mbtiles_id, zoom_level, tile_column, tile_row).
Declared on the models and created by an alembic migration; a test pins the
expected index set.
Move the filing-delete, upload-dispatch (create/import), export, and edit-apply
logic out of the route handlers into a services/ package. Service functions take
plain arguments and a database session and return plain data, so they are
testable without Flask; they raise ServiceError(message, status) for expected
failures, which the handlers translate into responses. Handlers become thin
request-parse-and-delegate wrappers. Adds unit tests for each flow.
Configure Jest via next/jest (jsdom environment, no browser) with an `npm test`
script and a CI job, and add initial component tests that pin how components read
API response shapes.
Return all error responses in a consistent {status: 'error', message} shape,
give failures proper HTTP status codes (several previously returned 200), and add
a global handler so unexpected exceptions return a clean JSON 500 instead of an
HTML error page. Update the one frontend component that read the previous error
key.
os.getenv returns a string and a non-empty value such as "0" is truthy in
Python, so a dev setting of IN_PRODUCTION=0 silently enabled production behavior
(Secure auth cookies). Interpret only explicit truthy strings ("1", "true", ...)
as production.
@shaddi shaddi merged commit 92d5062 into main Jun 6, 2026
2 checks passed
@shaddi shaddi deleted the api-refactor-and-tests branch June 9, 2026 00:33
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.

1 participant