From bd1fb69800e9780bdf470d5ec763bec4aaf1bd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Wed, 2 Sep 2026 14:50:58 +0200 Subject: [PATCH] [Oracle/Tests] Pin cmc coercion in CI run; scope the reserve pass The #7214 coercion assertion lived only in oracle_importer_benchmark_test, which gets no add_test and so never runs under ctest. Add NumericManaValueCoercedToCmc and LegacyConvertedManaCostCoercedToCmc to oracle_importer_test (a CI-ran binary): manaValue/convertedManaCost are JSON numbers in AllPrintings, and QJsonValue::toString() would drop them to an empty cmc without the #7214 coercion fix. Wrap the distinct-name reserve pass in a bare block so the ~35k name QStrings are handed back before the memory-heavy import loop starts. --- oracle/src/oracleimporter.cpp | 14 +++++++++----- tests/oracle/oracle_importer_test.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index f0dc3b1ae..49577baf0 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -555,13 +555,17 @@ int OracleImporter::startImport() // ships ~100k printings for ~35k names, so reserving the printing count // would overallocate ~3x (against this stack's RAM goal). Collecting // distinct names is cheap — one pass over the already-parsed name fields. - QSet distinctNames; - for (const SetToDownload &curSetToParse : allSets) { - for (const QJsonValue &cardValue : curSetToParse.getCards()) { - distinctNames.insert(cardValue.toObject().value("name").toString()); + { + QSet distinctNames; + for (const SetToDownload &curSetToParse : allSets) { + for (const QJsonValue &cardValue : curSetToParse.getCards()) { + distinctNames.insert(cardValue.toObject().value("name").toString()); + } } + cards.reserve(distinctNames.size()); + // The set goes out of scope here, handing the ~35k name QStrings back + // to the allocator before the (memory-heavy) import loop starts. } - cards.reserve(distinctNames.size()); // add an empty set for tokens CardSetPtr tokenSet = diff --git a/tests/oracle/oracle_importer_test.cpp b/tests/oracle/oracle_importer_test.cpp index 19f66e5e6..145a2ca0f 100644 --- a/tests/oracle/oracle_importer_test.cpp +++ b/tests/oracle/oracle_importer_test.cpp @@ -482,6 +482,33 @@ TEST_F(OracleImporterTest, ManaCostStripsBraces) ASSERT_EQ(result->getProperty("manacost"), "2WB"); } +// cmc comes through as a JSON number ("convertedManaCost"/"manaValue" are +// floats in AllPrintings), so this pins the number-to-text coercion that +// QJsonValue::toString() dropped in #7214. +TEST_F(OracleImporterTest, NumericManaValueCoercedToCmc) +{ + QJsonObject card = makeCard("Cmc Card"); + card["manaValue"] = 3; + QJsonArray cards{card}; + + importer->importCardsFromSet(set, cards); + auto result = importer->getCardList().value("Cmc Card"); + ASSERT_FALSE(result.isNull()); + ASSERT_EQ(result->getProperty("cmc"), "3"); +} + +TEST_F(OracleImporterTest, LegacyConvertedManaCostCoercedToCmc) +{ + QJsonObject card = makeCard("Legacy Cmc Card"); + card["convertedManaCost"] = 3.0; + QJsonArray cards{card}; + + importer->importCardsFromSet(set, cards); + auto result = importer->getCardList().value("Legacy Cmc Card"); + ASSERT_FALSE(result.isNull()); + ASSERT_EQ(result->getProperty("cmc"), "3"); +} + // ============================================================================ // Card deduplication tests // ============================================================================