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.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
test(cpp): fixed golden row counts so test listing stays fast
Adeshina Lasisia34113a106f4
diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.ymlindex 111b7b02..27f0f022 100644--- a/.github/workflows/cpp.yml+++ b/.github/workflows/cpp.yml@@ -42,7 +42,7 @@ concurrency:env:# The test floor: the number of ctest tests laya-cpp registers (the GoogleTest cases plus# compile_flags). Raise it with every test added.- MIN_TESTS: "212"+ MIN_TESTS: "213"GOLDENS: ${{ github.workspace }}/.cpp-goldensLAYA_GOLDENS: ${{ github.workspace }}/.cpp-goldensLAYA_REQUIRE_GOLDENS: "1" # a missing golden is a failure, never a skipdiff --git a/laya-cpp/CMakeLists.txt b/laya-cpp/CMakeLists.txtindex 18d66676..af2023d2 100644--- a/laya-cpp/CMakeLists.txt+++ b/laya-cpp/CMakeLists.txt@@ -54,7 +54,12 @@ if(LAYA_BUILD_TESTS)include(GoogleTest)# PRE_TEST: the parametrized rows are counted from the goldens, which exist at test time.- gtest_discover_tests(laya_tests DISCOVERY_MODE PRE_TEST)+ gtest_discover_tests(laya_tests DISCOVERY_MODE PRE_TEST DISCOVERY_TIMEOUT 120)++ # Listing must stay cheap (it runs before every ctest): bound it at 3 s with the goldens loaded.+ add_test(NAME discovery_fast+ COMMAND ${CMAKE_COMMAND} -DEXE=$<TARGET_FILE:laya_tests> -DLIMIT=3+ -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_discovery_time.cmake)# compile_commands.json is the record of what the compiler was really given, so this fails if# the floating point flags are dropped from either target.diff --git a/laya-cpp/cmake/check_discovery_time.cmake b/laya-cpp/cmake/check_discovery_time.cmakenew file mode 100644index 00000000..29d99d0e--- /dev/null+++ b/laya-cpp/cmake/check_discovery_time.cmake@@ -0,0 +1,11 @@+# Fails when `laya_tests --gtest_list_tests` takes longer than LIMIT seconds. Test registration must+# not load the goldens: ctest runs this listing before every run, with a timeout of its own.+execute_process(COMMAND ${EXE} --gtest_list_tests TIMEOUT ${LIMIT}+ RESULT_VARIABLE rc OUTPUT_VARIABLE out ERROR_VARIABLE err)+if(NOT rc STREQUAL "0")+ message(FATAL_ERROR "listing tests did not finish in ${LIMIT}s or failed: ${rc}")+endif()+string(LENGTH "${out}" n)+if(n LESS 1000)+ message(FATAL_ERROR "listing produced only ${n} bytes")+endif()diff --git a/laya-cpp/tests/foundation_test.cpp b/laya-cpp/tests/foundation_test.cppindex aa485a2b..5bf5425c 100644--- a/laya-cpp/tests/foundation_test.cpp+++ b/laya-cpp/tests/foundation_test.cpp@@ -114,6 +114,7 @@ TEST(Unicode, StripFieldsDecimal) {class DoublesChunk : public ::testing::TestWithParam<int> {};TEST_P(DoublesChunk, ReprFloatMatchesCPython) {LAYA_GOLDEN_LIST(rows, "python_json.json", "doubles");+ LAYA_EXPECT_ROWS(rows, 533);for (size_t i = size_t(GetParam()) * laya_test::kChunk; i < std::min(rows->size(), (size_t(GetParam()) + 1) * laya_test::kChunk); i++) {uint64_t bits = laya_test::BitsOf(*rows->value(i).Find("bits"));double v;@@ -121,7 +122,7 @@ TEST_P(DoublesChunk, ReprFloatMatchesCPython) {EXPECT_EQ(laya::pyjson::ReprFloat(v), rows->value(i).Find("repr")->as_string()) << "bits " << bits;}}-INSTANTIATE_TEST_SUITE_P(Golden, DoublesChunk, ::testing::ValuesIn(laya_test::Chunks("python_json.json", {"doubles"})));+INSTANTIATE_TEST_SUITE_P(Golden, DoublesChunk, ::testing::ValuesIn(laya_test::Chunks(533)));TEST(PyJson, ReprFloatNotationBoundaries) { // fixed for exponents in [-4, 16), scientific outsideEXPECT_EQ(laya::pyjson::ReprFloat(1e15), "1000000000000000.0");@@ -166,18 +167,20 @@ TEST(PyJson, ReprStringsDigestPercentRound4) {class Round4Chunk : public ::testing::TestWithParam<int> {};TEST_P(Round4Chunk, HalfEvenMatchesPython) {LAYA_GOLDEN_LIST(vals, "go_extra.json", "round4", "values");+ LAYA_EXPECT_ROWS(vals, 5605);const Value* want = At(laya_test::Load("go_extra.json", true), {"round4", "rounded"});for (size_t i = size_t(GetParam()) * laya_test::kChunk; i < std::min(vals->size(), (size_t(GetParam()) + 1) * laya_test::kChunk); i++) {double got = laya::pyjson::Round4(laya_test::Num(vals->value(i))), w = laya_test::Num(want->value(i));EXPECT_EQ(std::memcmp(&got, &w, 8), 0) << "row " << i << " " << got << " vs " << w;}}-INSTANTIATE_TEST_SUITE_P(Golden, Round4Chunk, ::testing::ValuesIn(laya_test::Chunks("go_extra.json", {"round4", "values"})));+INSTANTIATE_TEST_SUITE_P(Golden, Round4Chunk, ::testing::ValuesIn(laya_test::Chunks(5605)));// ---- pyvalue: json.loads / json.dumps ------------------------------------------------------------class StatesChunk : public ::testing::TestWithParam<int> {};TEST_P(StatesChunk, ParseAndDumpsMatchPython) {LAYA_GOLDEN_LIST(cases, "go_extra.json", "states", "cases");+ LAYA_EXPECT_ROWS(cases, 2000);for (size_t i = size_t(GetParam()) * laya_test::kChunk; i < std::min(cases->size(), (size_t(GetParam()) + 1) * laya_test::kChunk); i++) {const std::string& text = cases->value(i).Find("text")->as_string();auto v = pv::Parse(text);@@ -194,7 +197,7 @@ TEST_P(StatesChunk, ParseAndDumpsMatchPython) {EXPECT_EQ(v.value().kind() == pv::Value::Kind::Array, cases->value(i).Find("list")->as_bool()) << i;}}-INSTANTIATE_TEST_SUITE_P(Golden, StatesChunk, ::testing::ValuesIn(laya_test::Chunks("go_extra.json", {"states", "cases"})));+INSTANTIATE_TEST_SUITE_P(Golden, StatesChunk, ::testing::ValuesIn(laya_test::Chunks(2000)));TEST(PyValue, PythonRejectsAndLoneSurrogates) {LAYA_GOLDEN_LIST(bad, "go_extra.json", "states", "python_rejects");diff --git a/laya-cpp/tests/golden.hpp b/laya-cpp/tests/golden.hppindex d18b5732..f97db557 100644--- a/laya-cpp/tests/golden.hpp+++ b/laya-cpp/tests/golden.hpp@@ -45,6 +45,9 @@ inline const Value* Load(const std::string& file, bool report) {return &(cache[file] = std::move(parsed).value());}+#define LAYA_EXPECT_ROWS(list, n) \+ ASSERT_EQ((list)->size(), size_t(n)) << "the golden changed shape; update the row count in the test"+// Walks a path of object keys; nullptr when anything is missing.inline const Value* At(const Value* v, std::initializer_list<const char*> path) {for (const char* k : path) {@@ -70,16 +73,16 @@ inline bool RequireGoldens() {}constexpr size_t kChunk = 100; // rows per test case in the large families-inline std::vector<int> Chunks(const std::string& file, std::initializer_list<const char*> path) {- const Value* v = At(Load(file, false), path);- size_t rows = v == nullptr ? 1 : (v->size() + kChunk - 1) / kChunk;+// Parameter lists are built from fixed row counts, never from the golden: loading a 7.6 MB file at+// registration made `--gtest_list_tests` take seconds and tripped ctest's discovery timeout. Each+// test asserts the golden still holds exactly that many rows (as laya-go's tests do), so a changed+// golden fails loudly instead of leaving rows untested.+inline std::vector<int> Chunks(size_t rows) {std::vector<int> out;- for (size_t i = 0; i < rows; i++) out.push_back(int(i));+ for (size_t i = 0; i * kChunk < rows; i++) out.push_back(int(i));return out;}-inline std::vector<int> Rows(const std::string& file, std::initializer_list<const char*> path) {- const Value* v = At(Load(file, false), path);- size_t rows = v == nullptr ? 1 : v->size();+inline std::vector<int> Rows(size_t rows) {std::vector<int> out;for (size_t i = 0; i < rows; i++) out.push_back(int(i));return out;diff --git a/laya-cpp/tests/lang_test.cpp b/laya-cpp/tests/lang_test.cppindex da0937f8..cf0c956c 100644--- a/laya-cpp/tests/lang_test.cpp+++ b/laya-cpp/tests/lang_test.cpp@@ -34,6 +34,7 @@ void ExpectProfile(const Value& want, const lg::Profile& got, const std::string&class DetectRow : public ::testing::TestWithParam<int> {};TEST_P(DetectRow, MatchesPython) {LAYA_GOLDEN_LIST(rows, "lang_detect.json", "cases");+ LAYA_EXPECT_ROWS(rows, 106);const Value& row = rows->value(size_t(GetParam()));const std::string name = row.Find("name")->as_string();pv::Value state = StateOf(*row.Find("state"));@@ -62,7 +63,7 @@ TEST_P(DetectRow, MatchesPython) {EXPECT_EQ(lg::IsEnglish(state), row.Find("is_english")->as_bool()) << name;EXPECT_EQ(lg::DetectLanguage(state), a.language) << name;}-INSTANTIATE_TEST_SUITE_P(Golden, DetectRow, ::testing::ValuesIn(laya_test::Rows("lang_detect.json", {"cases"})));+INSTANTIATE_TEST_SUITE_P(Golden, DetectRow, ::testing::ValuesIn(laya_test::Rows(106)));TEST(Lang, ScriptOfMatchesPythonEverywhere) {LAYA_GOLDEN_LIST(want, "lang_detect.json", "unicode_digests", "script_of");