@@ -15329,15 +15329,38 @@ TEST(registry_short_name_indexes) {
1532915329 cbm_registry_build_type_short_index(®);
1533015330
1533115331 /* Qualified-name bare segment "Trait": types 0, 4, then the bare-QN type
15332- * 5. C-LSP applies its stricter dotted-QN predicate on top of this index. */
15332+ * 5. The iterator is a hash prefilter, so apply the exact predicate before
15333+ * asserting its order just like production consumers do. */
1533315334 CBMTypeNameIter nit;
1533415335 cbm_registry_types_by_short_name(®, "Trait", &nit);
15335- ASSERT_EQ(cbm_type_name_iter_next(&nit), 0);
15336- ASSERT_EQ(cbm_type_name_iter_next(&nit), 4);
15337- ASSERT_EQ(cbm_type_name_iter_next(&nit), 5);
15338- ASSERT_EQ(cbm_type_name_iter_next(&nit), -1);
15336+ {
15337+ int expected[] = {0, 4, 5};
15338+ int exact_count = 0;
15339+ int candidate;
15340+ while ((candidate = cbm_type_name_iter_next(&nit)) >= 0) {
15341+ const char *qn = reg.types[candidate].qualified_name;
15342+ const char *last_dot = qn ? strrchr(qn, '.') : NULL;
15343+ const char *candidate_short = last_dot ? last_dot + 1 : qn;
15344+ if (!candidate_short || strcmp(candidate_short, "Trait") != 0)
15345+ continue;
15346+ ASSERT_TRUE(exact_count < 3);
15347+ ASSERT_EQ(candidate, expected[exact_count++]);
15348+ }
15349+ ASSERT_EQ(exact_count, 3);
15350+ }
1533915351 cbm_registry_types_by_short_name(®, "Missing", &nit);
15340- ASSERT_EQ(cbm_type_name_iter_next(&nit), -1);
15352+ {
15353+ int exact_count = 0;
15354+ int candidate;
15355+ while ((candidate = cbm_type_name_iter_next(&nit)) >= 0) {
15356+ const char *qn = reg.types[candidate].qualified_name;
15357+ const char *last_dot = qn ? strrchr(qn, '.') : NULL;
15358+ const char *candidate_short = last_dot ? last_dot + 1 : qn;
15359+ if (candidate_short && strcmp(candidate_short, "Missing") == 0)
15360+ exact_count++;
15361+ }
15362+ ASSERT_EQ(exact_count, 0);
15363+ }
1534115364
1534215365 for (int name_i = 0; name_i < 23; name_i++) {
1534315366 char short_name[32];
@@ -15438,6 +15461,35 @@ TEST(registry_short_name_indexes) {
1543815461 ASSERT_EQ(fallback_count, 4);
1543915462 reg.type_short_buckets = saved_type_short_buckets;
1544015463
15464+ /* A failed rebuild must discard the previous auxiliary index. Re-finalize
15465+ * after adding the tail type so the QN boundary advances, then force arena
15466+ * exhaustion for the optional rebuild. The iterator must fall back to the
15467+ * complete linear scan instead of retaining the stale pre-tail index. */
15468+ cbm_registry_finalize(®);
15469+ int saved_nblocks = arena.nblocks;
15470+ size_t saved_used = arena.used;
15471+ arena.nblocks = CBM_ARENA_MAX_BLOCKS;
15472+ arena.used = arena.block_size;
15473+ cbm_registry_build_type_short_index(®);
15474+ arena.nblocks = saved_nblocks;
15475+ arena.used = saved_used;
15476+ ASSERT_NULL(reg.type_short_buckets);
15477+ ASSERT_NULL(reg.type_short_entries);
15478+ ASSERT_EQ(reg.type_short_bucket_count, 0);
15479+
15480+ cbm_registry_types_by_short_name(®, "Trait", &nit);
15481+ fallback_count = 0;
15482+ while ((candidate = cbm_type_name_iter_next(&nit)) >= 0) {
15483+ const char *qn = reg.types[candidate].qualified_name;
15484+ const char *last_dot = qn ? strrchr(qn, '.') : NULL;
15485+ const char *candidate_short = last_dot ? last_dot + 1 : qn;
15486+ if (!candidate_short || strcmp(candidate_short, "Trait") != 0)
15487+ continue;
15488+ ASSERT_TRUE(fallback_count < 4);
15489+ ASSERT_EQ(candidate, fallback_expected[fallback_count++]);
15490+ }
15491+ ASSERT_EQ(fallback_count, 4);
15492+
1544115493 cbm_arena_destroy(&arena);
1544215494 PASS();
1544315495}
0 commit comments