Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

test(rust): reject unknown checkpoint names in the in-crate test and keep the sample-input check in the router cell

kevin-gatimu84edf0921f99
diff --git a/laya-rust/src/batch_prediction.rs b/laya-rust/src/batch_prediction.rs
index 9fbb97c2..91e99c1e 100644
--- a/laya-rust/src/batch_prediction.rs
+++ b/laya-rust/src/batch_prediction.rs
@@ -413,6 +413,40 @@ mod tests {
/// `state_widths`, and the planned runs, `[rows, width]` per forward pass, must be the ones
/// Python made. Needs the tokenizer and the batch goldens, not a forward pass; skips like the
/// integration tests when either is missing.
+ /// Splits `LAYA_TEST_CHECKPOINTS` as `tests/common/test_artifacts.rs` does and panics on a name
+ /// that is not a checkpoint subdirectory.
+ fn selected_checkpoint_names(raw: &str) -> Vec<String> {
+ let names: Vec<String> = raw
+ .split(|c: char| c.is_whitespace() || c == ',')
+ .filter(|name| !name.is_empty())
+ .map(str::to_owned)
+ .collect();
+ let known = [
+ crate::LayaCheckpoint::English.subdir(),
+ crate::LayaCheckpoint::Multilingual.subdir(),
+ crate::LayaCheckpoint::TypedDecisions.subdir(),
+ ];
+ if let Some(unknown) = names.iter().find(|n| !known.contains(&n.as_str())) {
+ panic!("unknown LAYA_TEST_CHECKPOINTS entry '{unknown}' in '{raw}'");
+ }
+ names
+ }
+
+ #[test]
+ fn checkpoint_selection_accepts_known_names() {
+ assert!(selected_checkpoint_names("").is_empty());
+ assert_eq!(
+ selected_checkpoint_names(" english, typed-decisions "),
+ ["english", "typed-decisions"]
+ );
+ }
+
+ #[test]
+ #[should_panic(expected = "unknown LAYA_TEST_CHECKPOINTS entry 'typo' in 'english typo'")]
+ fn checkpoint_selection_rejects_an_unknown_name() {
+ selected_checkpoint_names("english typo");
+ }
+
#[test]
fn plans_the_recorded_session_runs() {
use crate::laya_config::LayaConfig;
@@ -422,12 +456,11 @@ mod tests {
use serde_json::Value;
// `LAYA_TEST_CHECKPOINTS` (space- or comma-separated subdirectory names) narrows this to the
- // checkpoints a parity job owns; unset runs all. Same semantics as `tests/common`.
- let selected = std::env::var("LAYA_TEST_CHECKPOINTS").unwrap_or_default();
- let selected: Vec<&str> = selected
- .split(|c: char| c.is_whitespace() || c == ',')
- .filter(|name| !name.is_empty())
- .collect();
+ // checkpoints a parity job owns; unset runs all. Same semantics as `tests/common`, including
+ // failing on an unknown name, so a library-only run cannot pass by ignoring a typo.
+ let selected =
+ selected_checkpoint_names(&std::env::var("LAYA_TEST_CHECKPOINTS").unwrap_or_default());
+ let selected: Vec<&str> = selected.iter().map(String::as_str).collect();
let mut checked_any = false;
for checkpoint in [
crate::LayaCheckpoint::Multilingual,
diff --git a/laya-rust/tests/router_end_to_end_tests.rs b/laya-rust/tests/router_end_to_end_tests.rs
index 852fe44a..dfeba210 100644
--- a/laya-rust/tests/router_end_to_end_tests.rs
+++ b/laya-rust/tests/router_end_to_end_tests.rs
@@ -116,6 +116,11 @@ fn router_predict_routes_and_matches_the_recorded_checkpoint_result() {
#[test]
fn sample_inputs_match_recorded_model_case_inputs() {
+ // Reads the english and multilingual goldens, which only the router cell regenerates; a single-
+ // checkpoint cell would otherwise check the committed copy of the checkpoint it does not own.
+ if !router_selected() {
+ return;
+ }
let sample_inputs = routing_golden::load("sample_inputs.json")
.expect("the routing sample fixture must be present");
let support = &sample_inputs["support_email"];