Repository navigation
Conversation
DocumentDB's documentdb_ttl_task pg_cron job purges expired documents every minute. checkAlerts tests evaluate alerts at fixed 2023/2024 dates, so their AlertHistory rows are already past the TTL; a purge landing between an evaluation and its assertion drops rows. Add an opt-in DOCDB_DISABLE_TTL to the DocumentDB entrypoint that unschedules the job, and set it only in docker-compose.ci.yml. Also reset the Slack webhook spy in the processAlert beforeEach: clearAllMocks keeps implementations, so a persistent mockRejectedValue would leak into later tests.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| jest | ||
| .spyOn(slack, 'postMessageToWebhook') | ||
| .mockReset() | ||
| .mockResolvedValueOnce(fromAny(null)); |
There was a problem hiding this comment.
🟡 P2 — After mockReset(), calls past the first one go to the real Slack webhook
Use .mockReset().mockResolvedValue(fromAny(null)) so every call in a test gets a default stub, not just the first. Why: the repo uses Jest 30 (packages/api/package.json), where mockReset() on a spyOn puts back the original function. The beforeEach then stubs only one call with mockResolvedValueOnce, so any later call runs the real postMessageToWebhook (packages/api/src/utils/slack.ts:13). That sends a real IncomingWebhook.send to https://hooks.slack.com/services/123. Before this PR, those calls were usually caught by a stub some earlier test had left behind with mockResolvedValue (e.g. lines 3081 and 8096). Now they reliably make real network calls. Example: the group-by skip test at ~7257/7278 expects 4 Slack calls and stubs none itself. Its calls 2–4 now reach the network, which makes the suite slower and dependent on the network — the kind of flakiness this PR is meant to remove.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
1 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 0 P3 1 posted as inline comment(s) on the changed lines. Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is a well-scoped test/CI-infra change (DocumentDB entrypoint, CI compose, one Jest 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (5): correctness, testing, reliability, maintainability, project-standards. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 479 passed • 1 skipped • 1126s
Tests ran across 4 shards in parallel. |
Summary
Fixes intermittent
checkAlerts.int.test.tsfailures where a test finds fewerAlertHistoryrows than it wrote (e.g. "expected 2, received 1").Cause: DocumentDB's
documentdb_ttl_taskpg_cron job purges expired documents once a minute. The checkAlerts tests evaluate alerts at fixed 2023/2024 dates, so every history row is already past the 30-day TTL oncreatedAt. When a purge lands between an evaluation and its assertion, rows disappear. In recent CI runs this shows up as a retry in shard 4 (about 2 of 48 jobs) thatjest.retryTimes(1)currently absorbs; any multi-step history test can be hit.Fix:
docker/documentdb/entrypoint.sh: new opt-inDOCDB_DISABLE_TTL. Whentrue, it unschedulesdocumentdb_ttl_taskon every boot. Default behavior is unchanged, so dev and e2e stacks keep TTL.docker-compose.ci.yml: setsDOCDB_DISABLE_TTL: 'true'for the integration-test DB. No int test relies on TTL deletion.checkAlerts.int.test.ts: reset the Slack webhook spy in theprocessAlertbeforeEach.jest.clearAllMocks()keeps implementations, so a test that sets a persistentmockRejectedValueleaks into later tests. This doesn't happen onmaintoday; it closes the gap (the same leak caused first-attempt failures in a downstream fork).Test and CI only; no product code changes, so no changeset.
How to reproduce
Starting point: a worktree with Docker;
yarn installandmake dev-int-buildonce. Export theHDX_CI_*ports fromscripts/slots.sh(hdx_ci_ports), start the stack withdocker compose -p $HDX_CI_PROJECT -f docker-compose.ci.yml up -d --wait, and run the file frompackages/apiwithJEST_RETRY_TIMES=0 DOTENV_CONFIG_PATH=.env.test DOTENV_CONFIG_OVERRIDE=true npx jest --config jest.int.config.js --runInBand --forceExit src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts.On
main:docker exec $HDX_CI_PROJECT-db-1 psql -h /tmp -U postgres -d postgres -c "select cron.alter_job(jobid, schedule := '1 seconds') from cron.job where jobname = 'documentdb_ttl_task'".On this branch:
docker compose ... build db) and recreate the stack.select jobname from cron.jobno longer listsdocumentdb_ttl_task, on a fresh boot and afterdocker restart.How to test locally or on Vercel
make dev-int-buildJEST_RETRY_TIMES=0 make dev-int FILE=checkAlerts.intReferences
--setParameter ttlMonitorEnabled=false)Note
Low Risk
Test and CI Docker configuration only; no application runtime or production deployment paths change.
Overview
Addresses intermittent
checkAlertsintegration failures whereAlertHistoryrows vanish between write and assert because DocumentDB’sdocumentdb_ttl_taskcron purges “expired” docs every minute while tests use fixed 2023/2024 timestamps (already past the 30-day TTL).CI DocumentDB:
DOCDB_DISABLE_TTLis a new opt-in flag inentrypoint.shthat unschedulesdocumentdb_ttl_taskon container start when set totrue; default stays unchanged for dev/e2e.docker-compose.ci.ymlturns it on for the integration-testdbservice.Test isolation: In the
processAlertsuite, the SlackpostMessageToWebhookspy now calls.mockReset()inbeforeEachso a prior test’smockRejectedValuedoesn’t leak afterjest.clearAllMocks().Reviewed by Cursor Bugbot for commit cc1e495. Bugbot is set up for automated code reviews on this repo. Configure here.