@smoothbricks/lmao 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/dist/allocator.wasm +0 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/lib/JsBufferStrategy.d.ts +4 -3
  6. package/dist/lib/JsBufferStrategy.d.ts.map +1 -1
  7. package/dist/lib/JsBufferStrategy.js +18 -11
  8. package/dist/lib/arrow/lease.d.ts +10 -0
  9. package/dist/lib/arrow/lease.d.ts.map +1 -0
  10. package/dist/lib/arrow/lease.js +33 -0
  11. package/dist/lib/arrow/utils.d.ts +3 -4
  12. package/dist/lib/arrow/utils.d.ts.map +1 -1
  13. package/dist/lib/arrow/utils.js +12 -13
  14. package/dist/lib/arrow/vocabularyDictionary.d.ts +21 -0
  15. package/dist/lib/arrow/vocabularyDictionary.d.ts.map +1 -0
  16. package/dist/lib/arrow/vocabularyDictionary.js +95 -0
  17. package/dist/lib/bufferStrategy.d.ts +3 -2
  18. package/dist/lib/bufferStrategy.d.ts.map +1 -1
  19. package/dist/lib/cloudflare/traceRows.d.ts.map +1 -1
  20. package/dist/lib/cloudflare/traceRows.js +3 -2
  21. package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -1
  22. package/dist/lib/codegen/evaluatorGenerator.js +12 -11
  23. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +44 -82
  24. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -1
  25. package/dist/lib/codegen/fixedPositionWriterGenerator.js +223 -162
  26. package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts +63 -0
  27. package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts.map +1 -0
  28. package/dist/lib/codegen/spanLoggerClosureMaterializer.js +447 -0
  29. package/dist/lib/codegen/spanLoggerGenerator.d.ts +36 -19
  30. package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -1
  31. package/dist/lib/codegen/spanLoggerGenerator.js +164 -158
  32. package/dist/lib/convertToArrow.d.ts +7 -2
  33. package/dist/lib/convertToArrow.d.ts.map +1 -1
  34. package/dist/lib/convertToArrow.js +499 -285
  35. package/dist/lib/defineOpContext.js +1 -1
  36. package/dist/lib/enumMetadata.d.ts +19 -0
  37. package/dist/lib/enumMetadata.d.ts.map +1 -0
  38. package/dist/lib/enumMetadata.js +86 -0
  39. package/dist/lib/flushScheduler.d.ts.map +1 -1
  40. package/dist/lib/flushScheduler.js +13 -4
  41. package/dist/lib/library.d.ts +16 -98
  42. package/dist/lib/library.d.ts.map +1 -1
  43. package/dist/lib/library.js +32 -525
  44. package/dist/lib/logBinding.d.ts +21 -27
  45. package/dist/lib/logBinding.d.ts.map +1 -1
  46. package/dist/lib/op.d.ts +30 -30
  47. package/dist/lib/op.d.ts.map +1 -1
  48. package/dist/lib/op.js +15 -22
  49. package/dist/lib/opContext/createOpGroup.d.ts +1 -1
  50. package/dist/lib/opContext/createOpGroup.d.ts.map +1 -1
  51. package/dist/lib/opContext/createOpGroup.js +22 -29
  52. package/dist/lib/opContext/defineOp.d.ts +4 -4
  53. package/dist/lib/opContext/defineOp.d.ts.map +1 -1
  54. package/dist/lib/opContext/defineOp.js +53 -10
  55. package/dist/lib/opContext/opGroupTypes.d.ts +2 -2
  56. package/dist/lib/opContext/opTypes.d.ts +1 -1
  57. package/dist/lib/opContext/opTypes.d.ts.map +1 -1
  58. package/dist/lib/opContext/spanContextTypes.d.ts +29 -14
  59. package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -1
  60. package/dist/lib/opContext/types.d.ts +4 -4
  61. package/dist/lib/opContext/types.d.ts.map +1 -1
  62. package/dist/lib/physicalLayoutPlan.d.ts +89 -0
  63. package/dist/lib/physicalLayoutPlan.d.ts.map +1 -0
  64. package/dist/lib/physicalLayoutPlan.js +442 -0
  65. package/dist/lib/resolveMessage.d.ts +9 -0
  66. package/dist/lib/resolveMessage.d.ts.map +1 -0
  67. package/dist/lib/resolveMessage.js +63 -0
  68. package/dist/lib/result.d.ts +5 -7
  69. package/dist/lib/result.d.ts.map +1 -1
  70. package/dist/lib/result.js +19 -26
  71. package/dist/lib/runtimeHint.d.ts +35 -0
  72. package/dist/lib/runtimeHint.d.ts.map +1 -0
  73. package/dist/lib/runtimeHint.js +79 -0
  74. package/dist/lib/schema/types.d.ts +1 -1
  75. package/dist/lib/schema/types.d.ts.map +1 -1
  76. package/dist/lib/span-buffer/aot/v1.d.ts +2 -0
  77. package/dist/lib/span-buffer/aot/v1.d.ts.map +1 -0
  78. package/dist/lib/span-buffer/aot/v1.js +24 -0
  79. package/dist/lib/spanBuffer.d.ts +33 -4
  80. package/dist/lib/spanBuffer.d.ts.map +1 -1
  81. package/dist/lib/spanBuffer.js +583 -91
  82. package/dist/lib/spanBufferStats.d.ts +1 -1
  83. package/dist/lib/spanBufferStats.d.ts.map +1 -1
  84. package/dist/lib/spanContext.d.ts +27 -51
  85. package/dist/lib/spanContext.d.ts.map +1 -1
  86. package/dist/lib/spanContext.js +822 -344
  87. package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -1
  88. package/dist/lib/sqlite/sqlite-common.js +20 -21
  89. package/dist/lib/testing/bun-harness.d.ts +8 -3
  90. package/dist/lib/testing/bun-harness.d.ts.map +1 -1
  91. package/dist/lib/testing/bun-harness.js +30 -18
  92. package/dist/lib/testing/extractFacts.d.ts +1 -1
  93. package/dist/lib/testing/extractFacts.d.ts.map +1 -1
  94. package/dist/lib/testing/extractFacts.js +55 -63
  95. package/dist/lib/testing/facts.d.ts +1 -1
  96. package/dist/lib/testing/facts.d.ts.map +1 -1
  97. package/dist/lib/testing/queryable-span.d.ts +1 -1
  98. package/dist/lib/testing/queryable-span.d.ts.map +1 -1
  99. package/dist/lib/testing/queryable-span.js +26 -28
  100. package/dist/lib/testing/span-query.d.ts.map +1 -1
  101. package/dist/lib/testing/span-query.js +19 -22
  102. package/dist/lib/testing/stdio-replay.d.ts.map +1 -1
  103. package/dist/lib/testing/stdio-replay.js +19 -8
  104. package/dist/lib/threadId.d.ts.map +1 -1
  105. package/dist/lib/threadId.js +6 -3
  106. package/dist/lib/traceRoot.d.ts +30 -8
  107. package/dist/lib/traceRoot.d.ts.map +1 -1
  108. package/dist/lib/traceRoot.es.d.ts +17 -15
  109. package/dist/lib/traceRoot.es.d.ts.map +1 -1
  110. package/dist/lib/traceRoot.es.js +68 -34
  111. package/dist/lib/traceRoot.js +11 -0
  112. package/dist/lib/traceRoot.node.d.ts +17 -19
  113. package/dist/lib/traceRoot.node.d.ts.map +1 -1
  114. package/dist/lib/traceRoot.node.js +66 -38
  115. package/dist/lib/traceTopology.d.ts +42 -0
  116. package/dist/lib/traceTopology.d.ts.map +1 -0
  117. package/dist/lib/traceTopology.js +260 -0
  118. package/dist/lib/tracer.d.ts +9 -5
  119. package/dist/lib/tracer.d.ts.map +1 -1
  120. package/dist/lib/tracer.js +65 -71
  121. package/dist/lib/tracers/ArrayQueueTracer.d.ts +1 -1
  122. package/dist/lib/tracers/ArrayQueueTracer.js +1 -1
  123. package/dist/lib/tracers/StdioTracer.d.ts.map +1 -1
  124. package/dist/lib/tracers/StdioTracer.js +15 -13
  125. package/dist/lib/tracers/TestTracer.d.ts +4 -6
  126. package/dist/lib/tracers/TestTracer.d.ts.map +1 -1
  127. package/dist/lib/tracers/TestTracer.js +6 -8
  128. package/dist/lib/types.d.ts +49 -32
  129. package/dist/lib/types.d.ts.map +1 -1
  130. package/dist/lib/vocabularyRegistry.d.ts +25 -0
  131. package/dist/lib/vocabularyRegistry.d.ts.map +1 -0
  132. package/dist/lib/vocabularyRegistry.js +372 -0
  133. package/dist/lib/wasm/WasmBufferStrategy.d.ts +6 -10
  134. package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -1
  135. package/dist/lib/wasm/WasmBufferStrategy.js +44 -37
  136. package/dist/lib/wasm/wasmAllocator.d.ts +27 -22
  137. package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -1
  138. package/dist/lib/wasm/wasmAllocator.js +66 -44
  139. package/dist/lib/wasm/wasmPhysicalLayout.d.ts +67 -0
  140. package/dist/lib/wasm/wasmPhysicalLayout.d.ts.map +1 -0
  141. package/dist/lib/wasm/wasmPhysicalLayout.js +179 -0
  142. package/dist/lib/wasm/wasmSpanBuffer.d.ts +79 -31
  143. package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -1
  144. package/dist/lib/wasm/wasmSpanBuffer.js +442 -272
  145. package/dist/lib/wasm/wasmTraceRoot.d.ts +24 -22
  146. package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -1
  147. package/dist/lib/wasm/wasmTraceRoot.js +110 -71
  148. package/dist/vocabulary/register/v1.d.ts +2 -0
  149. package/dist/vocabulary/register/v1.d.ts.map +1 -0
  150. package/dist/vocabulary/register/v1.js +1 -0
  151. package/dist/wasm.d.ts +5 -0
  152. package/dist/wasm.d.ts.map +1 -0
  153. package/dist/wasm.js +4 -0
  154. package/package.json +54 -6
  155. package/src/index.ts +1 -0
  156. package/src/lib/JsBufferStrategy.ts +27 -9
  157. package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +335 -37
  158. package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +97 -26
  159. package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +75 -15
  160. package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +30 -6
  161. package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +18 -21
  162. package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +5 -2
  163. package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +25 -7
  164. package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +3 -2
  165. package/src/lib/__tests__/buffer-overflow.test.ts +24 -18
  166. package/src/lib/__tests__/capability-span-context.test.ts +505 -0
  167. package/src/lib/__tests__/capacity-tuning.test.ts +5 -3
  168. package/src/lib/__tests__/eager-columns.test.ts +345 -0
  169. package/src/lib/__tests__/enum-metadata-aot.test.ts +153 -0
  170. package/src/lib/__tests__/enum-metadata.test.ts +177 -0
  171. package/src/lib/__tests__/fixtures/empty-vocabulary-runtime.fixture.ts +15 -0
  172. package/src/lib/__tests__/flushScheduler.test.ts +5 -1
  173. package/src/lib/__tests__/identity-view.property.test.ts +179 -0
  174. package/src/lib/__tests__/library.test.ts +19 -235
  175. package/src/lib/__tests__/message-buffer-families.test.ts +878 -0
  176. package/src/lib/__tests__/nested-library-tasks.test.ts +14 -15
  177. package/src/lib/__tests__/op-metadata.test.ts +1 -1
  178. package/src/lib/__tests__/op-type-safety.test.ts +5 -16
  179. package/src/lib/__tests__/physical-layout-plan.test.ts +333 -0
  180. package/src/lib/__tests__/remap-descriptor-integration.test.ts +381 -0
  181. package/src/lib/__tests__/root-context-construction.test.ts +414 -0
  182. package/src/lib/__tests__/span-auto-runtime.test.ts +386 -0
  183. package/src/lib/__tests__/span-buffer-segment-stats.test.ts +221 -0
  184. package/src/lib/__tests__/span-lifecycle.test.ts +53 -25
  185. package/src/lib/__tests__/spanbuffer-materializer-parity.test.ts +266 -0
  186. package/src/lib/__tests__/sync-async-trace.test.ts +24 -23
  187. package/src/lib/__tests__/tag-writer-aot.test.ts +214 -0
  188. package/src/lib/__tests__/test-helpers.ts +67 -12
  189. package/src/lib/__tests__/threadId.test.ts +62 -0
  190. package/src/lib/__tests__/timestamp.test.ts +221 -93
  191. package/src/lib/__tests__/traceTopology.property.test.ts +383 -0
  192. package/src/lib/__tests__/type-narrowing.test.ts +63 -0
  193. package/src/lib/__tests__/vocabulary-dense-decoding.test.ts +405 -0
  194. package/src/lib/__tests__/vocabularyRegistry.test.ts +313 -0
  195. package/src/lib/arrow/lease.ts +43 -0
  196. package/src/lib/arrow/utils.ts +10 -14
  197. package/src/lib/arrow/vocabularyDictionary.ts +123 -0
  198. package/src/lib/bufferStrategy.ts +9 -1
  199. package/src/lib/cloudflare/traceRows.ts +3 -2
  200. package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +21 -141
  201. package/src/lib/codegen/__tests__/fixedPositionWriter-parity.test.ts +273 -0
  202. package/src/lib/codegen/__tests__/fixedPositionWriter-uint64.test.ts +61 -34
  203. package/src/lib/codegen/__tests__/nullBitmap.test.ts +33 -37
  204. package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +34 -18
  205. package/src/lib/codegen/__tests__/spanLoggerMaterializerParity.test.ts +503 -0
  206. package/src/lib/codegen/evaluatorGenerator.ts +18 -13
  207. package/src/lib/codegen/fixedPositionWriterGenerator.ts +329 -245
  208. package/src/lib/codegen/spanLoggerClosureMaterializer.ts +598 -0
  209. package/src/lib/codegen/spanLoggerGenerator.ts +241 -177
  210. package/src/lib/convertToArrow.ts +598 -311
  211. package/src/lib/defineOpContext.ts +1 -1
  212. package/src/lib/enumMetadata.ts +121 -0
  213. package/src/lib/flushScheduler.ts +11 -5
  214. package/src/lib/library.ts +37 -595
  215. package/src/lib/logBinding.ts +21 -27
  216. package/src/lib/op.ts +75 -18
  217. package/src/lib/opContext/__tests__/retry.test.ts +27 -21
  218. package/src/lib/opContext/createOpGroup.ts +33 -31
  219. package/src/lib/opContext/defineOp.ts +88 -11
  220. package/src/lib/opContext/opGroupTypes.ts +2 -2
  221. package/src/lib/opContext/opTypes.ts +1 -1
  222. package/src/lib/opContext/spanContextTypes.ts +98 -17
  223. package/src/lib/opContext/types.ts +7 -3
  224. package/src/lib/physicalLayoutPlan.ts +598 -0
  225. package/src/lib/resolveMessage.ts +67 -0
  226. package/src/lib/result.ts +20 -33
  227. package/src/lib/runtimeHint.ts +98 -0
  228. package/src/lib/schema/__tests__/featureFlags.test.ts +2 -1
  229. package/src/lib/schema/builder.ts +1 -1
  230. package/src/lib/schema/types.ts +1 -1
  231. package/src/lib/span-buffer/aot/v1.ts +26 -0
  232. package/src/lib/spanBuffer.ts +658 -92
  233. package/src/lib/spanBufferStats.ts +1 -1
  234. package/src/lib/spanContext.ts +1350 -861
  235. package/src/lib/sqlite/sqlite-common.ts +20 -31
  236. package/src/lib/testing/__tests__/topology-traversal.test.ts +174 -0
  237. package/src/lib/testing/__tests__/vitest-harness.test.ts +2 -1
  238. package/src/lib/testing/bun-harness.ts +94 -43
  239. package/src/lib/testing/extractFacts.ts +64 -78
  240. package/src/lib/testing/facts.ts +1 -1
  241. package/src/lib/testing/queryable-span.ts +23 -30
  242. package/src/lib/testing/span-query.ts +16 -20
  243. package/src/lib/testing/stdio-replay.ts +25 -8
  244. package/src/lib/testing/vitest-harness.ts +1 -1
  245. package/src/lib/threadId.ts +6 -3
  246. package/src/lib/traceRoot.es.ts +77 -42
  247. package/src/lib/traceRoot.node.ts +75 -46
  248. package/src/lib/traceRoot.ts +41 -14
  249. package/src/lib/traceTopology.ts +279 -0
  250. package/src/lib/tracer.ts +109 -98
  251. package/src/lib/tracers/ArrayQueueTracer.ts +1 -1
  252. package/src/lib/tracers/StdioTracer.ts +15 -13
  253. package/src/lib/tracers/TestTracer.ts +6 -8
  254. package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +15 -10
  255. package/src/lib/tracers/__tests__/TestTracer.test.ts +23 -13
  256. package/src/lib/types.ts +64 -33
  257. package/src/lib/vocabularyRegistry.ts +439 -0
  258. package/src/lib/wasm/WasmBufferStrategy.ts +56 -48
  259. package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +215 -11
  260. package/src/lib/wasm/__tests__/allocatorFreeBlockClamp.test.ts +86 -0
  261. package/src/lib/wasm/__tests__/wasm-identity-view.test.ts +311 -0
  262. package/src/lib/wasm/__tests__/wasm-integration.test.ts +417 -44
  263. package/src/lib/wasm/__tests__/wasm-message-buffer-families.test.ts +588 -0
  264. package/src/lib/wasm/__tests__/wasmAllocator.test.ts +100 -668
  265. package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +419 -63
  266. package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +24 -29
  267. package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +2 -2
  268. package/src/lib/wasm/wasmAllocator.ts +131 -96
  269. package/src/lib/wasm/wasmPhysicalLayout.ts +309 -0
  270. package/src/lib/wasm/wasmSpanBuffer.ts +597 -341
  271. package/src/lib/wasm/wasmTraceRoot.ts +140 -78
  272. package/src/vocabulary/register/v1.ts +1 -0
  273. package/src/wasm.ts +19 -0
  274. package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +0 -319
  275. package/src/lib/__tests__/remapped-buffer-view.test.ts +0 -635
  276. package/src/lib/wasm/allocator.zig +0 -948
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Public integration contracts for immutable library remap descriptors.
3
+ *
4
+ * Mapped operations keep canonical child SpanBuffers in the logical tree. Arrow
5
+ * conversion applies their immutable descriptors only during cold traversal.
6
+ */
7
+
8
+ import { describe, expect, it } from 'bun:test';
9
+ // Must import test-helpers first to initialize timestamp implementation
10
+ import './test-helpers.js';
11
+ import type { Table } from '@uwdata/flechette';
12
+ import { convertSpanTreeToArrowTable } from '../convertToArrow.js';
13
+ import { defineOpContext } from '../defineOpContext.js';
14
+ import { S } from '../schema/builder.js';
15
+ import { defineLogSchema } from '../schema/defineLogSchema.js';
16
+ import { TestTracer } from '../tracers/TestTracer.js';
17
+ import { iterateSpanChildren } from '../traceTopology.js';
18
+ import type { AnySpanBuffer } from '../types.js';
19
+ import { createTestTracerOptions } from './test-helpers.js';
20
+
21
+ const ARROW_METADATA_FIELDS = [
22
+ 'timestamp',
23
+ 'trace_id',
24
+ 'thread_id',
25
+ 'span_id',
26
+ 'parent_thread_id',
27
+ 'parent_span_id',
28
+ 'entry_type',
29
+ 'package_name',
30
+ 'package_file',
31
+ 'git_sha',
32
+ 'message',
33
+ 'uint64_value',
34
+ ] as const;
35
+
36
+ function extractRows(table: Table, columns: readonly string[]): Array<Record<string, unknown>> {
37
+ return Array.from({ length: table.numRows }, (_, rowIndex) => {
38
+ const row: Record<string, unknown> = {};
39
+ for (const columnName of columns) {
40
+ const column = table.getChild(columnName);
41
+ if (!column) throw new Error(`Arrow table omitted '${columnName}'`);
42
+ row[columnName] = column.get(rowIndex);
43
+ }
44
+ return row;
45
+ });
46
+ }
47
+
48
+ function expectArrowSchema(table: Table, userFields: readonly string[]): void {
49
+ expect(table.schema.fields.map((field) => field.name)).toEqual([...ARROW_METADATA_FIELDS, ...userFields]);
50
+ }
51
+
52
+ describe('Library remap descriptor integration', () => {
53
+ it('composes nested prefixes for same-schema siblings without wrapping canonical child buffers', async () => {
54
+ const librarySchema = defineLogSchema({
55
+ value: S.number(),
56
+ label: S.category(),
57
+ });
58
+ const libraryContext = defineOpContext({ logSchema: librarySchema });
59
+ const childBuffers: AnySpanBuffer[] = [];
60
+ const libraryOps = libraryContext.defineOps({
61
+ recordNested: async (ctx) => {
62
+ childBuffers.push(ctx.buffer);
63
+ ctx.tag.value(11).label('nested');
64
+ return ctx.ok(null);
65
+ },
66
+ recordSibling: async (ctx) => {
67
+ childBuffers.push(ctx.buffer);
68
+ ctx.tag.value(22).label('sibling');
69
+ return ctx.ok(null);
70
+ },
71
+ });
72
+ const nested = libraryOps.prefix('api').prefix('v1');
73
+ const sibling = libraryOps.prefix('sibling');
74
+
75
+ const appContext = defineOpContext({
76
+ logSchema: defineLogSchema({ rootValue: S.number() }),
77
+ deps: { nested, sibling },
78
+ });
79
+ let rootBuffer: AnySpanBuffer | undefined;
80
+ const rootOp = appContext.defineOp('root-op', async (ctx) => {
81
+ rootBuffer = ctx.buffer;
82
+ ctx.tag.rootValue(1);
83
+ await ctx.span('nested-child', ctx.deps.nested.recordNested);
84
+ await ctx.span('sibling-child', ctx.deps.sibling.recordSibling);
85
+ return ctx.ok(null);
86
+ });
87
+
88
+ const { trace } = new TestTracer(appContext, createTestTracerOptions());
89
+ await trace('root-span', rootOp);
90
+
91
+ if (!rootBuffer) throw new Error('root span did not expose its buffer');
92
+ expect(childBuffers).toHaveLength(2);
93
+ const nestedBuffer = childBuffers[0];
94
+ const siblingBuffer = childBuffers[1];
95
+ if (!nestedBuffer || !siblingBuffer) throw new Error('library child buffers were not captured');
96
+
97
+ expect(Array.from(iterateSpanChildren(rootBuffer))).toEqual([nestedBuffer, siblingBuffer]);
98
+ expect(nestedBuffer._logSchema).toBe(libraryContext.logBinding.logSchema);
99
+ expect(siblingBuffer._logSchema).toBe(libraryContext.logBinding.logSchema);
100
+ expect(nestedBuffer.constructor).toBe(siblingBuffer.constructor);
101
+ expect(nestedBuffer._remapDescriptor).toBe(nested.recordNested.callsitePlan.remapDescriptor ?? undefined);
102
+ expect(siblingBuffer._remapDescriptor).toBe(sibling.recordSibling.callsitePlan.remapDescriptor ?? undefined);
103
+ expect(nested.recordNested.callsitePlan.remapDescriptor?.sourceNames).toEqual({
104
+ v1_api_value: 'value',
105
+ v1_api_label: 'label',
106
+ });
107
+ expect(sibling.recordSibling.callsitePlan.remapDescriptor?.sourceNames).toEqual({
108
+ sibling_value: 'value',
109
+ sibling_label: 'label',
110
+ });
111
+
112
+ const table = convertSpanTreeToArrowTable(rootBuffer);
113
+ expectArrowSchema(table, ['rootValue', 'v1_api_value', 'v1_api_label', 'sibling_value', 'sibling_label']);
114
+ expect(table.numRows).toBe(6);
115
+ expect(
116
+ extractRows(table, [
117
+ 'entry_type',
118
+ 'message',
119
+ 'rootValue',
120
+ 'v1_api_value',
121
+ 'v1_api_label',
122
+ 'sibling_value',
123
+ 'sibling_label',
124
+ ]),
125
+ ).toEqual([
126
+ {
127
+ entry_type: 'span-start',
128
+ message: 'root-span',
129
+ rootValue: 1,
130
+ v1_api_value: null,
131
+ v1_api_label: null,
132
+ sibling_value: null,
133
+ sibling_label: null,
134
+ },
135
+ {
136
+ entry_type: 'span-ok',
137
+ message: null,
138
+ rootValue: null,
139
+ v1_api_value: null,
140
+ v1_api_label: null,
141
+ sibling_value: null,
142
+ sibling_label: null,
143
+ },
144
+ {
145
+ entry_type: 'span-start',
146
+ message: 'nested-child',
147
+ rootValue: null,
148
+ v1_api_value: 11,
149
+ v1_api_label: 'nested',
150
+ sibling_value: null,
151
+ sibling_label: null,
152
+ },
153
+ {
154
+ entry_type: 'span-ok',
155
+ message: null,
156
+ rootValue: null,
157
+ v1_api_value: null,
158
+ v1_api_label: null,
159
+ sibling_value: null,
160
+ sibling_label: null,
161
+ },
162
+ {
163
+ entry_type: 'span-start',
164
+ message: 'sibling-child',
165
+ rootValue: null,
166
+ v1_api_value: null,
167
+ v1_api_label: null,
168
+ sibling_value: 22,
169
+ sibling_label: 'sibling',
170
+ },
171
+ {
172
+ entry_type: 'span-ok',
173
+ message: null,
174
+ rootValue: null,
175
+ v1_api_value: null,
176
+ v1_api_label: null,
177
+ sibling_value: null,
178
+ sibling_label: null,
179
+ },
180
+ ]);
181
+ });
182
+
183
+ it('keeps remapped values and nulls exact across an overflow chain', async () => {
184
+ const librarySchema = defineLogSchema({ value: S.number() });
185
+ const libraryContext = defineOpContext({ logSchema: librarySchema });
186
+ let childBuffer: AnySpanBuffer | undefined;
187
+ const libraryOps = libraryContext.defineOps({
188
+ overflow: async (ctx) => {
189
+ childBuffer = ctx.buffer;
190
+ ctx.tag.value(100);
191
+ for (let index = 0; index < 9; index++) {
192
+ const entry = ctx.log.info(`event-${index}`);
193
+ if (index % 2 === 0) entry.value(index);
194
+ }
195
+ return ctx.ok(null);
196
+ },
197
+ });
198
+ const mapped = libraryOps.prefix('overflow');
199
+ const originalCapacity = mapped.overflow.callsitePlan.SpanBufferClass.stats.capacity;
200
+ mapped.overflow.callsitePlan.SpanBufferClass.stats.capacity = 8;
201
+
202
+ const appContext = defineOpContext({
203
+ logSchema: defineLogSchema({}),
204
+ deps: { mapped },
205
+ });
206
+ let rootBuffer: AnySpanBuffer | undefined;
207
+ const rootOp = appContext.defineOp('root-op', async (ctx) => {
208
+ rootBuffer = ctx.buffer;
209
+ await ctx.span('overflow-child', ctx.deps.mapped.overflow);
210
+ return ctx.ok(null);
211
+ });
212
+
213
+ try {
214
+ const { trace } = new TestTracer(appContext, createTestTracerOptions());
215
+ await trace('root-span', rootOp);
216
+ } finally {
217
+ mapped.overflow.callsitePlan.SpanBufferClass.stats.capacity = originalCapacity;
218
+ }
219
+
220
+ if (!rootBuffer || !childBuffer) throw new Error('overflow trace did not expose its buffers');
221
+ expect(Array.from(iterateSpanChildren(rootBuffer))).toEqual([childBuffer]);
222
+ expect(childBuffer._overflow).toBeDefined();
223
+ expect(childBuffer._remapDescriptor).toBe(mapped.overflow.callsitePlan.remapDescriptor ?? undefined);
224
+
225
+ const table = convertSpanTreeToArrowTable(rootBuffer);
226
+ expectArrowSchema(table, ['overflow_value']);
227
+ expect(table.numRows).toBe(13);
228
+ expect(extractRows(table, ['entry_type', 'message', 'overflow_value'])).toEqual([
229
+ { entry_type: 'span-start', message: 'root-span', overflow_value: null },
230
+ { entry_type: 'span-ok', message: null, overflow_value: null },
231
+ { entry_type: 'span-start', message: 'overflow-child', overflow_value: 100 },
232
+ { entry_type: 'span-ok', message: null, overflow_value: null },
233
+ { entry_type: 'info', message: 'event-0', overflow_value: 0 },
234
+ { entry_type: 'info', message: 'event-1', overflow_value: null },
235
+ { entry_type: 'info', message: 'event-2', overflow_value: 2 },
236
+ { entry_type: 'info', message: 'event-3', overflow_value: null },
237
+ { entry_type: 'info', message: 'event-4', overflow_value: 4 },
238
+ { entry_type: 'info', message: 'event-5', overflow_value: null },
239
+ { entry_type: 'info', message: 'event-6', overflow_value: 6 },
240
+ { entry_type: 'info', message: 'event-7', overflow_value: null },
241
+ { entry_type: 'info', message: 'event-8', overflow_value: 8 },
242
+ ]);
243
+ });
244
+
245
+ it('preserves exact schema, preorder rows, nulls, and values through a depth-3 remapped tree', async () => {
246
+ const treeSchema = defineLogSchema({
247
+ outerValue: S.boolean(),
248
+ middleValue: S.number(),
249
+ leafValue: S.category(),
250
+ });
251
+ const leafContext = defineOpContext({ logSchema: treeSchema });
252
+ const leafOps = leafContext.defineOps({
253
+ run: async (ctx) => {
254
+ ctx.tag.leafValue('leaf');
255
+ return ctx.ok(null);
256
+ },
257
+ });
258
+ const mappedLeaf = leafOps
259
+ .mapColumns({ outerValue: null, middleValue: null, leafValue: 'leafValue' })
260
+ .prefix('leaf');
261
+
262
+ const middleContext = defineOpContext({ logSchema: treeSchema });
263
+ const middleOps = middleContext.defineOps({
264
+ run: async (ctx) => {
265
+ ctx.tag.middleValue(2);
266
+ await ctx.span('leaf-span', mappedLeaf.run);
267
+ return ctx.ok(null);
268
+ },
269
+ });
270
+ const mappedMiddle = middleOps
271
+ .mapColumns({ outerValue: null, middleValue: 'middleValue', leafValue: null })
272
+ .prefix('middle');
273
+
274
+ const outerContext = defineOpContext({ logSchema: treeSchema });
275
+ const outerOps = outerContext.defineOps({
276
+ run: async (ctx) => {
277
+ ctx.tag.outerValue(true);
278
+ await ctx.span('middle-span', mappedMiddle.run);
279
+ return ctx.ok(null);
280
+ },
281
+ });
282
+ const mappedOuter = outerOps
283
+ .mapColumns({ outerValue: 'outerValue', middleValue: null, leafValue: null })
284
+ .prefix('outer');
285
+
286
+ const appContext = defineOpContext({
287
+ logSchema: defineLogSchema({ rootValue: S.category() }),
288
+ deps: { outer: mappedOuter },
289
+ });
290
+ let rootBuffer: AnySpanBuffer | undefined;
291
+ const rootOp = appContext.defineOp('root-op', async (ctx) => {
292
+ rootBuffer = ctx.buffer;
293
+ ctx.tag.rootValue('root');
294
+ await ctx.span('outer-span', ctx.deps.outer.run);
295
+ return ctx.ok(null);
296
+ });
297
+
298
+ const { trace } = new TestTracer(appContext, createTestTracerOptions());
299
+ await trace('root-span', rootOp);
300
+
301
+ if (!rootBuffer) throw new Error('depth-3 trace did not expose its root buffer');
302
+ const table = convertSpanTreeToArrowTable(rootBuffer);
303
+ expectArrowSchema(table, ['rootValue', 'outer_outerValue', 'middle_middleValue', 'leaf_leafValue']);
304
+ expect(table.numRows).toBe(8);
305
+ expect(
306
+ extractRows(table, [
307
+ 'entry_type',
308
+ 'message',
309
+ 'rootValue',
310
+ 'outer_outerValue',
311
+ 'middle_middleValue',
312
+ 'leaf_leafValue',
313
+ ]),
314
+ ).toEqual([
315
+ {
316
+ entry_type: 'span-start',
317
+ message: 'root-span',
318
+ rootValue: 'root',
319
+ outer_outerValue: null,
320
+ middle_middleValue: null,
321
+ leaf_leafValue: null,
322
+ },
323
+ {
324
+ entry_type: 'span-ok',
325
+ message: null,
326
+ rootValue: null,
327
+ outer_outerValue: null,
328
+ middle_middleValue: null,
329
+ leaf_leafValue: null,
330
+ },
331
+ {
332
+ entry_type: 'span-start',
333
+ message: 'outer-span',
334
+ rootValue: null,
335
+ outer_outerValue: true,
336
+ middle_middleValue: null,
337
+ leaf_leafValue: null,
338
+ },
339
+ {
340
+ entry_type: 'span-ok',
341
+ message: null,
342
+ rootValue: null,
343
+ outer_outerValue: null,
344
+ middle_middleValue: null,
345
+ leaf_leafValue: null,
346
+ },
347
+ {
348
+ entry_type: 'span-start',
349
+ message: 'middle-span',
350
+ rootValue: null,
351
+ outer_outerValue: null,
352
+ middle_middleValue: 2,
353
+ leaf_leafValue: null,
354
+ },
355
+ {
356
+ entry_type: 'span-ok',
357
+ message: null,
358
+ rootValue: null,
359
+ outer_outerValue: null,
360
+ middle_middleValue: null,
361
+ leaf_leafValue: null,
362
+ },
363
+ {
364
+ entry_type: 'span-start',
365
+ message: 'leaf-span',
366
+ rootValue: null,
367
+ outer_outerValue: null,
368
+ middle_middleValue: null,
369
+ leaf_leafValue: 'leaf',
370
+ },
371
+ {
372
+ entry_type: 'span-ok',
373
+ message: null,
374
+ rootValue: null,
375
+ outer_outerValue: null,
376
+ middle_middleValue: null,
377
+ leaf_leafValue: null,
378
+ },
379
+ ]);
380
+ });
381
+ });