Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review: handle NaN in numeric answers, add string coercion tests
Adam Eivy921c18b24cdb
diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex 04e0c573cf..2f79b195af 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -137,11 +137,13 @@ export function usePostSession() {answered = value;correct = value !== null && String(value).toLowerCase().trim() === String(q.expected).toLowerCase().trim();} else if (currentDrill.type === 'estimation') {- answered = value === null ? null : Number(value);+ const num = value === null ? null : Number(value);+ answered = (num !== null && isNaN(num)) ? null : num;const tolerance = (currentDrill.config?.tolerancePct || 10) / 100;correct = answered !== null && Math.abs(answered - q.expected) <= Math.abs(q.expected * tolerance);} else {- answered = value === null ? null : Number(value);+ const num = value === null ? null : Number(value);+ answered = (num !== null && isNaN(num)) ? null : num;correct = answered === q.expected;}diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.jsindex e6852352f1..dfa80d38c5 100644--- a/server/services/meatspacePost.js+++ b/server/services/meatspacePost.js@@ -309,8 +309,9 @@ export function scoreDrill(type, questions, timeLimitMs, config = {}) {// Recompute expected from the prompt server-side — never trust client-provided expectedconst recomputed = questions.map(q => {const expected = computeExpectedFromPrompt(q.prompt);- // Coerce answered to number for math drills (handles string "42" → 42)- const answered = q.answered != null ? Number(q.answered) : null;+ // Coerce answered to number for math drills (handles string "42" → 42, NaN → null)+ const rawNum = q.answered != null ? Number(q.answered) : null;+ const answered = (rawNum !== null && isNaN(rawNum)) ? null : rawNum;let correct;if (expected == null || answered == null || isNaN(answered)) {correct = false;diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.jsindex 82df8c77d7..c57d0f5c4b 100644--- a/server/services/meatspacePost.test.js+++ b/server/services/meatspacePost.test.js@@ -323,4 +323,29 @@ describe('scoreDrill', () => {const { questions: q5 } = scoreDrill('estimation', questions, 60000, { tolerancePct: 5 });expect(q5[0].correct).toBe(false);});++ it('coerces string answered values to numbers', () => {+ const questions = [+ { prompt: '5 x 3', answered: '15', responseMs: 1000 },+ { prompt: '7 x 4', answered: '28', responseMs: 1500 }+ ];+ const { questions: recomputed, score } = scoreDrill('multiplication', questions, 60000);+ expect(recomputed[0].correct).toBe(true);+ expect(recomputed[0].answered).toBe(15);+ expect(recomputed[1].correct).toBe(true);+ expect(recomputed[1].answered).toBe(28);+ expect(score).toBeGreaterThanOrEqual(80);+ });++ it('treats non-numeric string answered as unanswered', () => {+ const questions = [+ { prompt: '5 x 3', answered: 'abc', responseMs: 1000 },+ { prompt: '7 x 4', answered: 'xyz', responseMs: 1500 }+ ];+ const { questions: recomputed } = scoreDrill('multiplication', questions, 60000);+ expect(recomputed[0].correct).toBe(false);+ expect(recomputed[0].answered).toBe(null);+ expect(recomputed[1].correct).toBe(false);+ expect(recomputed[1].answered).toBe(null);+ });});