@@ -13,6 +13,8 @@ import {
1313 ConsecutiveMistakeError ,
1414 isConsecutiveMistakeError ,
1515 extractConsecutiveMistakeErrorProperties ,
16+ rooCodeTelemetryEventSchema ,
17+ TelemetryEventName ,
1618} from "../telemetry.js"
1719
1820describe ( "telemetry error utilities" , ( ) => {
@@ -575,3 +577,79 @@ describe("telemetry error utilities", () => {
575577 } )
576578 } )
577579} )
580+
581+ describe ( "rooCodeTelemetryEventSchema run-state events" , ( ) => {
582+ const appProperties = {
583+ appName : "zoo-code" ,
584+ appVersion : "1.0.0" ,
585+ vscodeVersion : "1.100.0" ,
586+ platform : "linux" ,
587+ editorName : "vscode" ,
588+ language : "en" ,
589+ mode : "code" ,
590+ }
591+ const runStateProperties = {
592+ ...appProperties ,
593+ taskId : "task-1" ,
594+ kind : "rejection" ,
595+ eventTag : "askStarted" ,
596+ mismatched : [ ] ,
597+ phase : "running" ,
598+ streamTag : "none" ,
599+ abort : true ,
600+ }
601+
602+ it . each ( [ TelemetryEventName . RUN_STATE_DIVERGENCE , TelemetryEventName . RUN_STATE_KNOWN_RACE ] ) (
603+ "keeps the run-state properties of %s" ,
604+ ( type ) => {
605+ const result = rooCodeTelemetryEventSchema . safeParse ( {
606+ type,
607+ properties : { ...runStateProperties , raceId : "R-9" , mismatched : [ "abortReason" ] } ,
608+ } )
609+
610+ expect ( result . success ) . toBe ( true )
611+ expect ( result . data ?. properties ) . toMatchObject ( {
612+ taskId : "task-1" ,
613+ kind : "rejection" ,
614+ raceId : "R-9" ,
615+ eventTag : "askStarted" ,
616+ mismatched : [ "abortReason" ] ,
617+ phase : "running" ,
618+ streamTag : "none" ,
619+ abort : true ,
620+ } )
621+ } ,
622+ )
623+
624+ it ( "accepts an event without a race ID" , ( ) => {
625+ const result = rooCodeTelemetryEventSchema . safeParse ( {
626+ type : TelemetryEventName . RUN_STATE_DIVERGENCE ,
627+ properties : runStateProperties ,
628+ } )
629+
630+ expect ( result . success ) . toBe ( true )
631+ } )
632+
633+ it ( "rejects an unknown kind" , ( ) => {
634+ const result = rooCodeTelemetryEventSchema . safeParse ( {
635+ type : TelemetryEventName . RUN_STATE_DIVERGENCE ,
636+ properties : { ...runStateProperties , kind : "other" } ,
637+ } )
638+
639+ expect ( result . success ) . toBe ( false )
640+ } )
641+
642+ it . each ( [ "taskId" , "eventTag" , "mismatched" , "phase" , "streamTag" , "abort" ] ) (
643+ "rejects an event without %s" ,
644+ ( property ) => {
645+ const { [ property ] : _omitted , ...properties } = runStateProperties as Record < string , unknown >
646+
647+ const result = rooCodeTelemetryEventSchema . safeParse ( {
648+ type : TelemetryEventName . RUN_STATE_KNOWN_RACE ,
649+ properties,
650+ } )
651+
652+ expect ( result . success ) . toBe ( false )
653+ } ,
654+ )
655+ } )
0 commit comments