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
fix: show authoritative POST drill results after saving (#9459)
[._.]/ Adam Eivye648b616a0b0
diff --git a/client/src/components/meatspace/post/PostSessionResults.test.jsx b/client/src/components/meatspace/post/PostSessionResults.test.jsxindex 8b390fda5d..0f5713050d 100644--- a/client/src/components/meatspace/post/PostSessionResults.test.jsx+++ b/client/src/components/meatspace/post/PostSessionResults.test.jsx@@ -1,6 +1,15 @@import { describe, it, expect, vi } from 'vitest';import { render, screen, fireEvent, within, act } from '@testing-library/react';import PostSessionResults from './PostSessionResults';+import PostSessionSummary from './PostSessionSummary';+import { usePostSession } from '../../../hooks/usePostSession';+import { generatePostDrill, submitPostSession } from '../../../services/api';++vi.mock('../../../services/api', () => ({+ generatePostDrill: vi.fn(), submitPostSession: vi.fn(),+ scorePostLlmDrill: vi.fn(), submitTrainingRun: vi.fn(),+}));+vi.mock('../../ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn() } }));// Issue #2093 — the drill-breakdown expansion previously only ever showed// data for LLM drills (`isLlm && isExpanded && result.evaluation`); math and@@ -178,3 +187,43 @@ describe('PostSessionResults estimation grading band', () => {expect(screen.getByText('Within 3% counts — 3 significant figures is close enough')).toBeInTheDocument();});});+++describe('PostSessionResults saved acknowledgement (#9459)', () => {+ it('renders the saved score, metrics, and question review identically to the History summary', async () => {+ sessionStorage.clear();+ const tasks = [{ type: 'stroop', module: 'cognitive', score: 80, accuracy: 1, avgResponseMs: 1500,+ completion: 1, questions: [{ prompt: 'Saved color', expected: 'red', answered: 'red', correct: true, responseMs: 1500 }] }];+ generatePostDrill.mockResolvedValue({ type: 'stroop', trials: [], config: {} });+ submitPostSession.mockResolvedValue({ id: 'example-session', score: 80, tasks });+ function LiveResults() {+ const session = usePostSession();+ return <>+ <button onClick={() => session.startSession({ drills: [{ type: 'stroop', config: {} }] })}>Start example</button>+ <button onClick={() => session.completeCognitiveDrill({+ type: 'stroop', module: 'cognitive', score: 100, accuracy: 1, avgResponseMs: 100,+ questions: [{ prompt: 'Local color', correct: true }],+ })}>Finish example</button>+ <PostSessionResults session={session} onSaved={() => {}} onBack={() => {}} />+ </>;+ }+ const live = render(<LiveResults />);+ await act(async () => fireEvent.click(screen.getByText('Start example')));+ fireEvent.click(screen.getByText('Finish example'));+ expect(screen.getByText('100% acc · 0.1s')).toBeInTheDocument();+ await act(async () => fireEvent.click(screen.getByText('Save Session')));+ expect(screen.getByText('Back to Launcher')).toBeInTheDocument();+ expect(screen.getByText('100% acc · 1.5s')).toBeInTheDocument();+ const drillRow = screen.getByText('Stroop').closest('button');+ expect(within(drillRow).getByText('80')).toBeInTheDocument();+ fireEvent.click(drillRow);+ expect(screen.getByText('Saved color')).toBeInTheDocument();+ expect(screen.queryByText('Local color')).not.toBeInTheDocument();+ const liveTable = live.container.querySelector('table').textContent;+ live.unmount();+ const history = render(<PostSessionSummary drillResults={tasks} sessionScore={80} />);+ expect(screen.getByText('100% acc · 1.5s')).toBeInTheDocument();+ fireEvent.click(screen.getByText('Stroop'));+ expect(history.container.querySelector('table').textContent).toBe(liveTable);+ });+});diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex fb06ca948a..7860822b59 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -604,6 +604,17 @@ export function usePostSession() {return null;});if (!training) return null;+ if (Array.isArray(training.attempts)) {+ const localAttempts = new Map(attempts.map((attempt, index) => [attempt.id, { result: drillResults[index], index }]));+ setDrillResults(training.attempts+ .toSorted((a, b) => (localAttempts.get(a.id)?.index ?? Infinity) - (localAttempts.get(b.id)?.index ?? Infinity))+ .map(attempt => ({+ ...localAttempts.get(attempt.id)?.result,+ ...attempt,+ type: attempt.drillType,+ config: attempt.difficulty,+ })));+ }setSavedSession(training);toast.success('Training session logged');setState(STATES.SAVED);@@ -629,6 +640,7 @@ export function usePostSession() {return null;});if (!session) return null;+ if (Array.isArray(session.tasks)) setDrillResults(session.tasks);setSavedSession(session);// Replace the pre-save estimate (computeSessionScoreFromResults, a plain// per-domain average) with the server's authoritative score — which nowdiff --git a/client/src/hooks/usePostSession.test.js b/client/src/hooks/usePostSession.test.jsindex 60a41d95a3..ac59e22420 100644--- a/client/src/hooks/usePostSession.test.js+++ b/client/src/hooks/usePostSession.test.js@@ -1029,3 +1029,84 @@ describe('usePostSession — refresh-safe run + idempotent submit (issue #2098)'expect(next.result.current.runId).toBeNull();});});++describe('usePostSession — authoritative saved drill results (#9459)', () => {+ beforeEach(() => {+ vi.resetAllMocks();+ sessionStorage.clear();+ generatePostDrill.mockResolvedValue({ type: 'stroop', config: { seed: 'example' }, trials: [] });+ });++ async function completeRun(training = false, count = 1) {+ const hook = renderHook(() => usePostSession());+ await act(async () => {+ await hook.result.current.startSession({ drills: Array.from({ length: count }, () => ({ type: 'stroop', config: {} })), training });+ });+ act(() => hook.result.current.completeCognitiveDrill({+ module: 'cognitive', type: 'stroop', config: { seed: 'example' },+ score: 100, accuracy: 1, avgResponseMs: 100, completion: 1,+ questions: [{ prompt: 'RED', answered: 'red', correct: true, responseMs: 100 }],+ totalMs: 100,+ }));+ return hook;+ }++ it('adopts the entire scored task bundle together with the saved overall score', async () => {+ const tasks = [{ type: 'stroop', module: 'cognitive', score: 80, avgResponseMs: 1500,+ questions: [{ prompt: 'RED', answered: 'blue', correct: false, responseMs: 1500 }] }];+ submitPostSession.mockResolvedValue({ id: 'example-session', score: 80, tasks });+ const { result } = await completeRun();+ await act(async () => { await result.current.saveSession({}); });+ expect(result.current.state).toBe('saved');+ expect(result.current.sessionScore).toBe(80);+ expect(result.current.drillResults).toEqual(tasks);+ });++ it('matches training acknowledgements by stable identity while retaining execution order and presentation context', async () => {+ const { result } = await completeRun(true, 2);+ await act(async () => { await result.current.nextDrill(); });+ act(() => result.current.completeCognitiveDrill({+ module: 'cognitive', type: 'stroop', config: { seed: 'second' },+ score: 100, questions: [], totalMs: 500,+ }));+ submitTrainingRun.mockImplementation(async input => ({+ id: input.id,+ attempts: input.attempts.map((attempt, index) => ({+ ...attempt, difficulty: { seed: `saved-${index}` }, score: 80 - index,+ totalMs: 1500, avgResponseMs: 1500,+ questions: [{ prompt: `Saved ${index}`, correct: false }],+ scorerProvenance: 'server-deterministic',+ })).reverse(),+ }));+ await act(async () => { await result.current.saveSession({}); });+ const submitted = submitTrainingRun.mock.calls[0][0].attempts;+ expect(result.current.drillResults.map(result => result.id)).toEqual(submitted.map(attempt => attempt.id));+ expect(result.current.drillResults[0]).toMatchObject({+ type: 'stroop', config: { seed: 'saved-0' }, score: 80, avgResponseMs: 1500,+ totalMs: 1500, questions: [{ prompt: 'Saved 0', correct: false }],+ scorerProvenance: 'server-deterministic',+ });+ expect(result.current.drillResults[1].score).toBe(79);+ });++ it.each([false, true])('applies an explicitly empty saved bundle (training=%s)', async training => {+ const submit = training ? submitTrainingRun : submitPostSession;+ submit.mockResolvedValue({ id: 'example-saved', score: 0, [training ? 'attempts' : 'tasks']: [] });+ const { result } = await completeRun(training);+ await act(async () => { await result.current.saveSession({}); });+ expect(result.current.drillResults).toEqual([]);+ });++ it.each([false, true])('keeps results retryable on rejection and intact on a minimal acknowledgement (training=%s)', async training => {+ const submit = training ? submitTrainingRun : submitPostSession;+ submit.mockRejectedValueOnce(new Error('offline')).mockResolvedValueOnce({ id: 'example-saved', score: 80 });+ const { result } = await completeRun(training);+ const local = result.current.drillResults;+ await act(async () => { await result.current.saveSession({}); });+ expect(result.current.state).toBe('complete');+ expect(result.current.drillResults).toEqual(local);+ await act(async () => { await result.current.saveSession({}); });+ expect(result.current.state).toBe('saved');+ expect(result.current.drillResults).toEqual(local);+ });+});