@@ -174,6 +174,68 @@ describe("resource telemetry process model", () => {
174174 expect ( result . groups . electron . processCount ) . toBe ( 2 ) ;
175175 } ) ;
176176
177+ it ( "keeps backend descendants out of desktop totals when Electron launches the server" , ( ) => {
178+ const samples = [
179+ processSample ( { pid : 300 , ppid : 1 , startTimeMs : 1_000 , cpuPercent : 2 } ) ,
180+ processSample ( { pid : SERVER_PID , ppid : 300 , startTimeMs : 2_000 , cpuPercent : 5 } ) ,
181+ processSample ( { pid : 200 , ppid : SERVER_PID , startTimeMs : 3_000 , cpuPercent : 400 } ) ,
182+ processSample ( { pid : 201 , ppid : 200 , startTimeMs : 4_000 , cpuPercent : 100 } ) ,
183+ processSample ( { pid : 301 , ppid : 300 , startTimeMs : 3_000 , cpuPercent : 3 } ) ,
184+ processSample ( { pid : 900 , ppid : SERVER_PID , startTimeMs : 3_000 , cpuPercent : 1 } ) ,
185+ ] ;
186+ const desktop = desktopSnapshot ( BASE_TIME_MS , [
187+ electronMetric ( { pid : 300 , creationTimeMs : 1_000 , type : "Browser" } ) ,
188+ ] ) ;
189+ const first = merge ( {
190+ sidecarPid : 900 ,
191+ native : nativeSnapshot ( BASE_TIME_MS , samples ) ,
192+ desktop,
193+ } ) ;
194+ const result = merge ( {
195+ sidecarPid : 900 ,
196+ previous : first ,
197+ native : nativeSnapshot (
198+ BASE_TIME_MS + 1_000 ,
199+ samples . map ( ( sample ) => ( {
200+ ...sample ,
201+ cpuTimeMs : sample . cpuPercent * 10 ,
202+ ioReadBytes : sample . cpuPercent * 100 ,
203+ ioWriteBytes : sample . cpuPercent * 200 ,
204+ } ) ) ,
205+ 2 ,
206+ ) ,
207+ desktop,
208+ } ) ;
209+
210+ expect ( result . processes . find ( ( process ) => process . identity . pid === 200 ) ?. category ) . toBe (
211+ "server-child" ,
212+ ) ;
213+ expect ( result . processes . find ( ( process ) => process . identity . pid === 201 ) ?. category ) . toBe (
214+ "server-child" ,
215+ ) ;
216+ expect ( result . groups . backend ) . toMatchObject ( {
217+ processCount : 3 ,
218+ currentCpuPercent : 505 ,
219+ cpuTimeMs : 5_050 ,
220+ currentRssBytes : 3_072 ,
221+ ioReadBytes : 50_500 ,
222+ ioWriteBytes : 101_000 ,
223+ processStarts : 3 ,
224+ } ) ;
225+ expect ( result . groups . electron ) . toMatchObject ( {
226+ processCount : 2 ,
227+ currentCpuPercent : 5 ,
228+ cpuTimeMs : 50 ,
229+ currentRssBytes : 2_048 ,
230+ ioReadBytes : 500 ,
231+ ioWriteBytes : 1_000 ,
232+ processStarts : 2 ,
233+ } ) ;
234+ expect ( result . groups . monitor . processCount ) . toBe ( 1 ) ;
235+ expect ( result . groups . allT3 . currentCpuPercent ) . toBe ( 511 ) ;
236+ expect ( result . groups . allT3 . currentRssBytes ) . toBe ( 6_144 ) ;
237+ } ) ;
238+
177239 it ( "ignores stale Electron metrics after PID reuse" , ( ) => {
178240 const result = merge ( {
179241 native : nativeSnapshot ( BASE_TIME_MS , [
0 commit comments