mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
mcp: refactor for testability and add comprehensive test suite
- Refactor mcp.Server and router to accept injected I/O streams. - Implement McpHarness for high-fidelity MCP integration testing. - Add unit tests for protocol, tools, and resources modules. - Add integration tests covering initialization, tool/resource execution, and error handling. - Improve error reporting for malformed JSON requests.
This commit is contained in:
@@ -218,3 +218,27 @@ test "protocol error formatting" {
|
||||
|
||||
try testing.expectString("{\"jsonrpc\":\"2.0\",\"id\":\"abc\",\"error\":{\"code\":-32601,\"message\":\"Method not found\"}}", aw.written());
|
||||
}
|
||||
|
||||
test "JsonEscapingWriter" {
|
||||
var aw: std.Io.Writer.Allocating = .init(testing.allocator);
|
||||
defer aw.deinit();
|
||||
|
||||
var escaping_writer = JsonEscapingWriter.init(&aw.writer);
|
||||
|
||||
// test newlines and quotes
|
||||
try escaping_writer.writer.writeAll("hello\n\"world\"");
|
||||
|
||||
// the writer outputs escaped string chars without surrounding quotes
|
||||
try testing.expectString("hello\\n\\\"world\\\"", aw.written());
|
||||
}
|
||||
|
||||
test "RawJson serialization" {
|
||||
const raw = RawJson{ .json = "{\"test\": 123}" };
|
||||
|
||||
var aw: std.Io.Writer.Allocating = .init(testing.allocator);
|
||||
defer aw.deinit();
|
||||
|
||||
try std.json.Stringify.value(raw, .{}, &aw.writer);
|
||||
|
||||
try testing.expectString("{\"test\":123}", aw.written());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user