
PromptsTest.pudu
Pudu48 lines3.2 KB
1/** @Test.Domain.Catalog.PromptsTest.Suite — prompt templates and rendering */2module PuduLangMcp.Domain.Catalog.PromptsTest34import Std.Io as Io5import Std.Json as Json6import Std.List as List7import Std.Test as Test8import PuduLangMcp.Constants.Protocol as Protocol9import PuduLangMcp.Domain.Catalog.Prompts as Prompts10import PuduLangMcp.Errors.RpcError as RpcError111213fn rendered(name: Str, arguments: &Array[(Str, Json.Json)]) -> Result[Str, Int] {14 match Prompts.render(name, &Json.object(arguments)) {15 case Ok(held) => Ok(held[1])16 case Err(problem) => Err(RpcError.code(&problem))17 }18}192021fn main() -> Int {22 let names = Prompts.all().map(|spec: Prompts.PromptSpec| spec.name)23 let written = rendered("pudu_write_code", &[("task", Json.Text("parse a CSV line"))])24 let fixing = rendered("pudu_fix_diagnostics", &[("source", Json.Text("module Main")), ("diagnostics", Json.Text("E3001 here"))])25 let unfixed = rendered("pudu_fix_diagnostics", &[("source", Json.Text("module Main"))])26 let checks = Test.suite("Domain.Catalog.Prompts", &[27 Test.equals("names are unique", &List.distinct(&names).length(), &names.length()),28 Test.equals("four prompts are offered", &names.length(), &4),29 Test.that("the task reaches the message", match written { case Ok(text) => text.contains("parse a CSV line") case Err(_) => false }),30 Test.that("every message carries the conventions", match written { case Ok(text) => text.contains(Prompts.CONVENTIONS) case Err(_) => false }),31 Test.that("given diagnostics are quoted", match fixing { case Ok(text) => text.contains("E3001 here") case Err(_) => false }),32 Test.that("absent diagnostics point at pudu_check", match unfixed { case Ok(text) => text.contains("pudu_check") case Err(_) => false }),33 Test.that("the conventions state the interpolation rule", Prompts.CONVENTIONS.contains("\\\{")),34 Test.equals("an unknown prompt is invalid params", &rendered("pudu_nope", &[]), &Err(Protocol.INVALID_PARAMS)),35 Test.equals("a missing required argument is invalid params", &rendered("pudu_review", &[]), &Err(Protocol.INVALID_PARAMS)),36 Test.all("every prompt refuses its missing required arguments", &Prompts.all(), |spec: Prompts.PromptSpec| rendered(spec.name, &[]) == Err(Protocol.INVALID_PARAMS)),37 Test.equals("a fix needs its source", &rendered("pudu_fix_diagnostics", &[("diagnostics", Json.Text("E1"))]), &Err(Protocol.INVALID_PARAMS)),38 Test.equals("a blank required argument is invalid params", &rendered("pudu_review", &[("source", Json.Text(" "))]), &Err(Protocol.INVALID_PARAMS)),39 Test.equals("a non-string argument is invalid params", &rendered("pudu_explain", &[("topic", Json.Number(1))]), &Err(Protocol.INVALID_PARAMS)),40 Test.equals("a listed prompt names its required argument", &Json.path(&Prompts.toJson(&Prompts.all()[0]), &["arguments"]), &Some(Json.list(&[Json.object(&[("name", Json.Text("task")), ("description", Json.Text("What the code should do.")), ("required", Json.Boolean(true))])])))41 ])42 let ran = Test.run(&checks)43 for failure in Test.failuresOf(&ran) {44 let _reported = Io.writeErrorLine(failure)45 }46 Test.report(&ran)47}48