diff --git a/.planning/phases/16-store-modularization/16-02-PLAN.md b/.planning/phases/16-store-modularization/16-02-PLAN.md index 707a6482..fd6c54ff 100644 --- a/.planning/phases/16-store-modularization/16-02-PLAN.md +++ b/.planning/phases/16-store-modularization/16-02-PLAN.md @@ -142,16 +142,50 @@ The goal is to reduce executeWorkflow from ~800 lines to ~200 lines of orchestra executeWorkflow refactored to ~200 lines, uses extracted modules, all tests pass + + Task 4: Add unit tests for execution modules + src/store/execution/__tests__/utils.test.ts, src/store/execution/__tests__/nodeExecutors.test.ts + +Create comprehensive tests for the extracted execution modules: + +1. Create src/store/execution/__tests__/utils.test.ts: + - Test topologicalSort with simple linear graph (A -> B -> C) + - Test topologicalSort with branching graph (A -> B, A -> C, B -> D, C -> D) + - Test topologicalSort throws on cycle detection (A -> B -> C -> A) + - Test topologicalSort with disconnected nodes + - Test buildProviderHeaders returns correct headers for each provider type + - Test buildProviderHeaders with missing API keys returns base headers only + - Test getSourceOutput for each node type returns correct type/value + +2. Create src/store/execution/__tests__/nodeExecutors.test.ts: + - Test executeImageInput returns { continue: true } (no-op) + - Test executePrompt returns { continue: true } (no-op) + - Test executeAnnotation updates outputImage when sourceImage provided + - Test executeOutput updates node data with connected content + - Test executeNanaBanana handles missing text input (returns error) + - Test executeLlmGenerate handles missing text input (returns error) + - Mock fetch for API call tests + - Mock updateNodeData to verify state updates + +Focus on testing the pure logic and error cases. API success paths can use mocked fetch responses. + + npm test passes with new tests, coverage report shows execution modules covered + Unit tests added for execution utilities and node executors, all tests pass + + Before declaring plan complete: - [ ] `npm run build` succeeds without errors -- [ ] `npm test` passes all tests +- [ ] `npm test` passes all tests (existing + new execution module tests) - [ ] executeWorkflow function reduced from ~800 to ~200 lines - [ ] Workflow execution still works (test with a simple prompt -> generate -> output flow) - [ ] regenerateNode still works - [ ] Error handling preserved +- [ ] topologicalSort has test coverage including cycle detection +- [ ] buildProviderHeaders has test coverage for all provider types +- [ ] Node executors have test coverage for error cases @@ -160,6 +194,7 @@ Before declaring plan complete: - All verification checks pass - executeWorkflow is significantly shorter and more readable - Node execution logic is isolated and testable +- Execution modules have comprehensive test coverage - No regression in workflow execution behavior diff --git a/.planning/phases/16-store-modularization/16-03-PLAN.md b/.planning/phases/16-store-modularization/16-03-PLAN.md index 3ec5e805..e6df2702 100644 --- a/.planning/phases/16-store-modularization/16-03-PLAN.md +++ b/.planning/phases/16-store-modularization/16-03-PLAN.md @@ -184,17 +184,62 @@ Target: Main store file reduced from ~2800 to ~1500 lines. Store composed from slices, main file significantly reduced, all functionality preserved + + Task 4: Add unit tests for slices + src/store/slices/__tests__/groupSlice.test.ts, src/store/slices/__tests__/persistenceSlice.test.ts + +Create comprehensive tests for the extracted slices: + +1. Create src/store/slices/__tests__/groupSlice.test.ts: + - Test createGroup calculates correct bounding box from node positions + - Test createGroup assigns unique colors to groups + - Test createGroup sets groupId on all provided nodes + - Test deleteGroup removes group and clears groupId from nodes + - Test addNodesToGroup updates nodes' groupId + - Test removeNodesFromGroup clears groupId + - Test toggleGroupLock toggles the locked state + - Test moveGroupNodes updates position of all nodes in group + - Use Zustand's testing pattern: create isolated store instance per test + +2. Create src/store/slices/__tests__/persistenceSlice.test.ts: + - Test setWorkflowMetadata sets all metadata fields + - Test setWorkflowName marks as unsaved + - Test markAsUnsaved sets hasUnsavedChanges to true + - Test saveToFile calls fetch with correct payload (mock fetch) + - Test saveToFile updates lastSavedAt and hasUnsavedChanges on success + - Test loadWorkflow hydrates nodes/edges and resets execution state + - Test loadWorkflow migrates legacy nanoBanana nodes + - Test clearWorkflow resets all state + - Test initializeAutoSave/cleanupAutoSave manage interval + - Mock fetch, localStorage, and imageStorage utilities + +Testing pattern for Zustand slices: +```typescript +const createTestStore = () => create()((...args) => ({ + ...createGroupSlice(...args), + // minimal mock of other state needed + nodes: [], + edges: [], +})); +``` + + npm test passes with new slice tests, coverage for group and persistence slices + Unit tests added for both slices, all tests pass, slice functionality verified + + Before declaring plan complete: - [ ] `npm run build` succeeds without errors -- [ ] `npm test` passes all tests +- [ ] `npm test` passes all tests (existing + new slice tests) - [ ] workflowStore.ts reduced from ~2800 to ~1500 lines - [ ] Group operations work (create, lock, delete) - [ ] Save/load workflow works - [ ] Auto-save works - [ ] All exports maintained for backward compatibility +- [ ] groupSlice has test coverage for all operations +- [ ] persistenceSlice has test coverage for save/load/auto-save @@ -203,6 +248,7 @@ Before declaring plan complete: - All verification checks pass - Store properly composed from slices - Each slice is focused and cohesive +- All slices have comprehensive test coverage - No regression in any store functionality - Phase 16 complete: Store Modularization achieved