@@ -84,6 +84,64 @@ export const getE2ETestConfigDiagnostics = (extra = {}) => ({
8484 ...extra ,
8585} ) ;
8686
87+ const getObjectValue = ( value , key ) => {
88+ if ( ! value || typeof value !== 'object' || Array . isArray ( value ) ) {
89+ return undefined ;
90+ }
91+
92+ return value [ key ] ;
93+ } ;
94+
95+ const getObjectKeysDiagnostic = ( value ) => {
96+ if ( ! value || typeof value !== 'object' || Array . isArray ( value ) ) {
97+ return 'missing' ;
98+ }
99+
100+ const keys = Object . keys ( value ) . sort ( ) ;
101+ return keys . length > 0 ? keys . join ( ',' ) : 'none' ;
102+ } ;
103+
104+ export const getE2ERemoteFeatureFlagDiagnostics = ( state = { } , extra = { } ) => {
105+ const remoteFeatureFlags = getObjectValue ( state , 'remoteFeatureFlags' ) ;
106+ const rawRemoteFeatureFlags = getObjectValue ( state , 'rawRemoteFeatureFlags' ) ;
107+ const localOverrides = getObjectValue ( state , 'localOverrides' ) ;
108+
109+ return {
110+ source : extra . source ?? 'RemoteFeatureFlagController' ,
111+ phase : extra . phase ?? 'unknown' ,
112+ explorePageV2EnabledInApp : formatE2EDiagnosticValue (
113+ getObjectValue ( remoteFeatureFlags , 'explorePageV2Enabled' ) ,
114+ ) ,
115+ explorePageV2EnabledRaw : formatE2EDiagnosticValue (
116+ getObjectValue ( rawRemoteFeatureFlags , 'explorePageV2Enabled' ) ,
117+ ) ,
118+ explorePageV2EnabledOverride : formatE2EDiagnosticValue (
119+ getObjectValue ( localOverrides , 'explorePageV2Enabled' ) ,
120+ ) ,
121+ remoteFeatureFlagsCacheTimestamp : formatE2EDiagnosticValue (
122+ getObjectValue ( state , 'cacheTimestamp' ) ,
123+ ) ,
124+ remoteFeatureFlagsKeys : getObjectKeysDiagnostic ( remoteFeatureFlags ) ,
125+ rawRemoteFeatureFlagsKeys : getObjectKeysDiagnostic ( rawRemoteFeatureFlags ) ,
126+ localOverridesKeys : getObjectKeysDiagnostic ( localOverrides ) ,
127+ ...extra ,
128+ } ;
129+ } ;
130+
131+ export const postE2EDiagnostics = async ( diagnostics ) => {
132+ const postDiagnostics = testConfig . postE2EDiagnostics ;
133+
134+ if ( typeof postDiagnostics !== 'function' ) {
135+ return ;
136+ }
137+
138+ try {
139+ await postDiagnostics ( diagnostics ) ;
140+ } catch {
141+ // Diagnostics must never affect app startup or test behavior.
142+ }
143+ } ;
144+
87145export const appendE2EDiagnosticsToUrl = ( url , diagnostics ) => {
88146 const nextUrl = new URL ( url ) ;
89147 Object . entries ( diagnostics ) . forEach ( ( [ key , value ] ) => {
0 commit comments