Skip to content

Add tests and fix bugs#1

Merged
glen-level12 merged 3 commits into
level12:mainfrom
glen-level12:bug-fixes
Jun 4, 2026
Merged

Add tests and fix bugs#1
glen-level12 merged 3 commits into
level12:mainfrom
glen-level12:bug-fixes

Conversation

@glen-level12
Copy link
Copy Markdown
Collaborator

Added test to confirm functionality
A lot of tests, found 8 bugs, made a few small code improvements.

# File The bug User-visible symptom Fix
1 context.pyuser_resolve Only caught RuntimeError. When flask_login is installed but no LoginManager is configured, current_user._get_current_object() raises AttributeError. Every request 500s (the before_request hook calls user_resolve). Catch (RuntimeError, AttributeError) and degrade to "no user".
2 hypergen.pycheck_perms Looked up the login manager via current_app.extensions['login_manager'], but flask_login stores it as current_app.login_manager. The auto-redirect-to-login fallback (when login_url isn't passed) never fired; returned 403 instead of a 302 redirect. Prefer getattr(current_app, 'login_manager', None), falling back to the extensions dict.
3 imports.py — flat-namespace re-export from flask_hypergen import context as context_module resolved the instance context (shadowed by __init__), not the submodule, so its __all__ was empty. from flask_hypergen.imports import * silently exported only template and websocket, dropping context, liveview, action, callback, etc. Load real submodules via importlib.import_module(...).
4 liveview.py — callback payload Emitted the key eachUrlBlocks. Key name didn't match the JS client (blocksEachUrl), so the client never read it. Rename to blocksEachUrl.
5 liveview.pyENCODINGS No encoder for datetime.time. Serializing a time value failed or didn't round-trip. Add dt_time: lambda o: {'_': ['time', str(o)]}.
6 hypergen.pyplugins_exit_stack Hard-coded plugin.context() regardless of the requested method_name. Dynamic dispatch was broken; it always entered .context() even when asked for a different plugin method. Use stack.enter_context(getattr(plugin, method_name)()).
7 context.py — nested-context update guard if not new_value_at: treated a legitimately empty pmap as the "not immutable" failure (empty pmap is falsy). Nesting with context() where the merged result was an empty pmap wrongly raised TypeError ("Not immutable context variable…"). Change to if new_value_at is None: so only a real dict.update()None indicates a mutable value.

Tooling/dev-env bug (not in the library)

# File The bug Symptom Fix
8 tasks/mise-uv-init.py #!/usr/bin/env python3 shebang. During mise's env evaluation, env python3 resolves to mise's own shim, re-entering mise. mise exhausts process limits (os error 11) before any virtual environment exists. Replace with a polyglot /bin/sh + Python bootstrap that re-execs under the first real system python3 (plus a ruff.toml E402 per-file ignore).

@rsyring
Copy link
Copy Markdown
Member

rsyring commented Jun 4, 2026

I approved CI to run and it's currently failing.

Please provide better commit messages.

@glen-level12
Copy link
Copy Markdown
Collaborator Author

The CI issues appear to pre-date these changes. Folded in the fixes with a more detailed commit message.

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Jun 4, 2026

augment review

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Jun 4, 2026

🤖 Augment PR Summary

Summary: This PR substantially expands the test suite and fixes multiple functional bugs uncovered by the new coverage.

Changes:

  • Hardened context/user resolution to avoid 500s when flask_login is present but not fully configured.
  • Fixed permission/login redirect behavior by correctly locating Flask-Login’s login_manager.
  • Corrected plugin context dispatch so plugins_exit_stack enters the requested plugin method, not always .context().
  • Reworked flat-namespace re-exports in imports.py to import real submodules (avoiding name shadowing).
  • Aligned LiveView callback payload keys with the JS client (blocksEachUrl) and added JSON encoding for datetime.time.
  • Improved attribute handling in templates (removed a hard assertion) and added coverage for quote escaping.
  • Added extensive new tests across core APIs (routing, permissions, plugins, serialization, liveview/action behavior).
  • Tooling updates: Playwright Chromium install in nox, Ruff config tweaks, and a safer mise-uv-init bootstrap.

Technical Notes: Coverage notes are documented (including deliberate gaps/xfails) and overall coverage is reported as ~99%.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread noxfile.py
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

- Catch (RuntimeError, AttributeError) and degrade to "no user"
- Prefer getattr(current_app, 'login_manager', None), falling back to the extensions dict.
- Load real submodules via importlib.import_module(...)
- Rename to blocksEachUrl
- Add dt_time: lambda o: {'_': ['time', str(o)]}
- Use stack.enter_context(getattr(plugin, method_name)())
- Change to if new_value_at is None: so only a real dict.update() → None indicates a mutable value
- Replace with a polyglot /bin/sh + Python bootstrap that re-execs under the first real system python3
@glen-level12 glen-level12 merged commit d4939ed into level12:main Jun 4, 2026
5 checks passed
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