A3: accept a BOM before the first MCP message; plural-free Problems summary

Found by A2 while writing the alpha checklist: Windows PowerShell 5.1
prefixes piped stdin with a BOM, which lutra mcp rejected; the Problems
summary read "1 errors".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:42:14 +01:00
parent 68599fa2ac
commit c3acd9f60a
3 changed files with 10 additions and 2 deletions

View file

@ -53,7 +53,11 @@ pub enum Incoming {
/// The error response line to send back: a parse error for invalid /// The error response line to send back: a parse error for invalid
/// JSON, invalid request for anything that is not a single JSON-RPC 2.0 /// JSON, invalid request for anything that is not a single JSON-RPC 2.0
/// message, invalid params for params that are not an object. /// message, invalid params for params that are not an object.
///
/// A leading byte order mark is dropped first: Windows PowerShell 5.1
/// writes one when it pipes text into a native program.
pub fn parse(line: &str) -> Result<Incoming, String> { pub fn parse(line: &str) -> Result<Incoming, String> {
let line = line.strip_prefix('\u{feff}').unwrap_or(line);
let value: Value = serde_json::from_str(line) let value: Value = serde_json::from_str(line)
.map_err(|e| error(&Value::Null, codes::PARSE_ERROR, &e.to_string(), None))?; .map_err(|e| error(&Value::Null, codes::PARSE_ERROR, &e.to_string(), None))?;
let Value::Object(mut object) = value else { let Value::Object(mut object) = value else {
@ -176,6 +180,10 @@ mod tests {
}; };
assert_eq!(id, json!("a")); assert_eq!(id, json!("a"));
assert_eq!(params["k"], 1); assert_eq!(params["k"], 1);
assert!(matches!(
parse("\u{feff}{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"ping\"}"),
Ok(Incoming::Request { .. })
));
assert_eq!( assert_eq!(
parse(r#"{"jsonrpc":"2.0","method":"notifications/initialized"}"#).unwrap(), parse(r#"{"jsonrpc":"2.0","method":"notifications/initialized"}"#).unwrap(),
Incoming::Notification { Incoming::Notification {

View file

@ -223,7 +223,7 @@
"problems.severity.hint": "Hint", "problems.severity.hint": "Hint",
"problems.severity.info": "Information", "problems.severity.info": "Information",
"problems.severity.warning": "Warning", "problems.severity.warning": "Warning",
"problems.summary": "{errors} errors, {warnings} warnings, {infos} other", "problems.summary": "Errors: {errors}, warnings: {warnings}, other: {infos}",
"problems.toolWindow.title": "Problems", "problems.toolWindow.title": "Problems",
"project.empty.noFolder": "No folder is open.", "project.empty.noFolder": "No folder is open.",
"project.openFolder": "Open Folder…", "project.openFolder": "Open Folder…",

View file

@ -211,7 +211,7 @@ describe("ProblemsToolWindow", () => {
items: [diag(4, "warning", "Unused variable"), { ...diag(1, "error", "Undefined method"), code: "E12" }], items: [diag(4, "warning", "Unused variable"), { ...diag(1, "error", "Undefined method"), code: "E12" }],
}); });
await emit({ kind: "diagnosticsChanged", path: "a.php", items: [diag(0, "hint", "Could be final")] }); await emit({ kind: "diagnosticsChanged", path: "a.php", items: [diag(0, "hint", "Could be final")] });
expect(wrapper.get("[data-test=problems-status]").text()).toBe("1 errors, 1 warnings, 1 other"); expect(wrapper.get("[data-test=problems-status]").text()).toBe("Errors: 1, warnings: 1, other: 1");
const files = wrapper.findAll("[data-test=problems-file]").map((f) => f.text()); const files = wrapper.findAll("[data-test=problems-file]").map((f) => f.text());
expect(files[0]).toContain("a.php"); expect(files[0]).toContain("a.php");
expect(files[1]).toContain("Service.php"); expect(files[1]).toContain("Service.php");