//! The gates this group owes that no integration test can give it: the tools it //! registers, and the read registry's own consistency. //! //! Two of its three `it`s are the TypeScript buying with a test what Rust buys //! with the compiler — `kind_source` is an exhaustive `match` on //! `ProjectLinkKind`, so a kind with no projection and a projection for a kind //! that has LEFT the enum are both build failures rather than silence. What //! CANNOT be bought that way is the third: that each projection names a real //! table and only columns that table has, which is what `get_project` actually //! depends on and is asserted here. use cotton_core::constants::ProjectLinkKind; use cotton_store::schema::specs::spec_for; use super::{engine_shim::project_kind_table, handlers, kinds::kind_source}; #[test] fn registers_every_tool_it_claims_exactly_once() { let mut names: Vec<&str> = handlers().iter().map(|(name, _)| *name).collect(); names.sort_unstable(); let before = names.len(); names.dedup(); assert_eq!(before, names.len(), "a tool is registered twice"); assert_eq!(before, 6, "the group's tool count changed"); for name in &names { assert!( crate::mcp::protocol::tool_by_name(name).is_some(), "{name} is not in the catalogue" ); } } /// The assertion `get_project` actually depends on. Each projection is a /// literal select list; a column the schema dropped (or a table it renamed) is /// a 500 on somebody's session-start read, and nothing else in the suite /// touches the rarer kinds' projections. #[test] fn names_a_real_table_and_only_columns_that_table_has() { let mut problems: Vec = Vec::new(); for kind in ProjectLinkKind::ALL { let source = kind_source(kind); let Some(spec) = spec_for(source.table) else { problems.push(format!("{kind}: no table spec named \"{}\"", source.table)); continue; }; for column in source.columns { if !spec.columns.iter().any(|(name, _)| name == column) { problems.push(format!( "{kind}: {} has no column \"{column}\"", source.table )); } } // The discriminator core filters on (note vs journal) has to be there // too. if let Some(filter) = project_kind_table(kind).where_clause { for column in filter.columns() { if !spec.columns.iter().any(|(name, _)| *name == column) { problems.push(format!( "{kind}: {} has no filter column \"{column}\"", source.table )); } } } } assert!(problems.is_empty(), "{}", problems.join("\n")); } /// The table a kind's rows live in is ONE fact: core's registry decides it, and /// the projection takes it from there rather than typing it twice. #[test] fn every_projection_takes_its_table_from_cores_registry() { for kind in ProjectLinkKind::ALL { assert_eq!( kind_source(kind).table, project_kind_table(kind).table, "{kind} projects a table core does not name" ); } } /// A kind with no response group would be a member `get_project` gathers and /// never renders — the `list_by_tag` failure one layer down. #[test] fn every_kind_lands_in_a_named_group() { for kind in ProjectLinkKind::ALL { assert!( !kind_source(kind).group.is_empty(), "{kind} has no response group" ); } }