Skip to content

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

accept a POST applied-numeracy answer without restating the unit

[._.]/ Adam Eivy9bc6bc551887
diff --git a/client/src/components/meatspace/post/PostDrillRunner.jsx b/client/src/components/meatspace/post/PostDrillRunner.jsx
index 1e1866cc34..c5750efd4a 100644
--- a/client/src/components/meatspace/post/PostDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostDrillRunner.jsx
@@ -286,8 +286,8 @@ export default function PostDrillRunner({ session }) {
inputMode={isTextDrill ? 'text' : isAppliedNumeracy ? 'decimal' : 'numeric'}
value={inputValue}
onChange={e => setInputValue(e.target.value)}
- placeholder={isAppliedNumeracy ? 'Number and unit when requested' : 'Answer'}
- aria-label={isAppliedNumeracy ? 'Your numeric answer and unit when requested' : 'Your answer'}
+ placeholder={isAppliedNumeracy ? 'Number (unit optional)' : 'Answer'}
+ aria-label={isAppliedNumeracy ? 'Your numeric answer' : 'Your answer'}
autoFocus
className="w-full bg-port-bg border border-port-border rounded-lg px-4 py-3 text-xl font-mono text-white text-center placeholder-gray-600 focus:border-port-accent focus:outline-none"
/>
diff --git a/client/src/components/meatspace/post/PostDrillRunner.test.jsx b/client/src/components/meatspace/post/PostDrillRunner.test.jsx
index 442449993a..92db72d924 100644
--- a/client/src/components/meatspace/post/PostDrillRunner.test.jsx
+++ b/client/src/components/meatspace/post/PostDrillRunner.test.jsx
@@ -59,7 +59,7 @@ describe('PostDrillRunner Applied Numeracy', () => {
timeExpired: vi.fn(),
}} />);
- const input = screen.getByLabelText('Your numeric answer and unit when requested');
+ const input = screen.getByLabelText('Your numeric answer');
expect(input).toHaveAttribute('type', 'text');
expect(input).toHaveAttribute('inputmode', 'decimal');
});
diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.js
index 8fc3b6f931..bf4a0b6166 100644
--- a/client/src/components/meatspace/post/constants.js
+++ b/client/src/components/meatspace/post/constants.js
@@ -353,14 +353,15 @@ export function appliedNumeracyAnswerCorrect(value, question = {}) {
if (!parsed) return false;
let expected = question.expected;
let actual = parsed.numeric;
+ // Mirrors correctAppliedAnswer in server/lib/postAppliedNumeracy.js: a bare
+ // number is read as the unit the prompt asked for, a different compatible unit
+ // converts, and a trailing noun on a unitless question is ignored.
if (question.unit) {
- const suppliedFactor = question.unitOptions?.[parsed.unit];
+ const suppliedFactor = question.unitOptions?.[parsed.unit ?? question.unit];
const expectedFactor = question.unitOptions?.[question.unit];
if (!suppliedFactor || !expectedFactor) return false;
actual *= suppliedFactor;
expected *= expectedFactor;
- } else if (parsed.unit) {
- return false;
}
const tolerance = question.tolerance || {};
const margin = Math.max(tolerance.absolute || 0, Math.abs(expected) * (tolerance.relative || 0));
diff --git a/client/src/components/meatspace/post/constants.test.js b/client/src/components/meatspace/post/constants.test.js
index 998e8aa50f..3eb27d7740 100644
--- a/client/src/components/meatspace/post/constants.test.js
+++ b/client/src/components/meatspace/post/constants.test.js
@@ -29,15 +29,24 @@ describe('appliedNumeracyAnswerCorrect', () => {
unitAliases: { meters: 'm', kilometers: 'km' },
};
- it('accepts a compatible equivalent unit and rejects a missing unit', () => {
+ // Must stay in step with correctAppliedAnswer in server/lib/postAppliedNumeracy.js:
+ // this mirror drives the in-session feedback the server later re-scores.
+ it('accepts a compatible equivalent unit and reads a bare number as the requested unit', () => {
expect(appliedNumeracyAnswerCorrect('1.5 km', unitQuestion)).toBe(true);
- expect(appliedNumeracyAnswerCorrect('1500', unitQuestion)).toBe(false);
+ expect(appliedNumeracyAnswerCorrect('1500', unitQuestion)).toBe(true);
+ expect(appliedNumeracyAnswerCorrect('1.5', unitQuestion)).toBe(false);
+ expect(appliedNumeracyAnswerCorrect('1500 bananas', unitQuestion)).toBe(false);
});
it('accepts an equivalent fraction and rejects a zero denominator', () => {
expect(appliedNumeracyAnswerCorrect('2/4', { expected: 0.5 })).toBe(true);
expect(appliedNumeracyAnswerCorrect('2/0', { expected: 0.5 })).toBe(false);
});
+
+ it('ignores a redundant noun on a question that has no unit of its own', () => {
+ expect(appliedNumeracyAnswerCorrect('72 cards', { expected: 72 })).toBe(true);
+ expect(appliedNumeracyAnswerCorrect('71 cards', { expected: 72 })).toBe(false);
+ });
});
describe('computeDomainAverages', () => {
diff --git a/server/lib/postAppliedNumeracy.js b/server/lib/postAppliedNumeracy.js
index 3f1a500885..99fb96a0a1 100644
--- a/server/lib/postAppliedNumeracy.js
+++ b/server/lib/postAppliedNumeracy.js
@@ -61,7 +61,9 @@ function unitQuestion({ prompt, expected, unit, dimension, method, tolerance = n
);
return {
prompt,
- promptLabel: `Enter a number and unit (for example, ${trimNumber(expected)} ${unit})`,
+ // Names the unit rather than illustrating it: an example built from `expected`
+ // ("for example, 4000 ml") hands the user the answer before they solve it.
+ promptLabel: `Enter a number in ${unit} (naming another compatible unit also works)`,
expected,
unit,
dimension,
@@ -238,14 +240,17 @@ function correctAppliedAnswer(question, raw) {
if (!parsed) return { parsed: null, correct: false };
let expected = question.expected;
let actual = parsed.value;
+ // These drills grade the arithmetic, not the transcription. The prompt always
+ // names the unit to answer in, so a bare number is read as that unit
+ // ("Convert 4 l to ml" → "4000" means 4000 ml) and naming a different
+ // compatible unit still converts. On a question with no unit of its own, a
+ // trailing noun ("6 parts", "72 cards") carries no arithmetic and is ignored.
if (question.unit) {
- const unitFactor = question.unitOptions?.[parsed.unit];
+ const unitFactor = question.unitOptions?.[parsed.unit ?? question.unit];
const expectedFactor = question.unitOptions?.[question.unit];
if (!unitFactor || !expectedFactor) return { parsed, correct: false };
actual *= unitFactor;
expected *= expectedFactor;
- } else if (parsed.unit) {
- return { parsed, correct: false };
}
const difference = Math.abs(actual - expected);
const tolerance = question.tolerance || {};
diff --git a/server/lib/postAppliedNumeracy.test.js b/server/lib/postAppliedNumeracy.test.js
index ef6442edf7..ba8d699bde 100644
--- a/server/lib/postAppliedNumeracy.test.js
+++ b/server/lib/postAppliedNumeracy.test.js
@@ -34,7 +34,7 @@ describe('Applied Numeracy', () => {
expect(parseAppliedNumeracyAnswer('3/0')).toBe(null);
});
- it('requires a compatible unit while accepting equivalent unit conversions', () => {
+ it('reads a bare number as the requested unit while still converting named units', () => {
const drill = generateAppliedNumeracyDrill({ seed: 10, family: 'unit', count: 1, difficulty: 1 });
const question = drill.questions[0];
const units = Object.entries(question.unitOptions);
@@ -42,14 +42,35 @@ describe('Applied Numeracy', () => {
const equivalent = question.expected * question.unitOptions[question.unit] / alternateFactor;
const accepted = scoreAppliedNumeracyDrill([{ answered: `${equivalent} ${alternateUnit}`, responseMs: 1000 }], 120000, drill.config);
- const missingUnit = scoreAppliedNumeracyDrill([{ answered: String(question.expected), responseMs: 1000 }], 120000, drill.config);
+ const bareNumber = scoreAppliedNumeracyDrill([{ answered: String(question.expected), responseMs: 1000 }], 120000, drill.config);
+ // The unit is assumed, not ignored: the same digits under another unit stay wrong.
+ const bareWrongMagnitude = scoreAppliedNumeracyDrill([{ answered: String(equivalent), responseMs: 1000 }], 120000, drill.config);
const wrongUnit = scoreAppliedNumeracyDrill([{ answered: `${question.expected} bananas`, responseMs: 1000 }], 120000, drill.config);
expect(accepted.questions[0].correct).toBe(true);
- expect(missingUnit.questions[0].correct).toBe(false);
+ expect(bareNumber.questions[0].correct).toBe(true);
+ expect(bareWrongMagnitude.questions[0].correct).toBe(false);
expect(wrongUnit.questions[0].correct).toBe(false);
});
+ it('ignores a redundant noun on a question that has no unit of its own', () => {
+ const drill = generateAppliedNumeracyDrill({ seed: 22, family: 'rate', count: 1, difficulty: 2 });
+ const question = drill.questions[0];
+ const result = scoreAppliedNumeracyDrill([{ answered: `${question.expected} cards`, responseMs: 1000 }], 120000, drill.config);
+
+ expect(question.unit).toBeUndefined();
+ expect(result.questions[0].correct).toBe(true);
+ });
+
+ it('keeps the expected value out of the prompt label', () => {
+ // The label must carry no digits at all — the leak it guards against was an
+ // example built from the answer ("for example, 4000 ml").
+ const drill = generateAppliedNumeracyDrill({ seed: 10, count: 10, difficulty: 2 });
+ drill.questions.forEach((question) => {
+ expect(question.promptLabel).not.toMatch(/\d/);
+ });
+ });
+
it('honors inclusive absolute and relative tolerance boundaries', () => {
const absolute = generateAppliedNumeracyDrill({ seed: 5, family: 'estimate', count: 1, difficulty: 1 });
const absoluteQuestion = absolute.questions[0];