From 68ccfeebbf867fb5568a171548dcd451c01cc452 Mon Sep 17 00:00:00 2001 From: Furqan Date: Fri, 27 Nov 2026 09:34:46 +0000 Subject: [PATCH 1/2] fix(coach): show Pros & Cons score against the real maximum The Pros & Cons Challenge result card always rendered the final score as "X/100". The backend (EvaluateProsCons) scores each argument out of 10 and returns their sum, so the real maximum is 10 x the number of pros and cons submitted. Submitting one pro and one con scored 10 and 9 was shown as "19/100" instead of "19/20". Compute the maximum from the evaluated pros and cons. Points awarded by the backend are unchanged. Fixes #817 Signed-off-by: Furqan --- frontend/src/Pages/ProsConsChallenge.tsx | 8 ++- .../__tests__/ProsConsChallenge.test.tsx | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx diff --git a/frontend/src/Pages/ProsConsChallenge.tsx b/frontend/src/Pages/ProsConsChallenge.tsx index a783af0d..735afbab 100644 --- a/frontend/src/Pages/ProsConsChallenge.tsx +++ b/frontend/src/Pages/ProsConsChallenge.tsx @@ -19,6 +19,10 @@ interface Evaluation { const baseURL = config.baseUrl || 'http://localhost:1313'; +// Each argument is scored out of 10 and the final score is their sum +// (see EvaluateProsCons in backend/services/pros_cons.go). +const MAX_SCORE_PER_ARGUMENT = 10; + const ProsConsChallenge: React.FC = () => { const [token, setToken] = useState(null); const [topic, setTopic] = useState(null); @@ -213,7 +217,9 @@ const ProsConsChallenge: React.FC = () => {
-

Final Score: {evaluation.score}/100

+

+ Final Score: {evaluation.score}/{(evaluation.pros.length + evaluation.cons.length) * MAX_SCORE_PER_ARGUMENT} +

Based on {evaluation.pros.length} pros and {evaluation.cons.length} cons submitted

