Feature/SOF-7728 Update: add visualization with Prove#267
Conversation
📝 WalkthroughWalkthroughIntroduces a generalized viewer infrastructure in Changes
Sequence Diagram(s)(Skipped — changes are primarily refactor + a notebook update; no multi-component control flow requiring a sequence diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
7f54067 to
0763bf5
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Feature/sof-7728-1 update: optimize wave + prove
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@utils/visualize.py`:
- Around line 403-409: The code currently treats empty containers as falsy so
extra_config passed as {} or [] becomes the string "undefined"; change the
truthiness check to an explicit None check so only None maps to "undefined". In
visualize.py locate the block that sets extra_config_json (referencing the
extra_config variable and the extra_config_json assignment) and replace the
conditional expression that uses truthiness with a check like "if extra_config
is not None" so that empty dicts/lists serialize to their JSON ("{}"/"[]") while
None remains "undefined".
🧹 Nitpick comments (1)
utils/visualize.py (1)
190-230: CSS may not be loaded before the render function executes.The
css_loaderblock (inserting the<link>tag) is placed after the async IIFE that awaits the bundle and calls the render function. While the<link>insertion is synchronous, the browser fetches the stylesheet asynchronously. If the bundle resolves from cache before the stylesheet arrives, the viewer could briefly render unstyled.Consider moving the CSS insertion before the async IIFE so the browser starts fetching the stylesheet earlier:
Proposed fix
return f""" + {css_loader} const {data_var_name}={data_json}; const container = document.getElementById('{div_id}'); (async function() {{ await import('{bundle_url}'); window.{render_function}({data_var_name}, container{extra_config_arg}); }})(); - {css_loader} """
| if isinstance(results, dict): | ||
| results = [results] | ||
|
|
||
| timestamp = time.time() | ||
| div_id = f"prove-{timestamp}" | ||
| results_json = json.dumps(results) | ||
| extra_config_json = json.dumps(extra_config) if extra_config else "undefined" |
There was a problem hiding this comment.
extra_config={} silently becomes JS undefined due to falsy check.
bool({}) is False in Python, so passing an explicit empty dict (or empty list) to extra_config will serialize as "undefined" instead of "{}". If a caller ever passes extra_config={} intentionally, this would be surprising.
Proposed fix — use `is not None` instead of truthiness
- extra_config_json = json.dumps(extra_config) if extra_config else "undefined"
+ extra_config_json = json.dumps(extra_config) if extra_config is not None else "undefined"🤖 Prompt for AI Agents
In `@utils/visualize.py` around lines 403 - 409, The code currently treats empty
containers as falsy so extra_config passed as {} or [] becomes the string
"undefined"; change the truthiness check to an explicit None check so only None
maps to "undefined". In visualize.py locate the block that sets
extra_config_json (referencing the extra_config variable and the
extra_config_json assignment) and replace the conditional expression that uses
truthiness with a check like "if extra_config is not None" so that empty
dicts/lists serialize to their JSON ("{}"/"[]") while None remains "undefined".
Summary by CodeRabbit
New Features
Refactor