fix(create,export): refuse non-finite coordinates across every builder and at the serializer

Merged
LO
2mo ago
+362-13

Closes #5217

As requested, this is split into two commits so a bisect can separate them: the builder guards first, then the serializer.

Root cause

A non-finite Position reached serializeStepValue, which turns every non-finite number into $. $ is the ISO 10303-21 token for an omitted whole attribute. As a member of IfcCartesianPoint.Coordinates (a mandatory LIST [1:3] OF IfcLengthMeasure), (($,0,0)) is a malformed file, not a degraded value.

The two authoring paths agreed with each other on the gap. In-store door/window/column/slab/roof/plate/space and their IfcCreator.addIfc* twins skipped the finiteness check that wall/beam/member apply. Because both paths skipped the same builders, nothing looked inconsistent to a reviewer, while the reachable surface was doubled.

Fix

Commit 1 (builders).

  • In-store: Petru's assertFinitePoint3 on Position in the seven in-store builders, cherry-picked with authorship kept. The guard is conditional for the polygon variants of slab/roof/plate/space, where Position is optional.
  • IfcCreator: the guard is at the one place every IfcCartesianPoint is written (addCartesianPoint / addCartesianPoint2D), not as seven per-method lines. The issue listed seven methods, but the class is wider. addIfcStair, addIfcRamp, addIfcGableRoof, addIfcFooting, addIfcPile, addIfcFurnishingElement, addIfcBuildingElementProxy, hosted door and window fills, and openings all place a caller-supplied point with no check too. The chokepoint covers all of them with one line. It also keeps ifc-creator.ts within its module-size budget: the seven extra lines took it to 2850 against a budget of 2843, which failed check-module-size. On that path a non-finite value used to be written as the token NaN..

Commit 2 (serializer). You asked me to confirm that $ is never legitimately produced from a non-finite number before writing the throw. Petru's branch had held back on this because IfcMapConversion.Scale (real-slot-non-numeric.test.ts) relies on non-finite → $. Checking every serializeStepValue caller confirms your reading: the two cases differ by position, not by value.

  • Scale is a whole optional attribute. $ is correct there and still produced.
  • A non-finite list member has no legal reading anywhere, so serializeStepValue now throws for it. serializeAttributeSlot adds the entity type and attribute index to the error.
  • The only callers are the export's slot serializers (attribute-real-slots.ts, step-attribute-serializers.ts). The viewer's raw-step-format.ts and collab's mutation-bridge.ts mention the function only in comments.

The serializer guard is the backstop for every StoreEditor.addEntity caller: the builders, and also scripts, MCP and flow nodes (store-adapter.ts's bare params as … casts). It also covers inputs no builder guard names, such as a polygon OuterCurve vertex. null inside a list is unchanged. That's an explicit caller value, not a converted one, and it's outside this issue.

Evidence

RED→GREEN, each run against the unfixed file:

  • packages/create/src/in-store/position-finite-validation.test.ts (Petru's): 70 RED → GREEN. Mutation table on the issue.
  • ifc-creator.test.ts: with ifc-creator.ts at main, all 14 non-finite-Position cases fail (the 7 named plus the 7 other builders I added). All pass with the fix.
  • packages/export/src/nonfinite-list-member.test.ts (new): with the serializer at the builder-commit state, 2 of 5 fail. The failures are a list member refused, and an overlay IfcCartesianPoint([NaN,0,0]) export that now fails with IfcCartesianPoint attribute 0: Cannot write NaN as a STEP list member… instead of writing (($,0,0)). A whole-attribute NaN still gives $, and finite lists are unchanged.
  • real-slot-non-numeric.test.ts (the Scale → $ pin) still passes.

Full suites:

  • packages/create: 646/646.
  • packages/export: 1396 passed. The only failure is columns-to-parquet.test.ts, which timed out at 27s under local load. It's unrelated and passes on CI.

Typecheck (pnpm turbo run typecheck --filter=@ifc-lite/export --filter=@ifc-lite/create) and check-module-size are both OK.

Hard-boundary note: packages/create/** is also being edited by another session for LandXML export. This diff touches only ifc-creator.ts (two guard lines and a 6-line compaction of addLocalPlacement), the seven in-store builders, and tests.

Credit: the in-store builder guards and their test file come from Petru Conduraru's branch fix-5217-nonfinite-position.

Perf: not a perf-sensitive path.

🤖 Generated with Claude Code