Skip to content

fix plot show test mode#228

Merged
spytheman merged 1 commit intovlang:mainfrom
kbkpbot:fix-test-plot-show
Aug 23, 2025
Merged

fix plot show test mode#228
spytheman merged 1 commit intovlang:mainfrom
kbkpbot:fix-test-plot-show

Conversation

@kbkpbot
Copy link
Copy Markdown
Contributor

@kbkpbot kbkpbot commented Aug 23, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Resolved a test-mode issue in the plotting display path that could cause failures during test runs.
    • In test mode, plotting is now cleanly skipped with an informational message; regular runs still start the plot server and open the browser.
    • Improves stability in CI and local testing environments.
    • No changes to public APIs or user workflows.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 23, 2025

Walkthrough

A compile-time conditional in Plot.show was corrected from $if test ? { ... } to $if test { ... }. In test mode it prints an ignore message; otherwise it initializes the Plotly handler, starts the server, opens the URI, and waits. No APIs or data structures changed.

Changes

Cohort / File(s) Summary
Plot show conditional
plot/show.v
Fixed compile-time condition syntax from $if test ? { ... } to $if test { ... }; retained existing test vs. runtime logic (print in tests; otherwise init Plotly, start server, open URI, wait).

Sequence Diagram(s)

sequenceDiagram
    participant U as User Code
    participant P as Plot.show
    participant H as PlotlyHandler
    participant S as Server
    participant B as Browser

    U->>P: call show()
    alt test build
        P-->>U: print "ignored in test"
    else normal build
        P->>H: init handler
        P->>S: start server
        P->>B: open URI
        P-->>U: wait until close
    end
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A hop, a skip, a syntax tweak—
I nibbled off a tiny squeak.
Test paths hush, the brows’rs glow,
Servers hum, the plots now show.
Carrot-bright, my code’s concise—
One nibble fixed it, neat and nice. 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kbkpbot
Copy link
Copy Markdown
Contributor Author

kbkpbot commented Aug 23, 2025

where is my comment on this PR? :(

more discussion can be found at vlang/v#25150 (comment)

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
plot/show.v (2)

26-29: Respect PlotConfig.use_cdn instead of hard-coding true

The handler currently ignores the caller’s use_cdn preference. Propagate config.use_cdn for consistency with get_html(...) which already honors it.

-        mut handler := PlotlyHandler{
-            use_cdn: true
-            plot:    p
-        }
+        mut handler := PlotlyHandler{
+            use_cdn: config.use_cdn
+            plot:    p
+        }

40-44: Avoid leaking the background server/thread on early errors

If server.wait_till_running() or os.open_uri(...) fails, the spawned listen_and_serve() thread keeps running and show() returns an error without shutting it down. Wrap both calls with or { ... } to close the server and join the thread before propagating the error.

         t := spawn server.listen_and_serve()
-        server.wait_till_running()!
-        os.open_uri('http://${server.addr}')!
-        t.wait()
+        server.wait_till_running() or {
+            // Ensure cleanup on startup failure
+            server.close()
+            t.wait()
+            return err
+        }
+        os.open_uri('http://${server.addr}') or {
+            // Ensure cleanup if opening the browser fails
+            server.close()
+            t.wait()
+            return err
+        }
+        t.wait()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d4c2e33 and 3d760e3.

📒 Files selected for processing (1)
  • plot/show.v (1 hunks)
🔇 Additional comments (1)
plot/show.v (1)

23-25: Correct compile-time guard for tests

Using $if test { ... } is the right way to detect the built-in system define set by v test. This ensures show() is inert under v test without depending on a user-provided -d test. LGTM.

Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Thank you @kbkpbot.

@ulises-jeremias that coderabbit thing is insanely annoying.
I think it only serves to scare contributors and harms the project.

@spytheman spytheman merged commit aa57180 into vlang:main Aug 23, 2025
5 of 9 checks passed
ulises-jeremias added a commit that referenced this pull request Dec 27, 2025
* 'main' of github.com:vlang/vsl:
  noise: respect new wyhash v4.2 (#230)
  prepare for the fix for rand.shuffle in vlang/v#25617
  fix warnings for examples/gm_spatial_binning/main.v
  fix warnings and notices for examples/plot_radar_performance/main.v
  remove unused `import json` in examples/plot_violin_distributions/main.v
  fix plot show test mode (#228)
  add `// vtest retry: 3` to three_d_test.v too, to prevent false positives on the CI of the main V repo
  add `// vtest retry: 3` to readhdf5_test.v to prevent false positives on the CI of the main V repo
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