Spaces:
Sleeping
Sleeping
Show plain actual values in test table
Browse filesFiles changed (2)
93 unmodified lines94959697979899100310 unmodified lines41141241341441541641710 unmodified lines42842943043143243343493 unmodified lines mocks.updateRoundSettings.mockResolvedValue({ round_id: "round-prepared", timer_minutes: 0, chat_messages_per_student: 5, visibility: "private", status: "prepared" }); mocks.publicTests.mockResolvedValue({ file_path: "src/demo.py", functions: ["normalize"], total: 1, source: "# Test 1: normalize(*('value',))\n# Expected: 'value'" }); mocks.publicChallengeRounds.mockResolvedValue({ rounds: [] }); mocks.runTests.mockResolvedValue({ passed: 1, total: 2, score: 40, output: "Test 1: PASS", all_passed: false, per_test: [{ num: 1, status: "PASS" }, { num: 2, status: "FAIL" }] }); mocks.runTests.mockResolvedValue({ passed: 1, total: 2, score: 40, output: "Test 1: PASS", all_passed: false, per_test: [{ num: 1, status: "PASS", actual_raw: "1st", actual: "str len=3 diff@0: '1st'" }, { num: 2, status: "FAIL", actual_raw: "2nd", actual: "str len=3 diff@0: '2nd'" }] }); mocks.diff.mockResolvedValue({ diff: "-value = 0\n+value = 2", has_changes: true }); mocks.hint.mockResolvedValue({ response: "Check the return branch.", gave_hint: true, hints_used: 1, penalty: 2, chat_history: [] }); mocks.diagnosis.mockResolvedValue({ file_path: "src/demo.py", functions: ["normalize"], bug_description: "The function returns the input unchanged.", diff: "- return value\n+ return value.strip()" });310 unmodified lines expect(screen.getByText("Input")).toBeTruthy(); expect(screen.getByText("Expected")).toBeTruthy(); expect(screen.getByText("Actual")).toBeTruthy(); expect(screen.queryByText(/str len=/i)).toBeNull(); expect(screen.getByText(/Secret tests are not shown/)).toBeTruthy(); });
10 unmodified lines expect(mocks.editor.trigger).toHaveBeenCalledWith("toolbar", "redo", null); await user.click(screen.getByRole("button", { name: /^public tests$/i })); expect(await screen.findByText("Test 2")).toBeTruthy(); expect(screen.queryByText(/str len=/i)).toBeNull(); expect(mocks.runTests).toHaveBeenCalledWith("src/demo.py", challenge.code); await user.click(screen.getByRole("button", { name: /view changes/i })); expect(await screen.findByText(/\+value = 2/)).toBeTruthy();150 unmodified lines1511521531541551561571581591601611621631641651661671681691701711721731741055 unmodified lines12301231123212151233123412351236150 unmodified lines const chatMessageCount = challenge?.chat_messages_used ?? 0; const chatMessageLimit = challenge?.chat_messages_per_student ?? 5; const chatLimitReached = chatMessageCount >= chatMessageLimit && !challenge?.confirmation_pending;
function formatTestActual(actual: unknown): string { if (actual === undefined) return "—"; if (typeof actual === "object") return JSON.stringify(actual); const text = String(actual); const diagnostic = text.match(/^(?:str|int|float|bool|list|dict|tuple|NoneType)\b.*?:\s*(.+)$/); if (diagnostic) { const value = diagnostic[1].trim(); if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith('"') && value.endsWith('"')))) { return value.slice(1, -1); } return value; } if (text.length >= 2 && ((text.startsWith("'") && text.endsWith("'")) || (text.startsWith('"') && text.endsWith('"')))) { return text.slice(1, -1); } return text; } const joinedRoundIds = useMemo( () => new Set((studentHistory?.attempts ?? []).map((attempt) => attempt.round_id).filter((roundId): roundId is string => Boolean(roundId))), [studentHistory],1055 unmodified lines </section> )} {publicTestsView && <section className="test-panel public-tests-panel" aria-label="Public tests source"><div className="panel-heading"><div><p className="eyebrow">PUBLIC TESTS · {publicTestsView.file_path}</p><h2>{testResult ? `${testResult.passed} of ${testResult.total} passed` : `Showing ${publicTestsView.total} tests`}</h2></div>{testResult && <span className={`result-pill ${testResult.all_passed ? "pill-success" : "pill-warning"}`}>{testResult.all_passed ? <CheckCircle2 size={15} /> : <AlertCircle size={15} />}{testResult.all_passed ? "All passing" : "Needs work"}</span>}<button className="icon-button" onClick={() => { setPublicTestsView(null); setTestResult(null); }} aria-label="Close public tests"><XCircle size={16} /></button></div><div className="public-test-table simple-test-table"><div className="public-test-table-header"><span>Test</span><span>Function</span><span>Input</span><span>Expected</span><span>Actual</span></div>{((publicTestsView.tests && publicTestsView.tests.length ? publicTestsView.tests : (testResult?.per_test ?? []).map((item) => ({ num: item.num, function_name: item.function_name ?? "target", args: item.args ?? "Not provided", expected: item.expected ?? "Not provided" })))).map((test) => { const result = (testResult?.per_test ?? []).find((item) => item.num === test.num); const actual = result?.actual_raw ?? result?.actual; return <article className="simple-test-row" key={test.num}><div className="simple-test-status"><span className={result?.status === "PASS" ? "test-pass" : result?.status ? "test-fail" : "test-pending"}>{result?.status === "PASS" ? <Check size={15} /> : result?.status ? <XCircle size={15} /> : <TerminalSquare size={15} />}</span><strong>Test {test.num}</strong></div><button className="test-function-link" type="button" onClick={() => void handleJumpToTestFunction(test.function_name)}>{test.function_name}</button><code>{test.args}</code><code>{test.expected}</code><code>{actual === undefined ? (result ? "Not returned" : "—") : typeof actual === "object" ? JSON.stringify(actual) : String(actual)}</code></article>; })}</div><p className="muted-copy">Showing {publicTestsView.total} public tests. Secret tests are not shown.</p></section>} return <article className="simple-test-row" key={test.num}><div className="simple-test-status"><span className={result?.status === "PASS" ? "test-pass" : result?.status ? "test-fail" : "test-pending"}>{result?.status === "PASS" ? <Check size={15} /> : result?.status ? <XCircle size={15} /> : <TerminalSquare size={15} />}</span><strong>Test {test.num}</strong></div><button className="test-function-link" type="button" onClick={() => void handleJumpToTestFunction(test.function_name)}>{test.function_name}</button><code>{test.args}</code><code>{test.expected}</code><code>{actual === undefined ? (result ? "Not returned" : "—") : formatTestActual(actual)}</code></article>; })}</div><p className="muted-copy">Showing {publicTestsView.total} public tests. Secret tests are not shown.</p></section>} {diagnosis && <section className="test-panel diagnosis-panel"><div className="panel-heading"><div><p className="eyebrow">LOCAL TEST DIAGNOSIS</p><h2>{diagnosis.file_path}</h2></div><button className="icon-button" onClick={() => setDiagnosis(null)} aria-label="Close diagnosis"><XCircle size={16} /></button></div><p><strong>Function:</strong> {diagnosis.functions.join(", ") || "Target logic"}</p><p>{diagnosis.bug_description}</p><pre className="expected-diff">{diagnosis.diff || "No focused diff is available."}</pre></section>} {diffOpen && diffResult && <section className="test-panel diff-panel"><div className="panel-heading"><div><p className="eyebrow">WORKSPACE DIFF</p><h2>{diffResult.has_changes ? "Your changes" : "No changes yet"}</h2></div><button className="icon-button" onClick={() => setDiffOpen(false)} aria-label="Close diff"><XCircle size={16} /></button></div><pre className="diff-content">{diffResult.diff || "The file is unchanged from the buggy version."}</pre></section>} </section>frontend/src/App.test.tsx+3-1
frontend/src/App.tsx+19-1