Skip to content

feat(alerts): unmatch a sequence from an alert#582

Open
MateoLostanlen wants to merge 6 commits intomainfrom
feat/alert-sequence-unmatch
Open

feat(alerts): unmatch a sequence from an alert#582
MateoLostanlen wants to merge 6 commits intomainfrom
feat/alert-sequence-unmatch

Conversation

@MateoLostanlen
Copy link
Copy Markdown
Member

  • Add POST /alerts/{alert_id}/sequences/{sequence_id}/unmatch (admin + agent) that detaches a sequence from an alert and recomputes the alert state; if the sequence becomes orphaned a new alert is created for it. Reject when the alert has a single sequence.
  • Reject unmatch when the sequence's camera belongs to a different organization than the alert, to prevent cross-org alert creation.
  • Extract refresh_alert_state from endpoints/sequences.py into services/alerts.py so both endpoints share the helper.
  • Cover the new endpoint with tests for new-alert creation, no-op when the sequence is already linked elsewhere, single-sequence rejection, missing link, role and cross-org access denial.

Move the alert recomputation helper out of the sequences endpoint module so other endpoints can reuse it.
POST /alerts/{alert_id}/sequences/{sequence_id}/unmatch detaches a sequence from an alert and recomputes the alert state. If the sequence is no longer linked to any alert, a new alert is created for it. Restricted to admin and agent scopes; rejects unmatch when the alert has a single sequence.
Cover the new alert/sequence unmatch flow: new alert creation when the sequence becomes orphaned, no-op when the sequence is still linked elsewhere, single-sequence rejection, missing link, role and cross-org access denial.
Scope rejection from get_jwt returns 403, not 401. The label_sequence unit test now patches refresh_alert_state at its imported location.
Defensive guard so an authorized agent cannot trigger creation of an alert in another organization through a cross-org sequence link. Use the alert's organization_id when creating the replacement alert.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.98%. Comparing base (1f67522) to head (2070515).

Files with missing lines Patch % Lines
src/app/api/api_v1/endpoints/alerts.py 36.11% 23 Missing ⚠️
src/app/services/alerts.py 62.06% 11 Missing ⚠️
client/pyroclient/client.py 66.66% 1 Missing ⚠️
src/app/api/api_v1/endpoints/sequences.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #582      +/-   ##
==========================================
- Coverage   88.75%   87.98%   -0.77%     
==========================================
  Files          52       53       +1     
  Lines        2196     2239      +43     
==========================================
+ Hits         1949     1970      +21     
- Misses        247      269      +22     
Flag Coverage Δ
backend 87.87% <49.27%> (-0.78%) ⬇️
client 89.84% <66.66%> (-0.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Wrap the new POST /alerts/{alert_id}/sequences/{sequence_id}/unmatch route.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant