fix(server): promote a contained (not aggregated) spatial element into its own hierarchy node
Summary
apps/server/src/services/data_model/spatial.rsbuiltchildren_idsonly fromIfcRelAggregates, so anIfcSpace/IfcSpatialZoneplaced under its storey viaIfcRelContainedInSpatialStructureonly (the common Revit Family / Dynamo export pattern reported at #1075) never got its ownSpatialNode; it rendered as a plain element leaf, and its own contents were unreachable from the tree.- Mirrors
packages/parser/src/spatial-hierarchy-builder.ts'saddSpatialChild: a contained target that is itself a spatial-structure type (excludingIfcProject) is promoted intospatial_children_mapinstead ofelement_containment_map, deduped against anIfcRelAggregatesedge to the same parent so a doubly-linked space is not built twice. - Closes the type-list gap between Rust's
is_spatial_type(14 types) andpackages/data/src/spatial-types.ts'sSPATIAL_STRUCTURE_TYPE_ENUMS(17): addedIFCSPATIALZONE,IFCMARINEPART,IFCFACILITYPARTCOMMON. Also extended theelement_to_spacebucket to treatIfcSpatialZonelikeIfcSpace, matchingisSpaceLikeSpatialType.
Closes #3965
Scope
Spatial hierarchy only — relationships.rs (open PR #3969), metadata.rs and generated/attr_indices.rs (open PR #3956) untouched. No packages/* files changed, so no changeset.
Correction added during a claims-vs-diff audit (2026-09-06): the diff
is not scoped to the containment-promotion fix and type-list gap described
above. It also splits spatial.rs into three new modules that carry three
more, undescribed bug fixes: spatial_tree.rs adds a cycle guard for
build_spatial_nodes_recursive (an aggregate/containment cycle previously
SIGABRTed the whole server, since this recursion runs with
panic = 'abort') and fixes depth-capped entities being resurrected as
fake roots with their real children_ids still intact; spatial_elevation.rs
fixes IfcBuildingStorey elevation extraction, which previously read
attribute index 8 (CompositionType) instead of 9 (Elevation), so every
storey reported no elevation; and spatial_invariant.rs adds a
parent/child consistency check callable from a debug_assert! and the test
suite. None of this is mentioned above.
Test plan
- RED:
a_contained_not_aggregated_space_is_promoted_to_its_own_nodeandcontained_spatial_zone_and_ifc4x3_facility_parts_are_promoted_to_nodesfail on unfixed code (left: []/ node lookup panic). - GREEN after fix;
cargo test -p ifc-lite-server— 269 baseline + 9 new (9#[test]functions added acrosstests.rsandspatial_tests.rs, not 3 as originally stated here), so 278 passed, 0 failed. - Mutation 1 (disable promotion): both promotion-dependent tests fail.
- Mutation 2 (remove
IFCSPATIALZONEfromis_spatial_type): the zone/parts test fails. - Control: aggregated space unaffected (
builds_spatial_hierarchy_with_correct_parent_level_and_path,buckets_contained_elements_by_the_correct_spatial_container_kindstill pass unchanged). - Control: no-contained-spaces fixtures produce identical output (existing suite green, no regressions).
- Control: a space both aggregated and contained under the same parent appears exactly once (
a_space_both_aggregated_and_contained_under_the_same_parent_is_not_duplicated). - Control: browser/WASM path untouched (only
apps/serverfiles changed). -
cargo clippy -p ifc-lite-server -- -D warningsclean. -
node scripts/check-module-size.mjs— only the pre-existingCommandPalette.tsxfailure (fixed in open PR #3958); no new offender. -
node scripts/check-test-wiring.mjs,node scripts/check-source-text-assertions.mjs— both pass.
https://claude.ai/code/session_01QPHChk3Ve9N519A4kY7436
Summary by CodeRabbit
-
Improvements
- Improved IFC spatial hierarchy imports with safeguards against cyclic and excessively deep relationships.
- Spatial nodes now avoid dangling child references when relationships are incomplete or inconsistent.
- Storey elevations are extracted more reliably, including fallback to placement coordinates when needed.
- Added consistency checks to improve the reliability of parent-child hierarchy relationships.
-
Tests
- Added coverage for cyclic relationships, rescued orphan nodes, invalid child references, and spatial hierarchy consistency.