Files
lucisv/crates/lucisv_server/src/server/tests/apply_edit.rs
T
lucioandClaude Fable 5 b96827c51d Decomposition, lane C: lucisv_server's server.rs and completion.rs become modules, a pure move
TODO section 28, lane C (the file-size rule in CLAUDE.md).
server.rs (2 559 production + 6 293 test lines) becomes server/{mod,
dispatch, client, index, notification, progress, diagnostics, batch,
formatting, large_file, semantic_tokens}.rs with the tests in
server/tests/ (16 files, one per former banner section, 15 shared
helpers hoisted into the harness); completion.rs (1 716 + 2 463)
becomes completion/{mod, member, module, tiers, word, site,
harness}.rs with each provider's tests beside it. answer_request (393)
and handle_notification (197) stay whole as the dispatch tables they
are; perf.rs stays whole because its one sentence has no and. Every
import elsewhere in the crate resolves through pub(crate) re-exports,
so main.rs, inline.rs, instantiate.rs, hover.rs, nav.rs and state.rs
are byte-identical. Proof: per-binary counts identical (1 435 / 85 / 3;
workspace 3 215 / 48), e2e and the vsix smoke green, a live LSP session
against opentitan answering byte-identically from this build and the
base, and a line-multiset + signature census (360/360, 188/188) done
by the dev and redone from scratch by QA.

docs/features/decomposition-server/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-02 21:33:48 -07:00

127 lines
5.6 KiB
Rust

//! `workspace/applyEdit`: how a command's edit reaches the client, and what a refusal says.
use super::*;
// ------------------------------------------------------------------
// `workspace/applyEdit`
// ------------------------------------------------------------------
#[test]
fn a_command_pushes_its_edit_when_the_client_can_apply_one() {
// The bug this fixes: the edit used to be the request *result*, which
// the protocol does not define and every stock client drops.
let abilities = ClientAbilities { apply_edit: true, ..Default::default() };
let (_tree, mut session, params) = propagating("applyedit", abilities);
let result = session.result(ExecuteCommand::METHOD, params);
assert_eq!(result, Value::Null, "the edit is not the result any more");
let sent = session.sent();
assert_eq!(sent.len(), 1, "{sent:#?}");
assert_eq!(sent[0].method, ApplyWorkspaceEdit::METHOD);
assert_eq!(
sent[0].params["label"],
serde_json::json!(format!("lucisv: {}", ports::PROPAGATE_PORTS)),
"the undo stack needs a name for it"
);
let changes = sent[0].params["edit"]["changes"].as_object().expect("changes");
let edits = changes.values().next().expect("one file edited");
assert_eq!(edits[0]["newText"], ", .rst(rst)", "{:#?}", sent[0].params);
}
#[test]
fn a_client_that_cannot_apply_edits_still_gets_the_edit_back() {
// The documented fallback: for such a client, returning the edit is
// the only thing that could ever work.
let (_tree, mut session, params) = propagating("noapplyedit", ClientAbilities::default());
let result = session.result(ExecuteCommand::METHOD, params);
let changes = result["changes"].as_object().expect("the edit is the result");
let edits = changes.values().next().expect("one file edited");
assert_eq!(edits[0]["newText"], ", .rst(rst)");
assert!(session.sent().is_empty(), "and nothing is pushed at it");
}
#[test]
fn an_edit_the_editor_refused_is_reported_to_the_user() {
let abilities = ClientAbilities { apply_edit: true, ..Default::default() };
let (_tree, mut session, params) = propagating("refused", abilities);
session.result(ExecuteCommand::METHOD, params);
let sent = session.sent();
let id = sent[0].id.clone();
session.answer(
id,
serde_json::json!({ "applied": false, "failureReason": "the file is read-only" }),
);
let shown = session.shown();
assert_eq!(shown.len(), 1, "{shown:#?}");
assert_eq!(shown[0].0, MessageType::ERROR);
assert!(shown[0].1.contains(ports::PROPAGATE_PORTS), "{}", shown[0].1);
assert!(shown[0].1.contains("the file is read-only"), "{}", shown[0].1);
}
#[test]
fn an_edit_the_editor_applied_is_said_nothing_about() {
let abilities = ClientAbilities { apply_edit: true, ..Default::default() };
let (_tree, mut session, params) = propagating("applied", abilities);
session.result(ExecuteCommand::METHOD, params);
let id = session.sent()[0].id.clone();
session.answer(id.clone(), serde_json::json!({ "applied": true }));
assert!(session.shown().is_empty(), "success is silent");
// And the id is spent: a duplicate answer says nothing either.
session.answer(id, serde_json::json!({ "applied": false }));
assert!(session.shown().is_empty(), "an answer to nothing is ignored");
}
#[test]
fn a_malformed_apply_edit_answer_is_reported_as_a_refusal() {
// QA attack: "a response that does not parse is a refusal" is stated
// in the Assumptions but was only exercised through `Err` results and
// a well-typed `applied: false`. This drives the branch where the
// payload is `Ok` JSON that does not deserialize as
// `ApplyWorkspaceEditResponse` at all (missing the required `applied`
// field) — the honest-refusal path, not a panic or a silent success.
let abilities = ClientAbilities { apply_edit: true, ..Default::default() };
let (_tree, mut session, params) = propagating("malformedapplyedit", abilities);
session.result(ExecuteCommand::METHOD, params);
let id = session.sent()[0].id.clone();
session.answer(id, serde_json::json!({ "notApplied": "whatever" }));
let shown = session.shown();
assert_eq!(shown.len(), 1, "an unparseable answer must still surface: {shown:#?}");
assert_eq!(shown[0].0, MessageType::ERROR);
assert!(shown[0].1.contains(ports::PROPAGATE_PORTS), "{}", shown[0].1);
}
#[test]
fn a_response_with_a_jsonrpc_error_is_reported_too() {
// The `Err` half of `response_result` — a client that rejects the
// `applyEdit` request outright at the JSON-RPC level, rather than
// answering it with `applied: false`.
let abilities = ClientAbilities { apply_edit: true, ..Default::default() };
let (_tree, mut session, params) = propagating("rpcerror", abilities);
session.result(ExecuteCommand::METHOD, params);
let id = session.sent()[0].id.clone();
session.server.response(Response::new_err(id, 1, "internal error".to_string()));
let shown = session.shown();
assert_eq!(shown.len(), 1, "{shown:#?}");
assert_eq!(shown[0].0, MessageType::ERROR);
assert!(shown[0].1.contains("internal error"), "{}", shown[0].1);
}
#[test]
fn a_watcher_registration_answer_is_still_ignored() {
// The one response that was always ignored must stay ignored now that
// responses are read at all — including an error one.
let tree = Tree::new("registeranswer");
let mut session = Session::new(vec![tree.path.clone()], true);
let id = session.sent()[0].id.clone();
session.answer(id.clone(), Value::Null);
session.server.response(Response::new_err(id, 1, "no thanks".to_string()));
assert!(session.shown().is_empty(), "nothing to tell the user");
}