@@ -933,7 +933,7 @@ describe('trackToolCall', () => {
933933 ) ;
934934 } ) ;
935935
936- it ( 'includes graphKey when provided ' , ( ) => {
936+ it ( 'includes graphKey when set on constructor ' , ( ) => {
937937 const tracker = new LDAIConfigTrackerImpl (
938938 mockLdClient ,
939939 testRunId ,
@@ -943,9 +943,10 @@ describe('trackToolCall', () => {
943943 modelName ,
944944 providerName ,
945945 testContext ,
946+ 'my-graph' ,
946947 ) ;
947948
948- tracker . trackToolCall ( 'my-tool' , 'my-graph' ) ;
949+ tracker . trackToolCall ( 'my-tool' ) ;
949950
950951 expect ( mockTrack ) . toHaveBeenCalledWith (
951952 '$ld:ai:tool_call' ,
@@ -993,8 +994,8 @@ describe('trackToolCalls', () => {
993994 } ) ;
994995} ) ;
995996
996- describe ( 'graphKey parameter support' , ( ) => {
997- it ( 'includes graphKey in trackDuration event' , ( ) => {
997+ describe ( 'graphKey constructor support' , ( ) => {
998+ it ( 'includes graphKey in trackDuration event when set on constructor ' , ( ) => {
998999 const tracker = new LDAIConfigTrackerImpl (
9991000 mockLdClient ,
10001001 testRunId ,
@@ -1004,9 +1005,10 @@ describe('graphKey parameter support', () => {
10041005 modelName ,
10051006 providerName ,
10061007 testContext ,
1008+ 'my-graph' ,
10071009 ) ;
10081010
1009- tracker . trackDuration ( 1000 , 'my-graph' ) ;
1011+ tracker . trackDuration ( 1000 ) ;
10101012
10111013 expect ( mockTrack ) . toHaveBeenCalledWith (
10121014 '$ld:ai:duration:total' ,
@@ -1016,7 +1018,7 @@ describe('graphKey parameter support', () => {
10161018 ) ;
10171019 } ) ;
10181020
1019- it ( 'includes graphKey in trackSuccess event' , ( ) => {
1021+ it ( 'includes graphKey in trackSuccess event when set on constructor ' , ( ) => {
10201022 const tracker = new LDAIConfigTrackerImpl (
10211023 mockLdClient ,
10221024 testRunId ,
@@ -1026,9 +1028,10 @@ describe('graphKey parameter support', () => {
10261028 modelName ,
10271029 providerName ,
10281030 testContext ,
1031+ 'my-graph' ,
10291032 ) ;
10301033
1031- tracker . trackSuccess ( 'my-graph' ) ;
1034+ tracker . trackSuccess ( ) ;
10321035
10331036 expect ( mockTrack ) . toHaveBeenCalledWith (
10341037 '$ld:ai:generation:success' ,
@@ -1038,7 +1041,7 @@ describe('graphKey parameter support', () => {
10381041 ) ;
10391042 } ) ;
10401043
1041- it ( 'does not include graphKey when not provided ' , ( ) => {
1044+ it ( 'does not include graphKey when not set on constructor ' , ( ) => {
10421045 const tracker = new LDAIConfigTrackerImpl (
10431046 mockLdClient ,
10441047 testRunId ,
@@ -1059,6 +1062,41 @@ describe('graphKey parameter support', () => {
10591062 1 ,
10601063 ) ;
10611064 } ) ;
1065+
1066+ it ( 'includes graphKey in getTrackData when set on constructor' , ( ) => {
1067+ const tracker = new LDAIConfigTrackerImpl (
1068+ mockLdClient ,
1069+ testRunId ,
1070+ configKey ,
1071+ variationKey ,
1072+ version ,
1073+ modelName ,
1074+ providerName ,
1075+ testContext ,
1076+ 'my-graph' ,
1077+ ) ;
1078+
1079+ expect ( tracker . getTrackData ( ) ) . toEqual ( {
1080+ ...getExpectedTrackData ( ) ,
1081+ graphKey : 'my-graph' ,
1082+ } ) ;
1083+ } ) ;
1084+
1085+ it ( 'does not include graphKey in getTrackData when not set' , ( ) => {
1086+ const tracker = new LDAIConfigTrackerImpl (
1087+ mockLdClient ,
1088+ testRunId ,
1089+ configKey ,
1090+ variationKey ,
1091+ version ,
1092+ modelName ,
1093+ providerName ,
1094+ testContext ,
1095+ ) ;
1096+
1097+ expect ( tracker . getTrackData ( ) ) . toEqual ( getExpectedTrackData ( ) ) ;
1098+ expect ( 'graphKey' in tracker . getTrackData ( ) ) . toBe ( false ) ;
1099+ } ) ;
10621100} ) ;
10631101
10641102describe ( 'at-most-once semantics' , ( ) => {
@@ -1311,4 +1349,96 @@ describe('fromResumptionToken', () => {
13111349 1 ,
13121350 ) ;
13131351 } ) ;
1352+
1353+ it ( 'includes graphKey in resumption token when set on constructor' , ( ) => {
1354+ const tracker = new LDAIConfigTrackerImpl (
1355+ mockLdClient ,
1356+ testRunId ,
1357+ configKey ,
1358+ variationKey ,
1359+ version ,
1360+ modelName ,
1361+ providerName ,
1362+ testContext ,
1363+ 'my-graph' ,
1364+ ) ;
1365+
1366+ const token = tracker . resumptionToken ;
1367+ const decoded = JSON . parse ( Buffer . from ( token , 'base64url' ) . toString ( 'utf8' ) ) ;
1368+
1369+ expect ( decoded ) . toEqual ( {
1370+ runId : testRunId ,
1371+ configKey,
1372+ variationKey,
1373+ version,
1374+ graphKey : 'my-graph' ,
1375+ } ) ;
1376+ } ) ;
1377+
1378+ it ( 'does not include graphKey in resumption token when not set' , ( ) => {
1379+ const tracker = new LDAIConfigTrackerImpl (
1380+ mockLdClient ,
1381+ testRunId ,
1382+ configKey ,
1383+ variationKey ,
1384+ version ,
1385+ modelName ,
1386+ providerName ,
1387+ testContext ,
1388+ ) ;
1389+
1390+ const token = tracker . resumptionToken ;
1391+ const decoded = JSON . parse ( Buffer . from ( token , 'base64url' ) . toString ( 'utf8' ) ) ;
1392+
1393+ expect ( decoded ) . toEqual ( {
1394+ runId : testRunId ,
1395+ configKey,
1396+ variationKey,
1397+ version,
1398+ } ) ;
1399+ expect ( 'graphKey' in decoded ) . toBe ( false ) ;
1400+ } ) ;
1401+
1402+ it ( 'reconstructs tracker with graphKey from resumption token' , ( ) => {
1403+ const original = new LDAIConfigTrackerImpl (
1404+ mockLdClient ,
1405+ testRunId ,
1406+ configKey ,
1407+ variationKey ,
1408+ version ,
1409+ modelName ,
1410+ providerName ,
1411+ testContext ,
1412+ 'my-graph' ,
1413+ ) ;
1414+
1415+ const reconstructed = LDAIConfigTrackerImpl . fromResumptionToken (
1416+ original . resumptionToken ,
1417+ mockLdClient ,
1418+ testContext ,
1419+ ) ;
1420+
1421+ expect ( reconstructed . getTrackData ( ) . graphKey ) . toBe ( 'my-graph' ) ;
1422+ } ) ;
1423+
1424+ it ( 'reconstructed tracker without graphKey does not include graphKey in track data' , ( ) => {
1425+ const original = new LDAIConfigTrackerImpl (
1426+ mockLdClient ,
1427+ testRunId ,
1428+ configKey ,
1429+ variationKey ,
1430+ version ,
1431+ modelName ,
1432+ providerName ,
1433+ testContext ,
1434+ ) ;
1435+
1436+ const reconstructed = LDAIConfigTrackerImpl . fromResumptionToken (
1437+ original . resumptionToken ,
1438+ mockLdClient ,
1439+ testContext ,
1440+ ) ;
1441+
1442+ expect ( 'graphKey' in reconstructed . getTrackData ( ) ) . toBe ( false ) ;
1443+ } ) ;
13141444} ) ;
0 commit comments