Skip to content

fix(server): quote startup curl example - #235

Merged
nachiketb-nvidia merged 1 commit into
mainfrom
agent/rust-banner-curl-quote
Jul 31, 2026
Merged

fix(server): quote startup curl example#235
nachiketb-nvidia merged 1 commit into
mainfrom
agent/rust-banner-curl-quote

Conversation

@nachiketb-nvidia

@nachiketb-nvidia nachiketb-nvidia commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What

Quotes the startup banner's example curl command so it remains copy-pasteable when:

  • the request URL contains IPv6 brackets, such as http://[::1]:4000
  • the generated JSON body contains an apostrophe from a configured route id

Also adds two concise comments documenting the non-obvious URL normalization behavior that CodeRabbit flagged.

Why

CodeRabbit was right: PR #234 could print invalid shell when a valid configured route id contained an apostrophe. A live server repro with route id switchyard/it's-valid showed the original banner emitted:

-d '{"model":"switchyard/it's-valid",...}'

which breaks single-quoted shell parsing.

How

Adds a tiny shell_quote helper for the generated URL and JSON body. It wraps values in single quotes and escapes embedded apostrophes using the standard '\'' shell representation.

Validation

  • cargo check -p switchyard-server
  • commit hooks ran cargo fmt and cargo clippy
  • live local server check:
    • config used no-op route id switchyard/it's-valid
    • server bound to IPv6 unspecified address with --host :: --port 0
    • banner printed quoted http://[::1]:...
    • curl to /v1/chat/completions returned 200 with model switchyard/it's-valid

No test files were added.

Summary by CodeRabbit

  • Bug Fixes
    • Improved startup-banner request examples with safer shell quoting for URLs and JSON payloads.
    • Corrected generated URLs for wildcard listeners and IPv6 addresses.

Signed-off-by: nachiketb <nachiketb@nvidia.com>
@nachiketb-nvidia
nachiketb-nvidia requested a review from a team as a code owner July 31, 2026 20:31
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The startup banner now generates shell-safe curl examples. It quotes URLs and JSON bodies, uses loopback addresses for wildcard listeners, and brackets IPv6 URL authorities.

Changes

Startup request examples

Layer / File(s) Summary
Shell-safe curl example generation
crates/switchyard-server/src/lib.rs
The startup example shell-quotes the request URL and JSON body. Wildcard listeners use loopback addresses, and IPv6 authorities use brackets. A shell_quote helper escapes embedded single quotes.

Estimated code review effort: 2 (Simple) | ~8 minutes

Poem

I’m a rabbit with a quoted curl,
Safe little strings in a shell-world swirl.
IPv6 wears brackets neat,
Loopback hops on tiny feet.
JSON tucked in, errors unfurled—
Hoppy commands for the world!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change to quote the startup curl example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/switchyard-server/src/lib.rs (1)

970-978: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for shell-safe examples.

Test an IPv6 listener and a route ID containing an apostrophe. Assert the generated command contains a bracketed IPv6 authority and the escaped apostrophe sequence in the JSON argument.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/switchyard-server/src/lib.rs` around lines 970 - 978, Add regression
coverage for the startup example rendering around the shell_quote usage in the
server banner formatter. Exercise an IPv6 listener and a route ID containing an
apostrophe, asserting the generated curl command uses a bracketed IPv6 authority
and preserves the shell-escaped apostrophe sequence in the JSON argument.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/switchyard-server/src/lib.rs`:
- Around line 1030-1032: Add a concise documentation comment immediately above
the private shell_quote function stating that it emits a POSIX shell
single-quoted argument and escapes embedded apostrophes; leave the
implementation unchanged.

---

Nitpick comments:
In `@crates/switchyard-server/src/lib.rs`:
- Around line 970-978: Add regression coverage for the startup example rendering
around the shell_quote usage in the server banner formatter. Exercise an IPv6
listener and a route ID containing an apostrophe, asserting the generated curl
command uses a bracketed IPv6 authority and preserves the shell-escaped
apostrophe sequence in the JSON argument.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7a3e162c-6a6c-4e8f-83fb-a22245f51acb

📥 Commits

Reviewing files that changed from the base of the PR and between a67536f and f0fd55c.

📒 Files selected for processing (1)
  • crates/switchyard-server/src/lib.rs

Comment thread crates/switchyard-server/src/lib.rs
@nachiketb-nvidia
nachiketb-nvidia merged commit 7e4929c into main Jul 31, 2026
18 checks passed
@nachiketb-nvidia
nachiketb-nvidia deleted the agent/rust-banner-curl-quote branch July 31, 2026 21:12
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