feat(jobs): add job payload validation before enqueueing (#1136)#1876
Open
Dickson2015 wants to merge 1 commit into
Open
feat(jobs): add job payload validation before enqueueing (#1136)#1876Dickson2015 wants to merge 1 commit into
Dickson2015 wants to merge 1 commit into
Conversation
…e#1136) Introduce JobPayloadValidatorService and per-queue class-validator schemas to reject malformed job payloads at the addJob() boundary, preventing bad data from ever entering the queue. Changes: - Add InvalidJobPayloadException (422 Unprocessable Entity) to app.exceptions.ts - Add job-payload.schemas.ts with 17 schema classes covering every typed queue: payouts, email, exports, reports, cleanup, maintenance, webhooks, analytics, quests, and dependency-freshness - Add job-payload-validator.service.ts with validate()/assertValid() supporting single-schema and multi-schema (union) queues; strips internal __trace keys before validation - Wire JobPayloadValidatorService into JobsService.addJob(); queues with no registered schema (notifications, scheduled, dead_letter) pass through without constraint - Register and export JobPayloadValidatorService in JobsModule - Add 48 unit tests (job-payload-validator.spec.ts) - Add 21 integration tests (jobs-payload-validation.integration-spec.ts) exercising the full addJob() → validator → queue.add() pipeline with BullMQ stubbed out All 69 new tests pass.
|
@Dickson2015 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! 🚀 |
Contributor
|
Great job so far There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass? |
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.
Linked Issue
Closes #1136
Description
What changed?
Introduces per-queue payload validation at the
JobsService.addJob()boundary. Malformed job payloads are now rejected with a422 Unprocessable Entityerror before they can enter any BullMQ queue, preventing silent bad data from being processed by workers.Why was it changed?
Issue #1136 identified that
addJob()accepted any payload without validation, allowing malformed jobs to sit in queues where they would fail at processing time with unhelpful errors. Validating at enqueue time provides an immediate, descriptive error to the caller and keeps queues clean.How was it implemented?
InvalidJobPayloadException(422) toapp.exceptions.tsjob-payload.schemas.tswith 17 class-validator schema classes, one per job shape, covering all typed queuesJobPayloadValidatorServicewith:validate(queue, data)— returns error strings or[]assertValid(queue, data)— throwsInvalidJobPayloadExceptionon failure__tracekeys added byTracingServicebefore validationassertValid()intoJobsService.addJob()before the queue enqueue callJobPayloadValidatorServiceinJobsModuleType of Change
Contract Changelog Discipline
Test Evidence
Unit Tests
npm run test)Integration Tests
addJob() → validator → queue.add()pipelineSwagger / API Documentation
Error Handling Checklist
InvalidJobPayloadExceptionextendsHttpExceptionwith422 Unprocessable EntityErrorthrown where an HTTP exception is expectederrorsarrayDatabase / Migration
Breaking Type / Model Changes (Frontend — FE-068)
Final Pre-Merge Checklist
mainconsole.log/ debug statements left in production codeAdditional Notes for Reviewer
notifications,scheduled,dead_letter) pass through any payload unchanged — these receive lightweight internal trigger objects validated upstream.__tracekey injected byTracingServiceis stripped before schema validation runs, so tracing context never causes false validation failures.JobPayloadValidatorServiceis optional in theJobsServiceconstructor (private readonly payloadValidator?: JobPayloadValidatorService) for backwards compatibility in existing unit tests that don't provide it.