
ErrorsTest.pudu
Pudu32 lines2.2 KB
1/** @Test.Errors.ErrorsTest.Suite — protocol codes and tool failure messages */2module PuduLangMcp.Errors.ErrorsTest34import Std.Io as Io5import Std.Json as Json6import Std.Test as Test7import PuduLangMcp.Constants.Protocol as Protocol8import PuduLangMcp.Errors.RpcError as RpcError9import PuduLangMcp.Errors.ToolError as ToolError101112fn main() -> Int {13 let problems = [RpcError.ParseError("x"), RpcError.InvalidRequest("x"), RpcError.MethodNotFound("x"), RpcError.InvalidParams("x"), RpcError.ResourceNotFound("x"), RpcError.UnsupportedVersion("x"), RpcError.Internal("x")]14 let codes = problems.map(|held: RpcError.ProtocolError| RpcError.code(&held))15 let checks = Test.suite("Errors", &[16 Test.equals("codes follow JSON-RPC and MCP", &codes, &[-32700, -32600, -32601, -32602, -32602, -32022, -32603]),17 Test.all("no code is in the legacy sub-range", &codes, |code: Int| code > -32000 || code < -32019),18 Test.equals("a method error names the method", &RpcError.message(&RpcError.MethodNotFound("tools/x")), &"Method not found: tools/x"),19 Test.equals("only two refusals carry data", &problems.filter(|held: RpcError.ProtocolError| RpcError.data(&held) != None).length(), &2),20 Test.equals("an unsupported version lists every supported one", &Json.path(&match RpcError.data(&RpcError.UnsupportedVersion("x")) { case Some(data) => data case None => Json.Null }, &["supported"]), &Some(Json.list(&Protocol.supportedVersions().map(|v: Str| Json.Text(v))))),21 Test.that("a missing toolchain says where to get one", ToolError.explain(&ToolError.ToolchainMissing).contains("pudu-lang.org/download")),22 Test.equals("an exclusive pair names both", &ToolError.explain(&ToolError.ExactlyOne(["source", "path"])), &"Give exactly one of 'source' or 'path'."),23 Test.equals("a timeout names its command and budget", &ToolError.explain(&ToolError.TimedOut("pudu run", 500)), &"'pudu run' did not finish within 500 ms and was stopped."),24 Test.equals("an unavailable feature says why, verbatim", &ToolError.explain(&ToolError.Unavailable("because")), &"because")25 ])26 let ran = Test.run(&checks)27 for failure in Test.failuresOf(&ran) {28 let _reported = Io.writeErrorLine(failure)29 }30 Test.report(&ran)31}32