Conversation
Separates app bootstrapping from route definitions so the demo-app repo's sync process (diff lib-examples/fastapi_routes.py against its own routes file) doesn't have to re-derive which lines are routes vs. app setup on every sync. - examples/fastapi_routes.py (renamed from fastapi_example.py, history preserved): APIRouter with every route, ContactForm/FeedbackForm, CSRF helpers, Jinja2Templates/safe_json_filter, FORM_REGISTRY, and create_refer_path. Dropped imports that moved out with app bootstrap (FastAPI, StaticFiles, SessionMiddleware, os, sys) and the now-unneeded sys.path.insert, since this module is only ever imported, never run directly. - examples/main.py (new): thin composition root — FastAPI() construction, session middleware, the /static mount, app.include_router(router), and the uvicorn entrypoint banner. Updated every reference to match: makefile (ex-run/ex-test/kill, using `main` instead of `fastapi_example`), tests/test_integration.py and tests/test_layouts.py (which monkeypatch templates/safe_json_filter for test-time template resolution — repointed to fastapi_routes, the module that now actually owns those names), README.md (+ docs/index.md, synced the same way `make create-docs-local` does), docs/validation_guide.md, and examples/README.md. Verified both entrypoint styles work in a fresh subprocess: `python examples/main.py` (direct execution) and `cd examples && python -c "import main"` (the flat-import style `uvicorn main:app` relies on). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…erified example Several specialized input subclasses (BirthdateInput, PercentageInput, RatingInput, HoneypotInput, and others) inherited ui_element from their parent instead of declaring their own, so they silently won the registry slot for base names like "hidden", "date", "number", and "range" — e.g. ui_element="hidden" resolved to HoneypotInput, which discards the value it's given. Gave each specialized class its own distinct ui_element and added tests/test_input_registry.py to guard against future collisions. Also expanded the packaged AI-assistant docs (claude/copilot/generic) with a complete FormModel + FastAPI worked example (verified end-to-end with a TestClient) and an authoritative table of every valid ui_element value, to stop assistants from guessing at plausible-sounding widget names that silently fall back to a plain text input. Added a test that cross-checks each doc's table against the real registry so they can't drift again. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Hoist the str(...) conversions out of two pytest.raises blocks so only the call expected to raise remains inside each. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Motivation
This pull request addresses two key areas to improve robustness and developer experience:
Fixing
ui_elementRegistry Collisions:Previously, it was possible for multiple input classes to silently register the same
ui_elementstring, leading to ambiguous or incorrect widget rendering (e.g.,ui_element="hidden","date","number", or"range"could resolve unpredictably). This PR ensures the registry now rejects duplicateui_elementassignments, enforcing a strict one-to-one mapping. This guarantees that everyui_elementvalue in the documentation or code resolves to exactly one component, eliminating subtle UI bugs and making the system more predictable and maintainable.Expanding AI Assistant Documentation with a Verified Example:
The AI instructions and docs are enhanced with a complete, end-to-end tested example and an authoritative, automatically verified table of all supported
ui_elementvalues. This removes ambiguity for language model integrations and ensures that documentation, code, and registry remain in sync. The new test (test_authoritative_ui_element_table_matches_registry) fails if the docs and registry diverge, enforcing documentation accuracy and preventing future regressions.Why this improves the project
ui_elementmappings prevents hard-to-diagnose UI bugs and ensures consistent rendering for all field types.ui_elementvalues and examples.Summary:
This PR tightens input widget registration to prevent collisions and raises the bar for documentation quality by making all
ui_elementreferences authoritative and test-verified. This leads to more robust forms and a better developer/onboarding experience.