Skip to content

Feature/export dlq drain tests - #1488

Merged
1nonlypiece merged 3 commits into
Disciplr-Org:mainfrom
chinecherem58:feature/export-dlq-drain-tests
Jul 30, 2026
Merged

Feature/export dlq drain tests#1488
1nonlypiece merged 3 commits into
Disciplr-Org:mainfrom
chinecherem58:feature/export-dlq-drain-tests

Conversation

@chinecherem58

Copy link
Copy Markdown
Contributor

Summary

Adds DLQ drain operations and metrics-hook test coverage for src/services/exportQueue.ts,
closing Issue #626.

Changes

src/tests/exportQueue.dlq-drain.test.ts (new file)

42-test suite covering all requirements from .kiro/specs/export-dlq/requirements.md:

  • Req 1 — Entry creation: addToDlq creates well-formed DlqEntry; failure classification
    (serialization_error, data_fetch_error, unknown_error); DLQ cap eviction (oldest evicted
    when full); processJob moves job to DLQ after exhausting maxAttempts; retryable jobs are
    NOT added to DLQ
  • Req 2 — PII sanitisation: userId and targetUserId replaced with 8-char opaque SHA-256
    tokens; raw user IDs, Stellar addresses never appear in DlqEntry; metrics hook receives only
    sanitised data
  • Req 3 — Query interface: getDlqEntries() returns newest-first snapshot; mutations to
    returned array don't affect store; getDlqEntry() returns entry or undefined;
    getDlqDepth() reflects current count
  • Req 4 — Drain operations: requeueDlqEntry returns true and re-creates processable
    pending job; returns false for unknown ID; discardDlqEntry permanently removes entry;
    clearDlq removes all and returns count
  • Req 5 — Metrics hook: fires dlq.entry_added, dlq.entry_requeued,
    dlq.entry_discarded, dlq.cleared with correct dlqDepth; throwing hook is caught and
    warn-logged without breaking the queue; no-hook mode works identically
  • Req 6 — Observability logging: warn log on add (no PII), info logs on
    requeue/discard/clear; all structured JSON

Edge cases: cap eviction, empty clearDlq, discard-then-requeue same ID, duplicate jobId,
JSON round-trip

docs/export.md

  • Added full DLQ drain/metrics API reference section

src/tests/exportQueue.dlq-drain.test.ts

  • Replaced jest.spyOn on read-only ESM export with an equivalent test strategy that avoids
    the ESM mutation restriction

Test Results

  • 42/42 tests pass
  • No PII leaks confirmed: raw userId / targetUserId / Stellar addresses never appear in any
    emitted event or log line

Closes #626

…ation

- Add DLQ types (DlqEntry, DlqMetricsEvent, MetricsHook, FailureReason,
  DlqEventType) to src/services/exportQueue.ts
- Implement addToDlq, configureDlq, resetDlq, getDlqEntries, getDlqEntry,
  getDlqDepth, requeueDlqEntry, discardDlqEntry, clearDlq
- Wire addToDlq into processJob on permanent failure (retries exhausted)
- PII sanitisation: userId/targetUserId replaced with SHA-256 opaque tokens
- DLQ capped at configurable maxDlqSize (default 100), oldest evicted on overflow
- MetricsHook fires on add/requeue/discard/clear; throwing hook caught + warn-logged
- Structured log lines at warn (add) and info (requeue/discard/clear) — no raw PII
- 42-test suite in src/tests/exportQueue.dlq-drain.test.ts covering all requirements:
  Req1 entry creation, Req2 PII sanitisation, Req3 query interface,
  Req4 drain operations, Req5 metrics hook isolation, Req6 observability logging
- Edge cases: cap eviction, empty clear, discard-then-requeue, duplicate jobId,
  round-trip JSON serialisation
- docs/export.md updated with full DLQ drain/metrics API reference

Closes Disciplr-Org#626
- Add buildValidationError, flattenZodErrors, formatIssuePath, formatValidationError
  to src/lib/validation.ts — required by security.integration.test.ts and
  src/tests/validation.test.ts
- Replace jest.spyOn on read-only ESM export (serializeExportData) with an
  alternative test strategy that achieves the same coverage without ESM hacks:
  use a 1-shot job (maxAttempts=1) to confirm DLQ entry is created, and verify
  the multi-attempt job is not in the DLQ (retryable path)
- All 122 security integration tests and 42 DLQ drain tests now pass
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@chinecherem58 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! 🚀

Learn more about application limits

@1nonlypiece
1nonlypiece merged commit 7a90fb9 into Disciplr-Org:main Jul 30, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DLQ drain and metrics-hook tests for ExportQueue dead-letter operations

2 participants