M1.3: engine workspace, file and buffer commands, event stream
State holds the open project (VFS project, watcher, watched directories)
and versioned buffers. New commands: project.open/close/children,
file.open/save/saveAll, buffer.get/edit/close. buffer.edit takes UTF-16
change sets based on a version and fails with the new stale_version code;
closing dirty buffers or projects without force fails with
unsaved_changes. Commands queue events (projectOpened, treeChanged,
bufferChanged, dirtyChanged, fileChangedOnDisk, ...) that the engine
returns in Outcome.events; Engine::pump_vfs maps changes on disk to
events and reloads clean buffers. project.children watches listed
directories, capped at 256 native / 32 polling, least recently listed
dropped first.
Control channel: events.subscribe streams {"event": ...} lines, with
bounded per-subscriber queues (lutra_control::Subscribers) and method docs
in methods.rs. testkit's EngineBackend and the desktop Host implement the
new Backend::subscribe. Verified with 14 engine integration tests, a TCP
events test and the running app over the control channel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a63ab4ac45
commit
f1976c7d67
30 changed files with 2235 additions and 46 deletions
|
|
@ -13,6 +13,9 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_json::{Value, json};
|
||||
|
||||
use crate::Backend;
|
||||
use crate::methods::{
|
||||
APP_PING, ENGINE_EXECUTE, ENGINE_LIST_COMMANDS, EVENTS_SUBSCRIBE, UI_SCREENSHOT,
|
||||
};
|
||||
|
||||
/// Largest accepted request line in bytes, newline excluded.
|
||||
pub const MAX_LINE_BYTES: usize = 16 * 1024 * 1024;
|
||||
|
|
@ -158,28 +161,33 @@ pub fn handle_line(line: &str, backend: &dyn Backend) -> Response {
|
|||
fn dispatch(request: Request, backend: &dyn Backend) -> Response {
|
||||
let Request { id, method, params } = request;
|
||||
match method.as_str() {
|
||||
"app.ping" => Response::ok(
|
||||
APP_PING => Response::ok(
|
||||
id,
|
||||
json!({ "pong": true, "version": env!("CARGO_PKG_VERSION") }),
|
||||
),
|
||||
"engine.execute" => match serde_json::from_value::<ExecuteParams>(params) {
|
||||
ENGINE_EXECUTE => match serde_json::from_value::<ExecuteParams>(params) {
|
||||
Ok(p) => match backend.execute(&p.command, p.params) {
|
||||
Ok(value) => Response::ok(id, value),
|
||||
Err(e) => engine_error(id, &e),
|
||||
},
|
||||
Err(e) => Response::err(id, codes::INVALID_PARAMS, e.to_string()),
|
||||
},
|
||||
"engine.listCommands" => match serde_json::to_value(backend.list_commands()) {
|
||||
ENGINE_LIST_COMMANDS => match serde_json::to_value(backend.list_commands()) {
|
||||
Ok(list) => Response::ok(id, list),
|
||||
Err(e) => Response::err(id, "internal", e.to_string()),
|
||||
},
|
||||
"ui.screenshot" => match serde_json::from_value::<ScreenshotParams>(params) {
|
||||
UI_SCREENSHOT => match serde_json::from_value::<ScreenshotParams>(params) {
|
||||
Ok(p) => match backend.screenshot(&p.path) {
|
||||
Ok(()) => Response::ok(id, json!({ "path": p.path })),
|
||||
Err(message) => Response::err(id, codes::SCREENSHOT_FAILED, message),
|
||||
},
|
||||
Err(e) => Response::err(id, codes::INVALID_PARAMS, e.to_string()),
|
||||
},
|
||||
EVENTS_SUBSCRIBE => Response::err(
|
||||
id,
|
||||
codes::INVALID_REQUEST,
|
||||
"events.subscribe needs a connection to stream on",
|
||||
),
|
||||
other => Response::err(
|
||||
id,
|
||||
codes::METHOD_NOT_FOUND,
|
||||
|
|
@ -234,12 +242,20 @@ mod tests {
|
|||
}
|
||||
Err("no window".into())
|
||||
}
|
||||
|
||||
fn subscribe(&self, _sink: crate::EventSink) {}
|
||||
}
|
||||
|
||||
fn call(line: &str) -> Response {
|
||||
handle_line(line, &TestBackend::new())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subscribe_needs_a_connection() {
|
||||
let r = call(r#"{"id":1,"method":"events.subscribe"}"#);
|
||||
assert_eq!(r.error.unwrap().code, "invalid_request");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ping() {
|
||||
let r = call(r#"{"id":1,"method":"app.ping"}"#);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue