fix(fulfillment): mark confirmed role observations as bound
This commit is contained in:
@@ -26,7 +26,6 @@ from web.backend.services.account_binding import (
|
||||
)
|
||||
from web.backend.services.douyu_binding import (
|
||||
BINDING_RECONCILE_CONFIRMED,
|
||||
BINDING_RECONCILE_STALE_PENDING,
|
||||
BINDING_VIEW_CONFIRMED,
|
||||
BINDING_VIEW_FAILED,
|
||||
BINDING_VIEW_NONE,
|
||||
@@ -563,7 +562,7 @@ def test_newer_observation_reconciles_pending_role_by_identity():
|
||||
assert fulfillment_view.effective_role_name == "续梦乖"
|
||||
|
||||
|
||||
def test_newer_observation_invalidates_different_pending_role():
|
||||
def test_newer_observation_confirms_bound_role_replacing_pending_role():
|
||||
account = _binding_account()
|
||||
account.game_name = "续梦乖"
|
||||
pending = resolve_douyu_binding(
|
||||
@@ -607,17 +606,17 @@ def test_newer_observation_invalidates_different_pending_role():
|
||||
fulfillment_view = resolve_fulfillment_binding(
|
||||
observation_task,
|
||||
account=account,
|
||||
binding_status="waiting_bind",
|
||||
binding_status="bound",
|
||||
)
|
||||
|
||||
assert reconciliation.action == BINDING_RECONCILE_STALE_PENDING
|
||||
assert reconciliation.action == BINDING_RECONCILE_CONFIRMED
|
||||
assert reconciliation.pending_role_name == "布丁贩卖机"
|
||||
assert reconciliation.observed_role_name == "续梦乖"
|
||||
assert fulfillment_view.status == BINDING_VIEW_NONE
|
||||
assert fulfillment_view.status == BINDING_VIEW_CONFIRMED
|
||||
assert fulfillment_view.pending_role_name == ""
|
||||
assert fulfillment_view.effective_role_name == "续梦乖"
|
||||
assert fulfillment_view.bind_ready_for_confirm is False
|
||||
assert fulfillment_view.bind_confirmed is False
|
||||
assert fulfillment_view.bind_confirmed is True
|
||||
|
||||
|
||||
def test_confirmed_new_role_replaces_account_current_role():
|
||||
|
||||
@@ -84,6 +84,42 @@ def test_http_response_keeps_application_cache_control():
|
||||
assert headers[b"x-content-type-options"] == b"nosniff"
|
||||
|
||||
|
||||
def test_html_response_gets_no_store_cache_control():
|
||||
async def app(scope, receive, send):
|
||||
assert scope["type"] == "http"
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 200,
|
||||
"headers": [],
|
||||
}
|
||||
)
|
||||
await send({"type": "http.response.body", "body": b"html"})
|
||||
|
||||
messages: list[dict] = []
|
||||
|
||||
async def send(message):
|
||||
messages.append(message)
|
||||
|
||||
async def receive():
|
||||
return {"type": "http.request", "body": b"", "more_body": False}
|
||||
|
||||
scope = {
|
||||
"type": "http",
|
||||
"method": "GET",
|
||||
"path": "/platform-fulfillment",
|
||||
"headers": [],
|
||||
"scheme": "http",
|
||||
"server": ("testserver", 80),
|
||||
"client": ("testclient", 123),
|
||||
"query_string": b"",
|
||||
}
|
||||
asyncio.run(SecurityHeadersMiddleware(app)(scope, receive, send))
|
||||
|
||||
headers = dict(messages[0]["headers"])
|
||||
assert headers[b"cache-control"] == b"no-store, max-age=0"
|
||||
|
||||
|
||||
def test_asset_response_gets_immutable_cache_control():
|
||||
message = _run_http("/assets/index-abc123.js")
|
||||
headers = dict(message["headers"])
|
||||
|
||||
@@ -2076,12 +2076,13 @@ class TestBindingAndCompletion(_Base):
|
||||
assert event.detail_json["previousBindTaskId"] == old_bind_task.id
|
||||
assert event.detail_json["bindTaskId"] == latest_bind_task.id
|
||||
|
||||
def test_newer_observation_invalidates_different_pending_role(self):
|
||||
def test_newer_observation_confirms_different_pending_role(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "续梦乖"
|
||||
account.game_channel = "手Q · 安卓(android)"
|
||||
account.role_bind_status = "bound"
|
||||
account.role_change_available_at = NOW + timedelta(days=6)
|
||||
pending_task = DouyuTask(
|
||||
batch_id="pending-old-role",
|
||||
account_id=task.account_id,
|
||||
@@ -2143,17 +2144,18 @@ class TestBindingAndCompletion(_Base):
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(
|
||||
task_id=task.id,
|
||||
event_type="binding_pending_observation_superseded",
|
||||
event_type="binding_observation_confirmed",
|
||||
)
|
||||
.one()
|
||||
)
|
||||
assert synced == 1
|
||||
assert task.bind_task_id == observation.id
|
||||
assert task.binding_status == "waiting_bind"
|
||||
assert task.execution_status == "waiting_bind"
|
||||
assert task.binding_status == "bound"
|
||||
assert task.execution_status == "bound"
|
||||
assert detail["task"]["bindTask"]["roleName"] == "续梦乖"
|
||||
assert detail["task"]["bindTask"]["bindReadyForConfirm"] is False
|
||||
assert detail["task"]["bindTask"]["bindConfirmed"] is False
|
||||
assert detail["task"]["bindTask"]["bindConfirmed"] is True
|
||||
assert detail["task"]["account"]["roleChangeAvailableAt"] is not None
|
||||
assert event.detail_json["pendingRoleName"] == "布丁贩卖机"
|
||||
assert event.detail_json["observedRoleName"] == "续梦乖"
|
||||
|
||||
@@ -2228,6 +2230,58 @@ class TestBindingAndCompletion(_Base):
|
||||
assert detail["task"]["bindTask"]["bindReadyForConfirm"] is False
|
||||
assert detail["task"]["bindTask"]["bindConfirmed"] is True
|
||||
|
||||
def test_startup_promotes_waiting_task_with_confirmed_observation(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "续梦乖"
|
||||
account.game_channel = "手Q · 安卓(android)"
|
||||
account.role_bind_status = "bound"
|
||||
account.role_change_available_at = NOW + timedelta(days=6)
|
||||
observation = DouyuTask(
|
||||
batch_id="observe-already-bound",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="query_game_name",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={
|
||||
"role_name": "续梦乖",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"is_bound_act": True,
|
||||
"bind_confirmed": True,
|
||||
"bind_phase": "confirmed",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(observation)
|
||||
self.session.flush()
|
||||
task.bind_task_id = observation.id
|
||||
task.binding_status = "waiting_bind"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
reconciled = service.reconcile_binding_observations(self.session)
|
||||
|
||||
self.session.refresh(task)
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
event = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(
|
||||
task_id=task.id,
|
||||
event_type="binding_observation_confirmed",
|
||||
)
|
||||
.one()
|
||||
)
|
||||
assert reconciled == 1
|
||||
assert task.binding_status == "bound"
|
||||
assert task.execution_status == "bound"
|
||||
assert detail["task"]["bindTask"]["roleName"] == "续梦乖"
|
||||
assert detail["task"]["bindTask"]["bindConfirmed"] is True
|
||||
assert detail["task"]["account"]["roleChangeAvailableAt"] is not None
|
||||
assert event.detail_json["observedRoleName"] == "续梦乖"
|
||||
|
||||
def test_refresh_binding_attaches_latest_pending_account_workbench_role(self):
|
||||
task = self._allocated()
|
||||
old_bind_task = DouyuTask(
|
||||
|
||||
Reference in New Issue
Block a user