@nathapp/nestjs-queue 2.1.0-rc.1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CLAUDE.md +16 -0
  2. package/TODO.md +15 -0
  3. package/dist/decorator/batch-process.decorator.d.ts +11 -0
  4. package/dist/decorator/batch-process.decorator.js +13 -0
  5. package/dist/decorator/batch-process.decorator.js.map +1 -0
  6. package/dist/decorator/index.d.ts +1 -0
  7. package/dist/decorator/index.js +1 -0
  8. package/dist/decorator/index.js.map +1 -1
  9. package/dist/enum/provider.enum.d.ts +0 -1
  10. package/dist/enum/provider.enum.js +0 -1
  11. package/dist/enum/provider.enum.js.map +1 -1
  12. package/dist/explorer/processor.explorer.d.ts +3 -0
  13. package/dist/explorer/processor.explorer.js +43 -1
  14. package/dist/explorer/processor.explorer.js.map +1 -1
  15. package/dist/interface/batch.interface.d.ts +23 -0
  16. package/dist/interface/batch.interface.js +3 -0
  17. package/dist/interface/batch.interface.js.map +1 -0
  18. package/dist/interface/index.d.ts +1 -0
  19. package/dist/interface/index.js +1 -0
  20. package/dist/interface/index.js.map +1 -1
  21. package/dist/interface/queue-options.interface.d.ts +9 -9
  22. package/dist/interface/queue-provider.interface.d.ts +13 -0
  23. package/dist/interface/queue-provider.interface.js.map +1 -1
  24. package/dist/module/queue.module.d.ts +5 -0
  25. package/dist/module/queue.module.js +64 -0
  26. package/dist/module/queue.module.js.map +1 -1
  27. package/dist/module/queue.provider.js +0 -3
  28. package/dist/module/queue.provider.js.map +1 -1
  29. package/dist/provider/bullmq/bullmq.provider.d.ts +9 -0
  30. package/dist/provider/bullmq/bullmq.provider.js +104 -0
  31. package/dist/provider/bullmq/bullmq.provider.js.map +1 -1
  32. package/dist/provider/index.d.ts +0 -1
  33. package/dist/provider/index.js +0 -1
  34. package/dist/provider/index.js.map +1 -1
  35. package/dist/provider/kafka/kafka.provider.d.ts +7 -0
  36. package/dist/provider/kafka/kafka.provider.js +150 -0
  37. package/dist/provider/kafka/kafka.provider.js.map +1 -1
  38. package/dist/provider/rabbitmq/rabbitmq.provider.d.ts +9 -0
  39. package/dist/provider/rabbitmq/rabbitmq.provider.js +171 -0
  40. package/dist/provider/rabbitmq/rabbitmq.provider.js.map +1 -1
  41. package/dist/utils/delayed-scheduler.js +2 -1
  42. package/dist/utils/delayed-scheduler.js.map +1 -1
  43. package/docs/BATCH_PROCESSING_PLAN.md +581 -0
  44. package/docs/COVERAGE_IMPLEMENTATION_TASKS.md +664 -0
  45. package/docs/COVERAGE_RECOVERY_PLAN.md +254 -0
  46. package/docs/IMPLEMENTATION_PLAN_FOR_PRODUCER.md +82 -0
  47. package/package.json +3 -2
  48. package/dist/provider/redis-pubsub/index.d.ts +0 -1
  49. package/dist/provider/redis-pubsub/index.js +0 -18
  50. package/dist/provider/redis-pubsub/index.js.map +0 -1
  51. package/dist/provider/redis-pubsub/redis-pubsub.provider.d.ts +0 -40
  52. package/dist/provider/redis-pubsub/redis-pubsub.provider.js +0 -226
  53. package/dist/provider/redis-pubsub/redis-pubsub.provider.js.map +0 -1
