Skip to content

fix(core): reject tower heights the STL name cannot encode (TSK-017) - #22

Merged
jmlweb merged 2 commits into
mainfrom
hustle/maintainer/task-2026-11-20
Nov 20, 2026
Merged

jmlweb merged 2 commits into
mainfrom
hustle/maintainer/task-2026-11-20

Conversation

@jmlweb

@jmlweb jmlweb commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Fixes TSK-017 (from RPT-010). ADR-0005 says the STL base name round-trips the tower config without loss. But validateTowerConfig accepted any finite block or base height at or above the minimum, while the filename codec rounds numbers to 0.001 mm. So a height like 10.0004 passed validation and was silently encoded as h10.

What changed

  • packages/core/src/tower-config.ts: adds NAME_DECIMALS (3), LARGEST_NAME_NUMBER_EXCLUDED (1e21) and roundToNameDecimals. validateTowerConfig now adds these problems for block and base height:
    • <label> must have at most 3 decimals when roundToNameDecimals(h) !== h.
    • <label> must be below 1e+21 mm when h >= 1e21. At that size String switches to exponent form, which the decode pattern cannot parse.
  • packages/core/src/filename-codec.ts: formatNumber now uses the shared roundToNameDecimals, so validation and the codec use one rounding rule.
  • Tests: see the criteria below.
  • Backlog: TSK-017 moved to complete with evidence. LRN-006 records the floating-point limits.

Acceptance criteria

  1. validateTowerConfig rejects block and base heights the codec cannot represent exactly. New test in tower-config.test.ts: "rejects heights finer than the 0.001 mm the STL name keeps". It failed before the fix (expected [] to deeply equal [ Array(1) ]) and passes now. The test also covers 1e21.

  2. The round-trip property draws heights from the full domain validation accepts. acceptedHeightArbitrary in filename-codec.test.ts draws from two sources:

    • thousandths from the minimum up to Number.MAX_SAFE_INTEGER / 1000;
    • any double below 1e21 that passes the precision predicate.

    Each draw is asserted to pass validateTowerConfig and to round-trip exactly. A boundary test also checks 6, 6.999, 10.001, 2^53/1000 and 1e18. Note: this property passes on the old code too, because its domain comes from the new predicate. The proof that the gap is closed is the validation test in criterion 1, which failed first. This property then shows that every height validation accepts round-trips.

  3. A test covers a height with more than 3 decimals being rejected. blockHeight: 10.0004 and baseHeight: 1.2345 are each rejected with ... must have at most 3 decimals. 10.001 and 1.234 are still accepted.

  4. pnpm typecheck and pnpm test pass. pnpm typecheck shows no errors. pnpm test shows 13 files passed, 1 skipped (the reference test that needs BGCODE_REFERENCE_DIR), and 137 tests passed, 5 skipped. pnpm build also passes. CI runs the same commands.

Known quirks at absurd sizes

These heights are far outside any real print. They are left as they are:

  • 1e20 is rejected as "at most 3 decimals" even though it has none. The cause is floating-point error: Math.round(1e20*1000)/1000 !== 1e20.
  • The cap message shows 1e+21 mm.

🤖 Generated with Claude Code

validateTowerConfig accepted any finite block or base height, but the
filename codec keeps only 3 decimals and String writes 1e21 and above in
exponent form, so the STL name silently lost precision (RPT-010).
Validation now rejects both, sharing roundToNameDecimals with the codec,
and the round-trip property draws heights from the whole accepted domain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmlweb

jmlweb commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

🤖 hustle review: approve — Validation now rejects heights the STL name cannot encode, and the codec shares the same rounding function. Tests cover the new rejections, the boundary heights and a round-trip property over the accepted domain. Backlog evidence matches the diff.

Resolve the task index conflict: keep TSK-017 complete, add TSK-018 to pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmlweb

jmlweb commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

🤖 hustle review: approve — Validation now rejects heights the STL name can't encode (more than 3 decimals, or 1e21 and above). The codec shares the same rounding function, and the tests and backlog evidence match the acceptance criteria. The 1e20 quirk is disclosed and harmless.

@jmlweb
jmlweb merged commit 354d45a into main Nov 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant