@@ -26,6 +26,7 @@ import * as Metric from "effect/Metric";
2626import * as Option from "effect/Option" ;
2727import * as Queue from "effect/Queue" ;
2828import * as Stream from "effect/Stream" ;
29+ import * as Tracer from "effect/Tracer" ;
2930import { TestClock } from "effect/testing" ;
3031import { describe , expect , it , vi } from "vite-plus/test" ;
3132
@@ -568,6 +569,46 @@ describe("OrchestrationEngine", () => {
568569 } ) . pipe ( Effect . provide ( makeOrchestrationLayer ( ) ) ) ,
569570 ) ;
570571
572+ const commandSpans : Array < Tracer . NativeSpan > = [ ] ;
573+ const recordingTracer = Tracer . make ( {
574+ span : ( options ) => {
575+ const span = new Tracer . NativeSpan ( options ) ;
576+ if ( options . name . startsWith ( "orchestration.command." ) ) commandSpans . push ( span ) ;
577+ return span ;
578+ } ,
579+ } ) ;
580+
581+ effectIt . effect ( "runs each command inside the dispatcher's trace" , ( ) =>
582+ Effect . gen ( function * ( ) {
583+ const engine = yield * OrchestrationEngineService ;
584+ const dispatcherSpan = yield * Effect . gen ( function * ( ) {
585+ yield * engine . dispatch ( {
586+ type : "project.create" ,
587+ commandId : CommandId . make ( "cmd-trace-parent-project-create" ) ,
588+ projectId : ProjectId . make ( "project-trace-parent" ) ,
589+ title : "Project" ,
590+ workspaceRoot : "/tmp/project-trace-parent" ,
591+ createdAt : now ( ) ,
592+ } ) ;
593+ return yield * Effect . currentSpan ;
594+ } ) . pipe ( Effect . withSpan ( "client.dispatch" ) ) ;
595+
596+ const commandSpan = commandSpans . find (
597+ ( span ) => span . name === "orchestration.command.project.create" ,
598+ ) ;
599+ expect ( commandSpan ?. traceId ) . toBe ( dispatcherSpan . traceId ) ;
600+ expect ( Option . map ( commandSpan ! . parent , ( parent ) => parent . spanId ) ) . toEqual (
601+ Option . some ( dispatcherSpan . spanId ) ,
602+ ) ;
603+ } ) . pipe (
604+ Effect . provide (
605+ makeOrchestrationLayer ( ) . pipe (
606+ Layer . provideMerge ( Layer . succeed ( Tracer . Tracer , recordingTracer ) ) ,
607+ ) ,
608+ ) ,
609+ ) ,
610+ ) ;
611+
571612 effectIt . effect (
572613 "rejects persisted changes and live background work without blocking unrelated threads" ,
573614 ( ) =>
0 commit comments