From 07ed3161353c4b567bcc9a83ed07e70d26538f25 Mon Sep 17 00:00:00 2001 From: John Dvorak Date: Fri, 22 May 2026 12:08:39 -0700 Subject: [PATCH] fix: NaN guard in normalizeOptionValue + warn on silent parser drops compiler.ts: normalizeOptionValue now rejects NaN numbers and empty strings. Previously typeof NaN === 'number' passed through and propagated into option values, causing predicate comparisons like value >= NaN to produce silent wrong results. grammar.ts: parseAssertion now emits console.warn when silently skipping unexpected tokens or failed clauses. Previously these returns-null were invisible to developers. 454 solver+DSL + 57 E2E tests pass. --- packages/imhotep-dsl/src/compiler.ts | 6 +++++- packages/imhotep-dsl/src/grammar.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/imhotep-dsl/src/compiler.ts b/packages/imhotep-dsl/src/compiler.ts index 04b741e..bd13669 100644 --- a/packages/imhotep-dsl/src/compiler.ts +++ b/packages/imhotep-dsl/src/compiler.ts @@ -73,7 +73,11 @@ function defaultNextId(prefix: string): string { function normalizeOptionValue(raw: unknown): number | string | undefined { if (raw === undefined || raw === null) return undefined - if (typeof raw === 'number' || typeof raw === 'string') return raw + if (typeof raw === 'number') return Number.isNaN(raw) ? undefined : raw + if (typeof raw === 'string') { + const trimmed = raw.trim() + return trimmed.length > 0 ? trimmed : undefined + } // String-parser/fluent path: LiteralNode or ToleranceLiteralNode if (typeof raw === 'object') { diff --git a/packages/imhotep-dsl/src/grammar.ts b/packages/imhotep-dsl/src/grammar.ts index 23bd810..25e8afe 100644 --- a/packages/imhotep-dsl/src/grammar.ts +++ b/packages/imhotep-dsl/src/grammar.ts @@ -952,6 +952,7 @@ export class GrammarParser { if (negated) { throw this.error(`Expected assertion after 'not'`) } + console.warn(`[imhotep-dsl] parseAssertion: unexpected token "${this.currentToken().value}" at line ${this.currentToken().start?.line}, skipping`) this.advance() return null } @@ -968,6 +969,7 @@ export class GrammarParser { if (quantifier) { throw this.error(`Expected assertion after quantifier '${quantifier.kind}'`) } + console.warn(`[imhotep-dsl] parseAssertion: could not parse clause for subject "${subject.value}" at line ${start?.line}, skipping`) return null }