From 96533a1c2008b154905592e56fb8dcecc3408a38 Mon Sep 17 00:00:00 2001 From: OoO Date: Mon, 18 May 2026 19:41:35 +0800 Subject: [PATCH] feat(market-intel): add alert review queue contract --- config.py | 2 +- ...s-platform-market-campaign-intelligence.md | 1 + routes/README.md | 2 +- services/market_intel/deployment_readiness.py | 2 + services/market_intel/opportunity_alerts.py | 86 +++++++++++++++++++ services/market_intel/service.py | 2 +- templates/market_intel/disabled.html | 64 +++++++++++++- tests/test_market_intel_skeleton.py | 66 ++++++++++---- 8 files changed, 202 insertions(+), 23 deletions(-) diff --git a/config.py b/config.py index 6752cf3..f428956 100644 --- a/config.py +++ b/config.py @@ -320,7 +320,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '') # ========================================== # 系統版本與路徑 # ========================================== -SYSTEM_VERSION = "V10.199" +SYSTEM_VERSION = "V10.200" LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log') public_url = PUBLIC_URL # 用於模板顯示 diff --git a/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md b/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md index 112db88..9b965c7 100644 --- a/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md +++ b/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md @@ -165,6 +165,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome - 2026-05-18 追加 opportunity alert plan preview:`services.market_intel.opportunity_alerts` 與 `/api/market_intel/opportunity_alert_plan` 定義人工審核、每日摘要、Telegram 候選、AI 摘要候選四種 channel 的最低門檻、去重節流、payload contract 與操作順序。此階段不建立 alert queue、不派送 Telegram、不呼叫 LLM、不寫 DB;所有告警必須先有 evidence bundle、dedupe key 與人工批准。 - 2026-05-18 追加 opportunity alert review preview:`/api/market_intel/opportunity_alert_plan` 擴充人工審核狀態與操作,定義 `draft → needs_review → approved_for_digest / approved_for_telegram / rejected / deferred` 流程、審核理由、審核者身分與派送前二次 gate。此階段不建立 review queue、不執行審核動作、不寫 approval record、不派送 Telegram、不呼叫 LLM。 - 2026-05-18 追加 deployment readiness modularization:將 `/api/market_intel/deployment_readiness` 的大型 app-only release gate 組裝邏輯由 `services.market_intel.service` 拆至 `services.market_intel.deployment_readiness`,主服務保留薄入口,避免後續 crawler / MCP / 審核功能推進時超過 800 行治理線;行為仍維持 preview-only,不執行 git、部署、SSH、migration 或 DB write。 +- 2026-05-18 追加 alert review queue contract:`/api/market_intel/opportunity_alert_plan` 補上 `market_alert_review_queue` 的 preview contract、required / audit / forbidden fields、priority lanes 與索引規劃。此階段只定義資料契約,不建立 review table、不寫 queue contract、不執行審核、不派送 Telegram、不呼叫 LLM。 ### Phase 4:Coupang / Shopee Adapter diff --git a/routes/README.md b/routes/README.md index 46c0adb..e5dbed5 100644 --- a/routes/README.md +++ b/routes/README.md @@ -19,7 +19,7 @@ | `edm_routes.py` | EDM 與節慶儀表板 | `/edm`, `/festival` | | `monthly_routes.py` | 月結分析 | `/monthly_summary_analysis`, `/api/monthly_summary_data` | | `daily_sales_routes.py` | 當日業績 | `/daily_sales`, `/daily_sales/export*` | -| `market_intel_routes.py` | 市場情報 Phase 40 deployment readiness modularization | `/market_intel`, `/market_intel/*`, `/api/market_intel/status`, `/api/market_intel/schema`, `/api/market_intel/schema_smoke`, `/api/market_intel/schema_db_probe`, `/api/market_intel/platform_seed_db_diff`, `/api/market_intel/legacy_source_bridge`, `/api/market_intel/mcp_readiness`, `/api/market_intel/mcp_tool_contract`, `/api/market_intel/mcp_deploy_preflight`, `/api/market_intel/mcp_activation_runbook`, `/api/market_intel/mcp_fetch_gate`, `/api/market_intel/scheduler_plan`, `/api/market_intel/match_review_plan`, `/api/market_intel/opportunity_plan`, `/api/market_intel/opportunity_scoring_plan`, `/api/market_intel/opportunity_evidence_plan`, `/api/market_intel/opportunity_alert_plan`, `/api/market_intel/adapters`, `/api/market_intel/dry_run_plan`, `/api/market_intel/discovery_plan`, `/api/market_intel/manual_discovery`, `/api/market_intel/candidate_preview`, `/api/market_intel/platform_seed_plan`, `/api/market_intel/platform_seed_write_guard`, `/api/market_intel/platform_seed_writer_plan`, `/api/market_intel/migration_blueprint`, `/api/market_intel/seed_writer_cli_status`, `/api/market_intel/write_approval_runbook`, `/api/market_intel/deployment_readiness` | +| `market_intel_routes.py` | 市場情報 Phase 41 alert review queue contract | `/market_intel`, `/market_intel/*`, `/api/market_intel/status`, `/api/market_intel/schema`, `/api/market_intel/schema_smoke`, `/api/market_intel/schema_db_probe`, `/api/market_intel/platform_seed_db_diff`, `/api/market_intel/legacy_source_bridge`, `/api/market_intel/mcp_readiness`, `/api/market_intel/mcp_tool_contract`, `/api/market_intel/mcp_deploy_preflight`, `/api/market_intel/mcp_activation_runbook`, `/api/market_intel/mcp_fetch_gate`, `/api/market_intel/scheduler_plan`, `/api/market_intel/match_review_plan`, `/api/market_intel/opportunity_plan`, `/api/market_intel/opportunity_scoring_plan`, `/api/market_intel/opportunity_evidence_plan`, `/api/market_intel/opportunity_alert_plan`, `/api/market_intel/adapters`, `/api/market_intel/dry_run_plan`, `/api/market_intel/discovery_plan`, `/api/market_intel/manual_discovery`, `/api/market_intel/candidate_preview`, `/api/market_intel/platform_seed_plan`, `/api/market_intel/platform_seed_write_guard`, `/api/market_intel/platform_seed_writer_plan`, `/api/market_intel/migration_blueprint`, `/api/market_intel/seed_writer_cli_status`, `/api/market_intel/write_approval_runbook`, `/api/market_intel/deployment_readiness` | | `api_routes.py` | 通用任務與查詢 API | `/api/run_task`, `/api/history/*` | | `export_routes.py` | 匯出功能 | `/api/export/*` | | `import_routes.py` | 匯入功能 | `/api/import_excel`, `/api/import/monthly_summary` | diff --git a/services/market_intel/deployment_readiness.py b/services/market_intel/deployment_readiness.py index 7bbb784..5fec76d 100644 --- a/services/market_intel/deployment_readiness.py +++ b/services/market_intel/deployment_readiness.py @@ -102,6 +102,8 @@ def build_deployment_readiness_preview( "opportunity_alert_plan_preview_safe": bool( opportunity_alert_plan["mode"] == "opportunity_alert_plan_preview" and not opportunity_alert_plan["alert_candidate_created"] + and not opportunity_alert_plan["review_queue_contract_written"] + and not opportunity_alert_plan["review_queue_table_created"] and not opportunity_alert_plan["review_action_executed"] and not opportunity_alert_plan["approval_record_written"] and not opportunity_alert_plan["telegram_dispatched"] diff --git a/services/market_intel/opportunity_alerts.py b/services/market_intel/opportunity_alerts.py index 670ea7b..89569ed 100644 --- a/services/market_intel/opportunity_alerts.py +++ b/services/market_intel/opportunity_alerts.py @@ -137,6 +137,82 @@ REVIEW_ACTIONS = ( }, ) +REVIEW_QUEUE_CONTRACT = { + "table_name": "market_alert_review_queue", + "primary_key": "id", + "required_fields": [ + "alert_candidate_id", + "review_state", + "priority_lane", + "threshold_level", + "total_score", + "evidence_bundle_id", + "dedupe_key", + "source_batch_id", + "created_at", + "updated_at", + ], + "audit_fields": [ + "reviewer_identity", + "review_action", + "review_reason", + "reviewed_at", + "previous_state", + "next_state", + ], + "forbidden_fields": [ + "customer_personal_data", + "login_required_price", + "cart_or_order_data", + "payment_or_shipping_data", + ], +} + +REVIEW_QUEUE_INDEXES = ( + { + "key": "idx_market_alert_review_queue_state_priority", + "columns": ["review_state", "priority_lane", "created_at"], + "purpose": "審核台依狀態與優先級快速排序。", + }, + { + "key": "ux_market_alert_review_queue_dedupe", + "columns": ["dedupe_key"], + "purpose": "避免同商品同活動同日重複進入審核佇列。", + }, + { + "key": "idx_market_alert_review_queue_bundle", + "columns": ["evidence_bundle_id", "source_batch_id"], + "purpose": "回查 evidence bundle 與來源批次。", + }, +) + +REVIEW_PRIORITY_LANES = ( + { + "key": "critical", + "label": "立即審核", + "max_age_hours": 2, + "minimum_threshold": "critical", + }, + { + "key": "high", + "label": "今日優先", + "max_age_hours": 8, + "minimum_threshold": "high", + }, + { + "key": "medium", + "label": "每日摘要候選", + "max_age_hours": 24, + "minimum_threshold": "medium", + }, + { + "key": "watch", + "label": "觀察池", + "max_age_hours": 72, + "minimum_threshold": "watch", + }, +) + def build_opportunity_alert_plan_preview( *, @@ -198,6 +274,9 @@ def build_opportunity_alert_plan_preview( "alert_candidate_created": False, "alert_queue_created": False, "review_queue_created": False, + "review_queue_contract_defined": True, + "review_queue_contract_written": False, + "review_queue_table_created": False, "review_action_executed": False, "approval_record_written": False, "telegram_dispatched": False, @@ -217,6 +296,9 @@ def build_opportunity_alert_plan_preview( "review_state_count": len(REVIEW_STATES), "review_states": list(REVIEW_STATES), "review_actions": list(REVIEW_ACTIONS), + "review_queue_contract": REVIEW_QUEUE_CONTRACT, + "review_queue_indexes": list(REVIEW_QUEUE_INDEXES), + "review_priority_lanes": list(REVIEW_PRIORITY_LANES), "throttle_policy": THROTTLE_POLICY, "gate_checks": gate_checks, "blocked_reasons": blocked_reasons, @@ -225,6 +307,8 @@ def build_opportunity_alert_plan_preview( "approval_reason_required": True, "reviewer_identity_required": True, "approved_candidate_still_requires_dispatch_gate": True, + "queue_item_requires_evidence_bundle": True, + "queue_item_requires_dedupe_key": True, }, "payload_contract": { "required_fields": [ @@ -252,6 +336,8 @@ def build_opportunity_alert_plan_preview( ], "safe_boundaries": [ "do_not_create_alert_queue_from_preview", + "do_not_create_review_queue_table_from_preview", + "do_not_write_review_queue_contract_from_preview", "do_not_dispatch_telegram_from_alert_preview", "do_not_call_llm_from_alert_preview", "do_not_notify_without_evidence_bundle", diff --git a/services/market_intel/service.py b/services/market_intel/service.py index 6502e95..c235dc2 100644 --- a/services/market_intel/service.py +++ b/services/market_intel/service.py @@ -83,7 +83,7 @@ class MarketIntelRuntimeStatus: class MarketIntelService: """市場情報入口服務,先集中 feature gate 與安全狀態。""" - phase = "phase_40_deployment_readiness_modularized" + phase = "phase_41_alert_review_queue_contract" def get_runtime_status(self) -> MarketIntelRuntimeStatus: return MarketIntelRuntimeStatus( diff --git a/templates/market_intel/disabled.html b/templates/market_intel/disabled.html index cc49071..c6e510a 100644 --- a/templates/market_intel/disabled.html +++ b/templates/market_intel/disabled.html @@ -1987,6 +1987,7 @@ `ready=${data.ready_for_alert_candidates ? 'yes' : 'no'}`, `channels=${data.channel_count || 0}`, `review=${data.review_state_count || 0}`, + `queue_contract=${data.review_queue_contract_defined ? 'defined' : 'missing'}`, `telegram=${data.telegram_dispatched ? 'sent' : 'blocked'}`, `llm=${data.llm_call_executed ? 'called' : 'blocked'}` ].map(item => `${escapeHtml(item)}`).join(''); @@ -2000,6 +2001,9 @@ const throttle = data.throttle_policy || {}; const reviewStates = data.review_states || []; const reviewActions = data.review_actions || []; + const queueContract = data.review_queue_contract || {}; + const queueIndexes = data.review_queue_indexes || []; + const priorityLanes = data.review_priority_lanes || []; const approval = data.approval_policy || {}; const sequence = data.operator_sequence || []; const payload = data.payload_contract || {}; @@ -2034,8 +2038,24 @@ reason=${item.requires_reason ? 'required' : 'optional'} `; + const renderPriorityLane = item => ` +
+ ${escapeHtml(item.key)} + ${escapeHtml(item.label)} / threshold=${escapeHtml(item.minimum_threshold)} + max_age=${escapeHtml(item.max_age_hours)}h +
+ `; + const renderQueueIndex = item => ` +
+
+ ${escapeHtml(item.key)} + ${escapeHtml((item.columns || []).join(' / '))} · ${escapeHtml(item.purpose)} +
+ PLANNED +
+ `; opportunityAlertBody.innerHTML = ` -
目前只定義告警候選與人工審核流程;不建立 alert queue、不建立 review queue、不執行審核動作、不派送 Telegram、不呼叫 LLM、不寫 DB。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}
+
目前只定義告警候選、人工審核流程與審核佇列資料契約;不建立 alert queue、不建立 review queue、不建立 review table、不執行審核動作、不派送 Telegram、不呼叫 LLM、不寫 DB。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}
dedupe=${escapeHtml(throttle.dedupe_window_hours || 'n/a')}h / telegram_daily=${escapeHtml(throttle.max_telegram_candidates_per_day || 0)} / ai_digest=${escapeHtml(throttle.max_ai_briefing_items_per_digest || 0)}
@@ -2105,6 +2125,48 @@ : '
尚未提供審核操作。
' }
+
+

