feat(gatekeeper): add PR merge automation service
Some checks failed
ci/woodpecker/push/ci Pipeline failed

This commit is contained in:
2026-03-10 21:35:11 -05:00
parent 3289677056
commit 6e2b9a307e
27 changed files with 1089 additions and 64 deletions

View File

@@ -12,6 +12,7 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
## What Was Implemented
### Database Schema
- **FederationEventSubscription Model**: New table for storing event subscriptions
- Fields: id, workspaceId, connectionId, eventType, metadata, isActive, timestamps
- Unique constraint on (workspaceId, connectionId, eventType)
@@ -21,6 +22,7 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
### Core Services
**EventService** (`event.service.ts`)
- `subscribeToEventType()`: Subscribe to events from remote instance
- `unsubscribeFromEventType()`: Remove event subscription
- `publishEvent()`: Publish events to all subscribed connections
@@ -35,6 +37,7 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
**EventController** (`event.controller.ts`)
**Authenticated Endpoints (require AuthGuard):**
- `POST /api/v1/federation/events/subscribe` - Subscribe to event type
- `POST /api/v1/federation/events/unsubscribe` - Unsubscribe from event type
- `POST /api/v1/federation/events/publish` - Publish event to subscribers
@@ -43,12 +46,14 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
- `GET /api/v1/federation/events/messages/:id` - Get single event message
**Public Endpoints (signature-verified):**
- `POST /api/v1/federation/incoming/event` - Receive event from remote instance
- `POST /api/v1/federation/incoming/event/ack` - Receive event acknowledgment
### Type Definitions
**Added to `message.types.ts`:**
- `EventMessage`: Outgoing event structure
- `EventAck`: Event acknowledgment structure
- `EventMessageDetails`: Event message response type
@@ -57,6 +62,7 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
### Data Transfer Objects
**event.dto.ts:**
- `SubscribeToEventDto`: Subscribe request
- `UnsubscribeFromEventDto`: Unsubscribe request
- `PublishEventDto`: Publish event request
@@ -66,12 +72,14 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
## Testing
### Test Coverage
- **EventService**: 18 unit tests, **89.09% coverage**
- **EventController**: 11 unit tests, **83.87% coverage**
- **Total**: 29 tests, all passing
- **Coverage**: Exceeds 85% minimum requirement
### Test Scenarios Covered
- Subscription creation and deletion
- Event publishing to multiple subscribers
- Failed delivery handling
@@ -84,17 +92,21 @@ Successfully implemented EVENT message type for federation, enabling pub/sub eve
## Design Patterns
### Consistency with Existing Code
- Follows patterns from `QueryService` and `CommandService`
- Reuses existing `SignatureService` for message verification
- Reuses existing `FederationService` for instance identity
- Uses existing `FederationMessage` model with new `eventType` field
### Event Type Naming Convention
Hierarchical dot-notation:
- `entity.action` (e.g., "task.created", "user.updated")
- `entity.action.detail` (e.g., "task.status.changed")
### Security Features
- All events signature-verified (RSA)
- Timestamp validation (prevents replay attacks)
- Connection status validation (only active connections)
@@ -103,14 +115,18 @@ Hierarchical dot-notation:
## Technical Details
### Database Migration
File: `20260203_add_federation_event_subscriptions/migration.sql`
- Adds `eventType` column to `federation_messages`
- Creates `federation_event_subscriptions` table
- Adds appropriate indexes for performance
- Establishes foreign key relationships
### Integration
Updated `federation.module.ts`:
- Added `EventService` to providers
- Added `EventController` to controllers
- Exported `EventService` for use by other modules
@@ -126,6 +142,7 @@ Updated `federation.module.ts`:
## Files Created/Modified
### New Files (7)
- `apps/api/src/federation/event.service.ts` (470 lines)
- `apps/api/src/federation/event.service.spec.ts` (1,088 lines)
- `apps/api/src/federation/event.controller.ts` (199 lines)
@@ -135,11 +152,13 @@ Updated `federation.module.ts`:
- `docs/scratchpads/90-event-subscriptions.md` (185 lines)
### Modified Files (3)
- `apps/api/src/federation/types/message.types.ts` (+118 lines)
- `apps/api/src/federation/federation.module.ts` (+3 lines)
- `apps/api/prisma/schema.prisma` (+27 lines)
### Total Changes
- **2,395 lines added**
- **5 lines removed**
- **10 files changed**
@@ -147,20 +166,25 @@ Updated `federation.module.ts`:
## Key Features
### Server-Side Event Filtering
Events are only sent to instances with active subscriptions for that event type. This prevents unnecessary network traffic and processing.
### Acknowledgment Protocol
Simple ACK pattern confirms event delivery:
1. Publisher sends event
2. Receiver processes and returns ACK
3. Publisher updates delivery status
### Error Handling
- Failed deliveries marked as FAILED with error message
- Connection errors logged but don't crash the system
- Invalid signatures rejected immediately
### Subscription Management
- Subscriptions persist in database
- Can be activated/deactivated without deletion
- Support for metadata (extensibility)
@@ -168,6 +192,7 @@ Simple ACK pattern confirms event delivery:
## Future Enhancements (Not Implemented)
These were considered but deferred to future issues:
- Event replay/history
- Event filtering by payload fields
- Webhook support for event delivery
@@ -179,11 +204,13 @@ These were considered but deferred to future issues:
## Performance Considerations
### Scalability
- Database indexes on eventType, connectionId, workspaceId
- Efficient queries with proper WHERE clauses
- Server-side filtering reduces network overhead
### Monitoring
- All operations logged with appropriate level
- Failed deliveries tracked in database
- Delivery timestamps recorded for analytics
@@ -191,12 +218,14 @@ These were considered but deferred to future issues:
## Documentation
### Inline Documentation
- JSDoc comments on all public methods
- Clear parameter descriptions
- Return type documentation
- Usage examples in comments
### Scratchpad Documentation
- Complete implementation plan
- Design decisions documented
- Testing strategy outlined
@@ -205,6 +234,7 @@ These were considered but deferred to future issues:
## Integration Testing Recommendations
While unit tests are comprehensive, recommend integration testing:
1. Set up two federated instances
2. Subscribe from Instance A to Instance B events
3. Publish event from Instance B
@@ -214,6 +244,7 @@ While unit tests are comprehensive, recommend integration testing:
## Conclusion
FED-007 (EVENT Subscriptions) is **complete and ready for code review**. The implementation:
- ✅ Follows TDD principles
- ✅ Meets 85%+ code coverage requirement
- ✅ Passes all quality gates (lint, typecheck, tests)