@smoothbricks/lmao 0.1.0
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.
- package/README.md +269 -0
- package/dist/allocator.wasm +0 -0
- package/dist/bun/preload.d.ts +11 -0
- package/dist/bun/preload.d.ts.map +1 -0
- package/dist/bun/preload.js +10 -0
- package/dist/bun/trace-preload.d.ts +8 -0
- package/dist/bun/trace-preload.d.ts.map +1 -0
- package/dist/bun/trace-preload.js +12 -0
- package/dist/es.d.ts +8 -0
- package/dist/es.d.ts.map +1 -0
- package/dist/es.js +9 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/lib/JsBufferStrategy.d.ts +49 -0
- package/dist/lib/JsBufferStrategy.d.ts.map +1 -0
- package/dist/lib/JsBufferStrategy.js +60 -0
- package/dist/lib/archive/chunkCompaction.d.ts +15 -0
- package/dist/lib/archive/chunkCompaction.d.ts.map +1 -0
- package/dist/lib/archive/chunkCompaction.js +24 -0
- package/dist/lib/archive/chunkEnvelope.d.ts +21 -0
- package/dist/lib/archive/chunkEnvelope.d.ts.map +1 -0
- package/dist/lib/archive/chunkEnvelope.js +55 -0
- package/dist/lib/archive/chunkRouting.d.ts +10 -0
- package/dist/lib/archive/chunkRouting.d.ts.map +1 -0
- package/dist/lib/archive/chunkRouting.js +47 -0
- package/dist/lib/archive/chunkStats.d.ts +12 -0
- package/dist/lib/archive/chunkStats.d.ts.map +1 -0
- package/dist/lib/archive/chunkStats.js +10 -0
- package/dist/lib/archive/index.d.ts +5 -0
- package/dist/lib/archive/index.d.ts.map +1 -0
- package/dist/lib/archive/index.js +4 -0
- package/dist/lib/arrow/capacityStats.d.ts +9 -0
- package/dist/lib/arrow/capacityStats.d.ts.map +1 -0
- package/dist/lib/arrow/capacityStats.js +231 -0
- package/dist/lib/arrow/dictionaries.d.ts +27 -0
- package/dist/lib/arrow/dictionaries.d.ts.map +1 -0
- package/dist/lib/arrow/dictionaries.js +135 -0
- package/dist/lib/arrow/flechette.d.ts +40 -0
- package/dist/lib/arrow/flechette.d.ts.map +1 -0
- package/dist/lib/arrow/flechette.js +67 -0
- package/dist/lib/arrow/utils.d.ts +38 -0
- package/dist/lib/arrow/utils.d.ts.map +1 -0
- package/dist/lib/arrow/utils.js +112 -0
- package/dist/lib/buffer/Nanoseconds.d.ts +109 -0
- package/dist/lib/buffer/Nanoseconds.d.ts.map +1 -0
- package/dist/lib/buffer/Nanoseconds.js +86 -0
- package/dist/lib/bufferStrategy.d.ts +95 -0
- package/dist/lib/bufferStrategy.d.ts.map +1 -0
- package/dist/lib/bufferStrategy.js +1 -0
- package/dist/lib/capacityTuning.d.ts +50 -0
- package/dist/lib/capacityTuning.d.ts.map +1 -0
- package/dist/lib/capacityTuning.js +65 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts +35 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/evaluatorGenerator.js +199 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +139 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.js +289 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts +115 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/spanLoggerGenerator.js +575 -0
- package/dist/lib/convertToArrow.d.ts +40 -0
- package/dist/lib/convertToArrow.d.ts.map +1 -0
- package/dist/lib/convertToArrow.js +1467 -0
- package/dist/lib/defineOpContext.d.ts +96 -0
- package/dist/lib/defineOpContext.d.ts.map +1 -0
- package/dist/lib/defineOpContext.js +227 -0
- package/dist/lib/errors/Blocked.d.ts +113 -0
- package/dist/lib/errors/Blocked.d.ts.map +1 -0
- package/dist/lib/errors/Blocked.js +68 -0
- package/dist/lib/errors/CodeError.d.ts +101 -0
- package/dist/lib/errors/CodeError.d.ts.map +1 -0
- package/dist/lib/errors/CodeError.js +42 -0
- package/dist/lib/errors/RetriesExhausted.d.ts +67 -0
- package/dist/lib/errors/RetriesExhausted.d.ts.map +1 -0
- package/dist/lib/errors/RetriesExhausted.js +31 -0
- package/dist/lib/errors/Transient.d.ts +115 -0
- package/dist/lib/errors/Transient.d.ts.map +1 -0
- package/dist/lib/errors/Transient.js +54 -0
- package/dist/lib/errors/index.d.ts +14 -0
- package/dist/lib/errors/index.d.ts.map +1 -0
- package/dist/lib/errors/index.js +16 -0
- package/dist/lib/errors/retry-policy.d.ts +60 -0
- package/dist/lib/errors/retry-policy.d.ts.map +1 -0
- package/dist/lib/errors/retry-policy.js +54 -0
- package/dist/lib/flushScheduler.d.ts +162 -0
- package/dist/lib/flushScheduler.d.ts.map +1 -0
- package/dist/lib/flushScheduler.js +388 -0
- package/dist/lib/library.d.ts +149 -0
- package/dist/lib/library.d.ts.map +1 -0
- package/dist/lib/library.js +588 -0
- package/dist/lib/logApi.d.ts +61 -0
- package/dist/lib/logApi.d.ts.map +1 -0
- package/dist/lib/logApi.js +12 -0
- package/dist/lib/logBinding.d.ts +63 -0
- package/dist/lib/logBinding.d.ts.map +1 -0
- package/dist/lib/logBinding.js +1 -0
- package/dist/lib/op.d.ts +105 -0
- package/dist/lib/op.d.ts.map +1 -0
- package/dist/lib/op.js +59 -0
- package/dist/lib/opContext/contextTypes.d.ts +88 -0
- package/dist/lib/opContext/contextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/contextTypes.js +34 -0
- package/dist/lib/opContext/createOpGroup.d.ts +57 -0
- package/dist/lib/opContext/createOpGroup.d.ts.map +1 -0
- package/dist/lib/opContext/createOpGroup.js +341 -0
- package/dist/lib/opContext/defineOp.d.ts +83 -0
- package/dist/lib/opContext/defineOp.d.ts.map +1 -0
- package/dist/lib/opContext/defineOp.js +197 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts +58 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts.map +1 -0
- package/dist/lib/opContext/featureFlagTypes.js +1 -0
- package/dist/lib/opContext/index.d.ts +13 -0
- package/dist/lib/opContext/index.d.ts.map +1 -0
- package/dist/lib/opContext/index.js +15 -0
- package/dist/lib/opContext/opGroupTypes.d.ts +250 -0
- package/dist/lib/opContext/opGroupTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opGroupTypes.js +31 -0
- package/dist/lib/opContext/opTypes.d.ts +48 -0
- package/dist/lib/opContext/opTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opTypes.js +7 -0
- package/dist/lib/opContext/spanContextTypes.d.ts +347 -0
- package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/spanContextTypes.js +1 -0
- package/dist/lib/opContext/types.d.ts +297 -0
- package/dist/lib/opContext/types.d.ts.map +1 -0
- package/dist/lib/opContext/types.js +16 -0
- package/dist/lib/result.d.ts +308 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +359 -0
- package/dist/lib/schema/LogSchema.d.ts +62 -0
- package/dist/lib/schema/LogSchema.d.ts.map +1 -0
- package/dist/lib/schema/LogSchema.js +134 -0
- package/dist/lib/schema/builder.d.ts +12 -0
- package/dist/lib/schema/builder.d.ts.map +1 -0
- package/dist/lib/schema/builder.js +169 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts +60 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts.map +1 -0
- package/dist/lib/schema/defineFeatureFlags.js +29 -0
- package/dist/lib/schema/defineLogSchema.d.ts +87 -0
- package/dist/lib/schema/defineLogSchema.d.ts.map +1 -0
- package/dist/lib/schema/defineLogSchema.js +171 -0
- package/dist/lib/schema/evaluator.d.ts +267 -0
- package/dist/lib/schema/evaluator.d.ts.map +1 -0
- package/dist/lib/schema/evaluator.js +169 -0
- package/dist/lib/schema/extend.d.ts +14 -0
- package/dist/lib/schema/extend.d.ts.map +1 -0
- package/dist/lib/schema/extend.js +51 -0
- package/dist/lib/schema/systemSchema.d.ts +112 -0
- package/dist/lib/schema/systemSchema.d.ts.map +1 -0
- package/dist/lib/schema/systemSchema.js +260 -0
- package/dist/lib/schema/typeGuards.d.ts +52 -0
- package/dist/lib/schema/typeGuards.d.ts.map +1 -0
- package/dist/lib/schema/typeGuards.js +127 -0
- package/dist/lib/schema/types.d.ts +156 -0
- package/dist/lib/schema/types.d.ts.map +1 -0
- package/dist/lib/schema/types.js +4 -0
- package/dist/lib/spanBuffer.d.ts +133 -0
- package/dist/lib/spanBuffer.d.ts.map +1 -0
- package/dist/lib/spanBuffer.js +442 -0
- package/dist/lib/spanBufferHelpers.d.ts +53 -0
- package/dist/lib/spanBufferHelpers.d.ts.map +1 -0
- package/dist/lib/spanBufferHelpers.js +65 -0
- package/dist/lib/spanBufferStats.d.ts +38 -0
- package/dist/lib/spanBufferStats.d.ts.map +1 -0
- package/dist/lib/spanBufferStats.js +1 -0
- package/dist/lib/spanContext.d.ts +141 -0
- package/dist/lib/spanContext.d.ts.map +1 -0
- package/dist/lib/spanContext.js +763 -0
- package/dist/lib/sqlite/index.d.ts +14 -0
- package/dist/lib/sqlite/index.d.ts.map +1 -0
- package/dist/lib/sqlite/index.js +12 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts +24 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-async-writer.js +65 -0
- package/dist/lib/sqlite/sqlite-common.d.ts +37 -0
- package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-common.js +207 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts +25 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-d1.js +67 -0
- package/dist/lib/sqlite/sqlite-db.d.ts +29 -0
- package/dist/lib/sqlite/sqlite-db.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-db.js +1 -0
- package/dist/lib/sqlite/sqlite-node.d.ts +16 -0
- package/dist/lib/sqlite/sqlite-node.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-node.js +68 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts +39 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-writer.js +78 -0
- package/dist/lib/testing/bun-harness.d.ts +150 -0
- package/dist/lib/testing/bun-harness.d.ts.map +1 -0
- package/dist/lib/testing/bun-harness.js +729 -0
- package/dist/lib/testing/extractFacts.d.ts +73 -0
- package/dist/lib/testing/extractFacts.d.ts.map +1 -0
- package/dist/lib/testing/extractFacts.js +237 -0
- package/dist/lib/testing/facts.d.ts +235 -0
- package/dist/lib/testing/facts.d.ts.map +1 -0
- package/dist/lib/testing/facts.js +209 -0
- package/dist/lib/testing/index.d.ts +58 -0
- package/dist/lib/testing/index.d.ts.map +1 -0
- package/dist/lib/testing/index.js +74 -0
- package/dist/lib/testing/queryable-span.d.ts +39 -0
- package/dist/lib/testing/queryable-span.d.ts.map +1 -0
- package/dist/lib/testing/queryable-span.js +58 -0
- package/dist/lib/testing/span-query.d.ts +21 -0
- package/dist/lib/testing/span-query.d.ts.map +1 -0
- package/dist/lib/testing/span-query.js +47 -0
- package/dist/lib/testing/stdio-replay.d.ts +4 -0
- package/dist/lib/testing/stdio-replay.d.ts.map +1 -0
- package/dist/lib/testing/stdio-replay.js +42 -0
- package/dist/lib/testing/trace-query.d.ts +59 -0
- package/dist/lib/testing/trace-query.d.ts.map +1 -0
- package/dist/lib/testing/trace-query.js +462 -0
- package/dist/lib/testing/vitest-harness.d.ts +135 -0
- package/dist/lib/testing/vitest-harness.d.ts.map +1 -0
- package/dist/lib/testing/vitest-harness.js +486 -0
- package/dist/lib/threadId.d.ts +58 -0
- package/dist/lib/threadId.d.ts.map +1 -0
- package/dist/lib/threadId.js +123 -0
- package/dist/lib/traceContext.d.ts +116 -0
- package/dist/lib/traceContext.d.ts.map +1 -0
- package/dist/lib/traceContext.js +37 -0
- package/dist/lib/traceId.d.ts +78 -0
- package/dist/lib/traceId.d.ts.map +1 -0
- package/dist/lib/traceId.js +87 -0
- package/dist/lib/traceRoot.d.ts +133 -0
- package/dist/lib/traceRoot.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.d.ts +75 -0
- package/dist/lib/traceRoot.es.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.js +129 -0
- package/dist/lib/traceRoot.js +19 -0
- package/dist/lib/traceRoot.node.d.ts +77 -0
- package/dist/lib/traceRoot.node.d.ts.map +1 -0
- package/dist/lib/traceRoot.node.js +133 -0
- package/dist/lib/traceRoot.universal.d.ts +3 -0
- package/dist/lib/traceRoot.universal.d.ts.map +1 -0
- package/dist/lib/traceRoot.universal.js +17 -0
- package/dist/lib/tracer.d.ts +296 -0
- package/dist/lib/tracer.d.ts.map +1 -0
- package/dist/lib/tracer.js +346 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts +56 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts.map +1 -0
- package/dist/lib/tracers/ArrayQueueTracer.js +67 -0
- package/dist/lib/tracers/CompositeTracer.d.ts +24 -0
- package/dist/lib/tracers/CompositeTracer.d.ts.map +1 -0
- package/dist/lib/tracers/CompositeTracer.js +57 -0
- package/dist/lib/tracers/NoOpTracer.d.ts +58 -0
- package/dist/lib/tracers/NoOpTracer.d.ts.map +1 -0
- package/dist/lib/tracers/NoOpTracer.js +41 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts +42 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts.map +1 -0
- package/dist/lib/tracers/SQLiteTracer.js +84 -0
- package/dist/lib/tracers/StdioTracer.d.ts +83 -0
- package/dist/lib/tracers/StdioTracer.d.ts.map +1 -0
- package/dist/lib/tracers/StdioTracer.js +270 -0
- package/dist/lib/tracers/TestTracer.d.ts +95 -0
- package/dist/lib/tracers/TestTracer.d.ts.map +1 -0
- package/dist/lib/tracers/TestTracer.js +87 -0
- package/dist/lib/tracers/index.d.ts +12 -0
- package/dist/lib/tracers/index.d.ts.map +1 -0
- package/dist/lib/tracers/index.js +11 -0
- package/dist/lib/types.d.ts +366 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utf8Cache.d.ts +111 -0
- package/dist/lib/utf8Cache.d.ts.map +1 -0
- package/dist/lib/utf8Cache.js +177 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts +88 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -0
- package/dist/lib/wasm/WasmBufferStrategy.js +138 -0
- package/dist/lib/wasm/wasmAllocator.d.ts +109 -0
- package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -0
- package/dist/lib/wasm/wasmAllocator.js +227 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts +123 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -0
- package/dist/lib/wasm/wasmSpanBuffer.js +772 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts +167 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -0
- package/dist/lib/wasm/wasmTraceRoot.js +264 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +8 -0
- package/dist/testing.d.ts +18 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/package.json +193 -0
- package/src/bun/preload.ts +11 -0
- package/src/bun/trace-preload.ts +14 -0
- package/src/es.ts +11 -0
- package/src/index.ts +194 -0
- package/src/lib/JsBufferStrategy.ts +102 -0
- package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +485 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +390 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +647 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +292 -0
- package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +354 -0
- package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +127 -0
- package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +392 -0
- package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +389 -0
- package/src/lib/__tests__/arrow-conversion-algorithms.test.ts +54 -0
- package/src/lib/__tests__/arrow-test-helpers.ts +71 -0
- package/src/lib/__tests__/binary-e2e.test.ts +203 -0
- package/src/lib/__tests__/buffer-overflow-op-api.test.ts +608 -0
- package/src/lib/__tests__/buffer-overflow.test.ts +612 -0
- package/src/lib/__tests__/capacity-tuning.test.ts +544 -0
- package/src/lib/__tests__/effective-schema.test.ts +439 -0
- package/src/lib/__tests__/flechette.test.ts +42 -0
- package/src/lib/__tests__/flushScheduler.test.ts +537 -0
- package/src/lib/__tests__/integration.test.ts +600 -0
- package/src/lib/__tests__/library.test.ts +934 -0
- package/src/lib/__tests__/nested-library-tasks.test.ts +849 -0
- package/src/lib/__tests__/op-context-binding.test.ts +135 -0
- package/src/lib/__tests__/op-metadata.test.ts +198 -0
- package/src/lib/__tests__/op-type-safety.test.ts +71 -0
- package/src/lib/__tests__/package-exports.test.ts +57 -0
- package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +319 -0
- package/src/lib/__tests__/remapped-buffer-view.test.ts +635 -0
- package/src/lib/__tests__/scope-attributes.test.ts +348 -0
- package/src/lib/__tests__/span-lifecycle.test.ts +680 -0
- package/src/lib/__tests__/sync-async-trace.test.ts +435 -0
- package/src/lib/__tests__/test-helpers.ts +318 -0
- package/src/lib/__tests__/timestamp.test.ts +259 -0
- package/src/lib/__tests__/trace-archive-primitives.test.ts +98 -0
- package/src/lib/__tests__/traceContext-type-enforcement.test.ts +271 -0
- package/src/lib/__tests__/tracer.test.ts +211 -0
- package/src/lib/__tests__/type-narrowing.test.ts +137 -0
- package/src/lib/archive/chunkCompaction.ts +44 -0
- package/src/lib/archive/chunkEnvelope.ts +79 -0
- package/src/lib/archive/chunkRouting.ts +70 -0
- package/src/lib/archive/chunkStats.ts +25 -0
- package/src/lib/archive/index.ts +4 -0
- package/src/lib/arrow/capacityStats.ts +340 -0
- package/src/lib/arrow/dictionaries.ts +159 -0
- package/src/lib/arrow/flechette.ts +114 -0
- package/src/lib/arrow/utils.ts +126 -0
- package/src/lib/buffer/Nanoseconds.ts +131 -0
- package/src/lib/bufferStrategy.ts +106 -0
- package/src/lib/capacityTuning.ts +102 -0
- package/src/lib/codegen/__tests__/__snapshots__/evaluatorGenerator.test.ts.snap +160 -0
- package/src/lib/codegen/__tests__/__snapshots__/scopeGenerator.test.ts.snap +196 -0
- package/src/lib/codegen/__tests__/__snapshots__/spanLoggerGenerator.test.ts.snap +1965 -0
- package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +516 -0
- package/src/lib/codegen/__tests__/nullBitmap.test.ts +207 -0
- package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +237 -0
- package/src/lib/codegen/evaluatorGenerator.ts +309 -0
- package/src/lib/codegen/fixedPositionWriterGenerator.ts +444 -0
- package/src/lib/codegen/spanLoggerGenerator.ts +715 -0
- package/src/lib/convertToArrow.ts +1805 -0
- package/src/lib/defineOpContext.ts +398 -0
- package/src/lib/errors/Blocked.ts +165 -0
- package/src/lib/errors/CodeError.ts +132 -0
- package/src/lib/errors/RetriesExhausted.ts +78 -0
- package/src/lib/errors/Transient.ts +168 -0
- package/src/lib/errors/__tests__/Blocked-config.test.ts +152 -0
- package/src/lib/errors/__tests__/Transient.test.ts +129 -0
- package/src/lib/errors/__tests__/retry-policy.test.ts +85 -0
- package/src/lib/errors/index.ts +24 -0
- package/src/lib/errors/retry-policy.ts +87 -0
- package/src/lib/flushScheduler.ts +509 -0
- package/src/lib/library.ts +682 -0
- package/src/lib/logApi.ts +70 -0
- package/src/lib/logBinding.ts +67 -0
- package/src/lib/op.ts +103 -0
- package/src/lib/opContext/__tests__/retry.test.ts +764 -0
- package/src/lib/opContext/contextTypes.ts +130 -0
- package/src/lib/opContext/createOpGroup.ts +456 -0
- package/src/lib/opContext/defineOp.ts +281 -0
- package/src/lib/opContext/featureFlagTypes.ts +54 -0
- package/src/lib/opContext/index.ts +16 -0
- package/src/lib/opContext/opGroupTypes.ts +342 -0
- package/src/lib/opContext/opTypes.ts +80 -0
- package/src/lib/opContext/spanContextTypes.ts +398 -0
- package/src/lib/opContext/types.ts +403 -0
- package/src/lib/result.ts +550 -0
- package/src/lib/schema/LogSchema.ts +153 -0
- package/src/lib/schema/__tests__/defineLogSchema.test.ts +342 -0
- package/src/lib/schema/__tests__/featureFlags.test.ts +443 -0
- package/src/lib/schema/builder.ts +201 -0
- package/src/lib/schema/defineFeatureFlags.ts +91 -0
- package/src/lib/schema/defineLogSchema.ts +291 -0
- package/src/lib/schema/evaluator.ts +404 -0
- package/src/lib/schema/extend.ts +69 -0
- package/src/lib/schema/systemSchema.ts +339 -0
- package/src/lib/schema/typeGuards.ts +163 -0
- package/src/lib/schema/types.ts +265 -0
- package/src/lib/spanBuffer.ts +571 -0
- package/src/lib/spanBufferHelpers.ts +73 -0
- package/src/lib/spanBufferStats.ts +40 -0
- package/src/lib/spanContext.ts +1566 -0
- package/src/lib/sqlite/__tests__/sqlite-common.test.ts +89 -0
- package/src/lib/sqlite/index.ts +26 -0
- package/src/lib/sqlite/sqlite-async-writer.ts +101 -0
- package/src/lib/sqlite/sqlite-common.ts +309 -0
- package/src/lib/sqlite/sqlite-d1.ts +104 -0
- package/src/lib/sqlite/sqlite-db.ts +32 -0
- package/src/lib/sqlite/sqlite-node.ts +83 -0
- package/src/lib/sqlite/sqlite-writer.ts +128 -0
- package/src/lib/testing/TRACE-TESTING.md +100 -0
- package/src/lib/testing/__tests__/bun-harness.test.ts +108 -0
- package/src/lib/testing/__tests__/extractFacts.test.ts +279 -0
- package/src/lib/testing/__tests__/facts.test.ts +324 -0
- package/src/lib/testing/__tests__/vitest-harness.test.ts +32 -0
- package/src/lib/testing/bun-harness.ts +990 -0
- package/src/lib/testing/extractFacts.ts +362 -0
- package/src/lib/testing/facts.ts +470 -0
- package/src/lib/testing/index.ts +141 -0
- package/src/lib/testing/queryable-span.ts +108 -0
- package/src/lib/testing/span-query.ts +65 -0
- package/src/lib/testing/stdio-replay.ts +50 -0
- package/src/lib/testing/trace-query.ts +329 -0
- package/src/lib/testing/vitest-harness.ts +691 -0
- package/src/lib/threadId.ts +135 -0
- package/src/lib/traceContext.ts +182 -0
- package/src/lib/traceId.ts +142 -0
- package/src/lib/traceRoot.es.ts +157 -0
- package/src/lib/traceRoot.node.ts +170 -0
- package/src/lib/traceRoot.ts +154 -0
- package/src/lib/traceRoot.universal.ts +22 -0
- package/src/lib/tracer.ts +896 -0
- package/src/lib/tracers/ArrayQueueTracer.ts +76 -0
- package/src/lib/tracers/CompositeTracer.ts +76 -0
- package/src/lib/tracers/NoOpTracer.ts +73 -0
- package/src/lib/tracers/SQLiteTracer.ts +115 -0
- package/src/lib/tracers/StdioTracer.ts +380 -0
- package/src/lib/tracers/TestTracer.ts +146 -0
- package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +184 -0
- package/src/lib/tracers/__tests__/NoOpTracer.test.ts +204 -0
- package/src/lib/tracers/__tests__/StdioTracer.test.ts +313 -0
- package/src/lib/tracers/__tests__/TestTracer.test.ts +200 -0
- package/src/lib/tracers/index.ts +12 -0
- package/src/lib/types.ts +498 -0
- package/src/lib/utf8Cache.ts +201 -0
- package/src/lib/wasm/WasmBufferStrategy.ts +219 -0
- package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +256 -0
- package/src/lib/wasm/__tests__/wasm-integration.test.ts +476 -0
- package/src/lib/wasm/__tests__/wasmAllocator.test.ts +699 -0
- package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +449 -0
- package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +390 -0
- package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +444 -0
- package/src/lib/wasm/allocator.zig +945 -0
- package/src/lib/wasm/wasmAllocator.ts +469 -0
- package/src/lib/wasm/wasmSpanBuffer.ts +1014 -0
- package/src/lib/wasm/wasmTraceRoot.ts +315 -0
- package/src/node.ts +10 -0
- package/src/testing.ts +18 -0
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* vitest integration for LMAO trace-testing.
|
|
5
|
+
*
|
|
6
|
+
* Same architecture as bun-harness: one root trace per test run,
|
|
7
|
+
* each it() creates a child span, describe path written to `describe` schema column.
|
|
8
|
+
*
|
|
9
|
+
* Supports lifecycle tracer outputs (SQLite, stdio, or both via CompositeTracer).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // vitest.config.ts
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* test: { setupFiles: ['./test-setup.ts'] },
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // test-setup.ts
|
|
19
|
+
* import { initTraceTestRun } from '@smoothbricks/lmao/testing/vitest';
|
|
20
|
+
* initTraceTestRun(myOpContext, { sqlite: { dbPath: '.trace-results.db' } });
|
|
21
|
+
*
|
|
22
|
+
* // my-test.test.ts
|
|
23
|
+
* import { describe, it, expect, useTestSpan } from '@smoothbricks/lmao/testing/vitest';
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module testing/vitest
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
afterAll as _afterAll,
|
|
31
|
+
afterEach as _afterEach,
|
|
32
|
+
beforeAll as _beforeAll,
|
|
33
|
+
beforeEach as _beforeEach,
|
|
34
|
+
describe as _describe,
|
|
35
|
+
expect as _expect,
|
|
36
|
+
it as _it,
|
|
37
|
+
} from 'vitest';
|
|
38
|
+
import { JsBufferStrategy } from '../JsBufferStrategy.js';
|
|
39
|
+
import type { SpanContext } from '../opContext/spanContextTypes.js';
|
|
40
|
+
import type { OpContextBinding, OpContextOf } from '../opContext/types.js';
|
|
41
|
+
import { S } from '../schema/builder.js';
|
|
42
|
+
import { isSpanContext } from '../spanContext.js';
|
|
43
|
+
import type { AsyncSQLiteDatabase, SyncSQLiteDatabase } from '../sqlite/sqlite-db.js';
|
|
44
|
+
import type { SQLiteWriterConfig } from '../sqlite/sqlite-writer.js';
|
|
45
|
+
import { createTraceRoot } from '../traceRoot.universal.js';
|
|
46
|
+
import { Tracer } from '../tracer.js';
|
|
47
|
+
import { CompositeTracer } from '../tracers/CompositeTracer.js';
|
|
48
|
+
import { SQLiteAsyncTracer, SQLiteTracer } from '../tracers/SQLiteTracer.js';
|
|
49
|
+
import { StdioTracer } from '../tracers/StdioTracer.js';
|
|
50
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
51
|
+
|
|
52
|
+
/** vitest expect() errors start with 'expect(received).' — distinguishes assertion failures from other throws */
|
|
53
|
+
function isExpectError(error: unknown): boolean {
|
|
54
|
+
return error instanceof Error && error.message.startsWith('expect(');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readGlobalValue(key: string): unknown {
|
|
58
|
+
return Reflect.get(globalThis, key);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readProcessEnv(name: string): string | undefined {
|
|
62
|
+
const processValue = Reflect.get(globalThis, 'process');
|
|
63
|
+
if (typeof processValue !== 'object' || processValue === null) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const env = Reflect.get(processValue, 'env');
|
|
68
|
+
if (typeof env !== 'object' || env === null) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const value = Reflect.get(env, name);
|
|
73
|
+
return typeof value === 'string' ? value : undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isVitestHarnessDebugEnabled(): boolean {
|
|
77
|
+
const globalDebug = readGlobalValue('__LMAO_VITEST_DEBUG__');
|
|
78
|
+
if (globalDebug === true) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const injectedDebug = readGlobalValue('__LMAO_VITEST_DEBUG_ENV__');
|
|
83
|
+
if (injectedDebug === '1' || injectedDebug === 'true') {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const envDebug = readProcessEnv('LMAO_VITEST_DEBUG');
|
|
88
|
+
return envDebug === '1' || envDebug === 'true';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function vitestHarnessDebug(message: string, data?: unknown): void {
|
|
92
|
+
if (!isVitestHarnessDebugEnabled()) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (data === undefined) {
|
|
97
|
+
console.error(`[lmao/vitest-harness] ${message}`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.error(`[lmao/vitest-harness] ${message}`, data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type TestBody = () => unknown | Promise<unknown>;
|
|
105
|
+
type SpanCtx<B extends OpContextBinding> = SpanContext<OpContextOf<B>>;
|
|
106
|
+
type VitestDescribeCallback = () => void;
|
|
107
|
+
type VitestDescribeBranch = (name: string, fn: VitestDescribeCallback) => unknown;
|
|
108
|
+
type VitestPublicTestCallback = () => void | Promise<void>;
|
|
109
|
+
type VitestPublicTestBranch = (name: string, fn: VitestPublicTestCallback) => unknown;
|
|
110
|
+
type VitestModuleIt = ((name: string, fn: TestBody) => unknown) & {
|
|
111
|
+
skip: (name: string, fn: VitestPublicTestCallback) => unknown;
|
|
112
|
+
only: (name: string, fn: VitestPublicTestCallback) => unknown;
|
|
113
|
+
todo: (name: string, fn: VitestPublicTestCallback) => unknown;
|
|
114
|
+
each: VitestEach;
|
|
115
|
+
skipIf: (condition: boolean) => (name: string, fn: VitestPublicTestCallback) => unknown;
|
|
116
|
+
};
|
|
117
|
+
type VitestEach = (...args: unknown[]) => unknown;
|
|
118
|
+
|
|
119
|
+
export type VitestDescribe = VitestDescribeBranch & {
|
|
120
|
+
skip: VitestDescribeBranch;
|
|
121
|
+
only: VitestDescribeBranch;
|
|
122
|
+
todo: VitestDescribeBranch;
|
|
123
|
+
each: VitestEach;
|
|
124
|
+
skipIf: (condition: boolean) => VitestDescribeBranch;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type VitestIt = VitestPublicTestBranch & {
|
|
128
|
+
skip: VitestPublicTestBranch;
|
|
129
|
+
only: VitestPublicTestBranch;
|
|
130
|
+
todo: VitestPublicTestBranch;
|
|
131
|
+
each: VitestEach;
|
|
132
|
+
skipIf: (condition: boolean) => VitestPublicTestBranch;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export interface VitestModuleShape {
|
|
136
|
+
describe: VitestDescribe;
|
|
137
|
+
it: VitestModuleIt;
|
|
138
|
+
test: VitestModuleIt;
|
|
139
|
+
[key: string]: unknown;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type SpanContextStore<Ctx> = {
|
|
143
|
+
run<R>(ctx: Ctx, fn: () => R): R;
|
|
144
|
+
getStore(): Ctx | undefined;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type AsyncLocalStorageLike<Ctx> = {
|
|
148
|
+
run<R>(store: Ctx, callback: () => R): R;
|
|
149
|
+
getStore(): Ctx | undefined;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
type AsyncLocalStorageCtor = new <Ctx>() => AsyncLocalStorageLike<Ctx>;
|
|
153
|
+
|
|
154
|
+
function isAsyncLocalStorageCtor(value: unknown): value is AsyncLocalStorageCtor {
|
|
155
|
+
return typeof value === 'function';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function writeDescribeTag(tag: unknown, describePath: string | null): void {
|
|
159
|
+
if (!describePath || typeof tag !== 'object' || tag === null) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const describeWriter = Reflect.get(tag, 'describe');
|
|
164
|
+
if (typeof describeWriter === 'function') {
|
|
165
|
+
describeWriter.call(tag, describePath);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const batchWriter = Reflect.get(tag, 'with');
|
|
170
|
+
if (typeof batchWriter === 'function') {
|
|
171
|
+
batchWriter.call(tag, { describe: describePath });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type SQLiteRuntimeConfig = SQLiteWriterConfig &
|
|
176
|
+
(
|
|
177
|
+
| {
|
|
178
|
+
/** Node/bun style synchronous SQLite driver (for example better-sqlite3). */
|
|
179
|
+
createDatabase: (path: string) => SyncSQLiteDatabase;
|
|
180
|
+
createAsyncDatabase?: never;
|
|
181
|
+
}
|
|
182
|
+
| {
|
|
183
|
+
/** Async SQLite driver (for example Cloudflare D1 adapter). */
|
|
184
|
+
createAsyncDatabase: (path: string) => AsyncSQLiteDatabase | Promise<AsyncSQLiteDatabase>;
|
|
185
|
+
createDatabase?: never;
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
type InitTraceTestRunOptions = {
|
|
190
|
+
/**
|
|
191
|
+
* Optional SQLite persistence target.
|
|
192
|
+
*
|
|
193
|
+
* Omit this to run traced tests without DB persistence.
|
|
194
|
+
*/
|
|
195
|
+
sqlite?: SQLiteRuntimeConfig;
|
|
196
|
+
/** Optional verbose stdout tracing; defaults to env flag detection. */
|
|
197
|
+
verbose?: boolean;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type TracerFactoryOptions<B extends OpContextBinding> = {
|
|
201
|
+
binding: B;
|
|
202
|
+
sqlite: InitTraceTestRunOptions['sqlite'];
|
|
203
|
+
verbose: boolean;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
function isTruthyEnvFlag(value: unknown): boolean {
|
|
207
|
+
return value === true || value === '1' || value === 'true';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function isVerboseTraceEnabled(explicitVerbose: boolean | undefined): boolean {
|
|
211
|
+
if (explicitVerbose !== undefined) {
|
|
212
|
+
return explicitVerbose;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const globalVerbose = readGlobalValue('__LMAO_TEST_TRACE_VERBOSE__');
|
|
216
|
+
if (isTruthyEnvFlag(globalVerbose)) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const injectedVerbose = readGlobalValue('__LMAO_TEST_TRACE_VERBOSE_ENV__');
|
|
221
|
+
if (isTruthyEnvFlag(injectedVerbose)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return isTruthyEnvFlag(readProcessEnv('LMAO_TEST_TRACE_VERBOSE'));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
class FallbackSpanContextStore<Ctx> implements SpanContextStore<Ctx> {
|
|
229
|
+
private current: Ctx | undefined;
|
|
230
|
+
|
|
231
|
+
run<R>(ctx: Ctx, fn: () => R): R {
|
|
232
|
+
const prev = this.current;
|
|
233
|
+
this.current = ctx;
|
|
234
|
+
try {
|
|
235
|
+
return fn();
|
|
236
|
+
} finally {
|
|
237
|
+
this.current = prev;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
getStore(): Ctx | undefined {
|
|
242
|
+
return this.current;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function tryCreateAsyncLocalStorageStore<Ctx>(): SpanContextStore<Ctx> | null {
|
|
247
|
+
const maybeCtor = Reflect.get(globalThis, 'AsyncLocalStorage');
|
|
248
|
+
if (!isAsyncLocalStorageCtor(maybeCtor)) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const storage = new maybeCtor<Ctx>();
|
|
253
|
+
return {
|
|
254
|
+
run<R>(ctx: Ctx, fn: () => R): R {
|
|
255
|
+
return storage.run(ctx, fn);
|
|
256
|
+
},
|
|
257
|
+
getStore(): Ctx | undefined {
|
|
258
|
+
return storage.getStore();
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function createDefaultSpanContextStore<Ctx>(): SpanContextStore<Ctx> {
|
|
264
|
+
const store = tryCreateAsyncLocalStorageStore<Ctx>();
|
|
265
|
+
if (store) {
|
|
266
|
+
vitestHarnessDebug('using AsyncLocalStorage span store');
|
|
267
|
+
return store;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Workers (e.g. Cloudflare Vitest pool) do not expose node:async_hooks.
|
|
271
|
+
// Fallback is safe for awaited test bodies, but detached async work will not
|
|
272
|
+
// retain the context automatically.
|
|
273
|
+
vitestHarnessDebug('using fallback span store');
|
|
274
|
+
return new FallbackSpanContextStore<Ctx>();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function createRootTracer<B extends OpContextBinding>({
|
|
278
|
+
binding,
|
|
279
|
+
sqlite,
|
|
280
|
+
verbose,
|
|
281
|
+
}: TracerFactoryOptions<B>): Tracer<B> {
|
|
282
|
+
const tracerOptions = {
|
|
283
|
+
bufferStrategy: new JsBufferStrategy<B['logBinding']['logSchema']>(),
|
|
284
|
+
createTraceRoot,
|
|
285
|
+
} as const;
|
|
286
|
+
|
|
287
|
+
let sqliteTracer: Tracer<B> | null = null;
|
|
288
|
+
if (sqlite?.createAsyncDatabase) {
|
|
289
|
+
const dbPath = sqlite.dbPath ?? '.trace-results.db';
|
|
290
|
+
sqliteTracer = new SQLiteAsyncTracer(binding, {
|
|
291
|
+
...tracerOptions,
|
|
292
|
+
db: sqlite.createAsyncDatabase(dbPath),
|
|
293
|
+
});
|
|
294
|
+
} else if (sqlite?.createDatabase) {
|
|
295
|
+
const db = sqlite.createDatabase(sqlite.dbPath ?? '.trace-results.db');
|
|
296
|
+
sqliteTracer = new SQLiteTracer(binding, {
|
|
297
|
+
...tracerOptions,
|
|
298
|
+
db,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (sqliteTracer) {
|
|
303
|
+
if (verbose) {
|
|
304
|
+
const stdioTracer = new StdioTracer(binding, {
|
|
305
|
+
...tracerOptions,
|
|
306
|
+
});
|
|
307
|
+
return new CompositeTracer(binding, {
|
|
308
|
+
...tracerOptions,
|
|
309
|
+
delegates: [stdioTracer, sqliteTracer],
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return sqliteTracer;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (verbose) {
|
|
316
|
+
return new StdioTracer(binding, {
|
|
317
|
+
...tracerOptions,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return new TestTracer(binding, {
|
|
322
|
+
...tracerOptions,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function closeTracer(tracer: Tracer<OpContextBinding>): Promise<void> {
|
|
327
|
+
const close = Reflect.get(tracer, 'close');
|
|
328
|
+
if (typeof close === 'function') {
|
|
329
|
+
await close.call(tracer);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
type VitestHarnessConfig<B extends OpContextBinding> = {
|
|
334
|
+
binding: B;
|
|
335
|
+
createSpanContextStore?: () => SpanContextStore<SpanCtx<B>>;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export type VitestTestTracer<B extends OpContextBinding> = {
|
|
339
|
+
initTraceTestRun(options?: InitTraceTestRunOptions): void;
|
|
340
|
+
useTestSpan(): SpanCtx<B>;
|
|
341
|
+
getTracer(): Tracer<B>;
|
|
342
|
+
createVitestMock<T extends VitestModuleShape>(vitestModule: T): T;
|
|
343
|
+
describe(name: string, fn: () => void): unknown;
|
|
344
|
+
it(name: string, fn: () => void | Promise<void>): void;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
export type VitestTestSuiteTracer<B extends OpContextBinding> = {
|
|
348
|
+
useTestTracer: VitestTestTracer<B>;
|
|
349
|
+
useTestSpan(): SpanCtx<B>;
|
|
350
|
+
setupVitestTestSuiteTracing(): void;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
type ActiveVitestTestTracer = {
|
|
354
|
+
initTraceTestRun(options?: InitTraceTestRunOptions): void;
|
|
355
|
+
useTestSpan(): unknown;
|
|
356
|
+
getTracer(): unknown;
|
|
357
|
+
createVitestMock<T extends VitestModuleShape>(vitestModule: T): T;
|
|
358
|
+
describe(name: string, fn: () => void): unknown;
|
|
359
|
+
it(name: string, fn: () => void | Promise<void>): void;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
let _activeSuiteTracer: ActiveVitestTestTracer | null = null;
|
|
363
|
+
|
|
364
|
+
function createActiveVitestTestTracer<B extends OpContextBinding>(tracer: VitestTestTracer<B>): ActiveVitestTestTracer {
|
|
365
|
+
return {
|
|
366
|
+
initTraceTestRun: (options) => tracer.initTraceTestRun(options),
|
|
367
|
+
useTestSpan: () => tracer.useTestSpan(),
|
|
368
|
+
getTracer: () => tracer.getTracer(),
|
|
369
|
+
createVitestMock: (vitestModule) => tracer.createVitestMock(vitestModule),
|
|
370
|
+
describe: (name, fn) => tracer.describe(name, fn),
|
|
371
|
+
it: (name, fn) => tracer.it(name, fn),
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function installVitestTestTracing<B extends OpContextBinding>(
|
|
376
|
+
tracer: VitestTestTracer<B>,
|
|
377
|
+
options?: InitTraceTestRunOptions,
|
|
378
|
+
): void {
|
|
379
|
+
tracer.initTraceTestRun(options);
|
|
380
|
+
_activeSuiteTracer = createActiveVitestTestTracer(tracer);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function makeVitestTestSuiteTracer<B extends OpContextBinding>(
|
|
384
|
+
config: VitestHarnessConfig<B>,
|
|
385
|
+
options?: InitTraceTestRunOptions,
|
|
386
|
+
): VitestTestSuiteTracer<B> {
|
|
387
|
+
const useTestTracer = makeVitestTestTracer(config);
|
|
388
|
+
return {
|
|
389
|
+
useTestTracer,
|
|
390
|
+
useTestSpan: () => useTestTracer.useTestSpan(),
|
|
391
|
+
setupVitestTestSuiteTracing: () => installVitestTestTracing(useTestTracer, options),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export function makeVitestTestTracer<B extends OpContextBinding>(config: VitestHarnessConfig<B>): VitestTestTracer<B> {
|
|
396
|
+
const { binding } = config;
|
|
397
|
+
const spanStore = config.createSpanContextStore?.() ?? createDefaultSpanContextStore<SpanCtx<B>>();
|
|
398
|
+
vitestHarnessDebug('created vitest test tracer instance');
|
|
399
|
+
|
|
400
|
+
let initialized = false;
|
|
401
|
+
let tracer: Tracer<B> | null = null;
|
|
402
|
+
let verboseTrace = false;
|
|
403
|
+
let rootCtx: SpanCtx<B> | null = null;
|
|
404
|
+
let resolveTestRun: (() => void) | null = null;
|
|
405
|
+
let rootTracePromise: Promise<unknown> | null = null;
|
|
406
|
+
const standaloneDescribeStack: string[] = [];
|
|
407
|
+
|
|
408
|
+
function getRootCtx(): SpanCtx<B> {
|
|
409
|
+
if (!rootCtx) {
|
|
410
|
+
throw new Error('Call initTraceTestRun() in setupFiles before tests');
|
|
411
|
+
}
|
|
412
|
+
return rootCtx;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function createExtendedBinding(): B {
|
|
416
|
+
const extendedSchema = binding.logBinding.logSchema.extend({ describe: S.category() });
|
|
417
|
+
const extendedBinding: B = {
|
|
418
|
+
...binding,
|
|
419
|
+
logBinding: { ...binding.logBinding, logSchema: extendedSchema },
|
|
420
|
+
};
|
|
421
|
+
return extendedBinding;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function initTraceTestRun(options?: InitTraceTestRunOptions): void {
|
|
425
|
+
if (initialized) {
|
|
426
|
+
throw new Error('initTraceTestRun() already called for this vitest tracer instance');
|
|
427
|
+
}
|
|
428
|
+
initialized = true;
|
|
429
|
+
verboseTrace = isVerboseTraceEnabled(options?.verbose);
|
|
430
|
+
vitestHarnessDebug('initTraceTestRun start', {
|
|
431
|
+
sqliteConfigured:
|
|
432
|
+
options?.sqlite?.createDatabase !== undefined || options?.sqlite?.createAsyncDatabase !== undefined,
|
|
433
|
+
verboseTrace,
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// Extend user's schema with `describe` column for test grouping.
|
|
437
|
+
const extendedBinding = createExtendedBinding();
|
|
438
|
+
|
|
439
|
+
tracer = createRootTracer({
|
|
440
|
+
binding: extendedBinding,
|
|
441
|
+
sqlite: options?.sqlite,
|
|
442
|
+
verbose: verboseTrace,
|
|
443
|
+
});
|
|
444
|
+
vitestHarnessDebug('created root tracer for vitest harness');
|
|
445
|
+
|
|
446
|
+
const activeTracer = tracer;
|
|
447
|
+
rootTracePromise = activeTracer.trace('test-run', (ctx: SpanCtx<B>) => {
|
|
448
|
+
rootCtx = ctx;
|
|
449
|
+
vitestHarnessDebug('root test-run span started', { trace_id: ctx.buffer.trace_id });
|
|
450
|
+
return new Promise<void>((resolve) => {
|
|
451
|
+
resolveTestRun = resolve;
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
vitestHarnessDebug('root trace promise created');
|
|
455
|
+
|
|
456
|
+
_afterAll(async () => {
|
|
457
|
+
vitestHarnessDebug('afterAll hook start');
|
|
458
|
+
if (resolveTestRun) {
|
|
459
|
+
resolveTestRun();
|
|
460
|
+
resolveTestRun = null;
|
|
461
|
+
vitestHarnessDebug('resolved root test-run promise');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (rootTracePromise) {
|
|
465
|
+
await rootTracePromise;
|
|
466
|
+
rootTracePromise = null;
|
|
467
|
+
vitestHarnessDebug('awaited root trace promise');
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (tracer && rootCtx) {
|
|
471
|
+
try {
|
|
472
|
+
vitestHarnessDebug('flushing tracer');
|
|
473
|
+
await tracer.flush();
|
|
474
|
+
if (options?.sqlite) {
|
|
475
|
+
const traceId = rootCtx.buffer.trace_id;
|
|
476
|
+
const dbPath = options.sqlite.dbPath ?? '.trace-results.db';
|
|
477
|
+
console.log(`\n[trace] trace_id: ${traceId} → ${dbPath}`);
|
|
478
|
+
}
|
|
479
|
+
} catch (error) {
|
|
480
|
+
console.error('[lmao/testing] SQLite flush error:', error);
|
|
481
|
+
} finally {
|
|
482
|
+
await closeTracer(tracer);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
vitestHarnessDebug('afterAll hook complete');
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function useTestSpan(): SpanCtx<B> {
|
|
490
|
+
const ctx = spanStore.getStore();
|
|
491
|
+
if (!ctx) {
|
|
492
|
+
throw new Error('useTestSpan() called outside of a traced it()');
|
|
493
|
+
}
|
|
494
|
+
return ctx;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function getTracer(): Tracer<B> {
|
|
498
|
+
if (!tracer) {
|
|
499
|
+
throw new Error('Call initTraceTestRun() in setupFiles before tests');
|
|
500
|
+
}
|
|
501
|
+
return tracer;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function createVitestMock<T extends VitestModuleShape>(vitestModule: T): T {
|
|
505
|
+
vitestHarnessDebug('createVitestMock called');
|
|
506
|
+
const currentRootCtx = getRootCtx();
|
|
507
|
+
const origIt = vitestModule.it;
|
|
508
|
+
const origDescribe = vitestModule.describe;
|
|
509
|
+
const describeStack: string[] = [];
|
|
510
|
+
|
|
511
|
+
function wrappedDescribe(name: string, fn: () => void) {
|
|
512
|
+
return origDescribe(name, () => {
|
|
513
|
+
describeStack.push(name);
|
|
514
|
+
try {
|
|
515
|
+
fn();
|
|
516
|
+
} finally {
|
|
517
|
+
describeStack.pop();
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
Object.assign(wrappedDescribe, {
|
|
523
|
+
skip: origDescribe.skip,
|
|
524
|
+
only: origDescribe.only,
|
|
525
|
+
todo: origDescribe.todo,
|
|
526
|
+
each: origDescribe.each,
|
|
527
|
+
skipIf: origDescribe.skipIf.bind(origDescribe),
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
function wrappedIt(name: string, fn: TestBody) {
|
|
531
|
+
const describePath = describeStack.length > 0 ? describeStack.join(' > ') : null;
|
|
532
|
+
return origIt(name, () =>
|
|
533
|
+
currentRootCtx.span(name, async (ctx) => {
|
|
534
|
+
writeDescribeTag(ctx.tag, describePath);
|
|
535
|
+
try {
|
|
536
|
+
await spanStore.run(ctx, fn);
|
|
537
|
+
return ctx.ok(undefined);
|
|
538
|
+
} catch (error) {
|
|
539
|
+
if (isExpectError(error)) {
|
|
540
|
+
return ctx.err(error);
|
|
541
|
+
}
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
}),
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
Object.assign(wrappedIt, {
|
|
549
|
+
skip: origIt.skip,
|
|
550
|
+
only: origIt.only,
|
|
551
|
+
todo: origIt.todo,
|
|
552
|
+
each: origIt.each,
|
|
553
|
+
skipIf: origIt.skipIf.bind(origIt),
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
return {
|
|
557
|
+
...vitestModule,
|
|
558
|
+
describe: wrappedDescribe,
|
|
559
|
+
it: wrappedIt,
|
|
560
|
+
test: wrappedIt,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function describe(name: string, fn: () => void) {
|
|
565
|
+
return _describe(name, () => {
|
|
566
|
+
standaloneDescribeStack.push(name);
|
|
567
|
+
try {
|
|
568
|
+
fn();
|
|
569
|
+
} finally {
|
|
570
|
+
standaloneDescribeStack.pop();
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function it(name: string, fn: () => void | Promise<void>): void {
|
|
576
|
+
const describePath = standaloneDescribeStack.length > 0 ? standaloneDescribeStack.join(' > ') : null;
|
|
577
|
+
_it(name, () => {
|
|
578
|
+
const currentRootCtx = getRootCtx();
|
|
579
|
+
return currentRootCtx.span(name, async (ctx) => {
|
|
580
|
+
writeDescribeTag(ctx.tag, describePath);
|
|
581
|
+
try {
|
|
582
|
+
await spanStore.run(ctx, fn);
|
|
583
|
+
return ctx.ok(undefined);
|
|
584
|
+
} catch (error) {
|
|
585
|
+
if (isExpectError(error)) {
|
|
586
|
+
return ctx.err(error);
|
|
587
|
+
}
|
|
588
|
+
throw error;
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return {
|
|
595
|
+
initTraceTestRun,
|
|
596
|
+
useTestSpan,
|
|
597
|
+
getTracer,
|
|
598
|
+
createVitestMock,
|
|
599
|
+
describe,
|
|
600
|
+
it,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function requireActiveSuiteTracer(message: string): ActiveVitestTestTracer {
|
|
605
|
+
if (!_activeSuiteTracer) {
|
|
606
|
+
throw new Error(message);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return _activeSuiteTracer;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** Initialize the root tracer for the entire vitest run. Call once in setupFiles. */
|
|
613
|
+
export function initTraceTestRun<B extends OpContextBinding>(opContext: B, options?: InitTraceTestRunOptions): void {
|
|
614
|
+
installVitestTestTracing(makeVitestTestTracer({ binding: opContext }), options);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/** Get the current span context from AsyncLocalStorage (inside an it() block) */
|
|
618
|
+
export function useTestSpan(): SpanContext<OpContextOf<OpContextBinding>> {
|
|
619
|
+
const ctx = requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').useTestSpan();
|
|
620
|
+
if (!isSpanContext(ctx)) {
|
|
621
|
+
throw new Error('Active suite tracer returned a non-span context');
|
|
622
|
+
}
|
|
623
|
+
return ctx;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Get the root tracer instance */
|
|
627
|
+
export function getTracer(): Tracer<OpContextBinding> {
|
|
628
|
+
const tracer = requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').getTracer();
|
|
629
|
+
if (!(tracer instanceof Tracer)) {
|
|
630
|
+
throw new Error('Active suite tracer returned a non-tracer');
|
|
631
|
+
}
|
|
632
|
+
return tracer;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Create a vitest mock replacement that wraps it()/test()/describe() with trace spans.
|
|
637
|
+
*
|
|
638
|
+
* Call this from a vitest setupFile via vi.mock:
|
|
639
|
+
* ```typescript
|
|
640
|
+
* vi.mock('vitest', async (importOriginal) => {
|
|
641
|
+
* const [mod, { createVitestMock }] = await Promise.all([
|
|
642
|
+
* importOriginal(),
|
|
643
|
+
* import('@smoothbricks/lmao/testing/vitest'),
|
|
644
|
+
* ]);
|
|
645
|
+
* return createVitestMock(mod);
|
|
646
|
+
* });
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @param vitestModule - The original vitest namespace from importOriginal()
|
|
650
|
+
*/
|
|
651
|
+
export function createVitestMock<T extends VitestModuleShape>(vitestModule: T): T {
|
|
652
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() before createVitestMock()').createVitestMock(vitestModule);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Wrapped describe — tracks describe nesting for the standalone export path.
|
|
657
|
+
* describe() callbacks run synchronously (just registering tests).
|
|
658
|
+
*/
|
|
659
|
+
const describeBase: VitestDescribeBranch = (name, fn) => {
|
|
660
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').describe(name, fn);
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
export const describe: VitestDescribe = Object.assign(describeBase, {
|
|
664
|
+
skip: (name: string, fn: VitestDescribeCallback) => _describe.skip(name, fn),
|
|
665
|
+
only: (name: string, fn: VitestDescribeCallback) => _describe.only(name, fn),
|
|
666
|
+
todo: (name: string, fn: VitestDescribeCallback) => _describe.todo(name, fn),
|
|
667
|
+
each: (...args: unknown[]) => Reflect.apply(_describe.each, _describe, args),
|
|
668
|
+
skipIf: (condition: boolean) => (condition ? _describe.skip : describe),
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
/** Wrapped it — creates a child span of the root trace for the test case */
|
|
672
|
+
const itBase: VitestPublicTestBranch = (name, fn) => {
|
|
673
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').it(name, fn);
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
export const it: VitestIt = Object.assign(itBase, {
|
|
677
|
+
skip: (name: string, fn: TestBody) => _it.skip(name, fn),
|
|
678
|
+
only: (name: string, fn: TestBody) => _it.only(name, fn),
|
|
679
|
+
todo: (name: string, fn: TestBody) => _it.todo(name, fn),
|
|
680
|
+
each: (...args: unknown[]) => Reflect.apply(_it.each, _it, args),
|
|
681
|
+
skipIf: (condition: boolean) => (condition ? _it.skip : it),
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
// Re-export everything else unchanged
|
|
685
|
+
export {
|
|
686
|
+
_afterAll as afterAll,
|
|
687
|
+
_afterEach as afterEach,
|
|
688
|
+
_beforeAll as beforeAll,
|
|
689
|
+
_beforeEach as beforeEach,
|
|
690
|
+
_expect as expect,
|
|
691
|
+
};
|