fix(server): resolve GlobalId/Name by schema position, not hardcoded IfcRoot indices

Merged
PE
3mo ago
+1710-52

Closes #3949.

The defect

apps/server/src/services/data_model/metadata.rs read every entity's global_id/name at the fixed IfcRoot attribute positions (0 and 2), unconditionally — no type gate, unlike description/object_type/tag/predefined_type three lines below, which already resolve per-type through a generated table (root_attr_indices).

IfcClassification's attribute order is Source(0), Edition(1), EditionDate(2), Name(3), ..., so this made global_id read Source and name read EditionDate. Measured (#90=IFCCLASSIFICATION('Src90','Ed90','2024-01-01','RealName90',$,$,$);): global_id=Some("Src90") name=Some("2024-01-01").

This is systemic across the registry: 357/776 types don't have GlobalId at index 0, and 346/776 don't have Name at index 2.

The fix

Mirrors what the TS/WASM path (getRootAttrIndices in packages/parser/src/columnar-parser.ts) already does — resolve GlobalId/Name by schema attribute name, per type:

  1. Extended RootAttrIndices with global_id/name fields.
  2. Extended scripts/generate-server-attr-indices.mjs to emit them (NAMES now ['GlobalId', 'Name', 'Description', 'ObjectType', 'Tag', 'PredefinedType']).
  3. Regenerated the committed table (attr_indices.rs, 776 types) — not hand-edited.
  4. Updated UNKNOWN_TYPE_FALLBACK and the metadata.rs call site to use the per-type indices.

UNKNOWN_TYPE_FALLBACK decision: for a type absent from the registry, global_id/name fall back to 0/2 — matching the convention the other four fields already use (description: 3, object_type: 4, tag: 7, the IfcElement layout), which preserves the pre-fix behaviour exactly for unknown types.

Verification

RED (before the fix): a test parsing the IfcClassification fixture above asserted global_id == None and name == Some("RealName90"); it failed with global_id: Some("Src90") (left) vs None (right).

Mutation: restored the hardcoded entity.get_string(0)/entity.get_string(2) and confirmed the same RED test fails identically.

Controls (all pass):

  • IfcWall (an IfcRoot subtype) still yields global_id/name at the same positions as before the fix.
  • A type absent from the registry falls back to GlobalId 0 / Name 2 / Description 3 / ObjectType 4 / Tag 7, per the stated convention.
  • extracts_classification_material_and_document_associations and the full existing suite pass unchanged (272 tests, 0 failed).

Scope

Only GlobalId/Name on this path. Does not touch packages/ids, apps/viewer, or classifications.rs (which already extracts correctly by its own attribute positions — see #3955 for the separate viewer-wiring gap).

Gates

  • cargo test -p ifc-lite-server: 272 passed, 0 failed.
  • cargo clippy -p ifc-lite-server -- -D warnings: clean.
  • node scripts/generate-server-attr-indices.mjs --check: in sync.
  • node scripts/check-module-size.mjs, check-test-wiring.mjs, check-source-text-assertions.mjs: all OK.
  • No rust/ or packages/* files touched, so no module_size_ratchet run and no changeset.

Summary by CodeRabbit

  • Bug Fixes
    • Improved entity metadata extraction for schema-specific types, ensuring names and global identifiers are read from the correct locations.
    • Preserved accurate metadata for standard entities while providing safer fallback handling for unknown entity types.
    • Improved handling of additional root metadata attributes, including descriptions, object types, tags, and predefined types.
    • Added coverage for classification metadata and other schema variations to prevent incorrect attribute mapping.