Skip to content

Feature: Fix ui_element registry collisions; expand AI assistant docs with a verified example - #180

Merged
devsetgo merged 6 commits into
mainfrom
dev
Jul 19, 2026
Merged

Feature: Fix ui_element registry collisions; expand AI assistant docs with a verified example#180
devsetgo merged 6 commits into
mainfrom
dev

Conversation

@devsetgo

@devsetgo devsetgo commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Motivation

This pull request addresses two key areas to improve robustness and developer experience:

  1. Fixing ui_element Registry Collisions:
    Previously, it was possible for multiple input classes to silently register the same ui_element string, 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 duplicate ui_element assignments, enforcing a strict one-to-one mapping. This guarantees that every ui_element value in the documentation or code resolves to exactly one component, eliminating subtle UI bugs and making the system more predictable and maintainable.

  2. 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_element values. 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

  • Reliability: Enforcing unique ui_element mappings prevents hard-to-diagnose UI bugs and ensures consistent rendering for all field types.
  • Documentation Accuracy: The AI assistant docs are now guaranteed to match the code. Integrators and developers will always have an up-to-date, verified reference of valid ui_element values and examples.
  • Test Coverage: The new test increases confidence in both code and docs by catching mismatches early.
  • Developer Experience: The improved examples, clearer file structure references, and explicit FastAPI composition patterns make it easier for new users to understand and extend the project.

Summary:
This PR tightens input widget registration to prevent collisions and raises the bar for documentation quality by making all ui_element references authoritative and test-verified. This leads to more robust forms and a better developer/onboarding experience.

devsetgo and others added 4 commits July 5, 2026 01:44
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>
@devsetgo devsetgo added bug Something isn't working documentation Improvements or additions to documentation Code Improvements Improvement for quality or tests only labels Jul 19, 2026
devsetgo and others added 2 commits July 19, 2026 12:27
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>
@sonarqubecloud

Copy link
Copy Markdown

@devsetgo
devsetgo merged commit 01c68e5 into main Jul 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working chore Code Improvements Improvement for quality or tests only docs documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant