fix(mcp): restore >0 validation and reject ambiguous numbers in measurement()

Adversarial-review follow-ups to the lingo measurement() field:
- Add a `positive` option (strict > 0) and use it for the non-zero dimension
  params. Swapping z.number().positive() → measurement(..,{min:0}) had started
  admitting 0 (the core node schemas have no positivity backstop), so a zero-size
  wall/opening/roof could be created. Inclusive-0 fields (overhang, sill height,
  knee-wall height, opening offset, roof pitch) keep min:0.
- Escalate AMBIGUOUS_NUMBER to error so "1,234" fails instead of silently reading
  as 1234 — a 1000x hazard for European decimals. Matches lingo's own /ai fields.
- roofLevelElevation reverted to z.number() (it's a level ordinal, not meters);
  radians fields now advertise radian-appropriate examples.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Aymeric Rabot
2026-07-08 13:09:59 +02:00
co-authored by Claude Opus 4.8
parent f66dcd438b
commit 3273aac551
7 changed files with 108 additions and 48 deletions
@@ -46,6 +46,19 @@ describe('measurement()', () => {
if (!r.success) expect(r.error.issues[0]?.message.toLowerCase()).toContain('number')
})
test('positive rejects zero and negatives (restores .positive() behavior)', () => {
const m = measurement('length', 'm', { positive: true })
expect(m.safeParse(0).success).toBe(false)
expect(m.safeParse('0m').success).toBe(false)
expect(m.safeParse(-1).success).toBe(false)
expect(m.parse(0.1)).toBe(0.1)
})
test('rejects ambiguous separators instead of a silent 1000x reading', () => {
const r = measurement('length', 'm').safeParse('1,234')
expect(r.success).toBe(false)
})
test('emits a number|string JSON schema advertising natural language', () => {
const schema = z.toJSONSchema(
measurement('length', 'm', { min: 0, description: 'Wall thickness.' }),