src/store/test-coverage.md
Overall Coverage: ~80% (94 test files, 1263 tests) šÆ
Breakdown:
Action Files Coverage: 40/40 tested (100%) š
All high priority files now have tests! ā
All medium priority files now have tests! ā
All 40 action files in the store now have comprehensive test coverage!
All store action tests should follow the patterns documented in:
.agents/skills/testing/references/zustand-store-action-test.mdKey principles:
act()useSWR globally and return data synchronouslyWhen to use subagents:
Subagent workflow:
Example usage:
Testing 3 files in discover store:
DO NOT:
For each action file, ensure:
Pattern 1: Simple Action File
store/domain/slices/feature/
āāā action.ts
āāā action.test.ts
āāā selectors.ts
āāā selectors.test.ts
Pattern 2: Complex Actions (Subdirectory)
store/domain/slices/feature/
āāā actions/
ā āāā __tests__/
ā ā āāā action1.test.ts
ā ā āāā action2.test.ts
ā āāā action1.ts
ā āāā action2.ts
ā āāā index.ts
āāā selectors/
IMPORTANT: Follow this complete workflow for every testing task. ALL steps are REQUIRED.
For files with multiple action files to test, use the Task tool to create subagents that work in parallel:
Workflow:
Example subagent prompt:
Write comprehensive tests for src/store/discover/slices/plugin/action.ts following .agents/skills/testing/references/zustand-store-action-test.md.
Requirements:
1. Write tests covering all actions in the file
2. Follow SWR hooks testing pattern (if applicable)
3. run type-check and lint to verify
4. Run tests to ensure they pass
5. Report back with:
- Number of tests written
- Test coverage areas
- Any issues encountered
DO NOT:
- Commit changes
- Update test-coverage.md
- Work on other action files
Benefits of subagents:
# List all action files without tests
for file in $(find src/store -name "action.ts" | grep -v test | sort); do
testfile="${file%.ts}.test.ts"
if [ ! -f "$testfile" ]; then
echo "ā $file"
fi
done
# 1. Write tests following the testing guide
# 2. Run tests to verify they pass
bunx vitest run --silent='passed-only' 'src/store/[domain]/slices/[slice]/action.test.ts'
# For actions in subdirectories:
bunx vitest run --silent='passed-only' 'src/store/[domain]/slices/[slice]/actions/__tests__/[action].test.ts'
CRITICAL: Run type check and lint before proceeding. Failing these checks means the task is incomplete.
# Check TypeScript types (from project root)
bun run type-check
# Fix any linting issues
bunx eslint src/store/[domain]/ --fix
Common Type Errors to Watch For:
Do NOT proceed to Step 3 if type/lint checks fail!
# Run coverage to get updated metrics
bunx vitest run --coverage 'src/store'
Before updating documentation, create a summary of what was accomplished:
Summary Checklist:
Example Summary:
Store: chat/slices/aiChat
Coverage: 65% ā 82% (+17%)
Tests Added: 52 new tests
Features Tested:
- Message streaming with tool calls
- RAG integration and chunk retrieval
- Error handling for API failures
- Abort controller management
Bugs Fixed: None
Guide Updates: Added streaming response mocking pattern
Based on your development summary, update the following sections:
Current Status section:
Coverage Status by Priority section:
Completed Work section:
# Verify all tests still pass
bunx vitest run 'src/store'
# Verify type check still passes
bun run type-check
# 1. Development Phase
# ... write code and tests ...
bunx vitest run --silent='passed-only' 'src/store/tool/slices/mcpStore/action.test.ts'
# 2. Type/Lint Phase (REQUIRED)
bun run type-check # Must pass!
bunx eslint src/store/tool/ --fix
# 3. Coverage Phase
bunx vitest run --coverage 'src/store'
# 4. Summarization Phase
# Create summary following the checklist above
# 5. Documentation Phase
# Update this file with summary and metrics
# 6. Final Verification
bunx vitest run 'src/store'
bun run type-check
# 7. Commit
git add .
git commit -m "ā
test: add comprehensive tests for mcpStore actions"
Scenario: Testing all discover store slices (plugin, mcp, assistant, model, provider)
Step 1: Launch Subagents in Parallel
Create 5 subagents, one for each action file:
// Launch all subagents in a single message with multiple Task tool calls
Task({
subagent_type: 'general-purpose',
description: 'Test plugin action',
prompt: `Write comprehensive tests for src/store/discover/slices/plugin/action.ts following .agents/skills/testing/references/zustand-store-action-test.md.
Requirements:
1. Write tests covering all actions (usePluginCategories, usePluginDetail, usePluginList, usePluginIdentifiers)
2. Follow SWR hooks testing pattern
3. run type-check and lint to verify
4. Run tests to ensure they pass
5. Report back with number of tests written and coverage areas
DO NOT commit changes or update test-coverage.md.`,
});
Task({
subagent_type: 'general-purpose',
description: 'Test mcp action',
prompt: `Write comprehensive tests for src/store/discover/slices/mcp/action.ts following .agents/skills/testing/references/zustand-store-action-test.md.
Requirements:
1. Write tests covering all actions (useFetchMcpDetail, useFetchMcpList, useMcpCategories)
2. Follow SWR hooks testing pattern
3. run type-check and lint to verify
4. Run tests to ensure they pass
5. Report back with number of tests written and coverage areas
DO NOT commit changes or update test-coverage.md.`,
});
// ... similar for assistant, model, provider ...
Step 2: Wait for All Subagents to Complete
Each subagent will:
Step 3: Review Results
After all subagents complete:
Step 4: Final Verification
# run type-check on entire project
bun run type-check
# Run lint on all new test files
bunx eslint src/store/discover/ --fix
# Run all new tests together
bunx vitest run 'src/store/discover/**/*.test.ts'
# Run coverage
bunx vitest run --coverage 'src/store'
Step 5: Update Documentation
# Update test-coverage.md with:
# - New overall coverage percentage
# - Number of new tests
# - List of newly tested action files
# - Session summary
Step 6: Create Single Commit
git add .
git commit -m "ā
test(store): add comprehensive tests for discover store
- Add tests for plugin, mcp, assistant, model, provider slices
- Coverage: X% ā Y% (+Z tests, 5 new test files)
- All tests pass typecheck and lint
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>"
Benefits:
Remember: A testing task is only complete when:
# Run all store tests
bunx vitest run 'src/store'
# Run all store tests with coverage
bunx vitest run --coverage 'src/store'
# Run specific store tests
bunx vitest run --silent='passed-only' 'src/store/[domain]/**/*.test.ts'
# Run specific action tests
bunx vitest run --silent='passed-only' 'src/store/[domain]/slices/[slice]/action.test.ts'
# Watch mode for development
bunx vitest watch 'src/store/[domain]/slices/[slice]/action.test.ts'
# Type check entire project (from project root)
bun run type-check
# Watch mode
bunx tsc --noEmit --watch
# Lint specific store
bunx eslint src/store/[domain]/ --fix
# Lint all stores
bunx eslint src/store/ --fix
# Lint without auto-fix (check only)
bunx eslint src/store/[domain]/
Session (2025-10-15 - Part 2): š 100% Action File Coverage Achieved!
discover/slices/assistant/action.test.ts - 10 tests covering assistant discovery (SWR hooks)discover/slices/provider/action.test.ts - 11 tests covering provider discovery (SWR hooks)discover/slices/model/action.test.ts - 12 tests covering model discovery (SWR hooks)knowledgeBase/slices/crud/action.test.ts - 19 tests covering KB CRUD operationsknowledgeBase/slices/content/action.test.ts - 10 tests covering KB content managementfile/slices/upload/action.test.ts - 18 tests covering file upload handlingfile/slices/chunk/action.test.ts - 18 tests covering file chunk operationsaiInfra/slices/aiModel/action.test.ts - 23 tests covering AI model managementchat/slices/thread/action.test.ts - 39 tests covering thread managementSession (2025-10-15 - Part 1): ā High Priority Files Testing Complete š
tool/slices/mcpStore/action.test.ts - 41 tests (1,120 LOC) covering MCP plugin managementfile/slices/fileManager/action.test.ts - 35 tests (692 LOC) covering file management operationsSession (2024-10-15): ā Discover Store Testing Complete
discover/slices/plugin/action.test.ts - 15 tests covering plugin discovery (SWR hooks)discover/slices/mcp/action.test.ts - 11 tests covering MCP discovery (SWR hooks)as any for test mock data where neededSession (2024-10-14): š Store Testing Documentation Created
Previous Work:
.agents/skills/testing/references/zustand-store-action-test.mdact() wrapper for state updates