|
10 | 10 | #include "test_helpers.h" |
11 | 11 | #include "foundation/mem.h" // cbm_mem_init/budget (back-pressure futile-nap test) |
12 | 12 | #include "pipeline/pipeline.h" |
| 13 | +#include "pipeline/lsp_surface.h" |
13 | 14 | #include "pipeline/pipeline_internal.h" |
14 | 15 | #include "pipeline/artifact.h" |
15 | 16 | #include "store/store.h" |
@@ -14185,6 +14186,48 @@ TEST(pipeline_seq_ts_cross_uses_shared_registry) { |
14185 | 14186 | PASS(); |
14186 | 14187 | } |
14187 | 14188 |
|
| 14189 | +/* Object arrays are non-flat in yyjson. Exercise ordered decoding and arena |
| 14190 | + * ownership across a large surface, including nested string arrays. */ |
| 14191 | +TEST(pipeline_lsp_surface_large_object_array_decode) { |
| 14192 | + const int count = 8192; |
| 14193 | + const size_t capacity = (size_t)count * 192 + 64; |
| 14194 | + char *json = malloc(capacity); |
| 14195 | + ASSERT_NOT_NULL(json); |
| 14196 | + size_t used = (size_t)snprintf(json, capacity, "{\"v\":1,\"lsp\":["); |
| 14197 | + for (int i = 0; i < count; i++) { |
| 14198 | + int n = snprintf(json + used, capacity - used, |
| 14199 | + "%s{\"qn\":\"pkg.f%d\",\"sn\":\"f%d\",\"lb\":\"Function\"," |
| 14200 | + "\"spt\":[\"str\",\"int\"],\"dec\":[\"first\",\"second\"]}", |
| 14201 | + i ? "," : "", i, i); |
| 14202 | + ASSERT_TRUE(n > 0 && (size_t)n < capacity - used); |
| 14203 | + used += (size_t)n; |
| 14204 | + } |
| 14205 | + snprintf(json + used, capacity - used, "]}"); |
| 14206 | + CBMArena arena; |
| 14207 | + cbm_arena_init(&arena); |
| 14208 | + CBMLSPDef *defs = NULL; |
| 14209 | + int decoded = cbm_lsp_surface_defs_from_json(&arena, json, &defs); |
| 14210 | + free(json); |
| 14211 | + ASSERT_EQ(decoded, count); |
| 14212 | + ASSERT_NOT_NULL(defs); |
| 14213 | + for (int i = 0; i < count; i++) { |
| 14214 | + char expected[64]; |
| 14215 | + snprintf(expected, sizeof(expected), "pkg.f%d", i); |
| 14216 | + ASSERT_STR_EQ(defs[i].qualified_name, expected); |
| 14217 | + snprintf(expected, sizeof(expected), "f%d", i); |
| 14218 | + ASSERT_STR_EQ(defs[i].short_name, expected); |
| 14219 | + ASSERT_STR_EQ(defs[i].label, "Function"); |
| 14220 | + ASSERT_EQ(defs[i].signature_param_count, 2); |
| 14221 | + ASSERT_STR_EQ(defs[i].signature_param_types[0], "str"); |
| 14222 | + ASSERT_STR_EQ(defs[i].signature_param_types[1], "int"); |
| 14223 | + ASSERT_STR_EQ(defs[i].decorators[0], "first"); |
| 14224 | + ASSERT_STR_EQ(defs[i].decorators[1], "second"); |
| 14225 | + ASSERT_NULL(defs[i].decorators[2]); |
| 14226 | + } |
| 14227 | + cbm_arena_destroy(&arena); |
| 14228 | + PASS(); |
| 14229 | +} |
| 14230 | + |
14188 | 14231 | /* The closure-repair route lives and dies by two properties of the persisted |
14189 | 14232 | * per-file LSP surface: a BODY edit must leave the surface_sha unchanged (the |
14190 | 14233 | * early cutoff -- no dependent recomputation owed), while a SIGNATURE edit |
@@ -15054,6 +15097,7 @@ TEST(pipeline_objectscript_export_range_join_keeps_one_trailing_marker) { |
15054 | 15097 | #endif |
15055 | 15098 |
|
15056 | 15099 | SUITE(pipeline) { |
| 15100 | + RUN_TEST(pipeline_lsp_surface_large_object_array_decode); |
15057 | 15101 | RUN_TEST(pipeline_lsp_surface_persisted_and_body_edit_invariant); |
15058 | 15102 | /* Index lock */ |
15059 | 15103 | RUN_TEST(pipeline_lock_try_acquire); |
|
0 commit comments