mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-28 15:40:04 +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:
@@ -105,3 +105,21 @@ pub fn handleRead(server: *Server, arena: std.mem.Allocator, req: protocol.Reque
|
||||
return server.sendError(req.id.?, .InvalidRequest, "Resource not found");
|
||||
}
|
||||
}
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
|
||||
test "resource_list contains expected resources" {
|
||||
try testing.expect(resource_list.len >= 2);
|
||||
try testing.expectString("mcp://page/html", resource_list[0].uri);
|
||||
try testing.expectString("mcp://page/markdown", resource_list[1].uri);
|
||||
}
|
||||
|
||||
test "ReadParams parsing" {
|
||||
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
const aa = arena.allocator();
|
||||
|
||||
const raw = "{\"uri\": \"mcp://page/html\"}";
|
||||
const parsed = try std.json.parseFromSlice(ReadParams, aa, raw, .{});
|
||||
try testing.expectString("mcp://page/html", parsed.value.uri);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user