@@ -7,6 +7,13 @@ networkSampleCDebug.js
77
88import { createNetworkDebugPluginDefinition } from "../../../engine/debug/network/index.js" ;
99import { asArray , asObject } from "../../../src/engine/debug/inspectors/shared/inspectorUtils.js" ;
10+ import {
11+ commandLinesForTrace ,
12+ getCommandSnapshot ,
13+ toNetworkSnapshot
14+ } from "../../../src/shared/utils/networkDebugUtils.js" ;
15+
16+ const NETWORK_SAMPLE_KEY = "networkSampleC" ;
1017
1118function sanitizeText ( value ) {
1219 return typeof value === "string" ? value . trim ( ) : "" ;
@@ -34,16 +41,8 @@ function formatEntityLine(entity, options = {}) {
3441 return `${ marker } ${ compactLabel } delta=${ frameDelta } status=${ status } severity=${ severity } align=${ alignment } ` ;
3542}
3643
37- function toNetworkSnapshot ( snapshot ) {
38- return asObject ( snapshot ?. assets ?. networkSampleC ) ;
39- }
40-
41- function getCommandSnapshot ( context ) {
42- return asObject ( context ?. assets ?. networkSampleC ) ;
43- }
44-
4544function toDivergenceLines ( snapshot ) {
46- const network = toNetworkSnapshot ( snapshot ) ;
45+ const network = toNetworkSnapshot ( snapshot , NETWORK_SAMPLE_KEY ) ;
4746 const scenario = asObject ( network . scenario ) ;
4847 const divergence = asObject ( network . divergence ) ;
4948 const transport = asObject ( network . network ) ;
@@ -78,7 +77,7 @@ function toDivergenceLines(snapshot) {
7877}
7978
8079function toTimelineLines ( snapshot ) {
81- const network = toNetworkSnapshot ( snapshot ) ;
80+ const network = toNetworkSnapshot ( snapshot , NETWORK_SAMPLE_KEY ) ;
8281 const timeline = asObject ( network . timeline ) ;
8382 const history = asObject ( timeline . history ) ;
8483 const entityHistory = asArray ( history . entities ) ;
@@ -117,7 +116,7 @@ function toTimelineLines(snapshot) {
117116}
118117
119118function toValidationLines ( snapshot ) {
120- const network = toNetworkSnapshot ( snapshot ) ;
119+ const network = toNetworkSnapshot ( snapshot , NETWORK_SAMPLE_KEY ) ;
121120 const validation = asObject ( network . validation ) ;
122121 const items = asArray ( validation . items ) ;
123122
@@ -135,7 +134,7 @@ function toValidationLines(snapshot) {
135134}
136135
137136function toRewindLines ( snapshot ) {
138- const network = toNetworkSnapshot ( snapshot ) ;
137+ const network = toNetworkSnapshot ( snapshot , NETWORK_SAMPLE_KEY ) ;
139138 const rewind = asObject ( network . rewindPreparation ) ;
140139 const rewindEntities = asArray ( rewind . entities ) ;
141140 const rewindSelected = asArray ( rewind . selectedEntityIds ) ;
@@ -171,7 +170,7 @@ function toRewindLines(snapshot) {
171170}
172171
173172function toTraceLines ( snapshot , maxLines = 10 ) {
174- const network = toNetworkSnapshot ( snapshot ) ;
173+ const network = toNetworkSnapshot ( snapshot , NETWORK_SAMPLE_KEY ) ;
175174 const trace = asObject ( network . trace ) ;
176175 const events = asArray ( trace . events ) ;
177176
@@ -193,7 +192,7 @@ function toTraceLines(snapshot, maxLines = 10) {
193192}
194193
195194function commandLinesForDivergence ( context ) {
196- const snapshot = getCommandSnapshot ( context ) ;
195+ const snapshot = getCommandSnapshot ( context , NETWORK_SAMPLE_KEY ) ;
197196 const scenario = asObject ( snapshot . scenario ) ;
198197 const divergence = asObject ( snapshot . divergence ) ;
199198 const network = asObject ( snapshot . network ) ;
@@ -223,37 +222,8 @@ function commandLinesForDivergence(context) {
223222 return lines ;
224223}
225224
226- function commandLinesForTrace ( context , args = [ ] ) {
227- const snapshot = getCommandSnapshot ( context ) ;
228- const trace = asObject ( snapshot . trace ) ;
229- const events = asArray ( trace . events ) ;
230-
231- const requestedCount = Number . parseInt ( args [ 0 ] , 10 ) ;
232- const count = Number . isFinite ( requestedCount )
233- ? Math . min ( 20 , Math . max ( 1 , requestedCount ) )
234- : 8 ;
235-
236- if ( events . length === 0 ) {
237- return [ "No network trace events recorded." ] ;
238- }
239-
240- return events
241- . slice ( - count )
242- . reverse ( )
243- . map ( ( event ) => {
244- const source = asObject ( event ) ;
245- const details = asObject ( source . details ) ;
246- const detailText = Object . keys ( details )
247- . slice ( 0 , 2 )
248- . map ( ( key ) => `${ key } =${ String ( details [ key ] ) } ` )
249- . join ( " " ) ;
250- const base = `${ asNumber ( source . timestampMs , 0 ) } ms ${ sanitizeText ( source . type ) || "EVENT" } phase=${ sanitizeText ( source . phaseId ) || "unknown" } ` ;
251- return detailText ? `${ base } ${ detailText } ` : base ;
252- } ) ;
253- }
254-
255225function commandLinesForValidation ( context ) {
256- const snapshot = getCommandSnapshot ( context ) ;
226+ const snapshot = getCommandSnapshot ( context , NETWORK_SAMPLE_KEY ) ;
257227 const validation = asObject ( snapshot . validation ) ;
258228 const items = asArray ( validation . items ) ;
259229
@@ -270,7 +240,7 @@ function commandLinesForValidation(context) {
270240}
271241
272242function commandLinesForReproduction ( context ) {
273- const snapshot = getCommandSnapshot ( context ) ;
243+ const snapshot = getCommandSnapshot ( context , NETWORK_SAMPLE_KEY ) ;
274244 const reproduction = asObject ( snapshot . reproduction ) ;
275245 const steps = asArray ( reproduction . steps ) ;
276246
@@ -288,7 +258,7 @@ function commandLinesForReproduction(context) {
288258}
289259
290260function commandLinesForRewind ( context ) {
291- const snapshot = getCommandSnapshot ( context ) ;
261+ const snapshot = getCommandSnapshot ( context , NETWORK_SAMPLE_KEY ) ;
292262 const rewind = asObject ( snapshot . rewindPreparation ) ;
293263 const rewindEntities = asArray ( rewind . entities ) ;
294264 const rewindSelected = asArray ( rewind . selectedEntityIds ) ;
@@ -499,7 +469,12 @@ export function createNetworkSampleCDebugPlugin() {
499469 return {
500470 status : "ready" ,
501471 title : "Network Trace" ,
502- lines : commandLinesForTrace ( context , args ) ,
472+ lines : commandLinesForTrace ( context , args , {
473+ sampleKey : NETWORK_SAMPLE_KEY ,
474+ phaseField : "phaseId" ,
475+ sanitizeText,
476+ formatNumber : asNumber
477+ } ) ,
503478 code : "NETWORK_TRACE"
504479 } ;
505480 }
0 commit comments