Implemented three new API endpoints for knowledge graph visualization: 1. GET /api/knowledge/graph - Full knowledge graph - Returns all entries and links with optional filtering - Supports filtering by tags, status, and node count limit - Includes orphan detection (entries with no links) 2. GET /api/knowledge/graph/stats - Graph statistics - Total entries and links counts - Orphan entries detection - Average links per entry - Top 10 most connected entries - Tag distribution across entries 3. GET /api/knowledge/graph/:slug - Entry-centered subgraph - Returns graph centered on specific entry - Supports depth parameter (1-5) for traversal distance - Includes all connected nodes up to specified depth New Files: - apps/api/src/knowledge/graph.controller.ts - apps/api/src/knowledge/graph.controller.spec.ts Modified Files: - apps/api/src/knowledge/dto/graph-query.dto.ts (added GraphFilterDto) - apps/api/src/knowledge/entities/graph.entity.ts (extended with new types) - apps/api/src/knowledge/services/graph.service.ts (added new methods) - apps/api/src/knowledge/services/graph.service.spec.ts (added tests) - apps/api/src/knowledge/knowledge.module.ts (registered controller) - apps/api/src/knowledge/dto/index.ts (exported new DTOs) - docs/scratchpads/71-graph-data-api.md (implementation notes) Test Coverage: 21 tests (all passing) - 14 service tests including orphan detection, filtering, statistics - 7 controller tests for all three endpoints Follows TDD principles with tests written before implementation. All code quality gates passed (lint, typecheck, tests). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
5.2 KiB
5.2 KiB
ORCH-112: Conflict Detection
Objective
Implement conflict detection service that detects merge conflicts before pushing to remote. This is the final git integration feature for Phase 3.
Approach
Architecture
- ConflictDetectionService: NestJS service that:
- Fetches latest changes from remote before push
- Detects merge conflicts using simple-git
- Returns detailed conflict information
- Supports both merge and rebase strategies
Conflict Detection Strategy
- Fetch remote branch
- Try merge/rebase in dry-run mode (or check status after fetch)
- Detect conflicts by:
- Checking git status for conflicted files
- Parsing merge output for conflict markers
- Checking for unmerged paths
- Return structured conflict information with file paths and details
Integration Points
- Uses GitOperationsService for basic git operations
- Will be called by orchestrator before push operations
- Provides retry capability with different strategies
Progress
- Review requirements from ORCH-112
- Examine existing git services (GitOperationsService, WorktreeManagerService)
- Identify types structure and patterns
- Create scratchpad
- Write tests for ConflictDetectionService (TDD - RED)
- Implement ConflictDetectionService (TDD - GREEN)
- Refactor implementation (TDD - REFACTOR)
- Add types to types/conflict-detection.types.ts
- Export from types/index.ts
- Update git.module.ts to include ConflictDetectionService
- Update git/index.ts exports
- Verify tests pass with ≥85% coverage (95.77% achieved)
- Create Gitea issue
- Close Gitea issue with completion notes
Completion Summary
Implementation completed successfully with all acceptance criteria met:
- ConflictDetectionService implemented with full TDD approach
- Supports both merge and rebase strategies
- Comprehensive error handling with ConflictDetectionError
- 18 unit tests covering all scenarios
- Coverage: 95.77% (exceeds 85% requirement)
- Proper cleanup after conflict detection
- Integrated into GitModule and exported
Files created/modified:
- apps/orchestrator/src/git/conflict-detection.service.ts
- apps/orchestrator/src/git/conflict-detection.service.spec.ts
- apps/orchestrator/src/git/types/conflict-detection.types.ts
- apps/orchestrator/src/git/types/index.ts (updated)
- apps/orchestrator/src/git/git.module.ts (updated)
- apps/orchestrator/src/git/index.ts (updated)
Testing Strategy
Unit Tests (TDD)
-
No conflicts scenario:
- Fetch succeeds
- No conflicts detected
- Returns clean status
-
Merge conflicts detected:
- Fetch succeeds
- Merge shows conflicts
- Returns conflict details with file paths
-
Rebase conflicts detected:
- Fetch succeeds
- Rebase shows conflicts
- Returns conflict details
-
Fetch failure:
- Remote unavailable
- Throws appropriate error
-
Check before push:
- Integration with conflict detection
- Prevents push if conflicts exist
Mock Strategy
- Mock simple-git for all git operations
- Mock GitOperationsService where needed
- Test both merge and rebase strategies
Technical Notes
Key Methods
// Check for conflicts before push
async checkForConflicts(
localPath: string,
remote: string = 'origin',
branch: string = 'develop',
strategy: 'merge' | 'rebase' = 'merge'
): Promise<ConflictCheckResult>
// Fetch latest from remote
async fetchRemote(
localPath: string,
remote: string = 'origin'
): Promise<void>
// Detect conflicts in current state
async detectConflicts(
localPath: string
): Promise<ConflictInfo[]>
Types
interface ConflictCheckResult {
hasConflicts: boolean;
conflicts: ConflictInfo[];
strategy: 'merge' | 'rebase';
canRetry: boolean;
}
interface ConflictInfo {
file: string;
type: 'content' | 'delete' | 'add';
ours?: string;
theirs?: string;
}
class ConflictDetectionError extends Error {
constructor(
message: string,
operation: string,
cause?: Error
)
}
Implementation Details
Git Commands
git fetch origin branch- Fetch latestgit merge --no-commit --no-ff origin/branch- Test mergegit merge --abort- Abort test mergegit status --porcelain- Check for conflictsgit diff --name-only --diff-filter=U- List conflicted files
Conflict Detection Logic
- Save current state
- Fetch remote
- Attempt merge/rebase (no commit)
- Check status for "UU" markers (unmerged)
- Parse conflict information
- Abort merge/rebase
- Return conflict details
Notes
Design Decisions
- Use
--no-commitflag to test merge without committing - Support both merge and rebase strategies
- Provide detailed conflict information for agent retry
- Clean up after detection (abort merge/rebase)
Error Handling
- GitOperationError for git command failures
- ConflictDetectionError for detection-specific issues
- Return structured errors for agent consumption
Dependencies
- simple-git library (already used in GitOperationsService)
- NestJS @Injectable decorator
- Logger for debugging
Next Steps
- Start with TDD: Write failing tests first
- Implement minimal code to pass tests
- Refactor for clarity
- Ensure coverage ≥85%
- Create and close Gitea issue