@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,486 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* vitest integration for LMAO trace-testing.
|
|
4
|
+
*
|
|
5
|
+
* Same architecture as bun-harness: one root trace per test run,
|
|
6
|
+
* each it() creates a child span, describe path written to `describe` schema column.
|
|
7
|
+
*
|
|
8
|
+
* Supports lifecycle tracer outputs (SQLite, stdio, or both via CompositeTracer).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // vitest.config.ts
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* test: { setupFiles: ['./test-setup.ts'] },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // test-setup.ts
|
|
18
|
+
* import { initTraceTestRun } from '@smoothbricks/lmao/testing/vitest';
|
|
19
|
+
* initTraceTestRun(myOpContext, { sqlite: { dbPath: '.trace-results.db' } });
|
|
20
|
+
*
|
|
21
|
+
* // my-test.test.ts
|
|
22
|
+
* import { describe, it, expect, useTestSpan } from '@smoothbricks/lmao/testing/vitest';
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @module testing/vitest
|
|
26
|
+
*/
|
|
27
|
+
import { afterAll as _afterAll, afterEach as _afterEach, beforeAll as _beforeAll, beforeEach as _beforeEach, describe as _describe, expect as _expect, it as _it, } from 'vitest';
|
|
28
|
+
import { JsBufferStrategy } from '../JsBufferStrategy.js';
|
|
29
|
+
import { S } from '../schema/builder.js';
|
|
30
|
+
import { isSpanContext } from '../spanContext.js';
|
|
31
|
+
import { createTraceRoot } from '../traceRoot.universal.js';
|
|
32
|
+
import { Tracer } from '../tracer.js';
|
|
33
|
+
import { CompositeTracer } from '../tracers/CompositeTracer.js';
|
|
34
|
+
import { SQLiteAsyncTracer, SQLiteTracer } from '../tracers/SQLiteTracer.js';
|
|
35
|
+
import { StdioTracer } from '../tracers/StdioTracer.js';
|
|
36
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
37
|
+
/** vitest expect() errors start with 'expect(received).' — distinguishes assertion failures from other throws */
|
|
38
|
+
function isExpectError(error) {
|
|
39
|
+
return error instanceof Error && error.message.startsWith('expect(');
|
|
40
|
+
}
|
|
41
|
+
function readGlobalValue(key) {
|
|
42
|
+
return Reflect.get(globalThis, key);
|
|
43
|
+
}
|
|
44
|
+
function readProcessEnv(name) {
|
|
45
|
+
const processValue = Reflect.get(globalThis, 'process');
|
|
46
|
+
if (typeof processValue !== 'object' || processValue === null) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const env = Reflect.get(processValue, 'env');
|
|
50
|
+
if (typeof env !== 'object' || env === null) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const value = Reflect.get(env, name);
|
|
54
|
+
return typeof value === 'string' ? value : undefined;
|
|
55
|
+
}
|
|
56
|
+
function isVitestHarnessDebugEnabled() {
|
|
57
|
+
const globalDebug = readGlobalValue('__LMAO_VITEST_DEBUG__');
|
|
58
|
+
if (globalDebug === true) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const injectedDebug = readGlobalValue('__LMAO_VITEST_DEBUG_ENV__');
|
|
62
|
+
if (injectedDebug === '1' || injectedDebug === 'true') {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const envDebug = readProcessEnv('LMAO_VITEST_DEBUG');
|
|
66
|
+
return envDebug === '1' || envDebug === 'true';
|
|
67
|
+
}
|
|
68
|
+
function vitestHarnessDebug(message, data) {
|
|
69
|
+
if (!isVitestHarnessDebugEnabled()) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (data === undefined) {
|
|
73
|
+
console.error(`[lmao/vitest-harness] ${message}`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
console.error(`[lmao/vitest-harness] ${message}`, data);
|
|
77
|
+
}
|
|
78
|
+
function isAsyncLocalStorageCtor(value) {
|
|
79
|
+
return typeof value === 'function';
|
|
80
|
+
}
|
|
81
|
+
function writeDescribeTag(tag, describePath) {
|
|
82
|
+
if (!describePath || typeof tag !== 'object' || tag === null) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const describeWriter = Reflect.get(tag, 'describe');
|
|
86
|
+
if (typeof describeWriter === 'function') {
|
|
87
|
+
describeWriter.call(tag, describePath);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const batchWriter = Reflect.get(tag, 'with');
|
|
91
|
+
if (typeof batchWriter === 'function') {
|
|
92
|
+
batchWriter.call(tag, { describe: describePath });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isTruthyEnvFlag(value) {
|
|
96
|
+
return value === true || value === '1' || value === 'true';
|
|
97
|
+
}
|
|
98
|
+
function isVerboseTraceEnabled(explicitVerbose) {
|
|
99
|
+
if (explicitVerbose !== undefined) {
|
|
100
|
+
return explicitVerbose;
|
|
101
|
+
}
|
|
102
|
+
const globalVerbose = readGlobalValue('__LMAO_TEST_TRACE_VERBOSE__');
|
|
103
|
+
if (isTruthyEnvFlag(globalVerbose)) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
const injectedVerbose = readGlobalValue('__LMAO_TEST_TRACE_VERBOSE_ENV__');
|
|
107
|
+
if (isTruthyEnvFlag(injectedVerbose)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return isTruthyEnvFlag(readProcessEnv('LMAO_TEST_TRACE_VERBOSE'));
|
|
111
|
+
}
|
|
112
|
+
class FallbackSpanContextStore {
|
|
113
|
+
current;
|
|
114
|
+
run(ctx, fn) {
|
|
115
|
+
const prev = this.current;
|
|
116
|
+
this.current = ctx;
|
|
117
|
+
try {
|
|
118
|
+
return fn();
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
this.current = prev;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getStore() {
|
|
125
|
+
return this.current;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function tryCreateAsyncLocalStorageStore() {
|
|
129
|
+
const maybeCtor = Reflect.get(globalThis, 'AsyncLocalStorage');
|
|
130
|
+
if (!isAsyncLocalStorageCtor(maybeCtor)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const storage = new maybeCtor();
|
|
134
|
+
return {
|
|
135
|
+
run(ctx, fn) {
|
|
136
|
+
return storage.run(ctx, fn);
|
|
137
|
+
},
|
|
138
|
+
getStore() {
|
|
139
|
+
return storage.getStore();
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function createDefaultSpanContextStore() {
|
|
144
|
+
const store = tryCreateAsyncLocalStorageStore();
|
|
145
|
+
if (store) {
|
|
146
|
+
vitestHarnessDebug('using AsyncLocalStorage span store');
|
|
147
|
+
return store;
|
|
148
|
+
}
|
|
149
|
+
// Workers (e.g. Cloudflare Vitest pool) do not expose node:async_hooks.
|
|
150
|
+
// Fallback is safe for awaited test bodies, but detached async work will not
|
|
151
|
+
// retain the context automatically.
|
|
152
|
+
vitestHarnessDebug('using fallback span store');
|
|
153
|
+
return new FallbackSpanContextStore();
|
|
154
|
+
}
|
|
155
|
+
function createRootTracer({ binding, sqlite, verbose, }) {
|
|
156
|
+
const tracerOptions = {
|
|
157
|
+
bufferStrategy: new JsBufferStrategy(),
|
|
158
|
+
createTraceRoot,
|
|
159
|
+
};
|
|
160
|
+
let sqliteTracer = null;
|
|
161
|
+
if (sqlite?.createAsyncDatabase) {
|
|
162
|
+
const dbPath = sqlite.dbPath ?? '.trace-results.db';
|
|
163
|
+
sqliteTracer = new SQLiteAsyncTracer(binding, {
|
|
164
|
+
...tracerOptions,
|
|
165
|
+
db: sqlite.createAsyncDatabase(dbPath),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else if (sqlite?.createDatabase) {
|
|
169
|
+
const db = sqlite.createDatabase(sqlite.dbPath ?? '.trace-results.db');
|
|
170
|
+
sqliteTracer = new SQLiteTracer(binding, {
|
|
171
|
+
...tracerOptions,
|
|
172
|
+
db,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (sqliteTracer) {
|
|
176
|
+
if (verbose) {
|
|
177
|
+
const stdioTracer = new StdioTracer(binding, {
|
|
178
|
+
...tracerOptions,
|
|
179
|
+
});
|
|
180
|
+
return new CompositeTracer(binding, {
|
|
181
|
+
...tracerOptions,
|
|
182
|
+
delegates: [stdioTracer, sqliteTracer],
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return sqliteTracer;
|
|
186
|
+
}
|
|
187
|
+
if (verbose) {
|
|
188
|
+
return new StdioTracer(binding, {
|
|
189
|
+
...tracerOptions,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return new TestTracer(binding, {
|
|
193
|
+
...tracerOptions,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async function closeTracer(tracer) {
|
|
197
|
+
const close = Reflect.get(tracer, 'close');
|
|
198
|
+
if (typeof close === 'function') {
|
|
199
|
+
await close.call(tracer);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let _activeSuiteTracer = null;
|
|
203
|
+
function createActiveVitestTestTracer(tracer) {
|
|
204
|
+
return {
|
|
205
|
+
initTraceTestRun: (options) => tracer.initTraceTestRun(options),
|
|
206
|
+
useTestSpan: () => tracer.useTestSpan(),
|
|
207
|
+
getTracer: () => tracer.getTracer(),
|
|
208
|
+
createVitestMock: (vitestModule) => tracer.createVitestMock(vitestModule),
|
|
209
|
+
describe: (name, fn) => tracer.describe(name, fn),
|
|
210
|
+
it: (name, fn) => tracer.it(name, fn),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
export function installVitestTestTracing(tracer, options) {
|
|
214
|
+
tracer.initTraceTestRun(options);
|
|
215
|
+
_activeSuiteTracer = createActiveVitestTestTracer(tracer);
|
|
216
|
+
}
|
|
217
|
+
export function makeVitestTestSuiteTracer(config, options) {
|
|
218
|
+
const useTestTracer = makeVitestTestTracer(config);
|
|
219
|
+
return {
|
|
220
|
+
useTestTracer,
|
|
221
|
+
useTestSpan: () => useTestTracer.useTestSpan(),
|
|
222
|
+
setupVitestTestSuiteTracing: () => installVitestTestTracing(useTestTracer, options),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export function makeVitestTestTracer(config) {
|
|
226
|
+
const { binding } = config;
|
|
227
|
+
const spanStore = config.createSpanContextStore?.() ?? createDefaultSpanContextStore();
|
|
228
|
+
vitestHarnessDebug('created vitest test tracer instance');
|
|
229
|
+
let initialized = false;
|
|
230
|
+
let tracer = null;
|
|
231
|
+
let verboseTrace = false;
|
|
232
|
+
let rootCtx = null;
|
|
233
|
+
let resolveTestRun = null;
|
|
234
|
+
let rootTracePromise = null;
|
|
235
|
+
const standaloneDescribeStack = [];
|
|
236
|
+
function getRootCtx() {
|
|
237
|
+
if (!rootCtx) {
|
|
238
|
+
throw new Error('Call initTraceTestRun() in setupFiles before tests');
|
|
239
|
+
}
|
|
240
|
+
return rootCtx;
|
|
241
|
+
}
|
|
242
|
+
function createExtendedBinding() {
|
|
243
|
+
const extendedSchema = binding.logBinding.logSchema.extend({ describe: S.category() });
|
|
244
|
+
const extendedBinding = {
|
|
245
|
+
...binding,
|
|
246
|
+
logBinding: { ...binding.logBinding, logSchema: extendedSchema },
|
|
247
|
+
};
|
|
248
|
+
return extendedBinding;
|
|
249
|
+
}
|
|
250
|
+
function initTraceTestRun(options) {
|
|
251
|
+
if (initialized) {
|
|
252
|
+
throw new Error('initTraceTestRun() already called for this vitest tracer instance');
|
|
253
|
+
}
|
|
254
|
+
initialized = true;
|
|
255
|
+
verboseTrace = isVerboseTraceEnabled(options?.verbose);
|
|
256
|
+
vitestHarnessDebug('initTraceTestRun start', {
|
|
257
|
+
sqliteConfigured: options?.sqlite?.createDatabase !== undefined || options?.sqlite?.createAsyncDatabase !== undefined,
|
|
258
|
+
verboseTrace,
|
|
259
|
+
});
|
|
260
|
+
// Extend user's schema with `describe` column for test grouping.
|
|
261
|
+
const extendedBinding = createExtendedBinding();
|
|
262
|
+
tracer = createRootTracer({
|
|
263
|
+
binding: extendedBinding,
|
|
264
|
+
sqlite: options?.sqlite,
|
|
265
|
+
verbose: verboseTrace,
|
|
266
|
+
});
|
|
267
|
+
vitestHarnessDebug('created root tracer for vitest harness');
|
|
268
|
+
const activeTracer = tracer;
|
|
269
|
+
rootTracePromise = activeTracer.trace('test-run', (ctx) => {
|
|
270
|
+
rootCtx = ctx;
|
|
271
|
+
vitestHarnessDebug('root test-run span started', { trace_id: ctx.buffer.trace_id });
|
|
272
|
+
return new Promise((resolve) => {
|
|
273
|
+
resolveTestRun = resolve;
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
vitestHarnessDebug('root trace promise created');
|
|
277
|
+
_afterAll(async () => {
|
|
278
|
+
vitestHarnessDebug('afterAll hook start');
|
|
279
|
+
if (resolveTestRun) {
|
|
280
|
+
resolveTestRun();
|
|
281
|
+
resolveTestRun = null;
|
|
282
|
+
vitestHarnessDebug('resolved root test-run promise');
|
|
283
|
+
}
|
|
284
|
+
if (rootTracePromise) {
|
|
285
|
+
await rootTracePromise;
|
|
286
|
+
rootTracePromise = null;
|
|
287
|
+
vitestHarnessDebug('awaited root trace promise');
|
|
288
|
+
}
|
|
289
|
+
if (tracer && rootCtx) {
|
|
290
|
+
try {
|
|
291
|
+
vitestHarnessDebug('flushing tracer');
|
|
292
|
+
await tracer.flush();
|
|
293
|
+
if (options?.sqlite) {
|
|
294
|
+
const traceId = rootCtx.buffer.trace_id;
|
|
295
|
+
const dbPath = options.sqlite.dbPath ?? '.trace-results.db';
|
|
296
|
+
console.log(`\n[trace] trace_id: ${traceId} → ${dbPath}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.error('[lmao/testing] SQLite flush error:', error);
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
await closeTracer(tracer);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
vitestHarnessDebug('afterAll hook complete');
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function useTestSpan() {
|
|
310
|
+
const ctx = spanStore.getStore();
|
|
311
|
+
if (!ctx) {
|
|
312
|
+
throw new Error('useTestSpan() called outside of a traced it()');
|
|
313
|
+
}
|
|
314
|
+
return ctx;
|
|
315
|
+
}
|
|
316
|
+
function getTracer() {
|
|
317
|
+
if (!tracer) {
|
|
318
|
+
throw new Error('Call initTraceTestRun() in setupFiles before tests');
|
|
319
|
+
}
|
|
320
|
+
return tracer;
|
|
321
|
+
}
|
|
322
|
+
function createVitestMock(vitestModule) {
|
|
323
|
+
vitestHarnessDebug('createVitestMock called');
|
|
324
|
+
const currentRootCtx = getRootCtx();
|
|
325
|
+
const origIt = vitestModule.it;
|
|
326
|
+
const origDescribe = vitestModule.describe;
|
|
327
|
+
const describeStack = [];
|
|
328
|
+
function wrappedDescribe(name, fn) {
|
|
329
|
+
return origDescribe(name, () => {
|
|
330
|
+
describeStack.push(name);
|
|
331
|
+
try {
|
|
332
|
+
fn();
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
describeStack.pop();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
Object.assign(wrappedDescribe, {
|
|
340
|
+
skip: origDescribe.skip,
|
|
341
|
+
only: origDescribe.only,
|
|
342
|
+
todo: origDescribe.todo,
|
|
343
|
+
each: origDescribe.each,
|
|
344
|
+
skipIf: origDescribe.skipIf.bind(origDescribe),
|
|
345
|
+
});
|
|
346
|
+
function wrappedIt(name, fn) {
|
|
347
|
+
const describePath = describeStack.length > 0 ? describeStack.join(' > ') : null;
|
|
348
|
+
return origIt(name, () => currentRootCtx.span(name, async (ctx) => {
|
|
349
|
+
writeDescribeTag(ctx.tag, describePath);
|
|
350
|
+
try {
|
|
351
|
+
await spanStore.run(ctx, fn);
|
|
352
|
+
return ctx.ok(undefined);
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
if (isExpectError(error)) {
|
|
356
|
+
return ctx.err(error);
|
|
357
|
+
}
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
Object.assign(wrappedIt, {
|
|
363
|
+
skip: origIt.skip,
|
|
364
|
+
only: origIt.only,
|
|
365
|
+
todo: origIt.todo,
|
|
366
|
+
each: origIt.each,
|
|
367
|
+
skipIf: origIt.skipIf.bind(origIt),
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
...vitestModule,
|
|
371
|
+
describe: wrappedDescribe,
|
|
372
|
+
it: wrappedIt,
|
|
373
|
+
test: wrappedIt,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function describe(name, fn) {
|
|
377
|
+
return _describe(name, () => {
|
|
378
|
+
standaloneDescribeStack.push(name);
|
|
379
|
+
try {
|
|
380
|
+
fn();
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
standaloneDescribeStack.pop();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
function it(name, fn) {
|
|
388
|
+
const describePath = standaloneDescribeStack.length > 0 ? standaloneDescribeStack.join(' > ') : null;
|
|
389
|
+
_it(name, () => {
|
|
390
|
+
const currentRootCtx = getRootCtx();
|
|
391
|
+
return currentRootCtx.span(name, async (ctx) => {
|
|
392
|
+
writeDescribeTag(ctx.tag, describePath);
|
|
393
|
+
try {
|
|
394
|
+
await spanStore.run(ctx, fn);
|
|
395
|
+
return ctx.ok(undefined);
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
if (isExpectError(error)) {
|
|
399
|
+
return ctx.err(error);
|
|
400
|
+
}
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
initTraceTestRun,
|
|
408
|
+
useTestSpan,
|
|
409
|
+
getTracer,
|
|
410
|
+
createVitestMock,
|
|
411
|
+
describe,
|
|
412
|
+
it,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function requireActiveSuiteTracer(message) {
|
|
416
|
+
if (!_activeSuiteTracer) {
|
|
417
|
+
throw new Error(message);
|
|
418
|
+
}
|
|
419
|
+
return _activeSuiteTracer;
|
|
420
|
+
}
|
|
421
|
+
/** Initialize the root tracer for the entire vitest run. Call once in setupFiles. */
|
|
422
|
+
export function initTraceTestRun(opContext, options) {
|
|
423
|
+
installVitestTestTracing(makeVitestTestTracer({ binding: opContext }), options);
|
|
424
|
+
}
|
|
425
|
+
/** Get the current span context from AsyncLocalStorage (inside an it() block) */
|
|
426
|
+
export function useTestSpan() {
|
|
427
|
+
const ctx = requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').useTestSpan();
|
|
428
|
+
if (!isSpanContext(ctx)) {
|
|
429
|
+
throw new Error('Active suite tracer returned a non-span context');
|
|
430
|
+
}
|
|
431
|
+
return ctx;
|
|
432
|
+
}
|
|
433
|
+
/** Get the root tracer instance */
|
|
434
|
+
export function getTracer() {
|
|
435
|
+
const tracer = requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').getTracer();
|
|
436
|
+
if (!(tracer instanceof Tracer)) {
|
|
437
|
+
throw new Error('Active suite tracer returned a non-tracer');
|
|
438
|
+
}
|
|
439
|
+
return tracer;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create a vitest mock replacement that wraps it()/test()/describe() with trace spans.
|
|
443
|
+
*
|
|
444
|
+
* Call this from a vitest setupFile via vi.mock:
|
|
445
|
+
* ```typescript
|
|
446
|
+
* vi.mock('vitest', async (importOriginal) => {
|
|
447
|
+
* const [mod, { createVitestMock }] = await Promise.all([
|
|
448
|
+
* importOriginal(),
|
|
449
|
+
* import('@smoothbricks/lmao/testing/vitest'),
|
|
450
|
+
* ]);
|
|
451
|
+
* return createVitestMock(mod);
|
|
452
|
+
* });
|
|
453
|
+
* ```
|
|
454
|
+
*
|
|
455
|
+
* @param vitestModule - The original vitest namespace from importOriginal()
|
|
456
|
+
*/
|
|
457
|
+
export function createVitestMock(vitestModule) {
|
|
458
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() before createVitestMock()').createVitestMock(vitestModule);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Wrapped describe — tracks describe nesting for the standalone export path.
|
|
462
|
+
* describe() callbacks run synchronously (just registering tests).
|
|
463
|
+
*/
|
|
464
|
+
const describeBase = (name, fn) => {
|
|
465
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').describe(name, fn);
|
|
466
|
+
};
|
|
467
|
+
export const describe = Object.assign(describeBase, {
|
|
468
|
+
skip: (name, fn) => _describe.skip(name, fn),
|
|
469
|
+
only: (name, fn) => _describe.only(name, fn),
|
|
470
|
+
todo: (name, fn) => _describe.todo(name, fn),
|
|
471
|
+
each: (...args) => Reflect.apply(_describe.each, _describe, args),
|
|
472
|
+
skipIf: (condition) => (condition ? _describe.skip : describe),
|
|
473
|
+
});
|
|
474
|
+
/** Wrapped it — creates a child span of the root trace for the test case */
|
|
475
|
+
const itBase = (name, fn) => {
|
|
476
|
+
return requireActiveSuiteTracer('Call initTraceTestRun() in setupFiles before tests').it(name, fn);
|
|
477
|
+
};
|
|
478
|
+
export const it = Object.assign(itBase, {
|
|
479
|
+
skip: (name, fn) => _it.skip(name, fn),
|
|
480
|
+
only: (name, fn) => _it.only(name, fn),
|
|
481
|
+
todo: (name, fn) => _it.todo(name, fn),
|
|
482
|
+
each: (...args) => Reflect.apply(_it.each, _it, args),
|
|
483
|
+
skipIf: (condition) => (condition ? _it.skip : it),
|
|
484
|
+
});
|
|
485
|
+
// Re-export everything else unchanged
|
|
486
|
+
export { _afterAll as afterAll, _afterEach as afterEach, _beforeAll as beforeAll, _beforeEach as beforeEach, _expect as expect, };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thread ID - Process-level unique identifier for distributed span identification
|
|
3
|
+
*
|
|
4
|
+
* Each worker/process gets a unique 64-bit random ID that remains constant
|
|
5
|
+
* for the lifetime of the process. Combined with a local incrementing counter,
|
|
6
|
+
* this provides globally unique span IDs without coordination.
|
|
7
|
+
*
|
|
8
|
+
* The thread ID is stored as raw bytes (Uint8Array) to enable zero-copy
|
|
9
|
+
* writes to SpanBuffer identity sections.
|
|
10
|
+
*
|
|
11
|
+
* ## Module-level = Per-Process/Worker Singleton
|
|
12
|
+
*
|
|
13
|
+
* ES modules are instantiated once per JavaScript realm:
|
|
14
|
+
* - **Node.js main process**: One thread ID per process
|
|
15
|
+
* - **Node.js worker_threads**: Each Worker gets its own module instance → own thread ID
|
|
16
|
+
* - **Browser main thread**: One thread ID
|
|
17
|
+
* - **Web Workers**: Each Worker gets its own module instance → own thread ID
|
|
18
|
+
*
|
|
19
|
+
* This is exactly what we want: each "thread of execution" automatically gets
|
|
20
|
+
* a unique ID without any explicit thread-local storage API.
|
|
21
|
+
*
|
|
22
|
+
* @module threadId
|
|
23
|
+
*/
|
|
24
|
+
/** Thread ID size in bytes */
|
|
25
|
+
export declare const THREAD_ID_BYTES = 8;
|
|
26
|
+
/**
|
|
27
|
+
* Copy the process thread ID bytes to a destination buffer.
|
|
28
|
+
* This is the primary hot-path API for SpanBuffer construction.
|
|
29
|
+
*
|
|
30
|
+
* @param dest - Destination Uint8Array
|
|
31
|
+
* @param offset - Byte offset in destination
|
|
32
|
+
*/
|
|
33
|
+
export declare function copyThreadIdTo(dest: Uint8Array, offset: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the process thread ID as a BigInt.
|
|
36
|
+
* Use copyThreadIdTo() for hot-path writes; this is for Arrow conversion.
|
|
37
|
+
*
|
|
38
|
+
* @returns 64-bit thread ID as BigInt
|
|
39
|
+
*/
|
|
40
|
+
export declare function getThreadId(): bigint;
|
|
41
|
+
/**
|
|
42
|
+
* Write the process thread ID to a BigUint64Array at the given index.
|
|
43
|
+
* Avoids BigInt conversion by writing bytes directly to the underlying buffer.
|
|
44
|
+
*
|
|
45
|
+
* @param dest - Destination BigUint64Array
|
|
46
|
+
* @param index - Element index (not byte offset)
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeThreadIdToUint64Array(dest: BigUint64Array, index: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* Reset thread ID for testing purposes only.
|
|
51
|
+
*
|
|
52
|
+
* **WARNING**: Only use in tests! Resetting in production would break
|
|
53
|
+
* span ID uniqueness guarantees.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function _resetThreadId(): void;
|
|
58
|
+
//# sourceMappingURL=threadId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threadId.d.ts","sourceRoot":"","sources":["../../src/lib/threadId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,8BAA8B;AAC9B,eAAO,MAAM,eAAe,IAAI,CAAC;AAwCjC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAMrE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAmBpC;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOpF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAGrC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thread ID - Process-level unique identifier for distributed span identification
|
|
3
|
+
*
|
|
4
|
+
* Each worker/process gets a unique 64-bit random ID that remains constant
|
|
5
|
+
* for the lifetime of the process. Combined with a local incrementing counter,
|
|
6
|
+
* this provides globally unique span IDs without coordination.
|
|
7
|
+
*
|
|
8
|
+
* The thread ID is stored as raw bytes (Uint8Array) to enable zero-copy
|
|
9
|
+
* writes to SpanBuffer identity sections.
|
|
10
|
+
*
|
|
11
|
+
* ## Module-level = Per-Process/Worker Singleton
|
|
12
|
+
*
|
|
13
|
+
* ES modules are instantiated once per JavaScript realm:
|
|
14
|
+
* - **Node.js main process**: One thread ID per process
|
|
15
|
+
* - **Node.js worker_threads**: Each Worker gets its own module instance → own thread ID
|
|
16
|
+
* - **Browser main thread**: One thread ID
|
|
17
|
+
* - **Web Workers**: Each Worker gets its own module instance → own thread ID
|
|
18
|
+
*
|
|
19
|
+
* This is exactly what we want: each "thread of execution" automatically gets
|
|
20
|
+
* a unique ID without any explicit thread-local storage API.
|
|
21
|
+
*
|
|
22
|
+
* @module threadId
|
|
23
|
+
*/
|
|
24
|
+
/** Thread ID size in bytes */
|
|
25
|
+
export const THREAD_ID_BYTES = 8;
|
|
26
|
+
/** Process-level thread ID bytes (lazily initialized) */
|
|
27
|
+
let threadIdBytes = null;
|
|
28
|
+
/** Cached BigInt representation (lazily computed) */
|
|
29
|
+
let threadIdBigInt = null;
|
|
30
|
+
/**
|
|
31
|
+
* Ensure thread ID is initialized.
|
|
32
|
+
* Called lazily on first access.
|
|
33
|
+
*/
|
|
34
|
+
function ensureInitialized() {
|
|
35
|
+
if (threadIdBytes !== null)
|
|
36
|
+
return;
|
|
37
|
+
threadIdBytes = new Uint8Array(THREAD_ID_BYTES);
|
|
38
|
+
// Use Web Crypto API - available in browsers, Node 19+, Deno, Bun, Workers
|
|
39
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
40
|
+
crypto.getRandomValues(threadIdBytes);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// For Node.js < 19, try to use node:crypto
|
|
44
|
+
try {
|
|
45
|
+
const nodeCrypto = require('node:crypto');
|
|
46
|
+
if (nodeCrypto && typeof nodeCrypto.randomFillSync === 'function') {
|
|
47
|
+
nodeCrypto.randomFillSync(threadIdBytes);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// node:crypto not available
|
|
53
|
+
}
|
|
54
|
+
throw new Error('crypto.getRandomValues is not available. ' +
|
|
55
|
+
'For React Native, install and import "react-native-get-random-values" before using this library.');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Copy the process thread ID bytes to a destination buffer.
|
|
59
|
+
* This is the primary hot-path API for SpanBuffer construction.
|
|
60
|
+
*
|
|
61
|
+
* @param dest - Destination Uint8Array
|
|
62
|
+
* @param offset - Byte offset in destination
|
|
63
|
+
*/
|
|
64
|
+
export function copyThreadIdTo(dest, offset) {
|
|
65
|
+
ensureInitialized();
|
|
66
|
+
if (!threadIdBytes) {
|
|
67
|
+
throw new Error('ThreadId bytes not initialized');
|
|
68
|
+
}
|
|
69
|
+
dest.set(threadIdBytes, offset);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the process thread ID as a BigInt.
|
|
73
|
+
* Use copyThreadIdTo() for hot-path writes; this is for Arrow conversion.
|
|
74
|
+
*
|
|
75
|
+
* @returns 64-bit thread ID as BigInt
|
|
76
|
+
*/
|
|
77
|
+
export function getThreadId() {
|
|
78
|
+
ensureInitialized();
|
|
79
|
+
if (threadIdBigInt === null) {
|
|
80
|
+
if (!threadIdBytes) {
|
|
81
|
+
throw new Error('ThreadId bytes not initialized');
|
|
82
|
+
}
|
|
83
|
+
const b = threadIdBytes;
|
|
84
|
+
// Little-endian conversion to match identity byte layout
|
|
85
|
+
threadIdBigInt =
|
|
86
|
+
BigInt(b[0]) |
|
|
87
|
+
(BigInt(b[1]) << 8n) |
|
|
88
|
+
(BigInt(b[2]) << 16n) |
|
|
89
|
+
(BigInt(b[3]) << 24n) |
|
|
90
|
+
(BigInt(b[4]) << 32n) |
|
|
91
|
+
(BigInt(b[5]) << 40n) |
|
|
92
|
+
(BigInt(b[6]) << 48n) |
|
|
93
|
+
(BigInt(b[7]) << 56n);
|
|
94
|
+
}
|
|
95
|
+
return threadIdBigInt;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Write the process thread ID to a BigUint64Array at the given index.
|
|
99
|
+
* Avoids BigInt conversion by writing bytes directly to the underlying buffer.
|
|
100
|
+
*
|
|
101
|
+
* @param dest - Destination BigUint64Array
|
|
102
|
+
* @param index - Element index (not byte offset)
|
|
103
|
+
*/
|
|
104
|
+
export function writeThreadIdToUint64Array(dest, index) {
|
|
105
|
+
ensureInitialized();
|
|
106
|
+
if (!threadIdBytes) {
|
|
107
|
+
throw new Error('ThreadId bytes not initialized');
|
|
108
|
+
}
|
|
109
|
+
const byteView = new Uint8Array(dest.buffer, dest.byteOffset + index * 8, 8);
|
|
110
|
+
byteView.set(threadIdBytes);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Reset thread ID for testing purposes only.
|
|
114
|
+
*
|
|
115
|
+
* **WARNING**: Only use in tests! Resetting in production would break
|
|
116
|
+
* span ID uniqueness guarantees.
|
|
117
|
+
*
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
export function _resetThreadId() {
|
|
121
|
+
threadIdBytes = null;
|
|
122
|
+
threadIdBigInt = null;
|
|
123
|
+
}
|