mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 07:12:47 +03:00
fix(cli-rs): report an unknown drive version instead of an empty one
Handshake.Identity.version is a NonEmptyString, and TS's SimulationServer.start defaults it to 'unknown'. opencode_drive's handshake sent an empty version as given; it now reports 'unknown', and the TUI no longer defaults it itself.
This commit is contained in:
@@ -158,7 +158,8 @@ pub enum Role {
|
||||
Backend,
|
||||
}
|
||||
|
||||
/// `Handshake.dispatch` for the `ui` role, after the checks `Handshake.Params` makes while decoding.
|
||||
/// `Handshake.dispatch` for the `ui` role, after the checks `Handshake.Params` makes while decoding. An empty
|
||||
/// `version` reports `unknown`, as `SimulationServer.start` defaults it: the schema takes no empty string.
|
||||
pub fn handshake(params: &HandshakeParams, version: &str) -> Result<Value, String> {
|
||||
check(params)?;
|
||||
if params.expected_role != Role::Ui {
|
||||
@@ -179,7 +180,7 @@ pub fn handshake(params: &HandshakeParams, version: &str) -> Result<Value, Strin
|
||||
Ok(json!({
|
||||
"protocolVersion": 1,
|
||||
"role": "ui",
|
||||
"server": { "name": "opencode", "version": version },
|
||||
"server": { "name": "opencode", "version": if version.is_empty() { "unknown" } else { version } },
|
||||
"capabilities": CAPABILITIES,
|
||||
}))
|
||||
}
|
||||
@@ -225,6 +226,10 @@ mod tests {
|
||||
assert_eq!(ok["protocolVersion"], 1);
|
||||
assert_eq!(ok["server"], json!({ "name": "opencode", "version": "9.9.9" }));
|
||||
assert_eq!(ok["capabilities"].as_array().unwrap().len(), CAPABILITIES.len());
|
||||
let Request::Handshake(params) = decode(&handshake_request("ui", "[1]", "[]")).unwrap().request else {
|
||||
panic!("not a handshake")
|
||||
};
|
||||
assert_eq!(handshake(¶ms, "").unwrap()["server"]["version"], "unknown");
|
||||
assert_eq!(
|
||||
answer(&handshake_request("backend", "[1]", "[]")).unwrap_err(),
|
||||
"Expected simulation endpoint role backend, received ui"
|
||||
|
||||
@@ -24,8 +24,7 @@ pub fn run(manifest: Manifest, options: AppOptions, launch: Launch) -> opentui::
|
||||
// Nothing draws over stderr without a terminal, and the driver reads the endpoint line from it.
|
||||
app: AppOptions { capture_stderr: false, ..options },
|
||||
})?;
|
||||
let version =
|
||||
Some(launch.args.version.clone()).filter(|version| !version.is_empty()).unwrap_or_else(|| "unknown".into());
|
||||
let version = launch.args.version.clone();
|
||||
crate::app::run_on(app, launch, |tui| {
|
||||
let server = start(tui, manifest.ui_addr(), version)?;
|
||||
eprintln!("opencode drive ui websocket: {}", server.url());
|
||||
|
||||
Reference in New Issue
Block a user