Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Add router eval: 47 cases and a runner with per-space misroute rate

Ada (kwant bot)91429f46e827
diff --git a/tests/router_eval/README.md b/tests/router_eval/README.md
new file mode 100644
index 00000000..3000a10e
--- /dev/null
+++ b/tests/router_eval/README.md
@@ -0,0 +1,14 @@
+# Router eval
+
+47 messages with the expected routing, across 3 fixture spaces (`kitchen` mirrors the corn-dog screenshot,
+`software`, `duo`). 15 expect `concierge`, 2 expect `ask`. The runner is `tests/router_eval_test.rs`.
+
+ cargo test --test router_eval_test router_eval -- --ignored --nocapture
+
+Prints the misroute rate per space, the no-match rate and every failure. `ROUTER_EVAL_MAX_MISROUTE=0.05`
+turns it into a gate. A *misroute* is a wrong destination; a *basis mismatch* is the right destination
+for the wrong stated reason, reported separately.
+
+`expect.route` is a member name, `concierge` or `ask`. `expect.basis` lists accepted bases (omitted = any).
+`laya` fixes a confident titles-only Laya guess (case 1 reproduces the screenshot). `channel` is `general`,
+a members' channel name or `dm`; the runner passes it once the router takes a channel kind (see `route_case`).
diff --git a/tests/router_eval/cases.json b/tests/router_eval/cases.json
new file mode 100644
index 00000000..51d6e345
--- /dev/null
+++ b/tests/router_eval/cases.json
@@ -0,0 +1,762 @@
+{
+ "about": "Routing eval for kwant's team router. expect.route is a member name, 'concierge' or 'ask'; expect.basis lists accepted bases; channel is general, a members' channel name, or dm; laya (optional) is a confident Laya guess from titles alone.",
+ "spaces": {
+ "kitchen": {
+ "about": "Mirrors the screenshot space: a restaurant crew plus a small tech and TikTok team.",
+ "lead": "TechLead",
+ "members": [
+ {
+ "name": "Architect",
+ "title": "Systems Architect",
+ "persona": "Architecture"
+ },
+ {
+ "name": "TechLead",
+ "title": "Tech Lead",
+ "persona": "Leads engineering and coordinates the team"
+ },
+ {
+ "name": "DevOps",
+ "title": "DevOps Engineer",
+ "persona": "DevOps and deployments"
+ },
+ {
+ "name": "HeadChef",
+ "title": "Head Chef",
+ "persona": "Runs the kitchen: menus, techniques, recipes and cooking questions"
+ },
+ {
+ "name": "Nutritionist",
+ "title": "Nutritionist",
+ "persona": "Nutrition, calories, macros, diets and meal plans"
+ },
+ {
+ "name": "Sous",
+ "title": "Sous Chef",
+ "persona": "Prep lists, kitchen schedules and station coordination"
+ },
+ {
+ "name": "Pantry",
+ "title": "Pantry Manager",
+ "persona": "Stock counts, ordering and suppliers"
+ },
+ {
+ "name": "Pastry",
+ "title": "Pastry Chef",
+ "persona": "Pastry, bread, dough and desserts"
+ },
+ {
+ "name": "TikTokLead",
+ "title": "TikTok Lead",
+ "persona": "Plans the TikTok channel and content calendar"
+ },
+ {
+ "name": "Scriptwriter",
+ "title": "TikTok Scriptwriter & Hook Specialist",
+ "persona": "Writes TikTok scripts and hooks"
+ },
+ {
+ "name": "Analyst",
+ "title": "Data Analyst",
+ "persona": "Analyses sales, churn and retention numbers"
+ },
+ {
+ "name": "Community",
+ "title": "Community Manager",
+ "persona": "Answers followers and moderates the community"
+ }
+ ]
+ },
+ "software": {
+ "about": "A typical software team.",
+ "lead": "Backend",
+ "members": [
+ {
+ "name": "Frontend",
+ "title": "Frontend Engineer",
+ "persona": "Builds the web interface"
+ },
+ {
+ "name": "Backend",
+ "title": "Backend Engineer",
+ "persona": "Builds APIs and services"
+ },
+ {
+ "name": "QA",
+ "title": "QA Engineer",
+ "persona": "Test plans and regression testing"
+ },
+ {
+ "name": "DevOps",
+ "title": "DevOps Engineer",
+ "persona": "CI, deployment and infrastructure"
+ },
+ {
+ "name": "Designer",
+ "title": "Brand Designer",
+ "persona": "Logos, palettes and mockups"
+ },
+ {
+ "name": "Marketer",
+ "title": "Growth Marketer",
+ "persona": "Campaigns, copy and launches"
+ },
+ {
+ "name": "Researcher",
+ "title": "Market Researcher",
+ "persona": "Competitor and market research"
+ }
+ ]
+ },
+ "duo": {
+ "about": "A small two-bot space.",
+ "lead": "Coder",
+ "members": [
+ {
+ "name": "Writer",
+ "title": "Copywriter",
+ "persona": "Writes copy and blog posts"
+ },
+ {
+ "name": "Coder",
+ "title": "Backend Engineer",
+ "persona": "Writes and fixes code"
+ }
+ ]
+ }
+ },
+ "cases": [
+ {
+ "id": 1,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Best place to eat corn dogs in Munich tomorrow?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "Scriptwriter",
+ "confident": true
+ },
+ "note": "The screenshot bug: a confident titles-only Laya guess picked Scriptwriter."
+ },
+ {
+ "id": 2,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Best place to eat corn dogs in Munich tomorrow?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "note": "Same message, Laya unreachable."
+ },
+ {
+ "id": 3,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "What's the weather going to be in Berlin this weekend?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "Analyst",
+ "confident": true
+ }
+ },
+ {
+ "id": 4,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Can you recommend a good book on stoicism?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 5,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "How do I get from Munich airport to the city centre?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "DevOps",
+ "confident": true
+ }
+ },
+ {
+ "id": 6,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "What's the capital of Australia?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 7,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Give me a fun fact about octopuses",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 8,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Translate 'good morning' into Italian",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 9,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Is a standing desk worth buying?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "Architect",
+ "confident": true
+ }
+ },
+ {
+ "id": 10,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Any nice hiking trails near Salzburg?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 11,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "How should I braise short ribs so they stay moist?",
+ "expect": {
+ "route": "HeadChef",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "Near miss: food, but it IS the chef's work."
+ },
+ {
+ "id": 12,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Plan a high-protein meal for a marathon week",
+ "expect": {
+ "route": "Nutritionist",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 13,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "How many calories are in a corn dog?",
+ "expect": {
+ "route": "Nutritionist",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "Near miss: corn dogs again, but a nutrition question."
+ },
+ {
+ "id": 14,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Write a TikTok hook about corn dogs",
+ "expect": {
+ "route": "Scriptwriter",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "Near miss: corn dogs again, but a TikTok script."
+ },
+ {
+ "id": 15,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Our deploy pipeline keeps failing in CI",
+ "expect": {
+ "route": "DevOps",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 16,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Which dough is better for croissants, laminated or puff?",
+ "expect": {
+ "route": "Pastry",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 17,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "We're running low on flour and butter, update the stock",
+ "expect": {
+ "route": "Pantry",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 18,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "@Scriptwriter how long should the intro be?",
+ "expect": {
+ "route": "Scriptwriter",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "@mention"
+ },
+ {
+ "id": 19,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "@Nutritionist what's the weather in Rome?",
+ "expect": {
+ "route": "Nutritionist",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "@mention beats topic"
+ },
+ {
+ "id": 20,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "hi",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "note": "Greeting, nobody spoke yet, in #general"
+ },
+ {
+ "id": 21,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "hi",
+ "expect": {
+ "route": "Nutritionist",
+ "basis": [
+ "last"
+ ]
+ },
+ "last_speaker": "Nutritionist",
+ "note": "Greeting carries on with the last speaker"
+ },
+ {
+ "id": 22,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "thanks!",
+ "expect": {
+ "route": "HeadChef",
+ "basis": [
+ "last"
+ ]
+ },
+ "last_speaker": "HeadChef"
+ },
+ {
+ "id": 23,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Review the deploy pipeline and write a TikTok hook announcing the downtime",
+ "expect": {
+ "route": "TechLead",
+ "basis": [
+ "several"
+ ]
+ },
+ "note": "Multi-role goes to the lead"
+ },
+ {
+ "id": 24,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Analyze last month's churn and retention numbers",
+ "expect": {
+ "route": "Analyst",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 25,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Which dishes should go on tonight's menu?",
+ "expect": {
+ "route": "HeadChef",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 26,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "Write a post about our new sourdough",
+ "expect": {
+ "route": "ask",
+ "candidates": [
+ "Pastry",
+ "Community",
+ "Scriptwriter",
+ "TikTokLead"
+ ]
+ },
+ "note": "Unsure band: several plausible specialists, none clearly best"
+ },
+ {
+ "id": 27,
+ "space": "kitchen",
+ "channel": "general",
+ "message": "What should we post this week about the pastry specials?",
+ "expect": {
+ "route": "ask",
+ "candidates": [
+ "Pastry",
+ "Community",
+ "Scriptwriter",
+ "TikTokLead"
+ ]
+ },
+ "note": "Unsure band"
+ },
+ {
+ "id": 28,
+ "space": "software",
+ "channel": "general",
+ "message": "The login button is misaligned on mobile",
+ "expect": {
+ "route": "Frontend",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 29,
+ "space": "software",
+ "channel": "general",
+ "message": "Add an endpoint for exporting invoices as CSV",
+ "expect": {
+ "route": "Backend",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 30,
+ "space": "software",
+ "channel": "general",
+ "message": "Write a test plan for the checkout flow",
+ "expect": {
+ "route": "QA",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 31,
+ "space": "software",
+ "channel": "general",
+ "message": "Our docker build is slow in CI",
+ "expect": {
+ "route": "DevOps",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 32,
+ "space": "software",
+ "channel": "general",
+ "message": "Design a new logo and colour palette for the brand",
+ "expect": {
+ "route": "Designer",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 33,
+ "space": "software",
+ "channel": "general",
+ "message": "Draft a launch tweet and a newsletter",
+ "expect": {
+ "route": "Marketer",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 34,
+ "space": "software",
+ "channel": "general",
+ "message": "Survey what competitors charge and summarise the market",
+ "expect": {
+ "route": "Researcher",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 35,
+ "space": "software",
+ "channel": "general",
+ "message": "Where should we go for the team offsite dinner in Lisbon?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ },
+ "laya": {
+ "pick": "Marketer",
+ "confident": true
+ }
+ },
+ {
+ "id": 36,
+ "space": "software",
+ "channel": "general",
+ "message": "Any good podcasts about startups?",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 37,
+ "space": "software",
+ "channel": "general",
+ "message": "Update the API and the dashboard layout for the new schema",
+ "expect": {
+ "route": "Backend",
+ "basis": [
+ "several"
+ ]
+ },
+ "note": "Multi-role goes to the lead"
+ },
+ {
+ "id": 38,
+ "space": "software",
+ "channel": "design-review",
+ "message": "Best sandwich shop near the office?",
+ "expect": {
+ "route": "Backend",
+ "basis": [
+ "lead"
+ ]
+ },
+ "note": "Room purpose: in a members' channel, unrelated questions go to the lead, not the Concierge"
+ },
+ {
+ "id": 39,
+ "space": "software",
+ "channel": "dm",
+ "message": "@QA what's the weather like today?",
+ "expect": {
+ "route": "QA",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ },
+ "note": "@mention in a DM"
+ },
+ {
+ "id": 40,
+ "space": "software",
+ "channel": "general",
+ "message": "ok go ahead",
+ "expect": {
+ "route": "Backend",
+ "basis": [
+ "last"
+ ]
+ },
+ "last_speaker": "Backend"
+ },
+ {
+ "id": 41,
+ "space": "software",
+ "channel": "general",
+ "message": "Build me a team to launch the product",
+ "expect": {
+ "route": "Backend",
+ "basis": [
+ "team"
+ ]
+ },
+ "note": "Team-building request goes to the lead"
+ },
+ {
+ "id": 42,
+ "space": "duo",
+ "channel": "general",
+ "message": "Write a tagline for our app",
+ "expect": {
+ "route": "Writer",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 43,
+ "space": "duo",
+ "channel": "general",
+ "message": "Fix the crash in the parser",
+ "expect": {
+ "route": "Coder",
+ "basis": [
+ "keywords",
+ "skills"
+ ]
+ }
+ },
+ {
+ "id": 44,
+ "space": "duo",
+ "channel": "general",
+ "message": "Recommend a good coffee place in Vienna",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 45,
+ "space": "duo",
+ "channel": "general",
+ "message": "hello",
+ "expect": {
+ "route": "concierge",
+ "basis": [
+ "concierge"
+ ]
+ }
+ },
+ {
+ "id": 46,
+ "space": "duo",
+ "channel": "general",
+ "message": "Thanks, that's great",
+ "expect": {
+ "route": "Writer",
+ "basis": [
+ "last"
+ ]
+ },
+ "last_speaker": "Writer"
+ },
+ {
+ "id": 47,
+ "space": "duo",
+ "channel": "general",
+ "message": "Write a blog post and fix the SQL query",
+ "expect": {
+ "route": "Coder",
+ "basis": [
+ "several"
+ ]
+ },
+ "note": "Multi-role goes to the lead"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/tests/router_eval_test.rs b/tests/router_eval_test.rs
new file mode 100644
index 00000000..64da36a5
--- /dev/null
+++ b/tests/router_eval_test.rs
@@ -0,0 +1,167 @@
+//! Routing eval: feeds the cases in tests/router_eval/cases.json through the team router, without
+//! a live Laya (a case may carry a fixed Laya guess), and reports the misroute rate per space.
+//!
+//! * `router_eval_cases_are_well_formed` runs in CI: the data parses and every name resolves.
+//! * `router_eval` is `#[ignore]`d, because expected values for routes that don't exist yet
+//! (`concierge`, `ask`) fail by design. Run it on a branch with:
+//!
+//! cargo test --test router_eval_test router_eval -- --ignored --nocapture
+//!
+//! Set `ROUTER_EVAL_MAX_MISROUTE=0.05` to make it fail above a misroute rate (default: report only).
+//! Set `ROUTER_EVAL_CASES=/path/cases.json` to use another file.
+//!
+//! A *misroute* is a wrong destination. A *basis mismatch* is the right destination for the wrong
+//! stated reason (basis); it is reported apart, not counted as a misroute.
+//!
+//! When the router's signature changes (a channel kind, a Concierge), only `route_case` needs to change.
+
+use kwnt::db::models::Kwant;
+use kwnt::router::team::{pick_member_after, LayaGuess};
+use serde::Deserialize;
+use std::collections::BTreeMap;
+
+#[derive(Deserialize)]
+struct File {
+ spaces: BTreeMap<String, Space>,
+ cases: Vec<Case>,
+}
+#[derive(Deserialize)]
+struct Space {
+ lead: String,
+ members: Vec<Member>,
+}
+#[derive(Deserialize)]
+struct Member {
+ name: String,
+ title: String,
+ persona: String,
+}
+#[derive(Deserialize)]
+struct Case {
+ id: u32,
+ space: String,
+ channel: String,
+ message: String,
+ last_speaker: Option<String>,
+ laya: Option<LayaCase>,
+ expect: Expect,
+}
+#[derive(Deserialize)]
+struct LayaCase {
+ pick: String,
+ confident: bool,
+}
+#[derive(Deserialize)]
+struct Expect {
+ route: String,
+ #[serde(default)]
+ basis: Vec<String>,
+ #[serde(default)]
+ candidates: Vec<String>,
+}
+
+fn load() -> File {
+ let path = std::env::var("ROUTER_EVAL_CASES")
+ .unwrap_or_else(|_| format!("{}/tests/router_eval/cases.json", env!("CARGO_MANIFEST_DIR")));
+ serde_json::from_str(&std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{path}: {e}"))).expect("cases.json parses")
+}
+
+fn kwants(space: &Space) -> Vec<Kwant> {
+ space
+ .members
+ .iter()
+ .map(|m| Kwant {
+ space_id: kwnt::db::spaces::DEFAULT_SPACE_ID.into(),
+ id: format!("id-{}", m.name),
+ name: m.name.clone(),
+ title: m.title.clone(),
+ persona_prompt: m.persona.clone(),
+ soul: String::new(),
+ avatar_sprite: "x".into(),
+ driver_type: "api".into(),
+ preferred_model: "auto".into(),
+ temperature: 0.7,
+ max_tokens: 4096,
+ level: 1,
+ turns_completed: 0,
+ created_at: None,
+ })
+ .collect()
+}
+
+/// (destination, basis). Destination is a member name, `concierge` or `ask`.
+fn route_case(case: &Case, space: &Space, members: &[Kwant]) -> (String, String) {
+ let by_name = |n: &str| members.iter().find(|m| m.name == n).unwrap_or_else(|| panic!("case {}: no member {n}", case.id));
+ let laya = case.laya.as_ref().map(|l| LayaGuess { kwant: by_name(&l.pick), confident: l.confident });
+ let last = case.last_speaker.as_ref().map(|n| by_name(n).id.clone());
+ // main: no channel kind and no Concierge yet, so `case.channel` is not passed.
+ let pick = pick_member_after(&case.message, &by_name(&space.lead).id, members, laya, "channel lead", last.as_deref())
+ .expect("a pick");
+ let dest = match pick.basis {
+ "concierge" => "concierge".to_string(),
+ "ask" => "ask".to_string(),
+ _ => pick.kwant.name.clone(),
+ };
+ (dest, pick.basis.to_string())
+}
+
+#[test]
+fn router_eval_cases_are_well_formed() {
+ let f = load();
+ assert!(f.cases.len() >= 40, "at least 40 cases");
+ let mut ids = std::collections::BTreeSet::new();
+ for c in &f.cases {
+ assert!(ids.insert(c.id), "duplicate case id {}", c.id);
+ let s = f.spaces.get(&c.space).unwrap_or_else(|| panic!("case {}: unknown space {}", c.id, c.space));
+ let has = |n: &str| s.members.iter().any(|m| m.name == n);
+ assert!(has(&s.lead), "space {}: lead {} is not a member", c.space, s.lead);
+ for n in c.last_speaker.iter().chain(c.laya.iter().map(|l| &l.pick)).chain(&c.expect.candidates) {
+ assert!(has(n), "case {}: {n} is not in {}", c.id, c.space);
+ }
+ let r = &c.expect.route;
+ assert!(r == "concierge" || r == "ask" || has(r), "case {}: bad route {r}", c.id);
+ }
+ assert!(f.cases.iter().filter(|c| c.expect.route == "concierge").count() >= 10, "about 10 no-match cases");
+}
+
+#[test]
+#[ignore = "expected concierge/ask routes fail until the router overhaul lands; run with --ignored"]
+fn router_eval() {
+ let f = load();
+ // space -> (total, misroutes, basis mismatches)
+ let mut per: BTreeMap<String, (u32, u32, u32)> = BTreeMap::new();
+ let mut failures: Vec<String> = Vec::new();
+ for c in &f.cases {
+ let space = &f.spaces[&c.space];
+ let members = kwants(space);
+ let (dest, basis) = route_case(c, space, &members);
+ let e = per.entry(c.space.clone()).or_default();
+ e.0 += 1;
+ let route_ok = dest == c.expect.route;
+ let basis_ok = c.expect.basis.is_empty() || c.expect.basis.contains(&basis);
+ if !route_ok {
+ e.1 += 1;
+ failures.push(format!("MISROUTE #{:<2} [{}/{}] {:?}\n expected {} {:?}, got {} (basis {})", c.id, c.space, c.channel, c.message, c.expect.route, c.expect.basis, dest, basis));
+ } else if !basis_ok {
+ e.2 += 1;
+ failures.push(format!("BASIS #{:<2} [{}/{}] {:?}\n routed to {} as expected, but basis {} not in {:?}", c.id, c.space, c.channel, c.message, dest, basis, c.expect.basis));
+ }
+ }
+ let (t, m, b) = per.values().fold((0, 0, 0), |a, v| (a.0 + v.0, a.1 + v.1, a.2 + v.2));
+ println!("\nrouter eval: {} cases from {} spaces", t, per.len());
+ for (s, (t, m, b)) in &per {
+ println!(" {s:<9} {m:>2}/{t:<2} misrouted ({:>5.1}%), {b} basis mismatches", 100.0 * *m as f64 / *t as f64);
+ }
+ let no_match: Vec<&Case> = f.cases.iter().filter(|c| c.expect.route == "concierge").collect();
+ let no_match_bad = no_match.iter().filter(|c| failures.iter().any(|x| x.starts_with("MISROUTE") && x.contains(&format!("#{:<2} ", c.id)))).count();
+ println!(" TOTAL {m:>2}/{t:<2} misrouted ({:>5.1}%), {b} basis mismatches", 100.0 * m as f64 / t as f64);
+ println!(" no-match cases (expect concierge): {no_match_bad}/{} misrouted", no_match.len());
+ println!("\nfailures:");
+ for x in &failures {
+ println!(" {x}");
+ }
+ if let Ok(max) = std::env::var("ROUTER_EVAL_MAX_MISROUTE") {
+ let max: f64 = max.parse().expect("ROUTER_EVAL_MAX_MISROUTE is a number like 0.05");
+ assert!(m as f64 / t as f64 <= max, "misroute rate {:.3} above {max}", m as f64 / t as f64);
+ }
+}