test: undo/redo state integrity + ensureDataIds idempotency tests - #143
Conversation
✅ VERIFIEDReviewer: cb-team-reviewer Files Reviewed
SummaryPure test-only PR (zero production code changes). 50 new tests across two DI-extracted helper modules. undoRedoHelpers.js: Extracted dataIdHelpers.js: Extracted undoRedoState.test.js (27 tests): saveState (dedup, truncate redo, 50-cap, shift oldest, callbacks), undo (restore, consecutive, boundary guard), redo (restore, consecutive, boundary), interleaved cycles (full undo/redo traversal, rapid back-and-forth), resetHistory (clear + disable undo/redo + callbacks), canUndo/canRedo boundary conditions, state isolation (structuredClone independence), complex nested scheduleData round-trips. ensureDataIds.test.js (23 tests): ID assignment (single, multiple, cross-classroom), idempotency (existing preserved, multiple calls identical, three consecutive), mixed partial IDs, edge cases (null/undefined/empty/0 input, empty data, no days, empty day array, null classroom, non-array day, null items), ID format (non-empty, uniqueness ×100, base-36 chars), mutation behavior (same reference, in-place). Stage 1 — CorrectnessZero findings. No conflict markers. Imports resolve. Issue linkage (Closes #135, #137). No risk-flags triggered. Both DI extractions verified against source. Stage 2 — AdversarialZero findings. Dedup uses Evidence
|
Closes #135, Closes #137 - Extract undo/redo stack logic from History.js.html as DI pure module in tests/lib/undoRedoHelpers.js (saveState/undo/redo/resetHistory) - Extract ensureDataIds + generateUniqueId from JavaScript.html L881-900 as DI pure functions in tests/lib/dataIdHelpers.js - Add 27 tests in tests/unit/undoRedoState.test.js covering: - saveState dedup, redo truncation, 50-entry cap - undo/redo boundary guards, interleaved cycles - resetHistory, canUndo/canRedo, state isolation (structuredClone) - Complex nested scheduleData through undo/redo - Add 23 tests in tests/unit/ensureDataIds.test.js covering: - Adding IDs to items without them, idempotency across multiple calls - Mixed partial IDs, edge cases (null/undefined/empty/non-array) - ID format validation, mutation behavior - Update wiringContracts module count 13 → 15 Closes t-20260623135418587642-97909-0 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Agend-Agent: cb-team-impl Agend-Task: t-20260623135418587642-97909-0 Agend-Branch: test/wave3a-undo-redo-ensure-ids
7e2f6eb to
c327d31
Compare
What
Add comprehensive tests for undo/redo state management (#135) and ensureDataIds idempotency (#137).
Closes #135
Closes #137
How
createHistoryModuleundo/redo stack logic fromHistory.js.htmlL2-62 intotests/lib/undoRedoHelpers.js, preserving all behavioral contracts (dedup, redo truncation, 50-entry cap, boundary guards).ensureDataIds+generateUniqueIdfromJavaScript.htmlL881-900 intotests/lib/dataIdHelpers.jswith injectable ID generator for deterministic testing.tests/unit/undoRedoState.test.jscovering:tests/unit/ensureDataIds.test.jscovering:Scope
tests/lib/undoRedoHelpers.js(new),tests/lib/dataIdHelpers.js(new),tests/unit/undoRedoState.test.js(new),tests/unit/ensureDataIds.test.js(new),tests/unit/wiringContracts.test.js(count update)Verification
./workflow.sh t6— 8/8 PASS (t1-t5, t7-t9)npx vitest --run tests/unit/undoRedoState.test.js tests/unit/ensureDataIds.test.js— 50 tests passedgit diff --name-only origin/main...HEADshows only test filesfollows spec