fix: GenerateVisualizationHtml produces non-empty dataSources when called without snapshots#351
Conversation
…snapshots are passed Co-authored-by: witskeeper <5594094+witskeeper@users.noreply.github.com> Agent-Logs-Url: https://github.com/netcorepal/netcorepal-cloud-framework/sessions/9a0e5d36-f784-4c22-a030-0a202f9cec8e
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash in the embedded visualization page by ensuring VisualizationHtmlBuilder.GenerateVisualizationHtml always emits a non-empty dataSources array even when no snapshots are provided.
Changes:
- Add a runtime fallback path that builds a single
dataSourcesentry directly fromanalysisResultwhen the snapshot list is empty. - Add a unit test that covers calling
GenerateVisualizationHtml(result)without passingsnapshots.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/NetCorePal.Extensions.CodeAnalysis/VisualizationHtmlBuilder.cs | Adds a runtime fallback dataSources builder so the page script can safely read dataSources[0]. |
| test/NetCorePal.Extensions.CodeAnalysis.UnitTests/VisualizationHtmlBuilderTests.cs | Adds a regression test ensuring dataSources is non-empty and contains expected fields without snapshots. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 当没有快照时,直接从 analysisResult 构建包含单个 Runtime 数据源的 dataSources JSON 字符串 | ||
| private static string BuildDataSourcesJsonFromAnalysisResult(CodeFlowAnalysisResult analysisResult) | ||
| { | ||
| var architectureOverviewMermaid = | ||
| MermaidVisualizers.ArchitectureOverviewMermaidVisualizer.GenerateMermaid(analysisResult); | ||
| var allProcessingFlowMermaid = | ||
| MermaidVisualizers.ProcessingFlowMermaidVisualizer.GenerateMermaid(analysisResult); | ||
| var allAggregateMermaid = | ||
| MermaidVisualizers.AggregateRelationMermaidVisualizer.GenerateAllAggregateMermaid(analysisResult); |
There was a problem hiding this comment.
BuildDataSourcesJsonFromAnalysisResult duplicates most of the JSON assembly logic from BuildDataSourcesJson (mermaid generation + dataSource object shape). This increases drift risk if the dataSource schema changes in the future (one path may be updated and the other forgotten). Consider extracting a shared helper that builds a single dataSource entry from (analysisResult, metadata) and have both code paths call it (looping for snapshots vs. one-off for runtime).
There was a problem hiding this comment.
Done in 7514183. Extracted a shared BuildSingleDataSourceEntryJson(analysisResult, version, timestamp, description, hash, nodeCount, relationshipCount) helper. Both BuildDataSourcesJson (snapshot loop) and BuildDataSourcesJsonFromAnalysisResult (runtime fallback) now delegate to it — all JSON assembly and EscapeJavaScript calls live in one place.
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tion between snapshot and runtime paths Co-authored-by: witskeeper <5594094+witskeeper@users.noreply.github.com> Agent-Logs-Url: https://github.com/netcorepal/netcorepal-cloud-framework/sessions/8ed1e14d-3148-4d96-8663-ce2c347cca1f
…on-html-error' into copilot/fix-generate-visualization-html-error # Conflicts: # src/NetCorePal.Extensions.CodeAnalysis/VisualizationHtmlBuilder.cs
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
VisualizationHtmlBuilder.GenerateVisualizationHtmlemitteddataSources = []whenever nosnapshotsargument was passed, causing the page script to immediately throwTypeError: Cannot read properties of undefined (reading 'statistics')atdataSources[0].Changes
VisualizationHtmlBuilder.cssnapshotListis empty, route through a newBuildDataSourcesJsonFromAnalysisResultfallback instead ofBuildDataSourcesJson, producing a single-elementdataSourcesarray with description"Runtime"and metadata derived from the passed-inanalysisResult.metadata,analysisResult,statistics,diagrams,allChainFlowCharts,allAggregateRelationDiagrams), so the page script works identically regardless of which path produced the data.VisualizationHtmlBuilderTests.csGenerateVisualizationHtml_WithNoSnapshots_ShouldContainNonEmptyDataSourcescovering the previously broken call signature.Minimal working call (now works without workaround)
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.