From 6734dd43b93b4787d1d80272758d146b634be8c2 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 13 Nov 2026 12:58:56 -0600 Subject: [PATCH 01/59] refactor(validation): persist AI-graded outcome (pass|accepted) with legacy read shim (#3120) --- hugo-apps/src/validation/grading.ts | 28 ++++++++++---- test/unit/validation-grading.test.js | 55 +++++++++++++++++++--------- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/hugo-apps/src/validation/grading.ts b/hugo-apps/src/validation/grading.ts index f183d248d..c0b0cc523 100644 --- a/hugo-apps/src/validation/grading.ts +++ b/hugo-apps/src/validation/grading.ts @@ -103,36 +103,50 @@ export function gradeAnswers( const PERSIST_PREFIX = 'tutorial-validation-'; +export type PersistedOutcome = 'pass' | 'accepted'; + export function persistKey(slug: string, stepNumber: number): string { return `${PERSIST_PREFIX}${slug}-${stepNumber}`; } /** - * Read the persisted "answered correctly" flag for a (slug, step). + * Read the persisted outcome for a (slug, step). * Tolerant of localStorage failures (private mode, quota); returns null on any error * including malformed JSON. + * + * Back-compat: legacy {correct:true} entries read as {outcome:'pass'}. */ -export function readPersisted(slug: string, stepNumber: number): { correct: boolean } | null { +export function readPersisted(slug: string, stepNumber: number): { outcome: PersistedOutcome } | null { try { const raw = localStorage.getItem(persistKey(slug, stepNumber)); if (!raw) return null; const parsed = JSON.parse(raw); - return parsed?.correct === true ? { correct: true } : null; + + // Legacy back-compat: {correct:true} reads as {outcome:'pass'} + if (parsed?.correct === true) { + return { outcome: 'pass' }; + } + + // New shape: {outcome:'pass'|'accepted'} + if (parsed?.outcome === 'pass' || parsed?.outcome === 'accepted') { + return { outcome: parsed.outcome }; + } + + return null; } catch { return null; } } /** - * Write the "answered correctly" flag. Only persists on `correct: true`. + * Write the persisted outcome. Stores {outcome, timestamp}. * Silent on failure (private mode, quota exceeded, etc). */ -export function writePersisted(slug: string, stepNumber: number, correct: boolean): void { - if (!correct) return; +export function writePersisted(slug: string, stepNumber: number, outcome: PersistedOutcome): void { try { localStorage.setItem( persistKey(slug, stepNumber), - JSON.stringify({ correct: true, timestamp: Date.now() }) + JSON.stringify({ outcome, timestamp: Date.now() }) ); } catch { // private mode or quota exceeded — silent diff --git a/test/unit/validation-grading.test.js b/test/unit/validation-grading.test.js index bcae258b9..a853ee060 100644 --- a/test/unit/validation-grading.test.js +++ b/test/unit/validation-grading.test.js @@ -199,32 +199,53 @@ describe('validation grading.ts', () => { vi.unstubAllGlobals(); }); - it('readPersisted: returns { correct: true } for a valid entry', () => { - const ls = { getItem: vi.fn(() => JSON.stringify({ correct: true, timestamp: 123 })) }; + // ── writePersisted ────────────────────────────────────────────── + + it('writePersisted stores {outcome} shape', () => { + const store = {}; + const ls = { setItem: (k, v) => { store[k] = v; } }; vi.stubGlobal('localStorage', ls); - expect(readPersisted('foo', 1)).toEqual({ correct: true }); + writePersisted('slug', 2, 'accepted'); + expect(JSON.parse(store['tutorial-validation-slug-2']).outcome).toBe('accepted'); vi.unstubAllGlobals(); }); - // ── writePersisted ────────────────────────────────────────────── + it('writePersisted pass stores outcome pass', () => { + const store = {}; + const ls = { setItem: (k, v) => { store[k] = v; } }; + vi.stubGlobal('localStorage', ls); + writePersisted('slug', 1, 'pass'); + expect(JSON.parse(store['tutorial-validation-slug-1']).outcome).toBe('pass'); + vi.unstubAllGlobals(); + }); + + it('readPersisted returns the stored outcome', () => { + const store = {}; + const ls = { + setItem: (k, v) => { store[k] = v; }, + getItem: (k) => store[k] || null + }; + vi.stubGlobal('localStorage', ls); + writePersisted('slug', 3, 'accepted'); + expect(readPersisted('slug', 3)).toEqual({ outcome: 'accepted' }); + vi.unstubAllGlobals(); + }); - it('writePersisted: writes JSON when correct=true', () => { - const ls = { setItem: vi.fn() }; + it('readPersisted reads legacy {correct:true} as outcome pass', () => { + const store = { 'tutorial-validation-slug-9': JSON.stringify({ correct: true, timestamp: 1 }) }; + const ls = { getItem: (k) => store[k] || null }; vi.stubGlobal('localStorage', ls); - writePersisted('foo', 1, true); - expect(ls.setItem).toHaveBeenCalledTimes(1); - expect(ls.setItem).toHaveBeenCalledWith( - 'tutorial-validation-foo-1', - expect.stringMatching(/^\{"correct":true,"timestamp":\d+\}$/) - ); + expect(readPersisted('slug', 9)).toEqual({ outcome: 'pass' }); vi.unstubAllGlobals(); }); - it('writePersisted: does NOT write when correct=false', () => { - const ls = { setItem: vi.fn() }; + it('readPersisted returns null on malformed / missing / throwing storage', () => { + const store = {}; + const ls = { getItem: (k) => store[k] || null }; vi.stubGlobal('localStorage', ls); - writePersisted('foo', 1, false); - expect(ls.setItem).not.toHaveBeenCalled(); + expect(readPersisted('slug', 404)).toBeNull(); + store['tutorial-validation-slug-5'] = 'not json'; + expect(readPersisted('slug', 5)).toBeNull(); vi.unstubAllGlobals(); }); @@ -233,7 +254,7 @@ describe('validation grading.ts', () => { setItem: vi.fn(() => { throw new Error('quota exceeded'); }) }; vi.stubGlobal('localStorage', ls); - expect(() => writePersisted('foo', 1, true)).not.toThrow(); + expect(() => writePersisted('foo', 1, 'pass')).not.toThrow(); vi.unstubAllGlobals(); }); From 249767a0aa16d9016d7271d1d5899afcd57f802e Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 13 Nov 2026 13:04:48 -0600 Subject: [PATCH 02/59] feat(validation): Yellow answers require explicit Continue-anyway, no silent unlock (#3120) --- hugo-apps/src/validation/Validation.test.ts | 103 +++++++++++++++++--- hugo-apps/src/validation/Validation.vue | 33 +++++-- 2 files changed, 114 insertions(+), 22 deletions(-) diff --git a/hugo-apps/src/validation/Validation.test.ts b/hugo-apps/src/validation/Validation.test.ts index 89afc7e31..1766ce402 100644 --- a/hugo-apps/src/validation/Validation.test.ts +++ b/hugo-apps/src/validation/Validation.test.ts @@ -149,9 +149,11 @@ interface VmExposed { pending: boolean hint: string submitted: boolean + acknowledged: boolean perQuestionResults: Record onSubmit: () => Promise onTryAgain: () => void + onContinueAnyway: () => void _testSetAnswers: (next: Record) => void } @@ -235,7 +237,7 @@ describe('Validation.vue — #235 component flow', () => { ) expect(getVm(wrapper).result).toBe('correct') - expect(localStorageStore['tutorial-validation-persist-test-7']).toContain('"correct":true') + expect(localStorageStore['tutorial-validation-persist-test-7']).toContain('"outcome":"pass"') expect(eventSpy).toHaveBeenCalledTimes(1) expect((eventSpy.mock.calls[0][0] as CustomEvent).detail).toEqual({ stepNumber: 7 }) @@ -355,7 +357,7 @@ describe('Validation.vue — #235 component flow', () => { // Test 4: pass + partial → result=accepted (#2348: partial unlocks the step) // ───────────────────────────────────────────────────────────────────────── - it('AI Q1 pass + AI Q2 partial-with-hint → result=accepted, hint shown, step-validated fired (#2348)', async () => { + it('AI Q1 pass + AI Q2 partial-with-hint → result=accepted, hint shown, step NOT yet validated (#3120)', async () => { fetchMock .mockResolvedValueOnce(mockFetchResponse({ verdict: 'pass', summary: 'OK' })) .mockResolvedValueOnce(mockFetchResponse({ @@ -370,11 +372,17 @@ describe('Validation.vue — #235 component flow', () => { { 'q-ai': 'a1', 'q-ai-2': 'a2' } ) - // #2348: pass-or-partial with no fail is now ACCEPTED — the step unlocks - // and the advisory hint is surfaced, rather than blocking on 'partial'. + // #3120: pass-or-partial no longer auto-unlocks — learner must click "Continue anyway" expect(getVm(wrapper).result).toBe('accepted') expect(getVm(wrapper).hint).toBe('Consider edge cases.') + expect(eventSpy).not.toHaveBeenCalled() + + // After calling onContinueAnyway(), the step validates and acknowledged flips true + await getVm(wrapper).onContinueAnyway() + await wrapper.vm.$nextTick() expect(eventSpy).toHaveBeenCalledTimes(1) + expect(getVm(wrapper).acknowledged).toBe(true) + document.removeEventListener('step-validated', eventSpy) }) @@ -383,21 +391,25 @@ describe('Validation.vue — #235 component flow', () => { // regardless of whether a hint came back) // ───────────────────────────────────────────────────────────────────────── - it('AI Q partial with empty hint → result=accepted, empty hint (#2348)', async () => { + it('AI Q partial with empty hint → result=accepted, empty hint, step NOT yet validated (#3120)', async () => { fetchMock.mockResolvedValueOnce(mockFetchResponse({ verdict: 'partial', summary: 'Close', hint: '', })) + const eventSpy = vi.fn() + document.addEventListener('step-validated', eventSpy) + const wrapper = await submitWithAnswers( [TEXT_AI], { 'q-ai': 'something' } ) - // Partial is an accepting verdict now — even with no hint, the step - // unlocks. The accepted strip renders "Good enough…" without the - // "one thing to consider" clause (guarded by v-if="hint"). + // #3120: accepted no longer auto-fires step-validated — learner must click Continue anyway expect(getVm(wrapper).result).toBe('accepted') expect(getVm(wrapper).hint).toBe('') + expect(eventSpy).not.toHaveBeenCalled() + + document.removeEventListener('step-validated', eventSpy) }) // ───────────────────────────────────────────────────────────────────────── @@ -507,7 +519,7 @@ describe('Validation.vue — #235 component flow', () => { // verified manually in DEV per PR #602 verification table.) }) - it('accepted (single partial): unlocks step + persists, answer preserved (#2348)', async () => { + it('accepted (single partial): result=accepted, answer preserved, step NOT yet validated (#3120)', async () => { fetchMock.mockResolvedValueOnce(mockFetchResponse({ verdict: 'partial', summary: 'Close but missing X', hint: 'Think about X', })) @@ -521,18 +533,79 @@ describe('Validation.vue — #235 component flow', () => { { slug: 'partial-test', stepNumber: 1 }, ) - // #2348: a single partial now ACCEPTS the step (unlocks progression) and - // fires step-validated so the Done button re-enables. Advisory hint shown. + // #3120: accepted no longer auto-fires — learner must click Continue anyway. + // Advisory hint is still shown. expect(getVm(wrapper).result).toBe('accepted') expect(getVm(wrapper).hint).toBe('Think about X') - expect(eventSpy).toHaveBeenCalledTimes(1) - // Answer preserved (the textarea is never unmounted). NOTE: we assert on - // the answers ref, not a stub .exists() finder — happy-dom's stub-sibling - // rendering is unreliable (see the 'correct' test's note above). + expect(eventSpy).not.toHaveBeenCalled() + // Answer preserved (the textarea is never unmounted). const answersMap = (wrapper.vm as unknown as VmExposed & { answers: Record }).answers expect(answersMap['q-ai']).toBe('rough answer') document.removeEventListener('step-validated', eventSpy) }) + + // ───────────────────────────────────────────────────────────────────────── + // #3120: Continue anyway persists accepted outcome in localStorage + // ───────────────────────────────────────────────────────────────────────── + + it('Continue anyway persists accepted outcome in localStorage (#3120)', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Consider more detail.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'partial answer' }, + { slug: 'persist-accepted', stepNumber: 3 }, + ) + + expect(getVm(wrapper).result).toBe('accepted') + // Before clicking Continue anyway — nothing persisted yet + expect(localStorageStore['tutorial-validation-persist-accepted-3']).toBeUndefined() + + await getVm(wrapper).onContinueAnyway() + await wrapper.vm.$nextTick() + + expect(localStorageStore['tutorial-validation-persist-accepted-3']).toContain('"outcome":"accepted"') + }) + + // ───────────────────────────────────────────────────────────────────────── + // #3120: Resubmit after accepted can still reach correct + // ───────────────────────────────────────────────────────────────────────── + + it('Resubmit after accepted can reach correct (#3120)', async () => { + // First submit: partial → accepted (no persist yet) + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Be more specific.', + })) + + const wrapper = await mountValidation([TEXT_AI], { slug: 'resubmit-test', stepNumber: 2 }) + const vm = getVm(wrapper) + vm._testSetAnswers({ 'q-ai': 'rough answer' }) + await wrapper.vm.$nextTick() + await vm.onSubmit() + await flushPromises() + + expect(vm.result).toBe('accepted') + // Not persisted yet — learner hasn't clicked Continue anyway + expect(localStorageStore['tutorial-validation-resubmit-test-2']).toBeUndefined() + + // Learner tries again with a better answer + vm.onTryAgain() + await wrapper.vm.$nextTick() + + // Second submit: pass → correct + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'pass', summary: 'Perfect.', + })) + vm._testSetAnswers({ 'q-ai': 'better answer' }) + await wrapper.vm.$nextTick() + await vm.onSubmit() + await flushPromises() + + expect(vm.result).toBe('correct') + expect(localStorageStore['tutorial-validation-resubmit-test-2']).toContain('"outcome":"pass"') + }) }) // ───────────────────────────────────────────────────────────────────────────── diff --git a/hugo-apps/src/validation/Validation.vue b/hugo-apps/src/validation/Validation.vue index 8f6f2e1ed..eb4a05660 100644 --- a/hugo-apps/src/validation/Validation.vue +++ b/hugo-apps/src/validation/Validation.vue @@ -45,6 +45,7 @@ const submitted = ref(false); const result = ref<'correct' | 'accepted' | 'incorrect' | 'partial' | 'disabled' | null>(null); const pending = ref(false); const hint = ref(''); +const acknowledged = ref(false); // Per-question verdict map populated by onSubmit. Each question's submission // produces a verdict + optional hint; the template renders ✓ / ✗ / ⚠ next to @@ -104,7 +105,7 @@ onMounted(() => { // author preview UX. if (props.isPreview) return; const persisted = readPersisted(props.slug, props.stepNumber); - if (persisted?.correct) { + if (persisted?.outcome === 'pass') { submitted.value = true; result.value = 'correct'; // Backfill perQuestionResults so the rendered ✓/✗ shows on persisted-correct @@ -113,6 +114,13 @@ onMounted(() => { perQuestionResults.value[q.id] = { verdict: 'pass' }; } emitStepValidated(); + } else if (persisted?.outcome === 'accepted') { + // [#3120] Learner previously clicked "Continue anyway" — rehydrate to + // accepted+acknowledged without backfilling per-question pass verdicts. + submitted.value = true; + result.value = 'accepted'; + acknowledged.value = true; + emitStepValidated(); } }); @@ -350,16 +358,17 @@ async function onSubmit() { if (allPass) { result.value = 'correct'; hint.value = ''; - writePersisted(props.slug, props.stepNumber, true); + writePersisted(props.slug, props.stepNumber, 'pass'); + acknowledged.value = false; emitStepValidated(); } else if (allAccepted && anyPartial) { - // [#2348] All AI questions pass-or-partial (no fail): accept the step so - // the Done button unlocks, but still surface the advisory hint so the - // learner sees what they could have added. No "Try Again" — they're done. + // [#3120] All AI questions pass-or-partial (no fail): set accepted state + // and surface the advisory hint, but do NOT unlock yet — the learner must + // explicitly click "Continue anyway". writePersisted + emitStepValidated + // are deferred to onContinueAnyway(). result.value = 'accepted'; hint.value = firstHint; - writePersisted(props.slug, props.stepNumber, true); - emitStepValidated(); + acknowledged.value = false; } else if (firstHint) { // At least one hard fail, but it carries a hint (v2+ prompt provides // these). Use the 'partial' result-state so the hint surfaces in a @@ -398,6 +407,14 @@ function onTryAgain() { perQuestionResults.value = {}; } +// [#3120] Explicit continue: learner acknowledges the yellow (partial/accepted) +// outcome and explicitly opts in to unlock the step. +function onContinueAnyway(): void { + writePersisted(props.slug, props.stepNumber, 'accepted'); + emitStepValidated(); + acknowledged.value = true; +} + // [#235] Expose internals for component-level tests in Validation.test.ts. // Production callers don't reach into the component instance — these refs + // methods are normally only manipulated through the template. Keeping the @@ -423,6 +440,7 @@ defineExpose({ pending, hint, submitted, + acknowledged, perQuestionResults, // `answers` exposed read-only for tests so they can verify the typed // answer survives the lock (the template's :value bind on the textarea @@ -431,6 +449,7 @@ defineExpose({ // Methods onSubmit, onTryAgain, + onContinueAnyway, // Test setter — preserves reactivity that direct vm.answers = ... would lose _testSetAnswers, _testSetPending, From a581388890b065011a58507aa4225aade576d5fa Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 13 Nov 2026 13:15:11 -0600 Subject: [PATCH 03/59] feat(validation): editable Yellow box + Resubmit/Continue-anyway UI (#3120) --- hugo-apps/src/validation/Validation.test.ts | 134 ++++++++++++++++++++ hugo-apps/src/validation/Validation.vue | 72 +++++++++-- 2 files changed, 194 insertions(+), 12 deletions(-) diff --git a/hugo-apps/src/validation/Validation.test.ts b/hugo-apps/src/validation/Validation.test.ts index 1766ce402..e22de795f 100644 --- a/hugo-apps/src/validation/Validation.test.ts +++ b/hugo-apps/src/validation/Validation.test.ts @@ -772,3 +772,137 @@ describe('Validation.vue — #1740 multi-select MCQ', () => { expect(getVm(wrapper).result).toBe('incorrect') }) }) + +// ───────────────────────────────────────────────────────────────────────────── +// #3120 Yellow UX — editable box, Resubmit, Continue anyway template tests +// ───────────────────────────────────────────────────────────────────────────── + +describe('Validation.vue — #3120 Yellow state template', () => { + // ── accepted keeps textarea editable ────────────────────────────────────── + it('accepted state keeps the textarea editable (no disabled attr)', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Think more.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'my answer' }, + ) + + expect(getVm(wrapper).result).toBe('accepted') + // ui5-textarea is stubbed → . + // When result==='accepted' the textarea must NOT have `disabled` attr — + // so the learner can edit and resubmit. + const textarea = wrapper.find('ui5-textarea-stub') + expect(textarea.exists()).toBe(true) + expect(textarea.attributes('disabled')).toBeUndefined() + }) + + // ── accepted shows Resubmit + Continue anyway buttons and warning strip ─── + it('accepted state shows Resubmit and Continue-anyway buttons and ⚠ strip text', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Think more.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'my answer' }, + ) + + expect(getVm(wrapper).result).toBe('accepted') + + // Information-design strip is present (ui5-message-strip stubs don't render + // slot content with the 'true' stub, so we assert on the design attribute). + const strips = wrapper.findAll('ui5-message-strip-stub') + const infoStrip = strips.find((s) => s.attributes('design') === 'Information') + expect(infoStrip).toBeDefined() + + // Both action buttons present. ui5-button stubs with 'true' don't render + // slot text — assert by attribute: Resubmit has type="button", Continue + // anyway has design="Emphasized". + const buttons = wrapper.findAll('ui5-button-stub') + const resubmitBtn = buttons.find((b) => b.attributes('type') === 'button') + expect(resubmitBtn).toBeDefined() + const continueBtn = buttons.find((b) => b.attributes('design') === 'Emphasized') + expect(continueBtn).toBeDefined() + }) + + // ── after acknowledge: no Continue-anyway, textarea still editable ──────── + it('after onContinueAnyway: Continue-anyway gone, textarea editable, confirmation shown', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Be more specific.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'my answer' }, + ) + + expect(getVm(wrapper).result).toBe('accepted') + expect(getVm(wrapper).acknowledged).toBe(false) + + await getVm(wrapper).onContinueAnyway() + await wrapper.vm.$nextTick() + + expect(getVm(wrapper).acknowledged).toBe(true) + + // "Continue anyway" button must be gone (it has design="Emphasized"). + // After acknowledge the v-if="!acknowledged" removes it from the DOM. + const buttons = wrapper.findAll('ui5-button-stub') + const continueBtn = buttons.find((b) => b.attributes('design') === 'Emphasized') + expect(continueBtn).toBeUndefined() + + // Textarea still editable (not disabled). + const textarea = wrapper.find('ui5-textarea-stub') + expect(textarea.attributes('disabled')).toBeUndefined() + + // Positive-design (confirmation) strip is now shown. + const strips = wrapper.findAll('ui5-message-strip-stub') + const positiveStrip = strips.find((s) => s.attributes('design') === 'Positive') + expect(positiveStrip).toBeDefined() + }) + + // ── correct state still disables the textarea ───────────────────────────── + it('correct state still disables the textarea', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'pass', summary: 'Perfect.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'perfect answer' }, + ) + + expect(getVm(wrapper).result).toBe('correct') + const textarea = wrapper.find('ui5-textarea-stub') + expect(textarea.exists()).toBe(true) + // On correct, textarea must have a `disabled` attribute present (truthy). + // Vue Test Utils stubs render boolean attributes as "true" not "", + // so we assert the attribute exists (not undefined). + expect(textarea.attributes('disabled')).toBeDefined() + }) + + // ── onTryAgain resets acknowledged to false ─────────────────────────────── + it('onTryAgain resets acknowledged to false', async () => { + fetchMock.mockResolvedValueOnce(mockFetchResponse({ + verdict: 'partial', summary: 'Close', hint: 'Consider X.', + })) + + const wrapper = await submitWithAnswers( + [TEXT_AI], + { 'q-ai': 'rough answer' }, + ) + + expect(getVm(wrapper).result).toBe('accepted') + + // Click Continue anyway to set acknowledged=true. + await getVm(wrapper).onContinueAnyway() + await wrapper.vm.$nextTick() + expect(getVm(wrapper).acknowledged).toBe(true) + + // Try again must reset acknowledged to false. + getVm(wrapper).onTryAgain() + await wrapper.vm.$nextTick() + expect(getVm(wrapper).acknowledged).toBe(false) + }) +}) diff --git a/hugo-apps/src/validation/Validation.vue b/hugo-apps/src/validation/Validation.vue index eb4a05660..ff158aa24 100644 --- a/hugo-apps/src/validation/Validation.vue +++ b/hugo-apps/src/validation/Validation.vue @@ -403,6 +403,9 @@ function onTryAgain() { submitted.value = false; result.value = null; hint.value = ''; + // [#3120] Reset acknowledged so that after Continue-anyway → Try-again → + // accepted-again the "Continue anyway" button reappears. + acknowledged.value = false; // Clear per-question results too — the new submit will repopulate them. perQuestionResults.value = {}; } @@ -487,18 +490,27 @@ defineExpose({ Correct! Well done. - + + ⚠ Partially correct — your answer covers the main idea. + + - Good enough — you've got the main idea. + ✓ Counts — you've continued. You can still refine your answer and resubmit. + incorrect / error) can keep accepting input. + [#3120] accepted state is intentionally NOT disabled — the + learner can refine their answer and resubmit via the Resubmit + button. Only correct (permanently locked) disables the textarea. --> @@ -717,6 +732,39 @@ defineExpose({ Try Again + + +

From 1681bc0e4fc4f49ed7b8abf8dc4f434c9ebb6b83 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 13 Nov 2026 13:31:37 -0600 Subject: [PATCH 04/59] feat(reset): allow mid-tutorial reset; replace #2446 409 guard with rollup regression test (#3120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove the `if (!priorTutorialRow) reject(409)` gate in `doResetTutorialProgress` (srv/developer-service.js); reset now proceeds whenever `liveRows.length > 0`. - `previousAttemptCompletedAt` is `null` for a partial reset (already nullable). - Invert the two #2446 unit tests (now assert 200, rows superseded, fresh attempt). - Add replacement regression guard: seeds tutorial → GROUP via GroupPathItems, seeds GROUP TaskRecord as COMPLETED, partial-resets the tutorial, asserts getProgress returns completedSteps:[] AND the GROUP TaskRecord is NOT COMPLETED after the rollUpParentsForCompletion(allowDowngrade:true) call. --- package-lock.json | 32 +----- srv/developer-service.js | 19 ++-- test/unit/reset-tutorial-progress.test.js | 130 ++++++++++++++++++---- 3 files changed, 122 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index c895dc736..b08c71e85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "tutorials-ims", "version": "1.0.0", + "hasInstallScript": true, "workspaces": [ "packages/*" ], @@ -56,6 +57,7 @@ "node-sql-parser": "^5.4.0", "nodemailer": "9.0.3", "passport": "^0.7.0", + "patch-package": "8.0.1", "qrcode": "^1.5.4", "sharp": "0.35.3", "socket.io": "^4.8.3", @@ -79,7 +81,6 @@ "esbuild": "0.28.2", "fundamental-styles": "^0.41.7", "happy-dom": "20.14.3", - "patch-package": "8.0.1", "playwright-core": "^1.61.1", "postcss": "^8.5.16", "postcss-cli": "^11.0.1", @@ -11876,7 +11877,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", - "dev": true, "license": "BSD-2-Clause" }, "node_modules/@zxing/library": { @@ -12637,7 +12637,6 @@ }, "node_modules/braces": { "version": "3.0.3", - "dev": true, "license": "MIT", "dependencies": { "fill-range": "^7.1.1" @@ -12741,7 +12740,6 @@ "version": "1.0.9", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.9.tgz", "integrity": "sha512-a/hy+pNsFUTR+Iz8TCJvXudKVLAnz/DyeSUo10I5yvFDQJBFU2s9uqQpoSrJlroHUKoKqzg+epxyP9lqFdzfBQ==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -12906,7 +12904,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", @@ -13085,7 +13082,6 @@ "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", - "dev": true, "funding": [ { "type": "github", @@ -14316,7 +14312,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -15546,7 +15541,6 @@ }, "node_modules/fill-range": { "version": "7.1.1", - "dev": true, "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" @@ -15589,7 +15583,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz", "integrity": "sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ==", - "dev": true, "license": "Apache-2.0", "dependencies": { "micromatch": "^4.0.2" @@ -16069,7 +16062,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -16079,7 +16071,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" @@ -16673,7 +16664,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", - "dev": true, "license": "MIT", "bin": { "is-docker": "cli.js" @@ -16720,7 +16710,6 @@ }, "node_modules/is-number": { "version": "7.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=0.12.0" @@ -16789,7 +16778,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", - "dev": true, "license": "MIT", "dependencies": { "is-docker": "^2.0.0" @@ -17065,7 +17053,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.3.0.tgz", "integrity": "sha512-qtYiSSFlwot9XHtF9bD9c7rwKjr+RecWT//ZnPvSmEjpV5mmPOCN4j8UjY5hbjNkOwZ/jQv3J6R1/pL7RwgMsg==", - "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.8", @@ -17085,7 +17072,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true, "license": "MIT" }, "node_modules/jsonc-parser": { @@ -17097,7 +17083,6 @@ }, "node_modules/jsonfile": { "version": "6.2.1", - "dev": true, "license": "MIT", "dependencies": { "universalify": "^2.0.0" @@ -17110,7 +17095,6 @@ "version": "0.0.1", "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.1.tgz", "integrity": "sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==", - "dev": true, "license": "Public Domain", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -17228,7 +17212,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz", "integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==", - "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.1.11" @@ -18328,7 +18311,6 @@ }, "node_modules/micromatch": { "version": "4.0.8", - "dev": true, "license": "MIT", "dependencies": { "braces": "^3.0.3", @@ -18760,7 +18742,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -18845,7 +18826,6 @@ "version": "7.4.2", "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", - "dev": true, "license": "MIT", "dependencies": { "is-docker": "^2.0.0", @@ -19047,7 +19027,6 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/patch-package/-/patch-package-8.0.1.tgz", "integrity": "sha512-VsKRIA8f5uqHQ7NGhwIna6Bx6D9s/1iXlA1hthBVBEbkq+t4kXD0HHt+rJhf/Z+Ci0F/HCB2hvn0qLdLG+Qxlw==", - "dev": true, "license": "MIT", "dependencies": { "@yarnpkg/lockfile": "^1.1.0", @@ -19077,7 +19056,6 @@ "version": "10.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.2.0", @@ -19092,7 +19070,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -19102,7 +19079,6 @@ "version": "0.2.7", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz", "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==", - "dev": true, "license": "MIT", "engines": { "node": ">=14.14" @@ -20551,7 +20527,6 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "dev": true, "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", @@ -21209,7 +21184,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "license": "MIT", "dependencies": { "has-flag": "^4.0.0" @@ -21474,7 +21448,6 @@ }, "node_modules/to-regex-range": { "version": "5.0.1", - "dev": true, "license": "MIT", "dependencies": { "is-number": "^7.0.0" @@ -21752,7 +21725,6 @@ }, "node_modules/universalify": { "version": "2.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">= 10.0.0" diff --git a/srv/developer-service.js b/srv/developer-service.js index 21a571b65..f78fb86b4 100644 --- a/srv/developer-service.js +++ b/srv/developer-service.js @@ -244,21 +244,20 @@ export default class DeveloperService extends cds.ApplicationService { } // Capture the prior tutorial-level completion date BEFORE we update. + // null when the tutorial was never completed (partial reset) — already + // the correct nullable shape for the return type. const priorTutorialRow = liveRows.find( r => r.taskType === 'TUTORIAL' && r.status === 'COMPLETED' ); const previousAttemptCompletedAt = priorTutorialRow?.completionDate ?? null; - // A reset is only valid on a FULLY completed tutorial — it re-opens a done - // tutorial for another attempt. Partial progress (some steps done, tutorial - // still IN_PROGRESS) has nothing to "re-complete" and must NOT be resettable. - // The UI enforces this by only showing the reset button once the tutorial is - // completed; the OData action + MCP `reset_tutorial_progress` tool bypassed it - // (issue #2446), letting a partial reset supersede in-progress rows without - // clearing step status. Guard both paths at the shared handler. - if (!priorTutorialRow) { - return req.reject(409, 'This tutorial is not completed yet — only completed tutorials can be reset.'); - } + // A reset is valid whenever liveRows.length > 0 (checked above). The prior + // 409 guard (issue #2446 fix) required a COMPLETED tutorial-level row, but + // that was overly conservative: the handler already supersedes ALL live STEP + // + TUTORIAL rows (step 6) and calls rollUpParentsForCompletion(allowDowngrade) + // (step 8), so the inconsistent-rollup symptom of #2446 cannot arise. Gate + // relaxed in #3120; the replacement regression test checks the rollup + // downgrade path directly. // 4. Determine next attempt number const maxAttempt = Math.max(...liveRows.map(r => r.attemptNumber ?? 1)); diff --git a/test/unit/reset-tutorial-progress.test.js b/test/unit/reset-tutorial-progress.test.js index 7f8cb5068..b16899896 100644 --- a/test/unit/reset-tutorial-progress.test.js +++ b/test/unit/reset-tutorial-progress.test.js @@ -135,24 +135,32 @@ describe('resetTutorialProgress handler — happy path', () => { expect(live[0].progress).toBe(0); }); - it('rejects a second reset when the tutorial has not been re-completed (409)', async () => { + it('allows a second reset even when the tutorial has not been re-completed (gate relaxed #3120)', async () => { cds.context = { user: new cds.User({ id: 'sap-u1' }) }; const { DeveloperService } = cds.services; - // First reset succeeds (seed left a COMPLETED attempt-1). It leaves the - // tutorial IN_PROGRESS at attempt 2 — there is nothing COMPLETED to reset, - // so a second reset must reject (issue #2446 guard). - await DeveloperService.send({ event: 'resetTutorialProgress', data: { slug: 'reset-happy-path' } }); + // First reset: seed left a COMPLETED attempt-1, 4 rows superseded → attempt 2 IN_PROGRESS. + const result1 = await DeveloperService.send({ event: 'resetTutorialProgress', data: { slug: 'reset-happy-path' } }); + expect(result1.newAttemptNumber).toBe(2); + + // Second reset: attempt-2 IN_PROGRESS TUTORIAL row is live, so liveRows.length > 0. + // With the gate relaxed this now resolves (200) and bumps to attempt 3. cds.context = { user: new cds.User({ id: 'sap-u1' }) }; - await expect( - DeveloperService.send({ event: 'resetTutorialProgress', data: { slug: 'reset-happy-path' } }) - ).rejects.toMatchObject({ code: 409 }); + const result2 = await DeveloperService.send({ event: 'resetTutorialProgress', data: { slug: 'reset-happy-path' } }); + expect(result2.newAttemptNumber).toBe(3); + expect(result2.previousAttemptCompletedAt).toBeNull(); // attempt-2 was never completed + + // Attempt-3 IN_PROGRESS TUTORIAL row must exist. + const { TaskRecords } = cds.entities('com.sap.developers.ims'); + const live = await SELECT.from(TaskRecords).where({ user_ID: 'u1', status: 'IN_PROGRESS' }); + expect(live).toHaveLength(1); + expect(live[0].attemptNumber).toBe(3); }); - it('rejects reset of a partially-completed tutorial with 409 (issue #2446)', async () => { - // Regression guard for #2446: a user completed only step 1 (tutorial still - // IN_PROGRESS) then called reset via the API/MCP. The old handler allowed it - // — superseding the live step row WITHOUT clearing step status, leaving the - // schedule/points view inconsistent. Reset must require a COMPLETED tutorial. + it('resets a partially-completed tutorial (200, supersedes partial progress) (#3120 gate relaxed)', async () => { + // Was the #2446 regression guard (rejected with 409). Now relaxed: a partial reset + // supersedes the live STEP + TUTORIAL rows and creates a fresh attempt. + // The #2446 actual symptom (stale parent rollup / phantom points) is covered by + // the new rollup regression test below. const { Users, Tutorials, Steps, TaskRecords } = cds.entities('com.sap.developers.ims'); await DELETE.from(TaskRecords).where({ user_ID: 'u1' }); await DELETE.from(Steps).where({ tutorial_ID: 't1' }); @@ -177,14 +185,98 @@ describe('resetTutorialProgress handler — happy path', () => { cds.context = { user: new cds.User({ id: 'sap-u1' }) }; const { DeveloperService } = cds.services; - await expect( - DeveloperService.send({ event: 'resetTutorialProgress', data: { slug: 'partial-tut' } }) - ).rejects.toMatchObject({ code: 409 }); + // Now resolves: 2 live rows get superseded, fresh attempt-2 IN_PROGRESS TUTORIAL inserted. + const result = await DeveloperService.send({ + event: 'resetTutorialProgress', + data: { slug: 'partial-tut' }, + }); + expect(result.newAttemptNumber).toBe(2); + expect(result.supersededRecordCount).toBe(2); + expect(result.previousAttemptCompletedAt).toBeNull(); // partial attempt was never completed - // The partial progress must be untouched — no row superseded. + // Both live rows must now be SUPERSEDED. const rows = await SELECT.from(TaskRecords).where({ user_ID: 'u1' }); - expect(rows.every(r => r.status !== 'SUPERSEDED')).toBe(true); - expect(rows.find(r => r.taskType === 'STEP').status).toBe('COMPLETED'); + const superseded = rows.filter(r => r.status === 'SUPERSEDED'); + expect(superseded).toHaveLength(2); + + // A fresh attempt-2 IN_PROGRESS TUTORIAL row must exist. + const live = rows.filter(r => r.status === 'IN_PROGRESS'); + expect(live).toHaveLength(1); + expect(live[0].taskType).toBe('TUTORIAL'); + expect(live[0].attemptNumber).toBe(2); + expect(live[0].progress).toBe(0); + }); + + it('partial reset clears parent rollup + no phantom points (replacement #2446 regression guard)', async () => { + // Reproduces #2446's actual symptom: completing one step of a tutorial that belongs to + // a GROUP caused the GROUP to roll up to COMPLETED (phantom points). A subsequent partial + // reset must downgrade the parent via rollUpParentsForCompletion(allowDowngrade:true). + // + // Setup: tutorial → group (via GroupPathItems). The group is pre-seeded as COMPLETED + // (simulating the #2446 state: one-step tutorial completed → group rolled to COMPLETED). + // After the partial reset, getProgress returns completedSteps:[] AND the group TaskRecord + // must NOT be COMPLETED (rollUpParentsForCompletion downgraded it). + const { Users, Tutorials, Steps, Groups, GroupPathItems, TaskRecords } = cds.entities('com.sap.developers.ims'); + + // Clean up all entities in FK order (children → parents). + await DELETE.from(TaskRecords).where({ user_ID: 'u-2446' }); + await DELETE.from(GroupPathItems).where({ group_ID: 'g-2446' }); + await DELETE.from(Steps).where({ tutorial_ID: 't-2446' }); + await DELETE.from(Tutorials).where({ ID: 't-2446' }); + await DELETE.from(Groups).where({ ID: 'g-2446' }); + await DELETE.from(Users).where({ ID: 'u-2446' }); + + await INSERT.into(Users).entries({ ID: 'u-2446', uuid: 'u-2446', sapId: 'sap-u2446', legacyId: 8001 }); + await INSERT.into(Groups).entries({ ID: 'g-2446', slug: 'group-2446', title: 'Group 2446', legacyId: 9001 }); + await INSERT.into(Tutorials).entries({ + ID: 't-2446', slug: 'tut-2446', title: 'Tutorial 2446', legacyId: 6001, stepCount: 2, + }); + await INSERT.into(Steps).entries([ + { ID: 'sg1', tutorial_ID: 't-2446', stepOrder: 1, legacyId: 6101, title: 'Step 1' }, + { ID: 'sg2', tutorial_ID: 't-2446', stepOrder: 2, legacyId: 6102, title: 'Step 2' }, + ]); + // Wire tutorial to the group. + await INSERT.into(GroupPathItems).entries({ + ID: 'gpi-2446', group_ID: 'g-2446', tutorial_ID: 't-2446', itemOrder: 1, legacyId: 9101, + }); + + const now = new Date().toISOString(); + // Partial progress: step 1 done, tutorial IN_PROGRESS (never completed). + // The group TaskRecord is COMPLETED — simulating the pre-#2446-fix state where + // completing a single step caused a full group rollup. + await INSERT.into(TaskRecords).entries([ + { ID: 'tr-2446-s1', user_ID: 'u-2446', taskLegacyId: 6101, taskType: 'STEP', + status: 'COMPLETED', progress: 100, completionDate: now, attemptNumber: 1, legacyId: 8101 }, + { ID: 'tr-2446-tut', user_ID: 'u-2446', taskLegacyId: 6001, taskType: 'TUTORIAL', + status: 'IN_PROGRESS', progress: 50, attemptNumber: 1, legacyId: 8102 }, + { ID: 'tr-2446-grp', user_ID: 'u-2446', taskLegacyId: 9001, taskType: 'GROUP', + status: 'COMPLETED', progress: 100, completionDate: now, attemptNumber: 1, legacyId: 8103 }, + ]); + + cds.context = { user: new cds.User({ id: 'sap-u2446' }) }; + const { DeveloperService } = cds.services; + // Partial reset must succeed (gate relaxed). + const result = await DeveloperService.send({ + event: 'resetTutorialProgress', + data: { slug: 'tut-2446' }, + }); + expect(result.newAttemptNumber).toBe(2); + expect(result.previousAttemptCompletedAt).toBeNull(); + + // Assert: getProgress returns empty completedSteps — fresh attempt reads nothing. + cds.context = { user: new cds.User({ id: 'sap-u2446' }) }; + const progress = await DeveloperService.send({ + event: 'getProgress', + data: { slug: 'tut-2446' }, + }); + expect(progress.completedSteps).toEqual([]); + + // Assert: parent GROUP TaskRecord is NOT COMPLETED — rollUpParentsForCompletion + // with allowDowngrade:true downgraded it. This is the core #2446 symptom check: + // a partial reset must not leave stale/phantom completion records on parents. + const grpRow = await SELECT.one.from(TaskRecords).where({ user_ID: 'u-2446', taskType: 'GROUP' }); + expect(grpRow).toBeDefined(); + expect(grpRow.status).not.toBe('COMPLETED'); }); it('rejects unknown slug with 404', async () => { From 72442471e2b8678c9f3c3ad12a93678383519db6 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Fri, 13 Nov 2026 13:36:48 -0600 Subject: [PATCH 05/59] feat(reset): show Reset button at any progress + accurate confirm copy (#3120) --- .../src/tutorial-reset/TutorialReset.test.ts | 16 ++++++++++++---- hugo-apps/src/tutorial-reset/TutorialReset.vue | 17 +++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hugo-apps/src/tutorial-reset/TutorialReset.test.ts b/hugo-apps/src/tutorial-reset/TutorialReset.test.ts index bb7b1bad1..162a2d59c 100644 --- a/hugo-apps/src/tutorial-reset/TutorialReset.test.ts +++ b/hugo-apps/src/tutorial-reset/TutorialReset.test.ts @@ -129,12 +129,12 @@ function getVm(wrapper: ReturnType): VmExposed { // ───────────────────────────────────────────────────────────────────── describe('TutorialReset.vue — mount: getProgress branch', () => { - it('hides the reset button when progress is partial (completed < stepCount)', async () => { - setStepCount(5); - fetchMock.mockResolvedValueOnce(mockFetchResponse({ completedSteps: [1, 2, 3] })); + it('shows the reset button when there is partial progress', async () => { + setStepCount(3); + fetchMock.mockResolvedValueOnce(mockFetchResponse({ completedSteps: [1] })); const wrapper = await mountReset(); - expect(getVm(wrapper).showReset).toBe(false); + expect(getVm(wrapper).showReset).toBe(true); // Sanity: getProgress was the only fetch expect(fetchMock).toHaveBeenCalledTimes(1); @@ -142,6 +142,14 @@ describe('TutorialReset.vue — mount: getProgress branch', () => { expect(fetchMock.mock.calls[0][0]).toContain('slug=test-tutorial'); }); + it('hides the reset button when there is zero progress', async () => { + setStepCount(3); + fetchMock.mockResolvedValueOnce(mockFetchResponse({ completedSteps: [] })); + + const wrapper = await mountReset(); + expect(getVm(wrapper).showReset).toBe(false); + }); + it('shows the reset button when progress is complete (completed === stepCount)', async () => { setStepCount(3); fetchMock.mockResolvedValueOnce(mockFetchResponse({ completedSteps: [1, 2, 3] })); diff --git a/hugo-apps/src/tutorial-reset/TutorialReset.vue b/hugo-apps/src/tutorial-reset/TutorialReset.vue index 6e99e3e2a..62b3f4207 100644 --- a/hugo-apps/src/tutorial-reset/TutorialReset.vue +++ b/hugo-apps/src/tutorial-reset/TutorialReset.vue @@ -9,10 +9,9 @@ interface Props { const props = defineProps(); -// Whether to surface the reset button. We only show it AFTER the learner has -// completed every step of the tutorial — for partial-progress, "Reset" would -// imply nuking work they may not have intended to lose. The dataset.stepCount -// attribute is emitted on by the Hugo tutorial layout (Task 21). +// Whether to surface the reset button. We show it whenever the learner has +// ANY progress (completedCount > 0) so they can reset at any point, not only +// at full completion. The backend gate was relaxed in Task 4 (#3120). const showReset = ref(false); // Dialog open state — drives an imperative `.open` property write on the @@ -70,12 +69,6 @@ onMounted(async () => { const el = getDialogEl(); if (el) el.open = false; - // Read step-count from (Task 21 emits this). - // If the attribute is missing or malformed, default to a large number so - // we never wrongly surface the reset button on incomplete progress. - const stepCount = Number(document.documentElement.dataset.stepCount ?? '999'); - if (!Number.isFinite(stepCount) || stepCount <= 0) return; - try { const res = await fetch(`/api/getProgress?slug=${encodeURIComponent(props.slug)}`, { credentials: 'include', @@ -84,7 +77,7 @@ onMounted(async () => { const data = await res.json(); const completed: unknown = data?.completedSteps; const completedCount = Array.isArray(completed) ? completed.length : 0; - if (completedCount >= stepCount) { + if (completedCount > 0) { showReset.value = true; } } catch { @@ -196,7 +189,7 @@ defineExpose({ @close="closeDialog" >

- This will clear your completion record for this tutorial and + This will clear all your progress for this tutorial and you'll start again from step 1. Your other tutorials are unaffected.