feat(#71): implement graph data API
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>
This commit is contained in:
102
docs/scratchpads/orch-110-git-ops.md
Normal file
102
docs/scratchpads/orch-110-git-ops.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# ORCH-110: Git Operations (clone, commit, push)
|
||||
|
||||
## Objective
|
||||
|
||||
Implement git operations service using simple-git library to support agent git workflows.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [x] `src/git/git-operations.service.ts` implemented
|
||||
- [x] Clone repository
|
||||
- [x] Create branch
|
||||
- [x] Commit changes with message
|
||||
- [x] Push to remote
|
||||
- [x] Git config (user.name, user.email from environment)
|
||||
- [x] NestJS service with proper dependency injection
|
||||
- [x] Comprehensive unit tests following TDD principles
|
||||
- [x] Mock simple-git for unit tests (no actual git operations)
|
||||
- [x] Test coverage >= 85%
|
||||
|
||||
## Approach
|
||||
|
||||
Following TDD (Red-Green-Refactor):
|
||||
|
||||
1. **RED**: Write failing tests first
|
||||
- Test git config setup
|
||||
- Test clone repository
|
||||
- Test create branch
|
||||
- Test commit changes
|
||||
- Test push to remote
|
||||
- Test error handling
|
||||
|
||||
2. **GREEN**: Implement minimum code to pass tests
|
||||
- Create GitOperationsService with NestJS
|
||||
- Implement each git operation
|
||||
- Use simple-git library
|
||||
- Read config from ConfigService
|
||||
|
||||
3. **REFACTOR**: Improve code quality
|
||||
- Extract common patterns
|
||||
- Improve error messages
|
||||
- Add type safety
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
### Service Interface
|
||||
|
||||
```typescript
|
||||
class GitOperationsService {
|
||||
async cloneRepository(url: string, localPath: string): Promise<void>
|
||||
async createBranch(localPath: string, branchName: string): Promise<void>
|
||||
async commit(localPath: string, message: string): Promise<void>
|
||||
async push(localPath: string, remote?: string, branch?: string): Promise<void>
|
||||
}
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
|
||||
- simple-git: Git operations
|
||||
- @nestjs/config: Configuration
|
||||
- ConfigService: Access git config (userName, userEmail)
|
||||
|
||||
### Testing Strategy
|
||||
|
||||
- Mock simple-git using vitest.fn()
|
||||
- No actual git operations in tests
|
||||
- Test all success paths
|
||||
- Test error handling
|
||||
- Verify git config is set
|
||||
- Verify correct parameters passed to simple-git
|
||||
|
||||
## Progress
|
||||
|
||||
- [x] Create test file with failing tests
|
||||
- [x] Implement GitOperationsService
|
||||
- [x] All tests passing
|
||||
- [x] Coverage >= 85%
|
||||
- [x] Update git.module.ts
|
||||
- [x] Create types file
|
||||
- [x] Add index.ts exports
|
||||
|
||||
## Testing Results
|
||||
|
||||
```bash
|
||||
pnpm test src/git/git-operations.service.spec.ts --run
|
||||
# Test Files 1 passed (1)
|
||||
# Tests 14 passed (14)
|
||||
|
||||
pnpm test src/git/git-operations.service.spec.ts --coverage --run
|
||||
# Coverage: 100% statements, 85.71% branches, 100% functions, 100% lines
|
||||
# Exceeds 85% requirement ✓
|
||||
|
||||
pnpm typecheck
|
||||
# No errors ✓
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- simple-git already in package.json (v3.27.0)
|
||||
- Git config already in orchestrator.config.ts
|
||||
- Service uses dependency injection for testability
|
||||
- All git operations async
|
||||
- Error handling preserves original error messages
|
||||
Reference in New Issue
Block a user