diff --git a/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx b/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx new file mode 100644 index 00000000..dfeee1c7 --- /dev/null +++ b/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx @@ -0,0 +1,50 @@ +import { beforeEach, describe, expect, it } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import ProsConsChallenge from '../ProsConsChallenge'; +import { mockFetch } from '../../test/mockFetch'; + +const argument = (score: number) => ({ score, feedback: 'Good point.', counter: 'A counterpoint.' }); + +async function submit(pros: number[], cons: number[]) { + mockFetch([ + { match: '/coach/pros-cons/topic', body: { topic: 'Should homework be banned?' } }, + { + match: '/coach/pros-cons/submit', + method: 'POST', + body: { + pros: pros.map(argument), + cons: cons.map(argument), + score: [...pros, ...cons].reduce((sum, s) => sum + s, 0), + }, + }, + ]); + + const user = userEvent.setup(); + render(); + await user.click(screen.getByRole('button', { name: 'Get Topic' })); + for (let i = 0; i < pros.length; i++) { + await user.type(screen.getByPlaceholderText(`Pro ${i + 1}`), `pro ${i + 1}`); + } + for (let i = 0; i < cons.length; i++) { + await user.type(screen.getByPlaceholderText(`Con ${i + 1}`), `con ${i + 1}`); + } + await user.click(screen.getByRole('button', { name: 'Submit Arguments' })); +} + +describe('ProsConsChallenge final score', () => { + beforeEach(() => { + localStorage.setItem('token', 'test-token'); + }); + + it('shows the score out of 10 per submitted argument', async () => { + await submit([10], [9]); + expect(await screen.findByRole('heading', { name: 'Final Score: 19/20' })).toBeInTheDocument(); + expect(screen.queryByText(/\/100/)).not.toBeInTheDocument(); + }); + + it('shows /100 only when all 5 pros and 5 cons are submitted', async () => { + await submit([8, 7, 9, 6, 8], [7, 8, 9, 7, 6]); + expect(await screen.findByRole('heading', { name: 'Final Score: 75/100' })).toBeInTheDocument(); + }); +}); From 9887fea46c63288758bed65b9cdb521b6ab8d74f Mon Sep 17 00:00:00 2001 From: Furqan Date: Fri, 27 Nov 2026 09:53:02 +0000 Subject: [PATCH 2/2] fix(coach): base Pros & Cons maximum on the submitted argument count The maximum was computed from the number of entries in the evaluation response. The model response is not checked against the request, so a reply with fewer entries than were submitted would lower the maximum (e.g. 5 pros and 5 cons submitted, 1 of each returned, showed /20). Store how many pros and cons were submitted when the evaluation succeeds, use that for the maximum, and clear it when starting a new challenge. The score and points awarded are unchanged. Signed-off-by: Furqan --- frontend/src/Pages/ProsConsChallenge.tsx | 7 +++- .../__tests__/ProsConsChallenge.test.tsx | 40 ++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/frontend/src/Pages/ProsConsChallenge.tsx b/frontend/src/Pages/ProsConsChallenge.tsx index 735afbab..90e6bfdb 100644 --- a/frontend/src/Pages/ProsConsChallenge.tsx +++ b/frontend/src/Pages/ProsConsChallenge.tsx @@ -29,6 +29,9 @@ const ProsConsChallenge: React.FC = () => { const [pros, setPros] = useState(["", "", "", "", ""]); const [cons, setCons] = useState(["", "", "", "", ""]); const [evaluation, setEvaluation] = useState(null); + // Number of arguments actually submitted; the score maximum is based on this, + // not on how many entries the evaluation response happens to contain. + const [submittedCount, setSubmittedCount] = useState(0); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [currentStep, setCurrentStep] = useState(1); @@ -100,6 +103,7 @@ const ProsConsChallenge: React.FC = () => { const data = await response.json(); if (!response.ok) throw new Error(data.error || "Failed to evaluate arguments"); setEvaluation(data); + setSubmittedCount(validPros.length + validCons.length); setCurrentStep(3); } catch (err: any) { setError(err.message); @@ -113,6 +117,7 @@ const ProsConsChallenge: React.FC = () => { setPros(["", "", "", "", ""]); setCons(["", "", "", "", ""]); setEvaluation(null); + setSubmittedCount(0); setCurrentStep(1); setError(null); }; @@ -218,7 +223,7 @@ const ProsConsChallenge: React.FC = () => {

- Final Score: {evaluation.score}/{(evaluation.pros.length + evaluation.cons.length) * MAX_SCORE_PER_ARGUMENT} + Final Score: {evaluation.score}/{submittedCount * MAX_SCORE_PER_ARGUMENT}

Based on {evaluation.pros.length} pros and {evaluation.cons.length} cons submitted

diff --git a/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx b/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx index dfeee1c7..bc90fb83 100644 --- a/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx +++ b/frontend/src/Pages/__tests__/ProsConsChallenge.test.tsx @@ -6,16 +6,24 @@ import { mockFetch } from '../../test/mockFetch'; const argument = (score: number) => ({ score, feedback: 'Good point.', counter: 'A counterpoint.' }); -async function submit(pros: number[], cons: number[]) { +/** + * Fills `submitted.pros` pros and `submitted.cons` cons, then submits. + * `returned` is what the evaluation endpoint answers with (defaults to one + * entry per submitted argument). + */ +async function submit( + submitted: { pros: number; cons: number }, + returned: { pros: number[]; cons: number[] }, +) { mockFetch([ { match: '/coach/pros-cons/topic', body: { topic: 'Should homework be banned?' } }, { match: '/coach/pros-cons/submit', method: 'POST', body: { - pros: pros.map(argument), - cons: cons.map(argument), - score: [...pros, ...cons].reduce((sum, s) => sum + s, 0), + pros: returned.pros.map(argument), + cons: returned.cons.map(argument), + score: [...returned.pros, ...returned.cons].reduce((sum, s) => sum + s, 0), }, }, ]); @@ -23,13 +31,14 @@ async function submit(pros: number[], cons: number[]) { const user = userEvent.setup(); render(); await user.click(screen.getByRole('button', { name: 'Get Topic' })); - for (let i = 0; i < pros.length; i++) { + for (let i = 0; i < submitted.pros; i++) { await user.type(screen.getByPlaceholderText(`Pro ${i + 1}`), `pro ${i + 1}`); } - for (let i = 0; i < cons.length; i++) { + for (let i = 0; i < submitted.cons; i++) { await user.type(screen.getByPlaceholderText(`Con ${i + 1}`), `con ${i + 1}`); } await user.click(screen.getByRole('button', { name: 'Submit Arguments' })); + return user; } describe('ProsConsChallenge final score', () => { @@ -38,13 +47,26 @@ describe('ProsConsChallenge final score', () => { }); it('shows the score out of 10 per submitted argument', async () => { - await submit([10], [9]); + await submit({ pros: 1, cons: 1 }, { pros: [10], cons: [9] }); expect(await screen.findByRole('heading', { name: 'Final Score: 19/20' })).toBeInTheDocument(); expect(screen.queryByText(/\/100/)).not.toBeInTheDocument(); }); - it('shows /100 only when all 5 pros and 5 cons are submitted', async () => { - await submit([8, 7, 9, 6, 8], [7, 8, 9, 7, 6]); + it('shows /100 when all 5 pros and 5 cons are submitted', async () => { + await submit({ pros: 5, cons: 5 }, { pros: [8, 7, 9, 6, 8], cons: [7, 8, 9, 7, 6] }); expect(await screen.findByRole('heading', { name: 'Final Score: 75/100' })).toBeInTheDocument(); }); + + it('bases the maximum on what was submitted, not on how many entries the response has', async () => { + await submit({ pros: 5, cons: 5 }, { pros: [10], cons: [9] }); + expect(await screen.findByRole('heading', { name: 'Final Score: 19/100' })).toBeInTheDocument(); + }); + + it('starts a new challenge without keeping the previous maximum', async () => { + const user = await submit({ pros: 5, cons: 5 }, { pros: [8, 7, 9, 6, 8], cons: [7, 8, 9, 7, 6] }); + await screen.findByRole('heading', { name: 'Final Score: 75/100' }); + await user.click(screen.getByRole('button', { name: 'Try Another Challenge' })); + expect(screen.getByRole('button', { name: 'Get Topic' })).toBeInTheDocument(); + expect(screen.queryByRole('heading', { name: /Final Score/ })).not.toBeInTheDocument(); + }); });