REVIEW QUEUE CONTRACT

+
+
+
+ ${escapeHtml(queueContract.table_name || 'market_alert_review_queue')} + pk=${escapeHtml(queueContract.primary_key || 'id')} +
+ PREVIEW +
+
+
+ required_fields + ${escapeHtml((queueContract.required_fields || []).join(' / '))} +
+ REQUIRED +
+
+
+ audit_fields + ${escapeHtml((queueContract.audit_fields || []).join(' / '))} +
+ AUDIT +
+
+
+
+

PRIORITY LANES

+
${ + priorityLanes.length + ? priorityLanes.map(renderPriorityLane).join('') + : '
尚未提供優先級 lane。
' + }
+
+
+

QUEUE INDEXES

+
${ + queueIndexes.length + ? queueIndexes.map(renderQueueIndex).join('') + : '
尚未提供索引規劃。
' + }
+

APPROVAL POLICY

${ diff --git a/tests/test_market_intel_skeleton.py b/tests/test_market_intel_skeleton.py index 81ebc4b..64f5c57 100644 --- a/tests/test_market_intel_skeleton.py +++ b/tests/test_market_intel_skeleton.py @@ -477,6 +477,9 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint(): assert "data-market-intel-opportunity-alert-payload" in template assert "data-market-intel-opportunity-alert-review" in template assert "data-market-intel-opportunity-alert-actions" in template + assert "data-market-intel-opportunity-alert-queue-contract" in template + assert "data-market-intel-opportunity-alert-priority-lanes" in template + assert "data-market-intel-opportunity-alert-queue-indexes" in template assert "data-market-intel-opportunity-alert-approval" in template assert "data-market-intel-opportunity-alert-sequence" in template assert "data-market-intel-migration" in template @@ -527,7 +530,7 @@ def test_legacy_source_bridge_default_is_planned_only(): bridge = MarketIntelService().build_legacy_source_bridge() assert bridge["mode"] == "legacy_source_bridge_planned" - assert bridge["phase"] == "phase_40_deployment_readiness_modularized" + assert bridge["phase"] == "phase_41_alert_review_queue_contract" assert bridge["execute_requested"] is False assert bridge["read_only_query_executed"] is False assert bridge["database_connection_opened"] is False @@ -685,7 +688,7 @@ def test_mcp_tool_contract_preview_is_read_only_and_whitelisted(): contract = MarketIntelService().build_mcp_tool_contract() assert contract["mode"] == "mcp_tool_contract_preview" - assert contract["phase"] == "phase_40_deployment_readiness_modularized" + assert contract["phase"] == "phase_41_alert_review_queue_contract" assert contract["caller"] == "market_intel" assert contract["contract_ready"] is True assert contract["blocked_reasons"] == [] @@ -818,7 +821,7 @@ def test_mcp_activation_runbook_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "mcp_activation_runbook_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["deployment_actions_executed"] is False assert data["docker_command_executed"] is False assert data["ssh_command_executed"] is False @@ -831,7 +834,7 @@ def test_mcp_fetch_gate_default_blocks_external_fetch(): gate = MarketIntelService().build_mcp_fetch_gate(fetch_requested=True) assert gate["mode"] == "mcp_fetch_gate_planned" - assert gate["phase"] == "phase_40_deployment_readiness_modularized" + assert gate["phase"] == "phase_41_alert_review_queue_contract" assert gate["fetch_requested"] is True assert gate["manual_fetch_gate_open"] is False assert gate["network_request_allowed"] is False @@ -901,7 +904,7 @@ def test_mcp_fetch_gate_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "mcp_fetch_gate_planned" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["fetch_requested"] is False assert data["network_request_allowed"] is False assert data["external_network_executed"] is False @@ -913,7 +916,7 @@ def test_scheduler_plan_preview_blocks_job_attachment(): plan = MarketIntelService().build_scheduler_plan() assert plan["mode"] == "scheduler_attach_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_to_attach_scheduler"] is False assert plan["scheduler_attached"] is False assert plan["scheduler_registration_executed"] is False @@ -951,7 +954,7 @@ def test_scheduler_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "scheduler_attach_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["scheduler_registration_executed"] is False assert data["crawler_job_started"] is False assert data["external_network_executed"] is False @@ -962,7 +965,7 @@ def test_match_review_plan_preview_blocks_auto_confirm(): plan = MarketIntelService().build_match_review_plan() assert plan["mode"] == "match_review_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_for_review_queue"] is False assert plan["review_queue_created"] is False assert plan["auto_match_executed"] is False @@ -998,7 +1001,7 @@ def test_match_review_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "match_review_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["review_queue_created"] is False assert data["auto_confirm_executed"] is False assert data["external_network_executed"] is False @@ -1009,7 +1012,7 @@ def test_opportunity_plan_preview_blocks_alerts_and_ai_summary(): plan = MarketIntelService().build_opportunity_plan() assert plan["mode"] == "opportunity_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_for_opportunity_queue"] is False assert plan["opportunity_queue_created"] is False assert plan["threat_alert_dispatched"] is False @@ -1050,7 +1053,7 @@ def test_opportunity_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "opportunity_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["opportunity_queue_created"] is False assert data["threat_alert_dispatched"] is False assert data["ai_summary_generated"] is False @@ -1061,7 +1064,7 @@ def test_opportunity_scoring_plan_preview_blocks_scoring_and_alerts(): plan = MarketIntelService().build_opportunity_scoring_plan() assert plan["mode"] == "opportunity_scoring_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_for_scoring_job"] is False assert plan["scoring_job_created"] is False assert plan["score_calculation_executed"] is False @@ -1109,7 +1112,7 @@ def test_opportunity_scoring_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "opportunity_scoring_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["scoring_job_created"] is False assert data["score_calculation_executed"] is False assert data["sample_scores_generated"] is False @@ -1121,7 +1124,7 @@ def test_opportunity_evidence_plan_preview_blocks_queries_and_alerts(): plan = MarketIntelService().build_opportunity_evidence_plan() assert plan["mode"] == "opportunity_evidence_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_for_evidence_bundle"] is False assert plan["evidence_bundle_created"] is False assert plan["evidence_query_executed"] is False @@ -1167,7 +1170,7 @@ def test_opportunity_evidence_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "opportunity_evidence_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["evidence_bundle_created"] is False assert data["evidence_query_executed"] is False assert data["sample_evidence_generated"] is False @@ -1180,11 +1183,14 @@ def test_opportunity_alert_plan_preview_blocks_dispatch_and_llm_calls(): plan = MarketIntelService().build_opportunity_alert_plan() assert plan["mode"] == "opportunity_alert_plan_preview" - assert plan["phase"] == "phase_40_deployment_readiness_modularized" + assert plan["phase"] == "phase_41_alert_review_queue_contract" assert plan["ready_for_alert_candidates"] is False assert plan["alert_candidate_created"] is False assert plan["alert_queue_created"] is False assert plan["review_queue_created"] is False + assert plan["review_queue_contract_defined"] is True + assert plan["review_queue_contract_written"] is False + assert plan["review_queue_table_created"] is False assert plan["review_action_executed"] is False assert plan["approval_record_written"] is False assert plan["telegram_dispatched"] is False @@ -1220,12 +1226,29 @@ def test_opportunity_alert_plan_preview_blocks_dispatch_and_llm_calls(): "reject", "defer", } + assert plan["review_queue_contract"]["table_name"] == "market_alert_review_queue" + assert "alert_candidate_id" in plan["review_queue_contract"]["required_fields"] + assert "reviewer_identity" in plan["review_queue_contract"]["audit_fields"] + assert "payment_or_shipping_data" in plan["review_queue_contract"]["forbidden_fields"] + assert {item["key"] for item in plan["review_priority_lanes"]} == { + "critical", + "high", + "medium", + "watch", + } + assert {item["key"] for item in plan["review_queue_indexes"]} == { + "idx_market_alert_review_queue_state_priority", + "ux_market_alert_review_queue_dedupe", + "idx_market_alert_review_queue_bundle", + } assert plan["approval_policy"]["manual_approval_required_for_dispatch"] is True assert plan["approval_policy"]["reviewer_identity_required"] is True assert "evidence_bundle_ready" in plan["blocked_reasons"] assert "scoring_job_ready" in plan["blocked_reasons"] assert "operator_approval" in plan["blocked_reasons"] assert "do_not_dispatch_telegram_from_alert_preview" in plan["safe_boundaries"] + assert "do_not_create_review_queue_table_from_preview" in plan["safe_boundaries"] + assert "do_not_write_review_queue_contract_from_preview" in plan["safe_boundaries"] assert "do_not_call_llm_from_alert_preview" in plan["safe_boundaries"] assert "customer_personal_data" in plan["payload_contract"]["forbidden_fields"] @@ -1245,10 +1268,13 @@ def test_opportunity_alert_plan_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "opportunity_alert_plan_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["alert_candidate_created"] is False assert data["alert_queue_created"] is False assert data["review_queue_created"] is False + assert data["review_queue_contract_defined"] is True + assert data["review_queue_contract_written"] is False + assert data["review_queue_table_created"] is False assert data["review_action_executed"] is False assert data["approval_record_written"] is False assert data["telegram_dispatched"] is False @@ -1320,7 +1346,7 @@ def test_mcp_deploy_preflight_route_is_preview_only(): assert response.status_code == 200 assert data["mode"] == "mcp_external_deploy_preflight_preview" - assert data["phase"] == "phase_40_deployment_readiness_modularized" + assert data["phase"] == "phase_41_alert_review_queue_contract" assert data["deployment_actions_executed"] is False assert data["docker_command_executed"] is False assert data["ssh_command_executed"] is False @@ -1335,7 +1361,7 @@ def test_mcp_readiness_default_is_planned_only(monkeypatch): readiness = MarketIntelService().build_mcp_readiness() assert readiness["mode"] == "mcp_readiness_planned" - assert readiness["phase"] == "phase_40_deployment_readiness_modularized" + assert readiness["phase"] == "phase_41_alert_review_queue_contract" assert readiness["execute_requested"] is False assert readiness["router_enabled"] is False assert readiness["external_mcp_complete"] is False @@ -1788,6 +1814,8 @@ def test_deployment_readiness_reports_app_only_release_gate(): assert readiness["opportunity_evidence_plan"]["evidence_query_executed"] is False assert readiness["opportunity_evidence_plan"]["database_write_executed"] is False assert readiness["opportunity_alert_plan"]["alert_candidate_created"] is False + assert readiness["opportunity_alert_plan"]["review_queue_contract_written"] is False + assert readiness["opportunity_alert_plan"]["review_queue_table_created"] is False assert readiness["opportunity_alert_plan"]["review_action_executed"] is False assert readiness["opportunity_alert_plan"]["approval_record_written"] is False assert readiness["opportunity_alert_plan"]["telegram_dispatched"] is False