Repository navigation
fix(cli): validate collects @widget routes passed through a helper (#116) - #127
Conversation
…itrocloudofficial#116) @widget(helper("route")) and @widget(helper(route="route", ...)) are now collected, so the pizzaz template's three widgets are checked. A helper call with other positional arguments is skipped, since its first string is not necessarily the route.
|
Check:
|
|
Reviewed with develop ( ~sent from claude-code |
|
@manish-wekan results of the check you asked for, using the head of this PR (
|
…tes (nitrocloudofficial#116) An unrelated @widget(something("x")) call is no longer taken as a route, so it cannot cause a false 'missing HTML' warning. Helpers are found by parsing the project for functions that build a WidgetOptions (any file), plus WidgetOptions itself. The CLI test moves to tests/test_validate_widgets.py and runs the real command in a subprocess, so tests/test_cli.py stays at its 1589-line baseline.
|
@manish-wekan thanks, both points from your review are addressed in False positives from an unrelated helper. A helper call is now taken as a route only if it is test_cli.py size. I moved my CLI test out of CI is green on 3.10, 3.11 and 3.12. The screenshots from the deployment check are in the comment above. |
jpsiddharth2008
left a comment
There was a problem hiding this comment.
The Pizzaz fix and file-length changes look good. Two false-positive cases remain:
- panel("dashboard") returning WidgetOptions(route="card", description=description) incorrectly checks for dashboard.html.
- Helper names are matched globally, so a widget factory named panel in one module can cause an unrelated panel elsewhere to be classified as a factory.
Please verify that the argument feeds WidgetOptions.route, resolve helpers by their actual scope/import binding, and add regression tests for both case
…rocloudofficial#116) validate used a project-wide name match, so panel('dashboard') was checked for dashboard.html even when panel never passed that argument to WidgetOptions.route, and an unrelated panel in another module could be taken for a widget factory. Route discovery moves to nitrostack/cli/widget_routes.py and parses each file: - a function is a factory only if one of its parameters reaches WidgetOptions(route=...) (directly, or through another factory) and is not reassigned - the string is read from the argument at that parameter's position or keyword - a call counts only if its name resolves through the calling module's own definitions and imports (local def, from-import, alias, import module, relative import, class staticmethod/classmethod) to a real factory - a file that does not parse still yields its literal routes validators.py keeps only the file walk, so it drops from 499 to 454 lines.
|
@jpsiddharth2008 thanks, both cases are fixed in 1. The argument must feed 2. Names resolve through the calling module's own scope. A call counts only if its name resolves to a real factory through that module's definitions and imports: a local Tests (8 new, all fail on the previous commit): the The pizzaz template still reports its 3 routes. CI is green on 3.10, 3.11 and 3.12. |
…orators in validate Two regressions in the AST route discovery added in #127: - A name re-exported through a project module (for example shared/__init__.py doing `from nitrostack import WidgetOptions`) was not followed, so `from shared import WidgetOptions` skipped the missing-HTML check. Name lookup now follows re-exports through project modules, with a guard against import cycles. - Any decorator ending in `.widget` was treated as the SDK decorator, so `@pytest.mark.widget("smoke")` warned about a missing smoke.html. A `widget` decorator now counts only when it resolves to the SDK's own, by direct import, `import nitrostack`, or a project re-export. Adds regression tests for both, including aliases, multi-hop and cyclic re-exports, and a non-SDK name that is re-exported.



Fixes #116.
Problem
nitrostack-py validateonly found@widgetroutes written as string literals orWidgetOptions(route=...). The pizzaz template uses@widget(pizzaz_widget("pizza-map")), so its 3 widgets were never checked.Change
_collect_widget_routesalso collects:@widget(helper("route"))(a call whose only argument is the route)@widget(helper(route="route", ...))A helper call with other positional arguments is skipped on purpose. Its first string is not necessarily the route, and a wrong guess would give false warnings. Routes found this way go through the same checks as before (valid segment,
widgets/out/<route>.htmlexists and is not empty).I used the source-pattern option from the issue. Collecting routes from the registered app at runtime would need the project to import and run, which
validateavoids today.Tests
tests/test_validate_widgets.py: helper-wrapped routes (positional, dotted, keyword) are collected, pass when the HTML exists, an unsafe route is reported, other positional arguments are not guessed.pizza-list.htmlfrom a copy of the pizzaz template gives onefile is missingwarning.tests/test_cli.py: runs the realvalidatecommand on a copy of the pizzaz template. Clean output first, then a warning for only the removed widget.4 of the new tests and the CLI test fail without the fix. Full suite locally: 1330 passed. The failures are the code-mode template and wheel-build tests in
tests/test_project_templates.py, which also fail on unmodifieddevelophere because my venv lackssetuptoolsand the code-mode dependencies.