feat: high-impact override approval workflow with state machine and audit trail - #1268
Open
gracepeterfejokwu wants to merge 1 commit into
Open
feat: high-impact override approval workflow with state machine and audit trail#1268gracepeterfejokwu wants to merge 1 commit into
gracepeterfejokwu wants to merge 1 commit into
Conversation
…udit trail
Implements a four-state approval workflow for high-impact overrides that
require a separate approver identity before execution.
State machine: requested → approved → applied (happy path)
requested/approved → rejected
requested/approved → expired (TTL elapsed)
Key invariants enforced at the service layer:
- Self-approval prevention: requester ≠ approver (no bypass via role)
- Expiry check on every mutating operation (atomically transitions to expired)
- Legal-transition guard (LEGAL_TRANSITIONS matrix)
- Apply-twice protection (OverrideRequestAlreadyAppliedError)
- Tenant isolation on every query (tenant_id predicate in all SQL)
Changes:
- db/migrations.ts: migration 18 adds override_requests table with full
state machine CHECK constraint, indexes on tenant_id/status/resource
- audit/types.ts + audit/service.ts: OVERRIDE_REQUESTED/APPROVED/REJECTED/
APPLIED/EXPIRED audit actions (CRITICAL severity)
- lib/types.ts: 'override-requests' added to Resource union
- modules/overrideRequests/: new module with types, repository, service,
schemas (Zod), and routes
- app.ts: register /api/v1/override-requests router
Tests (61 passing, 0 regressions):
- overrideRequest.service.test.ts: unit tests covering all 5 required edge
cases (request by operator, self-approval, expired request, rejected
request, apply twice), plus audit trail emission, tenant isolation,
list/pagination, and not-found paths
- overrideRequest.routes.test.ts: integration tests covering auth (401),
role authorization (403), full happy-path lifecycle, all edge cases at
the HTTP layer, error envelope shape, and no stack-trace leakage
Security notes:
- All SQL uses parameterised prepared statements
- Tenant isolation enforced at every repository query
- Audit events are CRITICAL severity and swallowed on failure to avoid
disrupting primary flow (error still logged)
- Reason/rejectionReason stored verbatim — callers must sanitise PII
- tenantId uses 'default' for admin/auditor roles (single-tenant);
documented as TODO for multi-tenant JWT claim upgrade
Closes Talenttrust#1221
|
@gracepeterfejokwu Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a four-state approval workflow for high-impact overrides that require a separate approver identity before execution.
State machine: requested → approved → applied (happy path)
requested/approved → rejected
requested/approved → expired (TTL elapsed)
Key invariants enforced at the service layer:
Changes:
Tests (61 passing, 0 regressions):
Security notes:
Closes #1221
Pino Structured Logging Implementation
Summary
This PR implements Pino-based structured logging with comprehensive redaction rules and request correlation ID support as requested in the issue.
Changes Made
Core Logger Implementation
Request Correlation Middleware
Enhanced Features
Testing
Security Improvements
[REDACTED]Performance Benefits
Usage Examples
Basic Usage
Request-Scoped Logging
Child Loggers
Configuration
The logger supports environment-based configuration:
LOG_LEVEL: Set logging level (trace, debug, info, warn, error, fatal)NODE_ENV: Determines production vs development settingsHOSTNAME: Optional hostname for log contextMigration Notes
Testing
The implementation includes comprehensive tests covering:
To run tests (when Node.js environment is available):
Files Changed
src/logger.ts: Complete rewrite with Pino implementationsrc/logger.test.ts: Updated tests for new implementationsrc/middleware/requestLogger.ts: New request correlation middlewaresrc/middleware/requestLogger.test.ts: Tests for middleware functionalitypackage.json: Added Pino dependenciesThis implementation fully satisfies the requirements for secure, tested, and documented structured logging with comprehensive redaction rules and request correlation support.