@@ -0,0 +1,664 @@
1
+ # Coverage Recovery: Detailed Implementation Tasks
2
+
3
+ **Purpose**: Step-by-step tasks for lower-cost model coordination
4
+ **Target**: Branch coverage 72.14% → 80%+
5
+ **Workspace**: `packages/nestjs-queue`
6
+
7
+ ---
8
+
9
+ ## How to Use This Document
10
+
11
+ Each task is atomic and self-contained. Execute tasks in order within each phase. After each task:
12
+
13
+ 1. Run the specified test command
14
+ 2. If tests pass, commit with the provided message
15
+ 3. Move to the next task
16
+
17
+ Use `claude-coding-agent` with this prompt pattern:
18
+ ```
19
+ cd packages/nestjs-queue && claude --permission-mode bypassPermissions "TASK: [Task ID] - [Task Name]
20
+
21
+ [Copy task details here]
22
+
23
+ When done, commit and run: openclaw system event --text '[Task ID] complete' --mode now"
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Phase 1: Lock Renewal Tests (+8% branches)
29
+
30
+ ### Task 1.1: Create Lock Renewal Test File
31
+
32
+ **File to create**: `test/utils/lock-renewal.spec.ts`
33
+
34
+ **Code**:
35
+ ```typescript
36
+ import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals';
37
+ import { LockRenewal } from '../../lib/utils/lock-renewal';
38
+ import { IdempotencyStore } from '../../lib/interface/idempotency-store.interface';
39
+
40
+ describe('LockRenewal', () => {
41
+ let mockStore: jest.Mocked<IdempotencyStore>;
42
+ let lockRenewal: LockRenewal;
43
+
44
+ beforeEach(() => {
45
+ jest.useFakeTimers();
46
+ mockStore = {
47
+ markProcessing: jest.fn(),
48
+ markComplete: jest.fn(),
49
+ isProcessed: jest.fn(),
50
+ releaseLock: jest.fn(),
51
+ extendLock: jest.fn(),
52
+ close: jest.fn(),
53
+ } as any;
54
+ });
55
+
56
+ afterEach(() => {
57
+ if (lockRenewal) {
58
+ lockRenewal.stop();
59
+ }
60
+ jest.useRealTimers();
61
+ });
62
+
63
+ describe('constructor', () => {
64
+ it('should initialize with correct parameters', () => {
65
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 15000);
66
+ expect(lockRenewal).toBeDefined();
67
+ });
68
+
69
+ it('should default renewalInterval to lockTtl / 2', () => {
70
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000);
71
+ // Internal check via behavior - will extend at 15000ms
72
+ mockStore.extendLock!.mockResolvedValue(true);
73
+ lockRenewal.start();
74
+ jest.advanceTimersByTime(15000);
75
+ expect(mockStore.extendLock).toHaveBeenCalled();
76
+ });
77
+ });
78
+
79
+ describe('start', () => {
80
+ it('should not start if store does not support extendLock', () => {
81
+ const storeWithoutExtend = {
82
+ markProcessing: jest.fn(),
83
+ markComplete: jest.fn(),
84
+ isProcessed: jest.fn(),
85
+ releaseLock: jest.fn(),
86
+ close: jest.fn(),
87
+ } as any;
88
+ lockRenewal = new LockRenewal(storeWithoutExtend, 'job-123', 30000, 15000);
89
+ lockRenewal.start();
90
+ jest.advanceTimersByTime(20000);
91
+ // No error thrown, just doesn't do anything
92
+ expect(true).toBe(true);
93
+ });
94
+
95
+ it('should call extendLock at intervals', () => {
96
+ mockStore.extendLock!.mockResolvedValue(true);
97
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
98
+ lockRenewal.start();
99
+
100
+ jest.advanceTimersByTime(10000);
101
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
102
+ expect(mockStore.extendLock).toHaveBeenCalledWith('job-123', 30000);
103
+
104
+ jest.advanceTimersByTime(10000);
105
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(2);
106
+
107
+ jest.advanceTimersByTime(10000);
108
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(3);
109
+ });
110
+
111
+ it('should stop if extendLock returns false', async () => {
112
+ mockStore.extendLock!.mockResolvedValue(false);
113
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
114
+ lockRenewal.start();
115
+
116
+ jest.advanceTimersByTime(10000);
117
+ await Promise.resolve(); // Let async complete
118
+
119
+ jest.advanceTimersByTime(10000);
120
+ // Should only be called once since it stopped after first false
121
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
122
+ });
123
+
124
+ it('should handle extendLock errors gracefully', async () => {
125
+ mockStore.extendLock!.mockRejectedValue(new Error('Redis error'));
126
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
127
+
128
+ // Should not throw
129
+ lockRenewal.start();
130
+ jest.advanceTimersByTime(10000);
131
+ await Promise.resolve();
132
+
133
+ // Should continue despite error
134
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
135
+ });
136
+
137
+ it('should not start multiple times', () => {
138
+ mockStore.extendLock!.mockResolvedValue(true);
139
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
140
+ lockRenewal.start();
141
+ lockRenewal.start(); // Second call should be ignored
142
+
143
+ jest.advanceTimersByTime(10000);
144
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
145
+ });
146
+ });
147
+
148
+ describe('stop', () => {
149
+ it('should clear the interval', () => {
150
+ mockStore.extendLock!.mockResolvedValue(true);
151
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
152
+ lockRenewal.start();
153
+
154
+ jest.advanceTimersByTime(10000);
155
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
156
+
157
+ lockRenewal.stop();
158
+
159
+ jest.advanceTimersByTime(10000);
160
+ // Should still be 1 since we stopped
161
+ expect(mockStore.extendLock).toHaveBeenCalledTimes(1);
162
+ });
163
+
164
+ it('should be safe to call multiple times', () => {
165
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
166
+ lockRenewal.start();
167
+ lockRenewal.stop();
168
+ lockRenewal.stop();
169
+ lockRenewal.stop();
170
+ // No error thrown
171
+ expect(true).toBe(true);
172
+ });
173
+
174
+ it('should be safe to call before start', () => {
175
+ lockRenewal = new LockRenewal(mockStore, 'job-123', 30000, 10000);
176
+ lockRenewal.stop();
177
+ // No error thrown
178
+ expect(true).toBe(true);
179
+ });
180
+ });
181
+ });
182
+ ```
183
+
184
+ **Test command**:
185
+ ```bash
186
+ npm test -- test/utils/lock-renewal.spec.ts --coverage --collectCoverageFrom='lib/utils/lock-renewal.ts'
187
+ ```
188
+
189
+ **Expected coverage**: lock-renewal.ts → 90%+
190
+
191
+ **Commit message**: `test(utils): add comprehensive lock-renewal tests`
192
+
193
+ ---
194
+
195
+ ## Phase 2: BullMQ Batch Processing Tests (+4% branches)
196
+
197
+ ### Task 2.1: Add Batch Processing Tests to BullMQ Provider
198
+
199
+ **File to modify**: `test/bullmq.provider.spec.ts`
200
+
201
+ **Add this describe block** at the end of the file (before the final `});`):
202
+
203
+ ```typescript
204
+ describe('Batch Processing', () => {
205
+ describe('processBatch', () => {
206
+ it('should register batch worker for queue', async () => {
207
+ const batchProcessor = jest.fn<any>().mockResolvedValue({
208
+ totalJobs: 2,
209
+ successful: 2,
210
+ failed: 0,
211
+ results: [],
212
+ processingTimeMs: 100,
213
+ });
214
+
215
+ await provider.processBatch('batch-queue', batchProcessor, {
216
+ batchSize: 10,
217
+ batchTimeout: 5000,
218
+ });
219
+
220
+ expect(Worker).toHaveBeenCalledWith(
221
+ 'batch-queue',
222
+ expect.any(Function),
223
+ expect.objectContaining({
224
+ concurrency: 10,
225
+ }),
226
+ );
227
+ });
228
+
229
+ it('should accumulate jobs and call processor when batchSize reached', async () => {
230
+ const batchProcessor = jest.fn<any>().mockResolvedValue({
231
+ totalJobs: 2,
232
+ successful: 2,
233
+ failed: 0,
234
+ results: [
235
+ { jobId: 'job-1', success: true },
236
+ { jobId: 'job-2', success: true },
237
+ ],
238
+ processingTimeMs: 100,
239
+ });
240
+
241
+ let workerCallback: any;
242
+ (Worker as jest.MockedClass<typeof Worker>).mockImplementation((_queueName, callback) => {
243
+ workerCallback = callback;
244
+ return mockWorker as any;
245
+ });
246
+
247
+ await provider.processBatch('batch-queue', batchProcessor, {
248
+ batchSize: 2,
249
+ batchTimeout: 5000,
250
+ });
251
+
252
+ // Simulate two jobs arriving
253
+ const job1 = { id: 'job-1', name: 'test', data: {}, moveToCompleted: jest.fn() } as any;
254
+ const job2 = { id: 'job-2', name: 'test', data: {}, moveToCompleted: jest.fn() } as any;
255
+
256
+ await workerCallback(job1);
257
+ await workerCallback(job2);
258
+
259
+ // Batch processor should have been called
260
+ expect(batchProcessor).toHaveBeenCalled();
261
+ });
262
+
263
+ it('should use default options when not provided', async () => {
264
+ const batchProcessor = jest.fn<any>().mockResolvedValue({
265
+ totalJobs: 0,
266
+ successful: 0,
267
+ failed: 0,
268
+ results: [],
269
+ processingTimeMs: 0,
270
+ });
271
+
272
+ await provider.processBatch('batch-queue', batchProcessor);
273
+
274
+ expect(Worker).toHaveBeenCalledWith(
275
+ 'batch-queue',
276
+ expect.any(Function),
277
+ expect.objectContaining({
278
+ concurrency: 10, // default batchSize
279
+ }),
280
+ );
281
+ });
282
+ });
283
+
284
+ describe('addBatch', () => {
285
+ it('should add multiple jobs with batch grouping', async () => {
286
+ const jobs = [
287
+ { name: 'job1', data: { value: 1 } },
288
+ { name: 'job2', data: { value: 2 } },
289
+ ];
290
+
291
+ const mockJobs = jobs.map((job, index) => ({
292
+ id: `batch-${index}`,
293
+ name: job.name,
294
+ data: job.data,
295
+ opts: {},
296
+ timestamp: Date.now(),
297
+ attemptsMade: 0,
298
+ }));
299
+
300
+ mockQueue.addBulk.mockResolvedValue(mockJobs as any);
301
+
302
+ const result = await provider.addBatch('batch-queue', jobs, 'batch-123');
303
+
304
+ expect(mockQueue.addBulk).toHaveBeenCalled();
305
+ expect(result).toHaveLength(2);
306
+ });
307
+ });
308
+ });
309
+ ```
310
+
311
+ **Test command**:
312
+ ```bash
313
+ npm test -- test/bullmq.provider.spec.ts --coverage --collectCoverageFrom='lib/provider/bullmq/bullmq.provider.ts'
314
+ ```
315
+
316
+ **Commit message**: `test(bullmq): add batch processing tests`
317
+
318
+ ---
319
+
320
+ ## Phase 3: ProcessorExplorer Batch Integration Tests (+3% branches)
321
+
322
+ ### Task 3.1: Add Batch Discovery Tests
323
+
324
+ **File to modify**: `test/processor.explorer.spec.ts`
325
+
326
+ **Add this describe block** after the existing test blocks:
327
+
328
+ ```typescript
329
+ describe('Batch Processing Discovery', () => {
330
+ it('should discover @BatchProcess decorated methods', async () => {
331
+ class TestBatchProcessor {
332
+ async handleBatch(jobs: any[]) {
333
+ return { totalJobs: jobs.length, successful: jobs.length, failed: 0, results: [], processingTimeMs: 0 };
334
+ }
335
+ }
336
+
337
+ const instance = new TestBatchProcessor();
338
+ const wrapper = { instance, metatype: TestBatchProcessor };
339
+
340
+ discoveryService.getProviders.mockReturnValue([wrapper] as any);
341
+ reflector.get
342
+ .mockReturnValueOnce({ queueName: 'batch-queue' }) // PROCESSOR_METADATA
343
+ .mockReturnValueOnce(undefined) // PROCESS_METADATA
344
+ .mockReturnValueOnce(undefined) // ON_QUEUE_EVENT_METADATA
345
+ .mockReturnValueOnce({ batchSize: 50, batchTimeout: 1000, methodName: 'handleBatch' }); // BATCH_PROCESS_METADATA
346
+ metadataScanner.getAllMethodNames.mockReturnValue(['handleBatch']);
347
+
348
+ // Mock processBatch on provider
349
+ queueProvider.processBatch = jest.fn<any>().mockResolvedValue(undefined);
350
+
351
+ await explorer.onModuleInit();
352
+
353
+ expect(queueProvider.processBatch).toHaveBeenCalledWith(
354
+ 'batch-queue',
355
+ expect.any(Function),
356
+ expect.objectContaining({
357
+ batchSize: 50,
358
+ batchTimeout: 1000,
359
+ }),
360
+ );
361
+ });
362
+
363
+ it('should use default batch options when not specified', async () => {
364
+ class TestBatchProcessor {
365
+ async handleBatch(jobs: any[]) {
366
+ return { totalJobs: 0, successful: 0, failed: 0, results: [], processingTimeMs: 0 };
367
+ }
368
+ }
369
+
370
+ const instance = new TestBatchProcessor();
371
+ const wrapper = { instance, metatype: TestBatchProcessor };
372
+
373
+ discoveryService.getProviders.mockReturnValue([wrapper] as any);
374
+ reflector.get
375
+ .mockReturnValueOnce({ queueName: 'batch-queue' })
376
+ .mockReturnValueOnce(undefined)
377
+ .mockReturnValueOnce(undefined)
378
+ .mockReturnValueOnce({ methodName: 'handleBatch' }); // No options specified
379
+ metadataScanner.getAllMethodNames.mockReturnValue(['handleBatch']);
380
+
381
+ queueProvider.processBatch = jest.fn<any>().mockResolvedValue(undefined);
382
+
383
+ await explorer.onModuleInit();
384
+
385
+ expect(queueProvider.processBatch).toHaveBeenCalledWith(
386
+ 'batch-queue',
387
+ expect.any(Function),
388
+ expect.objectContaining({
389
+ batchSize: 10, // default
390
+ batchTimeout: 5000, // default
391
+ parallel: true, // default
392
+ continueOnError: true, // default
393
+ }),
394
+ );
395
+ });
396
+
397
+ it('should support both @Process and @BatchProcess on same class', async () => {
398
+ class MixedProcessor {
399
+ handleSingle(job: any) { return 'single'; }
400
+ handleBatch(jobs: any[]) { return { totalJobs: 0, successful: 0, failed: 0, results: [], processingTimeMs: 0 }; }
401
+ }
402
+
403
+ const instance = new MixedProcessor();
404
+ const wrapper = { instance, metatype: MixedProcessor };
405
+
406
+ discoveryService.getProviders.mockReturnValue([wrapper] as any);
407
+ reflector.get
408
+ .mockReturnValueOnce({ queueName: 'mixed-queue' })
409
+ // For handleSingle
410
+ .mockReturnValueOnce({ name: 'single-job', methodName: 'handleSingle' })
411
+ .mockReturnValueOnce(undefined)
412
+ .mockReturnValueOnce(undefined)
413
+ // For handleBatch
414
+ .mockReturnValueOnce(undefined)
415
+ .mockReturnValueOnce(undefined)
416
+ .mockReturnValueOnce({ batchSize: 20, methodName: 'handleBatch' });
417
+ metadataScanner.getAllMethodNames.mockReturnValue(['handleSingle', 'handleBatch']);
418
+
419
+ queueProvider.processBatch = jest.fn<any>().mockResolvedValue(undefined);
420
+
421
+ await explorer.onModuleInit();
422
+
423
+ expect(queueProvider.process).toHaveBeenCalled();
424
+ expect(queueProvider.processBatch).toHaveBeenCalled();
425
+ });
426
+ });
427
+ ```
428
+
429
+ **Test command**:
430
+ ```bash
431
+ npm test -- test/processor.explorer.spec.ts --coverage --collectCoverageFrom='lib/explorer/processor.explorer.ts'
432
+ ```
433
+
434
+ **Commit message**: `test(explorer): add batch processor discovery tests`
435
+
436
+ ---
437
+
438
+ ## Phase 4: Batch Decorator Tests (+1% branches)
439
+
440
+ ### Task 4.1: Add Decorator Tests
441
+
442
+ **File to modify**: `test/decorators.spec.ts`
443
+
444
+ **Add this describe block**:
445
+
446
+ ```typescript
447
+ describe('@BatchProcess Decorator', () => {
448
+ it('should set BATCH_PROCESS_METADATA on method', () => {
449
+ class TestClass {
450
+ @BatchProcess()
451
+ handleBatch() {}
452
+ }
453
+
454
+ const metadata = Reflect.getMetadata(
455
+ BATCH_PROCESS_METADATA,
456
+ TestClass.prototype.handleBatch,
457
+ );
458
+
459
+ expect(metadata).toBeDefined();
460
+ });
461
+
462
+ it('should store batchSize option', () => {
463
+ class TestClass {
464
+ @BatchProcess({ batchSize: 100 })
465
+ handleBatch() {}
466
+ }
467
+
468
+ const metadata = Reflect.getMetadata(
469
+ BATCH_PROCESS_METADATA,
470
+ TestClass.prototype.handleBatch,
471
+ );
472
+
473
+ expect(metadata.batchSize).toBe(100);
474
+ });
475
+
476
+ it('should store batchTimeout option', () => {
477
+ class TestClass {
478
+ @BatchProcess({ batchTimeout: 3000 })
479
+ handleBatch() {}
480
+ }
481
+
482
+ const metadata = Reflect.getMetadata(
483
+ BATCH_PROCESS_METADATA,
484
+ TestClass.prototype.handleBatch,
485
+ );
486
+
487
+ expect(metadata.batchTimeout).toBe(3000);
488
+ });
489
+
490
+ it('should store parallel option', () => {
491
+ class TestClass {
492
+ @BatchProcess({ parallel: false })
493
+ handleBatch() {}
494
+ }
495
+
496
+ const metadata = Reflect.getMetadata(
497
+ BATCH_PROCESS_METADATA,
498
+ TestClass.prototype.handleBatch,
499
+ );
500
+
501
+ expect(metadata.parallel).toBe(false);
502
+ });
503
+
504
+ it('should store all options together', () => {
505
+ class TestClass {
506
+ @BatchProcess({
507
+ batchSize: 50,
508
+ batchTimeout: 2000,
509
+ parallel: true,
510
+ maxParallel: 10,
511
+ continueOnError: false,
512
+ retryFailedIndividually: true,
513
+ })
514
+ handleBatch() {}
515
+ }
516
+
517
+ const metadata = Reflect.getMetadata(
518
+ BATCH_PROCESS_METADATA,
519
+ TestClass.prototype.handleBatch,
520
+ );
521
+
522
+ expect(metadata).toEqual(expect.objectContaining({
523
+ batchSize: 50,
524
+ batchTimeout: 2000,
525
+ parallel: true,
526
+ maxParallel: 10,
527
+ continueOnError: false,
528
+ retryFailedIndividually: true,
529
+ }));
530
+ });
531
+ });
532
+ ```
533
+
534
+ **Also add import at top of file**:
535
+ ```typescript
536
+ import { BatchProcess, BATCH_PROCESS_METADATA } from '../lib/decorator/batch-process.decorator';
537
+ ```
538
+
539
+ **Test command**:
540
+ ```bash
541
+ npm test -- test/decorators.spec.ts --coverage --collectCoverageFrom='lib/decorator/batch-process.decorator.ts'
542
+ ```
543
+
544
+ **Commit message**: `test(decorator): add @BatchProcess decorator tests`
545
+
546
+ ---
547
+
548
+ ## Phase 5: Provider Factory Tests (+2% branches)
549
+
550
+ ### Task 5.1: Add Provider Factory Branch Tests
551
+
552
+ **File to modify**: `test/queue.provider.spec.ts`
553
+
554
+ **Add these test cases** to cover the uncovered branches (lines 28-43):
555
+
556
+ ```typescript
557
+ describe('Provider Factory Branches', () => {
558
+ it('should handle useInMemoryIdempotency option', async () => {
559
+ const moduleWithIdempotency = await Test.createTestingModule({
560
+ imports: [
561
+ QueueModule.forRoot({
562
+ provider: QueueProviderType.BULLMQ,
563
+ connection: { host: 'localhost', port: 6379 },
564
+ useInMemoryIdempotency: true,
565
+ }),
566
+ ],
567
+ }).compile();
568
+
569
+ const service = moduleWithIdempotency.get(QueueService);
570
+ expect(service).toBeDefined();
571
+
572
+ await moduleWithIdempotency.close();
573
+ });
574
+
575
+ it('should not override custom idempotency store', async () => {
576
+ const customStore = {
577
+ markProcessing: jest.fn(),
578
+ markComplete: jest.fn(),
579
+ isProcessed: jest.fn(),
580
+ releaseLock: jest.fn(),
581
+ close: jest.fn(),
582
+ };
583
+
584
+ const moduleWithCustomStore = await Test.createTestingModule({
585
+ imports: [
586
+ QueueModule.forRoot({
587
+ provider: QueueProviderType.BULLMQ,
588
+ connection: { host: 'localhost', port: 6379 },
589
+ useInMemoryIdempotency: true,
590
+ idempotency: {
591
+ enabled: true,
592
+ store: customStore as any,
593
+ },
594
+ }),
595
+ ],
596
+ }).compile();
597
+
598
+ expect(moduleWithCustomStore).toBeDefined();
599
+
600
+ await moduleWithCustomStore.close();
601
+ });
602
+ });
603
+ ```
604
+
605
+ **Test command**:
606
+ ```bash
607
+ npm test -- test/queue.provider.spec.ts --coverage --collectCoverageFrom='lib/module/queue.provider.ts'
608
+ ```
609
+
610
+ **Commit message**: `test(module): add provider factory branch tests`
611
+
612
+ ---
613
+
614
+ ## Verification
615
+
616
+ After all phases complete, run full coverage check:
617
+
618
+ ```bash
619
+ npm run test:cov
620
+ ```
621
+
622
+ **Expected Result**: Global branch coverage ≥ 80%
623
+
624
+ ---
625
+
626
+ ## Final Changeset
627
+
628
+ After all tests pass, create changeset:
629
+
630
+ **File**: `.changeset/coverage-recovery.md`
631
+
632
+ ```markdown
633
+ ---
634
+ "@nathapp/nestjs-queue": patch
635
+ ---
636
+
637
+ ### Added
638
+ - Comprehensive lock renewal utility tests
639
+ - BullMQ batch processing tests
640
+ - ProcessorExplorer batch discovery tests
641
+ - @BatchProcess decorator tests
642
+ - Provider factory branch tests
643
+
644
+ ### Fixed
645
+ - Branch coverage restored to 80%+ threshold
646
+ ```
647
+
648
+ **Commit message**: `chore: add changeset for coverage recovery`
649
+
650
+ ---
651
+
652
+ ## Execution Checklist
653
+
654
+ - [ ] Phase 1: Task 1.1 - Lock Renewal Tests
655
+ - [ ] Phase 2: Task 2.1 - BullMQ Batch Tests
656
+ - [ ] Phase 3: Task 3.1 - Explorer Batch Tests
657
+ - [ ] Phase 4: Task 4.1 - Decorator Tests
658
+ - [ ] Phase 5: Task 5.1 - Provider Factory Tests
659
+ - [ ] Verification: Full coverage check
660
+ - [ ] Changeset created
661
+
662
+ ---
663
+
664
+ *Document ready for lower-model coordination.*