feat: v0.3.1 Quick Wins - Atomic Transactions & Input Validation#23
feat: v0.3.1 Quick Wins - Atomic Transactions & Input Validation#23
Conversation
Implement two quick wins for v0.3.1 (Issues #11 and #12): - Atomic multi-dependency transactions with all-or-nothing semantics - Input validation: max 100 deps/task, max 100 chain depth - New DependencyGraph.getMaxDepth() algorithm (DFS with memoization) - DependencyHandler refactored to use batch operations - 18 new comprehensive tests (221 total, was 203) Closes #11, Closes #12 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Compliance Guide 🔍(Compliance updated until commit 0d8379b)Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label Previous compliance checksCompliance check up to commit d85f619
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
…ication Addresses Qodo PR suggestion to centralize validation logic. Reduces addDependency method from ~120 lines to 13 lines. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…formance Fixes 6 issues identified in code review audit: 1. CRITICAL: Removed unused `visited` variable in getMaxDepth() - Dead code at src/core/dependency-graph.ts:378 2. HIGH: Removed redundant cycle detection in getMaxDepth() - Defensive check was unnecessary since callers validate - Lines 384-387 removed for cleaner code 3. HIGH: Extracted magic number 100 to named constants - Created MAX_DEPENDENCIES_PER_TASK = 100 - Created MAX_DEPENDENCY_CHAIN_DEPTH = 100 - Applied in 4 locations for better maintainability 4. BLOCKING: Fixed flaky performance test - Removed timing assertion that would fail in CI - Performance tests should be in separate benchmark suite 5. BLOCKING: Fixed Result pattern inconsistency - Changed getMaxDepth() return type from Result<number> to number - Method never errors, so Result wrapper was dead code - Updated all call sites and tests 6. HIGH: Optimized quadratic depth validation loop - Moved getMaxDepth() outside loop in addDependencies() - Reduced complexity from O(N * (V+E)) to O(V+E) - Calculate max depth once for all dependencies instead of per-dependency All 221 tests passing. Related: PR #23 code review findings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
User description
Summary
Implements two security and data consistency improvements for the task dependency system:
Changes
🔄 Atomic Batch Operations
addDependencies()method with all-or-nothing semantics🔒 Security Hardening
getMaxDepth()algorithm using DFS with memoization🧪 Test Coverage
Test plan
npm test- 221 tests)npm run build)Files Changed
src/core/interfaces.ts- AddedaddDependencies()to interfacesrc/core/dependency-graph.ts- AddedgetMaxDepth()algorithmsrc/implementations/dependency-repository.ts- Batch method + validationsrc/services/handlers/dependency-handler.ts- Atomic batch operationstests/unit/core/dependency-graph.test.ts- 7 new teststests/unit/implementations/dependency-repository.test.ts- 11 new testsCHANGELOG.md- Documented v0.3.1 changesCloses #11, Closes #12
🤖 Generated with Claude Code
PR Type
Enhancement, Tests
Description
Implements atomic batch dependency operations with all-or-nothing semantics
Adds input validation limits: max 100 dependencies per task, max 100 chain depth
New
DependencyGraph.getMaxDepth()algorithm using DFS with memoizationRefactors DependencyHandler to use atomic batch operations for consistency
Adds 18 comprehensive tests covering rollback, validation, and edge cases
Diagram Walkthrough
File Walkthrough
dependency-graph.ts
Add chain depth calculation algorithmsrc/core/dependency-graph.ts
getMaxDepth()method to calculate longest dependency chain froma task
interfaces.ts
Add batch dependency interface methodsrc/core/interfaces.ts
addDependencies()method signature to DependencyRepositoryinterface
dependency-repository.ts
Implement atomic batch operations and validation limitssrc/implementations/dependency-repository.ts
addDependency()getMaxDepth()to prevent stackoverflow
addDependencies()method with atomic transactionsemantics
.transaction()for true ACID complianceduplicates, task existence
dependency-handler.ts
Refactor to use atomic batch dependency operationssrc/services/handlers/dependency-handler.ts
handleTaskDelegated()to use atomicaddDependencies()instead of loop
dependency-graph.test.ts
Add comprehensive chain depth calculation teststests/unit/core/dependency-graph.test.ts
getMaxDepth()algorithm in new test suitediamond graphs
dependency-repository.test.ts
Add atomic batch and validation limit teststests/unit/implementations/dependency-repository.test.ts
duplicate, not found
verification
CHANGELOG.md
Document v0.3.1 features and test coverageCHANGELOG.md
deps, max 100 depth)
semantics