From cbbb1750a65bdbe351c11b634e86b585c2fbae0f Mon Sep 17 00:00:00 2001 From: Jeremy Huang <94247773+1jehuang@users.noreply.github.com> Date: Sun, 31 May 2026 21:17:56 -0700 Subject: [PATCH] Accept set_route as model switch alias Fixes #295 --- .../src/protocol_tests/misc_events.rs | 19 +++++++++++++++++++ crates/jcode-protocol/src/wire.rs | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/jcode-protocol/src/protocol_tests/misc_events.rs b/crates/jcode-protocol/src/protocol_tests/misc_events.rs index 9024f4fae..527aa545f 100644 --- a/crates/jcode-protocol/src/protocol_tests/misc_events.rs +++ b/crates/jcode-protocol/src/protocol_tests/misc_events.rs @@ -195,6 +195,25 @@ fn test_set_feature_roundtrip() -> Result<()> { Ok(()) } +#[test] +fn test_set_route_deserializes_as_set_model_compat_alias() -> Result<()> { + let decoded = parse_request_json(r#"{"type":"set_route","id":42,"model":"claude-opus-4-5"}"#)?; + let Request::SetModel { id, model } = decoded else { + return Err(anyhow!( + "expected set_route compatibility alias to decode as SetModel" + )); + }; + assert_eq!(id, 42); + assert_eq!(model, "claude-opus-4-5"); + + let encoded = serde_json::to_string(&Request::SetModel { + id: 43, + model: "gpt-5.5".to_string(), + })?; + assert!(encoded.contains("\"type\":\"set_model\"")); + Ok(()) +} + #[test] fn test_subscribe_request_roundtrip_preserves_session_takeover_flags() -> Result<()> { let req = Request::Subscribe { diff --git a/crates/jcode-protocol/src/wire.rs b/crates/jcode-protocol/src/wire.rs index 2fe1d72c0..583b29e1e 100644 --- a/crates/jcode-protocol/src/wire.rs +++ b/crates/jcode-protocol/src/wire.rs @@ -159,8 +159,12 @@ pub enum Request { #[serde(rename = "refresh_models")] RefreshModels { id: u64 }, - /// Set the active model by name + /// Set the active model by name. + /// + /// `set_route` is accepted as a legacy/desktop compatibility alias for + /// clients that briefly emitted route-oriented model switch requests. #[serde(rename = "set_model")] + #[serde(alias = "set_route")] SetModel { id: u64, model: String }, /// Set or clear the session-scoped subagent model preference.