UN-3450 [FEAT] Add golden-path smoke test for callback worker#1947
UN-3450 [FEAT] Add golden-path smoke test for callback worker#1947
Conversation
Adds workers/tests/test_callback_sanity.py mirroring the existing test_executor_sanity.py pattern. Covers: - Worker enums and registry (WorkerType.CALLBACK, QueueName.CALLBACK + CALLBACK_API, TaskName.PROCESS_BATCH_CALLBACK, health port 8083, WorkerRegistry queue config + task routing). - Celery task wiring (process_batch_callback, process_batch_callback_api, healthcheck — registration, retry config, max_retries, autoretry_for). - Full dispatch -> task -> return round-trip via Celery eager mode, using the simple healthcheck task (process_batch_callback itself needs a configured InternalAPIClient + downstream HTTP, which is heavy mocking territory unsuitable for a smoke test — covered later in #1.2 characterisation suite). Coverage gains on callback module: - callback/__init__.py: 0% -> 100% - callback/worker.py: 0% -> 52% - callback/tasks.py: 0% -> 10% - Module total: 0% -> 12% 14 tests, run in ~17s. Regression net for spine PRs #6 (CallbackStatus enum migration) and #13 (chord -> Barrier lift in callback chain). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedFailed to post review comments Summary by CodeRabbit
WalkthroughAdds a new test module that provides Phase 1 sanity checks for the callback worker: validates enums and registry config, verifies task wiring and retry settings, exercises an eager-mode healthcheck round-trip, and confirms healthcheck payload JSON-serializability. Includes an eager Celery app fixture. ChangesCallback Worker Phase 1 Sanity Tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~14 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| workers/tests/test_callback_sanity.py | New smoke-test file covering callback worker enums, Celery task wiring, and a healthcheck round-trip via eager mode; follows the established executor test pattern and correctly addresses both previous review comments |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[eager_app fixture\ncallback.worker.app] --> B[task_always_eager=True\nresult_backend=cache+memory://]
B --> C{Test class}
C --> D[TestWorkerEnumsAndRegistry\n7 enum/registry assertions]
C --> E[TestCeleryTaskWiring\n6 task wiring assertions]
C --> F[TestEagerHealthcheckRoundTrip\n2 round-trip assertions]
E --> E1[process_batch_callback\nmax_retries=0]
E --> E2[process_batch_callback_api\nmax_retries=3, backoff, jitter]
E --> E3[django compat shim registered]
F --> F1[healthcheck.apply\nresult.get]
F1 --> F2{assertions}
F2 --> F3[status==healthy\nworker_type==callback\ntask_id and worker_name present]
F2 --> F4[json.loads/json.dumps\nround-trip clean]
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
workers/tests/test_callback_sanity.py:144-149
Both `TestEagerHealthcheckRoundTrip` tests use `next(...)` without a default value. If no task name matches the predicate (e.g. after a refactor of the healthcheck task name), the generator raises `StopIteration`, which pytest surfaces as an `ERROR` rather than a clean `FAIL`. Adding a sentinel and an explicit assertion produces a much clearer failure message.
```suggestion
def test_eager_healthcheck_round_trip(self, eager_app):
# Find the healthcheck task; its module-qualified name varies.
healthcheck = next(
(t for name, t in eager_app.tasks.items()
if name.endswith(".healthcheck") or name == "healthcheck"),
None,
)
assert healthcheck is not None, "Healthcheck task not registered in eager_app"
```
### Issue 2 of 2
workers/tests/test_callback_sanity.py:160-167
Same `StopIteration`-instead-of-`AssertionError` issue applies to the second round-trip test. A `None` default + explicit assert keeps both tests consistent and gives a readable failure.
```suggestion
def test_healthcheck_result_is_json_serializable(self, eager_app):
"""Verify healthcheck output survives Celery serialization."""
import json
healthcheck = next(
(t for name, t in eager_app.tasks.items()
if name.endswith(".healthcheck") or name == "healthcheck"),
None,
)
assert healthcheck is not None, "Healthcheck task not registered in eager_app"
```
Reviews (2): Last reviewed commit: "UN-3450 [FEAT] Address Greptile review o..." | Re-trigger Greptile
Two P2 findings from Greptile, both fixed: 1. test_healthcheck_result_is_json_serializable: drop the `default=str` fallback in json.dumps. With it, any non-JSON-serializable value (UUID, datetime, custom object) gets silently coerced to a string — exactly the failure mode the test claims to catch. Without it, the assertion faithfully tests "round-trips cleanly via JSON" the way Celery's serializer would. 2. Add registration check for `process_batch_callback_django_compat` (the backward-compat task name `workflow_manager.workflow_v2. file_execution_tasks.process_batch_callback`). Both this task and `process_batch_callback` delegate to `_process_batch_callback_core`, so refactors that touch the core (e.g. the upcoming CallbackStatus enum migration) affect this path too. Three-line addition. 15 tests now (was 14), runtime 11s. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Test ResultsSummary
Runner Tests - Full Report
SDK1 Tests - Full Report
|



What
workers/tests/test_callback_sanity.py— golden-path smoke test for the callback worker.workers/tests/test_executor_sanity.pypattern for consistency.Why
The
callbackworker had 0% test coverage (607 statements). It's heavily modified by two upcoming PRs in the workers/ rollout:"completed" | "failed" | "skipped"literals acrosscallback/tasks.py.from celery import chordcall sites is in the callback chain.Without a smoke test in place, those PRs would be flying blind. This test gives them a regression net.
Reference: UN-3450.
How
test_executor_sanity.py(which is the existing reference smoke test for the executor worker — 73% coverage).TestWorkerEnumsAndRegistry— verifiesWorkerType.CALLBACK,QueueName.CALLBACK+CALLBACK_API,TaskName.PROCESS_BATCH_CALLBACK, health port8083,WorkerRegistryqueue config and task routing.TestCeleryTaskWiring— verifiesprocess_batch_callback,process_batch_callback_api, andhealthcheckare registered with the expected retry config (process_batch_callbackhasmax_retries=0per Django parity;process_batch_callback_apihas full backoff/jitter).TestEagerHealthcheckRoundTrip— exercises the full dispatch → task → return round-trip via Celery'stask_always_eager=Truemode, using the simplehealthchecktask.The full
process_batch_callbacktask isn't run end-to-end here — it requires a configuredInternalAPIClientand downstream HTTP calls, which is heavy mocking territory unsuitable for a smoke test. That's deferred to the upcoming characterisation suite. The simplehealthchecktask gives us a real round-trip without external dependencies.Coverage gains on
callbackmodulecallback/__init__.pycallback/worker.pycallback/tasks.pyTests run in ~17s.
Can this PR break any existing features. If yes, please list possible items. If no, please explain why.
No. Adds a new test file under
workers/tests/. No production code changed. The test uses aneager_appfixture that mutates the callback Celery app's config in-process (eager mode), then restores the original config in ayield-then-teardown pattern — same approach used intest_executor_sanity.py. No global state leaks across tests.Database Migrations
None.
Env Config
None. Test relies only on env vars already set by
workers/conftest.py.Related Issues or PRs
Dependencies Versions
None changed.
Notes on Testing
cd workers PYTHONPATH=.:../unstract .venv/bin/pytest tests/test_callback_sanity.py -vExpected: 14 passed in ~17s.
Existing tests unaffected — the new file lives alongside
test_executor_sanity.pyandtest_ide_callback.py.Screenshots
N/A — test file.
Checklist
🤖 Generated with Claude Code