-
-
Notifications
You must be signed in to change notification settings - Fork 117
Test and Index fix #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NeptuneHub
wants to merge
6
commits into
main
Choose a base branch
from
devel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test and Index fix #682
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82f70b6
UI/UX: accessibility pass + converge buttons onto .btn utilities
NeptuneHub ed87742
multiple fix
NeptuneHub 62a7700
test fix
NeptuneHub 0c7e0ae
REMOVED db migration and limiter
NeptuneHub e8e3079
remove blank space on app_auth.py
NeptuneHub 61c9e36
setup wizard dark mode fix
NeptuneHub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Coverage.py configuration for the unit test suite. | ||
| # Measures only first-party code: third-party venvs, the native standalone | ||
| # builds, screenshots and the test tree itself are excluded so the percentage | ||
| # reflects the application, not its dependencies. | ||
| [run] | ||
| branch = True | ||
| source = . | ||
| omit = | ||
| test/* | ||
| .venv/* | ||
| .venv-windows/* | ||
| native-build/* | ||
| screenshot/* | ||
| dist/* | ||
| query/* | ||
| */__pycache__/* | ||
|
|
||
| [report] | ||
| show_missing = True | ||
| skip_covered = False | ||
| precision = 1 | ||
| exclude_also = | ||
| if __name__ == .__main__.: | ||
| raise NotImplementedError | ||
| if TYPE_CHECKING: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Type Check (mypy) | ||
|
|
||
| # Static type-checking scoped (via mypy.ini) to small, self-contained core | ||
| # modules so the gate passes today and can be widened as modules gain hints. | ||
| # Independent of the test/build workflows. | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
| push: | ||
| branches: [ main ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| mypy: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install mypy | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install mypy | ||
|
|
||
| - name: Run mypy (scoped to core modules via mypy.ini) | ||
| run: mypy --config-file mypy.ini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Versioned, ordered schema migrations. | ||
| # | ||
| # The base schema is created idempotently by database.init_db(). This module | ||
| # layers run-once, ordered migrations on top and records applied versions in the | ||
| # schema_version table, giving a real upgrade path between releases. To add a | ||
| # migration, append (version, name, fn) to MIGRATIONS with the next integer; | ||
| # never edit or renumber a migration that has already shipped. | ||
|
|
||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Everything created by init_db() is recorded as the baseline. | ||
| BASELINE_VERSION = 0 | ||
|
|
||
|
|
||
| def _ensure_version_table(cur): | ||
| cur.execute( | ||
| "CREATE TABLE IF NOT EXISTS schema_version (" | ||
| "version INTEGER PRIMARY KEY, " | ||
| "name TEXT NOT NULL, " | ||
| "applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)" | ||
| ) | ||
|
|
||
|
|
||
| def _applied_versions(cur): | ||
| cur.execute("SELECT version FROM schema_version") | ||
| return {row[0] for row in cur.fetchall()} | ||
|
|
||
|
|
||
| # Ordered migrations. Each fn receives a live DB cursor and applies one change. | ||
| # Example: | ||
| # def _m1_add_score_bpm(cur): | ||
| # cur.execute("ALTER TABLE score ADD COLUMN IF NOT EXISTS bpm REAL") | ||
| # MIGRATIONS = [(1, "add score.bpm", _m1_add_score_bpm)] | ||
| MIGRATIONS: list = [] | ||
|
|
||
|
|
||
| def run_schema_migrations(cur, migrations=None): | ||
| # Apply every not-yet-applied migration in version order; returns the count | ||
| # newly applied. Idempotent: a migration already in schema_version is skipped. | ||
| migrations = MIGRATIONS if migrations is None else migrations | ||
| _ensure_version_table(cur) | ||
| done = _applied_versions(cur) | ||
|
|
||
| if BASELINE_VERSION not in done: | ||
| cur.execute( | ||
| "INSERT INTO schema_version (version, name) VALUES (%s, %s) " | ||
| "ON CONFLICT (version) DO NOTHING", | ||
| (BASELINE_VERSION, "baseline"), | ||
| ) | ||
| done.add(BASELINE_VERSION) | ||
|
|
||
| applied = 0 | ||
| for version, name, fn in sorted(migrations, key=lambda m: m[0]): | ||
| if version in done: | ||
| continue | ||
| logger.info("Applying schema migration %d: %s", version, name) | ||
| fn(cur) | ||
| cur.execute( | ||
| "INSERT INTO schema_version (version, name) VALUES (%s, %s) " | ||
| "ON CONFLICT (version) DO NOTHING", | ||
| (version, name), | ||
| ) | ||
| done.add(version) | ||
| applied += 1 | ||
| return applied | ||
|
|
||
|
|
||
| def get_schema_version(cur): | ||
| # Highest applied version, or -1 if the table is empty / absent. | ||
| _ensure_version_table(cur) | ||
| cur.execute("SELECT COALESCE(MAX(version), -1) FROM schema_version") | ||
| return cur.fetchone()[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Static type-checking, scoped to small, self-contained core modules so the | ||
| # check is a real gate that passes today. Widen `files` as more modules gain | ||
| # type hints. The bulk of the codebase is untyped, hence the lenient defaults | ||
| # (no disallow_untyped_defs) -- this catches concrete type errors, not missing | ||
| # annotations. | ||
| [mypy] | ||
| python_version = 3.11 | ||
| ignore_missing_imports = True | ||
| # Errors are reported only for the modules listed in `files`; imported-but-not | ||
| # scoped modules are followed for type info but their own errors are suppressed. | ||
| follow_imports = silent | ||
| warn_redundant_casts = True | ||
| no_implicit_optional = True | ||
| warn_unused_ignores = False | ||
| show_error_codes = True | ||
| files = | ||
| config.py, | ||
| db_migrations.py, | ||
| sanitization.py, | ||
| ssrf_guard.py, | ||
| tz_helper.py, | ||
| proxy_prefix.py, | ||
| rate_limit.py, | ||
| error/ | ||
|
|
||
| # Tests are not type-checked. | ||
| [mypy-test.*] | ||
| ignore_errors = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Shared flask-limiter instance. | ||
| # | ||
| # Defined in its own module (importing nothing from app.py / app_auth.py) so | ||
| # both the app factory and the auth routes can attach limits without a circular | ||
| # import. Enforcement only happens once limiter.init_app(app) runs in app.py; | ||
| # unit tests that build a bare Flask app and never call it are unaffected. | ||
| # | ||
| # flask-limiter is treated as optional: if it is not installed (e.g. a slim | ||
| # build variant), rate limiting degrades to a no-op rather than crashing the | ||
| # app at import time. | ||
|
|
||
| import logging | ||
|
|
||
| import config | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class _NoopLimiter: | ||
| # Stand-in used when flask-limiter is unavailable. limit() returns an | ||
| # identity decorator and init_app() does nothing, so callers are unchanged. | ||
| def limit(self, *args, **kwargs): | ||
| def decorator(func): | ||
| return func | ||
| return decorator | ||
|
|
||
| def init_app(self, app): | ||
|
Check warning on line 27 in rate_limit.py
|
||
| return None | ||
|
|
||
|
|
||
| try: | ||
| from flask_limiter import Limiter | ||
| from flask_limiter.util import get_remote_address | ||
|
|
||
| # default_limits is empty: only explicitly decorated endpoints (login, user | ||
| # administration) are limited, so normal high-frequency polling is never | ||
| # throttled. storage falls back to in-process memory when Redis is | ||
| # unreachable; swallow_errors keeps a storage hiccup from 500-ing a request | ||
| # (it fails open rather than locking users out). | ||
| limiter = Limiter( | ||
| key_func=get_remote_address, | ||
| default_limits=[], | ||
| storage_uri=config.RATE_LIMIT_STORAGE_URI or "memory://", | ||
| strategy="fixed-window", | ||
| swallow_errors=True, | ||
| enabled=config.RATE_LIMIT_ENABLED, | ||
| ) | ||
| except ImportError: | ||
| logger.warning("flask-limiter not installed; API rate limiting is disabled.") | ||
| limiter = _NoopLimiter() # type: ignore[assignment] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.