mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-07-26 03:22:55 +02:00
94dd4c9b42
Replaces the httpx-based smoke tests in tests/e2e/ with a browser E2E suite
under e2e/, running against a self-contained throwaway stack that never
touches the local development database.
Stack & data isolation (e2e/docker-compose.test.yml):
- Own ephemeral Postgres 17 (schema via the `migrate` service / Alembic),
distinct project name + named volumes, no host DB port, no \${VAR}
interpolation. `make e2e-down` destroys everything.
- OIDC enabled with a known session secret; WEB_AUTO_REFRESH_SECONDS=2 so
polling is assertable; CONTENT_HOME mounts a test markdown page.
- Deterministic seeder (e2e/seed_data.py) run via global setup inside the
collector container: nodes/observers with `area` tags, adverts, messages
on the public (17) + a custom channel, raw packets + path hops keyed to
node prefixes, a route + health/history, profiles + adoptions, and
event_observers rows so the observer filter/badges resolve.
Auth & tests:
- Forged signed `meshcore-session` cookies (e2e/mint_session.py,
itsdangerous) for admin/member identities -> storageState; no real IdP
needed. 31 specs across 12 files cover global nav/theme, profile
menu+edit, home hero, dashboard widgets, list filters/auto-refresh/row
actions, observer toggles, the path-node overlay, map filters +
show-labels, members, markdown pages, and routes add/edit/delete
(persistence, validation, confirm dialog). workers:1 / fullyParallel:false
against the single shared backend; targeted data-testids added to React
components for stable selectors.
Fixes surfaced while running the suite on fresh Postgres:
- Migration 5e3b712ccf10 aborted on Postgres: its route-health backfill
queries the live Route model (which now has max_path_length) before that
column exists. The swallowed error left the transaction aborted, killing
the subsequent alembic_version stamp. Wrapped the backfill in a SAVEPOINT
so a failure rolls back cleanly without blocking the migration.
- Restored the full ABUSE_* env set required by the MQTT broker, and set
the web service's API_KEY to the admin key (admin writes go through the
proxy as a Bearer token).
31/31 passing; tsc (frontend+e2e), pytest (1460), and pre-commit green.
75 lines
2.4 KiB
Makefile
75 lines
2.4 KiB
Makefile
COMPOSE_PROJECT_NAME ?= hub
|
|
PROFILES ?= mqtt core
|
|
COMPOSE_FILES = -f docker-compose.yml -f docker-compose.dev.yml
|
|
VOLUMES = $(COMPOSE_PROJECT_NAME)_data $(COMPOSE_PROJECT_NAME)_mqtt_data \
|
|
$(COMPOSE_PROJECT_NAME)_observer_data
|
|
|
|
.PHONY: build up down logs backup restore test test-cov test-unit test-frontend \
|
|
e2e-build e2e-up e2e-down e2e-seed e2e-test
|
|
|
|
build:
|
|
docker compose $(COMPOSE_FILES) --profile all build --no-cache
|
|
|
|
up:
|
|
docker compose $(COMPOSE_FILES) $(foreach p,$(PROFILES),--profile $(p)) up -d --force-recreate
|
|
|
|
down:
|
|
docker compose $(COMPOSE_FILES) --profile all down --remove-orphans
|
|
|
|
logs:
|
|
docker compose $(COMPOSE_FILES) --profile all logs -f
|
|
|
|
backup:
|
|
@mkdir -p backup
|
|
@for vol in $(VOLUMES); do \
|
|
echo "Backing up $$vol..."; \
|
|
docker run --rm -v $$vol:/data -v $(PWD)/backup:/backup \
|
|
alpine tar czf /backup/$$vol-$$(date +%Y%m%d-%H%M%S).tar.gz -C / data; \
|
|
done
|
|
@echo "Backups saved to $(PWD)/backup/"
|
|
|
|
restore:
|
|
@if [ -z "$(FILE)" ]; then echo "Usage: make restore FILE=backup/<tarball>"; exit 1; fi
|
|
@vol=$$(basename $(FILE) | sed 's/-[0-9]\{8\}-[0-9]\{6\}\.tar\.gz//'); \
|
|
echo "Restoring $$vol from $(FILE)..."; \
|
|
docker run --rm -v $$vol:/data -v $(PWD)/backup:/backup \
|
|
alpine sh -c "cd / && tar xzf /backup/$$(basename $(FILE))"
|
|
|
|
# --- Tests ---------------------------------------------------------------
|
|
# Coverage is opt-in (use test-cov). Dev loop runs in parallel across cores.
|
|
# `test` runs the backend suite then the frontend (vitest) suite.
|
|
test:
|
|
pytest -nauto --no-cov
|
|
$(MAKE) test-frontend
|
|
|
|
test-cov:
|
|
pytest --cov=meshcore_hub --cov-report=term-missing
|
|
|
|
test-unit:
|
|
pytest -nauto --no-cov tests/test_common/ tests/test_api/ tests/test_collector/ tests/test_web/
|
|
|
|
test-frontend:
|
|
npm run test:frontend
|
|
|
|
# --- E2E (Playwright) ---------------------------------------------------
|
|
# Self-contained throwaway stack (own ephemeral Postgres, isolated volumes).
|
|
# make e2e-build && make e2e-up # start the stack (build first time)
|
|
# make e2e-test # seeds data, then runs the Playwright suite
|
|
# make e2e-down # tears everything down (destroys the DB)
|
|
E2E_COMPOSE = docker compose -f e2e/docker-compose.test.yml
|
|
|
|
e2e-build:
|
|
$(E2E_COMPOSE) build
|
|
|
|
e2e-up:
|
|
$(E2E_COMPOSE) up -d
|
|
|
|
e2e-down:
|
|
$(E2E_COMPOSE) down -v --remove-orphans
|
|
|
|
e2e-seed:
|
|
$(E2E_COMPOSE) exec -T collector python /seed_data.py
|
|
|
|
e2e-test:
|
|
npm run test:e2e
|