feat(tests): let managers escalate and directly resolve disputed tests
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
Request Discussion only ever nudged the peer lead, and the one-time
manager notification when a dispute starts had no real follow-up
action attached to it — a manager could be told a dispute existed but
had no way to actually do anything about it. Adds:
- POST /tests/{id}/escalate-to-manager — either lead can explicitly
ask managers to step in, distinct from the passive initial notice.
- POST /tests/{id}/manager-resolve-dispute — a manager decides the
final outcome (validated/rejected) directly, bypassing both leads'
votes entirely, reusing the same dual-validation event dispatch so
Jira/notifications behave like any other resolution.
Both leads are notified of the manager's final call, win or lose.
This commit is contained in:
@@ -1341,6 +1341,50 @@ def resolve_dispute(db: Session, test: Test, user: User, target_team: str, notes
|
||||
return test
|
||||
|
||||
|
||||
def resolve_dispute_by_manager(db: Session, test: Test, user: User, outcome: str, notes: str | None = None) -> Test:
|
||||
"""A manager makes the final call on a disputed test — validated or rejected.
|
||||
|
||||
Unlike ``resolve_dispute`` (only the approving lead flipping their own
|
||||
vote), this is a manager override that ends the standoff directly,
|
||||
without either lead having to concede. Reuses the same dual-validation
|
||||
event dispatch as a normal in_review resolution so Jira/notifications
|
||||
behave identically to an ordinary validated/rejected outcome.
|
||||
"""
|
||||
if test.state != TestState.disputed:
|
||||
raise InvalidOperationError("Test is not in disputed state")
|
||||
|
||||
entity = TestEntity.from_orm(test)
|
||||
entity.resolve_dispute_by_manager(outcome)
|
||||
entity.apply_to(test)
|
||||
db.flush()
|
||||
|
||||
log_action(
|
||||
db, user_id=user.id, action="manager_resolve_dispute",
|
||||
entity_type="test", entity_id=test.id,
|
||||
details={"outcome": outcome, "notes": notes, "test_name": test.name},
|
||||
)
|
||||
|
||||
_dispatch_dual_validation_effects(db, test, entity, actor=user)
|
||||
|
||||
# Let both leads know the manager made the final call, not just whichever
|
||||
# side "won" — the losing side needs to know just as much.
|
||||
for lead_id in filter(None, {test.red_validated_by, test.blue_validated_by}):
|
||||
try:
|
||||
create_notification(
|
||||
db, user_id=lead_id, type="manager_dispute_resolution",
|
||||
title=f"Manager resolved disputed test as {outcome}",
|
||||
message=(
|
||||
f'{user.username} resolved the dispute on "{test.name}" as {outcome}.'
|
||||
+ (f" Notes: {notes}" if notes else "")
|
||||
),
|
||||
entity_type="test", entity_id=test.id,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("Notification failed for test %s: %s", test.id, e, exc_info=True)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
# Define function handle_remediation_completed
|
||||
def handle_remediation_completed(db: Session, test: Test, user: User) -> Test | None:
|
||||
"""Create a re-test when remediation is completed.
|
||||
|
||||
Reference in New Issue
Block a user