feat: pass opportunityId to assess-urls worker for precheck persistence#1983
feat: pass opportunityId to assess-urls worker for precheck persistence#1983danielbatica wants to merge 3 commits intomainfrom
Conversation
|
This PR will trigger a minor release when merged. |
Include opportunityId in SQS message for assess-urls action to enable worker to fetch and update suggestion entities with precheck results, preventing data loss from async Lambda invocations. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
27ab161 to
526959f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Update existing test to verify opportunityId is included in both the response body and SQS message payload. Add dedicated test to explicitly verify opportunityId is passed to worker for precheck result persistence. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
iuliag
left a comment
There was a problem hiding this comment.
The new field autofixPrecheckStatus is stored on Suggestion but SuggestionDto in this repo is not updated to expose it. If any consumer (UI, reporting) needs to read this field via the API, a DTO update and endpoint change will be needed later. Depends on what was the intended outcome.
| expect(mockSqs.sendMessage).to.have.been.calledOnce; | ||
| const payload = mockSqs.sendMessage.firstCall.args[1]; | ||
| expect(payload).to.have.property('opportunityId', OPPORTUNITY_ID); | ||
| // Verify opportunityId is passed alongside siteId and action |
There was a problem hiding this comment.
This new test duplicates assertions already present in the updated existing test above and adds value only in its additional expect(payload).to.include({...}) assertion (which checks three fields together).
Consider either removing the duplicate by merging the two tests or making the new test genuinely distinct.
solaris007
left a comment
There was a problem hiding this comment.
Hey @danielbatica,
Strengths
- Clean, focused diff - adds
opportunityIdto the SQS payload and response, nothing more. - Correct use of the established conditional spread pattern for
precheckOnly(suggestions.js:984). - Existing tests updated to verify
opportunityIdin both the response body and SQS payload (suggestions.test.js:3973,3980). - CI is passing.
Issues
Important (Should Fix)
1. OpenAPI spec contradicts the code change
The spec at docs/openapi/site-opportunities.yaml describes the assess-urls flow as intentionally omitting opportunityId. The code now sends it, but the spec still says the opposite. This was a deliberate design decision documented recently. The spec needs to be updated in this PR, and the PR description should explain what changed that invalidates the original rationale.
2. Deleted design comment without replacement
suggestions.js:976: The removed comment "Intentionally omit opportunityId: worker uses context differently for URL-based assessments" was a deliberate architectural note. It's been silently removed without explaining why the design changed. Replace with a brief note (e.g., // opportunityId needed for precheck result persistence on Suggestion).
3. Incomplete feature chain - no downstream consumer
This PR sends opportunityId to the worker, and #1449 adds the storage field, but the autofix worker currently has no handler that reads opportunityId from the assess-urls message and writes to autofixPrecheckStatus. If a worker PR exists or is planned, please link to it. If these are intentional prep work, say so explicitly.
4. SuggestionDto not updated
As @iuliag noted, autofixPrecheckStatus is stored on Suggestion but SuggestionDto does not expose it. If any consumer (UI, reporting) needs to read precheck results via the API, a DTO update will be needed.
Minor (Nice to Have)
5. Duplicative test
suggestions.test.js:3997-4022: The new test "passes opportunityId to worker for precheck result persistence" is nearly identical to the existing test above it (updated at lines 3971-3984). Both send the same request and verify opportunityId in the payload. Either remove the duplicate or differentiate the scenario.
Recommendations
- Update the OpenAPI spec to reflect the new behavior and explain the design change.
- Document the release ordering explicitly: shared first, API second, worker third. Link all three PRs.
- Ensure the worker PR handles missing
opportunityIdgracefully in case deploys get reordered.
Assessment
Ready to merge? No
The OpenAPI spec contradicts the code change, creating a contract inconsistency. The feature chain is incomplete without a corresponding worker PR. Also blocked on #1449 (schema change) which has failing CI.
Next Steps
- Update the OpenAPI spec to match the new behavior.
- Replace the deleted design comment with updated reasoning.
- Link to the worker PR that completes the feature chain.
- Wait for #1449 to pass CI and merge before releasing this.
Summary
opportunityIdin SQS message payload for assess-urls actionProblem
The assess-urls worker needs opportunityId to fetch suggestion entities and save precheck results to the database. Previously, opportunityId was intentionally omitted from the SQS message, causing precheck results to be lost when the async Lambda completed.
Solution
Pass opportunityId in the SQS message so the worker can:
autofixPrecheckStatusfield on each suggestionCode Changes
Test plan
Dependencies
Release Order
🤖 Generated with Claude Code