feat(viewer): per-model load report with actionable geometry warnings

Merged
PE
3mo ago
+662-19

Closes #3927

What

A compact per-model Load Report panel: source/schema, resolved load path (wasm/cache/server/point-cloud), tessellation tier and fast-mode setting, and the load's existing GeometryDiagnostics (CSG failures, silent no-op cuts, dropped representation items, oversized content-hash reference drops) rendered as actionable text. JSON export mirrors the IDS export pattern.

  • apps/viewer/src/lib/loadReport.ts — pure aggregation (buildLoadReport/buildLoadReports), JSON export (buildLoadReportJSON/downloadLoadReportJSON), and ModelLoadReportFields (the new fields mixed into FederatedModel) plus buildModelLoadReportPatch, a small helper shared by useIfcLoader.ts's two finalizeModel write sites so they can't drift.
  • apps/viewer/src/components/viewer/LoadReportPanel.tsx — the panel UI.
  • apps/viewer/src/store/types.ts — FederatedModel extends ModelLoadReportFields (diagnostics, loadFormat, loadPath, tessellationTier, skipSmallCuts).
  • apps/viewer/src/hooks/useIfcLoader.ts — threads loadDiagnostics/format/tier/skip-cuts onto the model record at every finalizeModel call site (point-cloud, IFCX, GLB, cache-hit, server, wasm-streaming ×2), respecting the existing TDZ hazard around loadTessellationTier/skipSmallCutsAtLoad (same reasoning instancedShards documents there — some call sites run before those consts are declared, so the affected fields are only ever supplied where the setting genuinely applies).
  • Workspace-panel registry wiring: lib/panels/registry.ts (new loadReport panel id), lib/panels/renderPanelBody.tsx, toolbar/useWorkspacePanelControls.ts, CommandPalette.tsx (new panel:loadReport command), ribbon/tabs/AnalyzeTab.tsx (new ribbon button).

Assumptions

  • Affected entities: only GeometryDiagnostics.worstHosts entries become affected-entity rows, because those are the only diagnostic category carrying an identity (productId + ifcType). unsupportedItemsByType and failuresByReason carry only a reason string and a count — no identity — so they surface as aggregate actionable text instead of a fabricated entity row. This follows directly from the contract's own shape.
  • "Renderable": a worst-host entry is treated as selectable/frameable only when it carries a captured bbox (the one signal in the contract that a mesh is actually present). Without a bbox, the row shows its source identity (#productId IfcType) as plain, unclickable text rather than inventing a selection target.

Why no MainToolbar dropdown entry

I initially added one, but MainToolbar.tsx is already at its module-size budget (1165 lines) and the entry pushed it to 1166 — one line over. Rather than raise the allowlisted budget, I removed the toolbar entry entirely: the Analyze ribbon button and the command palette entry (panel:loadReport) already give full discoverability, matching how e.g. the sources panel isn't in the ribbon either. Not an oversight — a deliberate trade against the module-size gate.

Also flag-free: the new loadReport panel id has no dedicated *PanelVisible boolean, following the zones panel's precedent (#1869) — openWorkspacePanel's existing non-SIDEBAR_PANEL_FLAGS branch adopts it directly.

Tests

  • apps/viewer/src/lib/loadReport.test.ts (new, 15 tests, node:test): covers the unavailable/clean/issues-found distinction, every diagnostic category's actionable text, approximation-setting notes, globalId resolution (productId + idOffset), the renderable-vs-identity-only gate, and refusing to invent an affected entity from unsupportedItemsByType.
  • Mutation-tested the core logic: (1) swapped the dropped-items guard to check totalCsgFailures instead of totalUnsupportedItems → 2 tests failed; (2) deleted the silentNoOps action branch entirely → 2 tests failed; (3) forced renderable: true unconditionally → 1 test failed. All three caught, then reverted.
  • UI wiring (the panel component, registry, ribbon button, command palette entry) is not unit-tested — no existing test harness in this codebase covers that layer for sibling panels either.

What I ran (not the full suite)

Given apps/viewer's ~666-file suite is slow and is CI's job, I ran only the targeted tests: loadReport.test.ts (new, 15/15) plus every existing sibling test file for the modules I touched — lib/panels/registry.test.ts, store/types.test.ts, and all 7 useIfcLoader.*.test.tsx files (cache-hit telemetry, primary/GLB federation offset, federated id offset, cache staleness, IFCX stale guard, SAB streaming, instanced-shards TDZ, federated align stale guard) — 53/53 passing. renderPanelBody.tsx, useWorkspacePanelControls.ts, CommandPalette.tsx, and AnalyzeTab.tsx have no sibling test files.

Update: the full pnpm test --filter @ifc-lite/viewer run I'd started in the background (and moved on from without waiting) has since finished: 6937 tests, 6931 pass, 0 fail, 6 skipped (pre-existing skips, unrelated to this change), exit code 0.

Also ran: pnpm typecheck (full monorepo via turbo, 89/89 tasks), node scripts/check-module-size.mjs (0 new over budget), node scripts/check-test-wiring.mjs, node scripts/check-source-text-assertions.mjs — all green.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Added a per-model Load Report panel accessible from the Analyze tab and command palette.
    • View source details, loading settings, diagnostics, geometry warnings, and affected entities.
    • Select and frame renderable affected entities in the viewer.
    • Export load reports as JSON.
    • Clearly distinguishes unavailable diagnostics, clean loads, and loads with issues.
  • Bug Fixes

    • Improved visibility of loading diagnostics and geometry-related problems across supported model loading paths.