Skip to content

Commit 5184493

Browse files
Michaelclaude
andcommitted
fix(graph-analysis): handle NaN in quality scoring for graphs with no edges
CHANGES: - backend/services/local-graph-analysis.cjs: - Add isNaN() checks for modularity (lines 307, 313-315) - Default NaN values to 0 to prevent quality score from being NaN - backend/tests/results/.gitkeep: - Create results directory for test outputs (fixes CI failures) BEFORE: - Graphs with isolated nodes (no edges) produced NaN quality scores - drive-webhook.test.cjs and google-workspace-validation.test.cjs failed on CI due to missing results directory AFTER: - Quality scores default to 0 when graph has no edges - structure-lens-v2.test.cjs passes (8/8 tests) - Results directory exists for test outputs VERIFICATION: node backend/tests/structure-lens-v2.test.cjs → 8 passed, 0 failed IMPACT: Fixes test failures in PR #52 and #53 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 57d3ecf commit 5184493

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

backend/services/local-graph-analysis.cjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,16 @@ function calculateQualityScore(graph, centrality, communityDetails, gaps) {
304304
const metrics = {
305305
nodeCount: graph.order,
306306
edgeCount: graph.size,
307-
modularity: communityDetails.modularity,
307+
modularity: isNaN(communityDetails.modularity) ? 0 : communityDetails.modularity,
308308
gapCount: gaps.length,
309309
avgCentrality: Object.values(centrality).reduce((a, b) => a + b, 0) / graph.order
310310
};
311311

312+
// Handle NaN avgCentrality (when graph has no edges)
313+
if (isNaN(metrics.avgCentrality)) {
314+
metrics.avgCentrality = 0;
315+
}
316+
312317
// Higher modularity = better separated topics (50 points)
313318
const modularityScore = Math.min(metrics.modularity * 50, 50);
314319

backend/tests/results/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)