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 04a81f3..5845e05 100644
--- a/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md
+++ b/docs/adr/ADR-035-cross-platform-market-campaign-intelligence.md
@@ -158,6 +158,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
- 2026-05-18 追加 MCP activation runbook preview:`services.market_intel.mcp_activation_runbook` 與 `/api/market_intel/mcp_activation_runbook` 只輸出人工啟用順序與 gate:補必要 env、人工建立/驗證 `mcp_readonly`、啟動外部 MCP stack、四個 health 全過、最後才允許 `MCP_ROUTER_ENABLED=true`。此 runbook 不執行 docker/SSH、不寫 env、不建立 DB role、不跑 health、不啟用 router、不寫 DB、不掛 scheduler。
- 2026-05-18 追加 MCP fetch gate preview:`services.market_intel.mcp_fetch_gate` 與 `/api/market_intel/mcp_fetch_gate` 將人工 discovery fetch 改成必須先通過市場情報 feature flags、MCP readiness、router、外部 MCP health 與 tool contract gate;`run_manual_discovery(fetch=true)` 即使 flags 開啟也會先被此 gate 阻擋,直到 MCP 條件全過。此 gate 不抓電商頁、不寫 DB、不掛 scheduler、不執行 deployment,UI 預設只呼叫 `fetch=false&execute=false`。
- 2026-05-18 追加 scheduler attach plan preview:`services.market_intel.scheduler_plan` 與 `/api/market_intel/scheduler_plan` 描述未來 `campaign_discovery_daily`、`campaign_product_probe`、`product_match_review_seed` 三個 job 的 cadence、gate、fallback 與安全邊界。此階段不註冊 scheduler job、不啟動 crawler、不連外、不寫 DB;排程掛載必須等 migration、seed、MCP fetch gate、manual sample 與人工批准全過。
+- 2026-05-18 追加 match review plan preview:`services.market_intel.match_review_plan` 與 `/api/market_intel/match_review_plan` 定義商品比對訊號、分數門檻、`needs_review → confirmed/rejected` HITL 流程與安全邊界。此階段不建立 review queue、不自動 confirmed、不寫 `market_product_matches`、不呼叫 MCP;價格只能作為輔助訊號,不能單獨決定同品比對。
### Phase 4:Coupang / Shopee Adapter
diff --git a/routes/README.md b/routes/README.md
index 8707520..8ebb902 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 33 scheduler attach plan preview | `/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/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 34 match review plan preview | `/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/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/routes/market_intel_routes.py b/routes/market_intel_routes.py
index 122fef0..ccd5f18 100644
--- a/routes/market_intel_routes.py
+++ b/routes/market_intel_routes.py
@@ -157,6 +157,12 @@ def market_intel_scheduler_plan():
return jsonify(_service().build_scheduler_plan())
+@market_intel_bp.route("/api/market_intel/match_review_plan")
+@login_required
+def market_intel_match_review_plan():
+ return jsonify(_service().build_match_review_plan())
+
+
@market_intel_bp.route("/api/market_intel/adapters")
@login_required
def market_intel_adapters():
diff --git a/services/market_intel/match_review_plan.py b/services/market_intel/match_review_plan.py
new file mode 100644
index 0000000..c99e044
--- /dev/null
+++ b/services/market_intel/match_review_plan.py
@@ -0,0 +1,147 @@
+"""市場情報商品比對審核 preview。
+
+只定義比對訊號、分數門檻與人工覆核流程;不查 DB、不寫 DB、不呼叫 MCP。
+"""
+
+
+MATCH_SCORING_SIGNALS = (
+ {
+ "key": "platform_product_id_or_i_code",
+ "label": "平台商品 ID / MOMO i_code 精準命中",
+ "weight": 0.35,
+ "source": "market_campaign_products + products",
+ },
+ {
+ "key": "brand_and_series",
+ "label": "品牌、系列與型號 token 一致",
+ "weight": 0.24,
+ "source": "normalized product name",
+ },
+ {
+ "key": "spec_token_overlap",
+ "label": "容量、入數、尺寸、顏色等規格 token overlap",
+ "weight": 0.22,
+ "source": "ProductNameParser / parser diagnostics",
+ },
+ {
+ "key": "price_band_reasonable",
+ "label": "跨平台價格落在合理區間,避免不同規格誤配",
+ "weight": 0.12,
+ "source": "price history / competitor price cache",
+ },
+ {
+ "key": "image_or_url_hint",
+ "label": "圖片網址、活動 URL 或來源頁提示",
+ "weight": 0.07,
+ "source": "campaign product metadata",
+ },
+)
+
+
+MATCH_THRESHOLDS = {
+ "auto_match_candidate_min": 0.88,
+ "needs_review_min": 0.62,
+ "reject_suggestion_below": 0.38,
+ "auto_confirm_enabled": False,
+}
+
+
+def build_match_review_plan_preview(
+ *,
+ runtime_status,
+ mcp_tool_contract,
+ legacy_source_bridge,
+ schema_smoke,
+):
+ """建立商品比對審核計畫;不產生 match rows、不自動確認。"""
+ schema_passed = bool(
+ schema_smoke.get("passed")
+ or (schema_smoke.get("schema_smoke") or {}).get("passed")
+ )
+ contract_tools = mcp_tool_contract.get("tools") or []
+ match_lookup_ready = any(
+ item.get("name") == "market_product_match_lookup"
+ and item.get("read_only")
+ and item.get("router_tools_whitelisted")
+ for item in contract_tools
+ )
+ legacy_bridge_safe = (
+ legacy_source_bridge.get("mode") == "legacy_source_bridge_planned"
+ and not legacy_source_bridge.get("read_only_query_executed")
+ and not legacy_source_bridge.get("database_write_executed")
+ )
+ gate_checks = {
+ "schema_smoke_passed": schema_passed,
+ "market_product_matches_table_planned": "market_product_matches"
+ in (schema_smoke.get("expected_tables") or []),
+ "mcp_match_lookup_contract_ready": match_lookup_ready,
+ "legacy_bridge_planned_safe": legacy_bridge_safe,
+ "database_write_still_blocked": not bool(
+ runtime_status.database_write_allowed
+ ),
+ "scheduler_detached": not bool(runtime_status.scheduler_attached),
+ "auto_confirm_disabled": not MATCH_THRESHOLDS["auto_confirm_enabled"],
+ "manual_operator_approval": False,
+ }
+ blocked_reasons = [
+ key for key, passed in gate_checks.items()
+ if not passed
+ ]
+
+ return {
+ "mode": "match_review_plan_preview",
+ "ready_for_review_queue": False,
+ "review_queue_created": False,
+ "auto_match_executed": False,
+ "auto_confirm_executed": False,
+ "database_session_created": False,
+ "database_write_executed": False,
+ "database_commit_executed": False,
+ "external_network_executed": False,
+ "scheduler_attached": False,
+ "writes_executed": False,
+ "would_write_database": False,
+ "thresholds": MATCH_THRESHOLDS,
+ "scoring_signals": list(MATCH_SCORING_SIGNALS),
+ "planned_status_flow": [
+ "needs_review",
+ "confirmed",
+ "rejected",
+ ],
+ "gate_checks": gate_checks,
+ "blocked_reasons": blocked_reasons,
+ "review_actions": [
+ {
+ "key": "confirm_match",
+ "label": "人工確認競品商品與 MOMO 商品為同款或等效規格",
+ "writes_database": True,
+ "requires_operator": True,
+ },
+ {
+ "key": "reject_match",
+ "label": "人工拒絕誤配候選,保留 reason 供規則調整",
+ "writes_database": True,
+ "requires_operator": True,
+ },
+ {
+ "key": "merge_duplicate_candidate",
+ "label": "合併同一競品商品的重複候選",
+ "writes_database": True,
+ "requires_operator": True,
+ },
+ ],
+ "operator_sequence": [
+ "先完成 market_* schema 與 seed 寫入",
+ "以 read-only bridge 盤點 PChome / MOMO 舊資料來源",
+ "用 market_product_match_lookup 只讀查詢候選,不直接建立 match rows",
+ "人工審核 needs_review queue 後才允許 confirmed / rejected 寫入",
+ "任何 auto_match 只能產生候選分數,不得自動 confirmed",
+ ],
+ "safe_boundaries": [
+ "do_not_auto_confirm_matches",
+ "do_not_write_match_rows_from_preview",
+ "do_not_call_external_mcp_from_preview",
+ "do_not_attach_scheduler_for_match_review",
+ "do_not_use_price_only_as_match_reason",
+ ],
+ }
diff --git a/services/market_intel/service.py b/services/market_intel/service.py
index e8a8f1d..ea6d42c 100644
--- a/services/market_intel/service.py
+++ b/services/market_intel/service.py
@@ -20,6 +20,7 @@ from services.market_intel.adapters import (
from services.market_intel.candidate_preview import build_candidate_preview_from_discovery
from services.market_intel.discovery_runner import ManualDiscoveryRunner
from services.market_intel.legacy_source_bridge import build_legacy_source_bridge_plan
+from services.market_intel.match_review_plan import build_match_review_plan_preview
from services.market_intel.mcp_activation_runbook import build_mcp_activation_runbook_preview
from services.market_intel.mcp_contract import build_mcp_tool_contract_preview
from services.market_intel.mcp_deploy_preflight import build_mcp_deploy_preflight_plan
@@ -69,7 +70,7 @@ class MarketIntelRuntimeStatus:
class MarketIntelService:
"""市場情報入口服務,先集中 feature gate 與安全狀態。"""
- phase = "phase_33_scheduler_plan_preview"
+ phase = "phase_34_match_review_plan_preview"
def get_runtime_status(self) -> MarketIntelRuntimeStatus:
return MarketIntelRuntimeStatus(
@@ -377,6 +378,21 @@ class MarketIntelService:
plan["phase"] = self.phase
return plan
+ def build_match_review_plan(self):
+ """回報商品比對審核計畫;不建立 queue、不自動確認。"""
+ schema_smoke = self.build_schema_smoke()
+ plan = build_match_review_plan_preview(
+ runtime_status=self.get_runtime_status(),
+ mcp_tool_contract=self.build_mcp_tool_contract(),
+ legacy_source_bridge=self.build_legacy_source_bridge(),
+ schema_smoke={
+ **schema_smoke["schema_smoke"],
+ "expected_tables": schema_smoke["expected_tables"],
+ },
+ )
+ plan["phase"] = self.phase
+ return plan
+
def build_platform_seed_writer_plan(self, platform_code="all"):
"""建立 platform seed writer dry-run plan,不建立 DB session。"""
seed_plan = self.build_platform_seed_plan(platform_code=platform_code)
@@ -457,6 +473,7 @@ class MarketIntelService:
mcp_activation_runbook = self.build_mcp_activation_runbook()
mcp_fetch_gate = self.build_mcp_fetch_gate()
scheduler_plan = self.build_scheduler_plan()
+ match_review_plan = self.build_match_review_plan()
checks = {
"schema_smoke_passed": bool(schema_smoke["passed"]),
"feature_flags_default_safe": bool(
@@ -507,6 +524,12 @@ class MarketIntelService:
and not scheduler_plan["crawler_job_started"]
and not scheduler_plan["database_write_executed"]
),
+ "match_review_plan_preview_safe": bool(
+ match_review_plan["mode"] == "match_review_plan_preview"
+ and not match_review_plan["review_queue_created"]
+ and not match_review_plan["auto_confirm_executed"]
+ and not match_review_plan["database_write_executed"]
+ ),
}
ready_for_production_deploy = all(checks.values())
blocked_reasons = [
@@ -636,6 +659,7 @@ class MarketIntelService:
"/api/market_intel/mcp_activation_runbook",
"/api/market_intel/mcp_fetch_gate",
"/api/market_intel/scheduler_plan",
+ "/api/market_intel/match_review_plan",
],
"status": status.to_dict(),
"schema_smoke": schema_smoke,
@@ -656,4 +680,5 @@ class MarketIntelService:
"mcp_activation_runbook": mcp_activation_runbook,
"mcp_fetch_gate": mcp_fetch_gate,
"scheduler_plan": scheduler_plan,
+ "match_review_plan": match_review_plan,
}
diff --git a/templates/market_intel/disabled.html b/templates/market_intel/disabled.html
index bdc45f4..8ce8101 100644
--- a/templates/market_intel/disabled.html
+++ b/templates/market_intel/disabled.html
@@ -504,6 +504,24 @@
+
+
+
+
MATCH REVIEW / PLAN
+
商品比對審核計畫
+
+
+
+
+ loading
+
+
+
+
@@ -574,10 +592,11 @@
const mcpActivationRoot = document.querySelector('[data-market-intel-mcp-activation]');
const mcpFetchGateRoot = document.querySelector('[data-market-intel-mcp-fetch-gate]');
const schedulerRoot = document.querySelector('[data-market-intel-scheduler]');
+ const matchReviewRoot = document.querySelector('[data-market-intel-match-review]');
const migrationRoot = document.querySelector('[data-market-intel-migration]');
const approvalRoot = document.querySelector('[data-market-intel-approval]');
const deployRoot = document.querySelector('[data-market-intel-deploy]');
- if (!root && !writerRoot && !cliRoot && !dbProbeRoot && !seedDiffRoot && !legacyBridgeRoot && !mcpReadinessRoot && !mcpPreflightRoot && !mcpActivationRoot && !mcpFetchGateRoot && !schedulerRoot && !migrationRoot && !approvalRoot && !deployRoot) return;
+ if (!root && !writerRoot && !cliRoot && !dbProbeRoot && !seedDiffRoot && !legacyBridgeRoot && !mcpReadinessRoot && !mcpPreflightRoot && !mcpActivationRoot && !mcpFetchGateRoot && !schedulerRoot && !matchReviewRoot && !migrationRoot && !approvalRoot && !deployRoot) return;
const meta = root ? root.querySelector('[data-market-intel-preview-meta]') : null;
const body = root ? root.querySelector('[data-market-intel-preview-body]') : null;
@@ -623,6 +642,10 @@
const schedulerBody = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-body]') : null;
const schedulerRefresh = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-refresh]') : null;
const schedulerEndpoint = "{{ url_for('market_intel.market_intel_scheduler_plan') }}";
+ const matchReviewMeta = matchReviewRoot ? matchReviewRoot.querySelector('[data-market-intel-match-review-meta]') : null;
+ const matchReviewBody = matchReviewRoot ? matchReviewRoot.querySelector('[data-market-intel-match-review-body]') : null;
+ const matchReviewRefresh = matchReviewRoot ? matchReviewRoot.querySelector('[data-market-intel-match-review-refresh]') : null;
+ const matchReviewEndpoint = "{{ url_for('market_intel.market_intel_match_review_plan') }}";
const migrationMeta = migrationRoot ? migrationRoot.querySelector('[data-market-intel-migration-meta]') : null;
const migrationBody = migrationRoot ? migrationRoot.querySelector('[data-market-intel-migration-body]') : null;
const migrationRefresh = migrationRoot ? migrationRoot.querySelector('[data-market-intel-migration-refresh]') : null;
@@ -1423,6 +1446,109 @@
}
};
+ const renderMatchReviewMeta = data => {
+ const thresholds = data.thresholds || {};
+ matchReviewMeta.innerHTML = [
+ `mode=${data.mode || 'unknown'}`,
+ `ready=${data.ready_for_review_queue ? 'yes' : 'no'}`,
+ `signals=${(data.scoring_signals || []).length}`,
+ `auto_confirm=${thresholds.auto_confirm_enabled ? 'on' : 'off'}`,
+ `writes=${data.writes_executed ? 'executed' : 'blocked'}`
+ ].map(item => `
${escapeHtml(item)}`).join('');
+ };
+
+ const renderMatchReviewBody = data => {
+ const blockers = (data.blocked_reasons || []).join(' / ');
+ const checks = Object.entries(data.gate_checks || {});
+ const signals = data.scoring_signals || [];
+ const actions = data.review_actions || [];
+ const sequence = data.operator_sequence || [];
+ const renderCheck = ([name, passed]) => `
+
+
+ ${escapeHtml(name)}
+
+
${passed ? 'PASS' : 'BLOCK'}
+
+ `;
+ const renderSignal = item => `
+
+ ${escapeHtml(item.key)}
+ ${escapeHtml(item.label)}
+ weight=${escapeHtml(item.weight)} / ${escapeHtml(item.source)}
+
+ `;
+ const renderAction = item => `
+
+
+ ${escapeHtml(item.key)}
+ ${escapeHtml(item.label)}
+
+
${item.requires_operator ? 'HITL' : 'AUTO'}
+
+ `;
+ matchReviewBody.innerHTML = `
+
商品比對目前只建立審核規則與 HITL 流程;不建立 queue、不自動確認、不寫 DB、不呼叫外部 MCP。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}
+
+
+
MATCH GATES
+
${
+ checks.length
+ ? checks.map(renderCheck).join('')
+ : '
尚未提供比對 gate。
'
+ }
+
+
+
SCORING SIGNALS
+
${
+ signals.length
+ ? signals.map(renderSignal).join('')
+ : '
尚未提供比對訊號。
'
+ }
+
+
+
REVIEW ACTIONS
+
${
+ actions.length
+ ? actions.map(renderAction).join('')
+ : '
尚未提供審核動作。
'
+ }
+
+
+
OPERATOR SEQUENCE
+
${
+ sequence.length
+ ? sequence.map((item, index) => `
+
+
+ ${escapeHtml(`step_${index + 1}`)}
+ ${escapeHtml(item)}
+
+
REQUIRED
+
+ `).join('')
+ : '
尚未提供操作順序。
'
+ }
+
+
+ `;
+ };
+
+ const loadMatchReview = async () => {
+ if (!matchReviewMeta || !matchReviewBody) return;
+ matchReviewBody.innerHTML = '
讀取商品比對審核計畫中...
';
+ try {
+ const response = await fetch(matchReviewEndpoint, { credentials: 'same-origin' });
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
+ const data = await response.json();
+ renderMatchReviewMeta(data);
+ renderMatchReviewBody(data);
+ } catch (error) {
+ matchReviewMeta.innerHTML = '
error';
+ matchReviewBody.innerHTML = `
商品比對審核計畫讀取失敗:${escapeHtml(error.message)}
`;
+ }
+ };
+
const renderMigrationMeta = data => {
const seedWriter = data.command_plan && data.command_plan.seed_writer_command
? data.command_plan.seed_writer_command
@@ -1690,6 +1816,9 @@
if (schedulerRefresh) {
schedulerRefresh.addEventListener('click', loadScheduler);
}
+ if (matchReviewRefresh) {
+ matchReviewRefresh.addEventListener('click', loadMatchReview);
+ }
if (migrationRefresh) {
migrationRefresh.addEventListener('click', loadMigration);
}
@@ -1710,6 +1839,7 @@
loadMcpActivation();
loadMcpFetchGate();
loadScheduler();
+ loadMatchReview();
loadMigration();
loadApproval();
loadDeploy();
diff --git a/tests/test_market_intel_skeleton.py b/tests/test_market_intel_skeleton.py
index abf8cb9..99c4aa2 100644
--- a/tests/test_market_intel_skeleton.py
+++ b/tests/test_market_intel_skeleton.py
@@ -448,6 +448,11 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
assert "data-market-intel-scheduler-jobs" in template
assert "data-market-intel-scheduler-sequence" in template
assert "data-market-intel-scheduler-fallback" in template
+ assert "data-market-intel-match-review" in template
+ assert "data-market-intel-match-review-checks" in template
+ assert "data-market-intel-match-review-signals" in template
+ assert "data-market-intel-match-review-actions" in template
+ assert "data-market-intel-match-review-sequence" in template
assert "data-market-intel-migration" in template
assert "data-market-intel-migration-tables" in template
assert "data-market-intel-approval" in template
@@ -466,6 +471,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
assert "market_intel.market_intel_mcp_activation_runbook" in template
assert "market_intel.market_intel_mcp_fetch_gate" in template
assert "market_intel.market_intel_scheduler_plan" in template
+ assert "market_intel.market_intel_match_review_plan" in template
assert "market_intel.market_intel_migration_blueprint" in template
assert "market_intel.market_intel_write_approval_runbook" in template
assert "market_intel.market_intel_deployment_readiness" in template
@@ -491,7 +497,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_33_scheduler_plan_preview"
+ assert bridge["phase"] == "phase_34_match_review_plan_preview"
assert bridge["execute_requested"] is False
assert bridge["read_only_query_executed"] is False
assert bridge["database_connection_opened"] is False
@@ -649,7 +655,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_33_scheduler_plan_preview"
+ assert contract["phase"] == "phase_34_match_review_plan_preview"
assert contract["caller"] == "market_intel"
assert contract["contract_ready"] is True
assert contract["blocked_reasons"] == []
@@ -782,7 +788,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_33_scheduler_plan_preview"
+ assert data["phase"] == "phase_34_match_review_plan_preview"
assert data["deployment_actions_executed"] is False
assert data["docker_command_executed"] is False
assert data["ssh_command_executed"] is False
@@ -795,7 +801,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_33_scheduler_plan_preview"
+ assert gate["phase"] == "phase_34_match_review_plan_preview"
assert gate["fetch_requested"] is True
assert gate["manual_fetch_gate_open"] is False
assert gate["network_request_allowed"] is False
@@ -865,7 +871,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_33_scheduler_plan_preview"
+ assert data["phase"] == "phase_34_match_review_plan_preview"
assert data["fetch_requested"] is False
assert data["network_request_allowed"] is False
assert data["external_network_executed"] is False
@@ -877,7 +883,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_33_scheduler_plan_preview"
+ assert plan["phase"] == "phase_34_match_review_plan_preview"
assert plan["ready_to_attach_scheduler"] is False
assert plan["scheduler_attached"] is False
assert plan["scheduler_registration_executed"] is False
@@ -915,13 +921,60 @@ def test_scheduler_plan_route_is_preview_only():
assert response.status_code == 200
assert data["mode"] == "scheduler_attach_plan_preview"
- assert data["phase"] == "phase_33_scheduler_plan_preview"
+ assert data["phase"] == "phase_34_match_review_plan_preview"
assert data["scheduler_registration_executed"] is False
assert data["crawler_job_started"] is False
assert data["external_network_executed"] is False
assert data["database_write_executed"] is False
+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_34_match_review_plan_preview"
+ assert plan["ready_for_review_queue"] is False
+ assert plan["review_queue_created"] is False
+ assert plan["auto_match_executed"] is False
+ assert plan["auto_confirm_executed"] is False
+ assert plan["database_session_created"] is False
+ assert plan["database_write_executed"] is False
+ assert plan["database_commit_executed"] is False
+ assert plan["external_network_executed"] is False
+ assert plan["scheduler_attached"] is False
+ assert plan["writes_executed"] is False
+ assert plan["would_write_database"] is False
+ assert plan["thresholds"]["auto_confirm_enabled"] is False
+ assert len(plan["scoring_signals"]) >= 5
+ assert "needs_review" in plan["planned_status_flow"]
+ assert "confirmed" in plan["planned_status_flow"]
+ assert "manual_operator_approval" in plan["blocked_reasons"]
+ assert "do_not_auto_confirm_matches" in plan["safe_boundaries"]
+ assert all(item["requires_operator"] for item in plan["review_actions"])
+
+
+def test_match_review_plan_route_is_preview_only():
+ from routes.market_intel_routes import market_intel_bp
+
+ app = Flask(__name__)
+ app.secret_key = "test-secret"
+ app.register_blueprint(market_intel_bp)
+ client = app.test_client()
+ with client.session_transaction() as session:
+ session["logged_in"] = True
+
+ response = client.get("/api/market_intel/match_review_plan")
+ data = response.get_json()
+
+ assert response.status_code == 200
+ assert data["mode"] == "match_review_plan_preview"
+ assert data["phase"] == "phase_34_match_review_plan_preview"
+ assert data["review_queue_created"] is False
+ assert data["auto_confirm_executed"] is False
+ assert data["external_network_executed"] is False
+ assert data["database_write_executed"] is False
+
+
def test_mcp_deploy_preflight_blocks_without_required_env():
preflight = build_mcp_deploy_preflight_plan(env={})
@@ -985,7 +1038,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_33_scheduler_plan_preview"
+ assert data["phase"] == "phase_34_match_review_plan_preview"
assert data["deployment_actions_executed"] is False
assert data["docker_command_executed"] is False
assert data["ssh_command_executed"] is False
@@ -1000,7 +1053,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_33_scheduler_plan_preview"
+ assert readiness["phase"] == "phase_34_match_review_plan_preview"
assert readiness["execute_requested"] is False
assert readiness["router_enabled"] is False
assert readiness["external_mcp_complete"] is False
@@ -1388,6 +1441,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
assert readiness["checks"]["mcp_activation_runbook_preview_safe"] is True
assert readiness["checks"]["mcp_fetch_gate_preview_safe"] is True
assert readiness["checks"]["scheduler_plan_preview_safe"] is True
+ assert readiness["checks"]["match_review_plan_preview_safe"] is True
assert readiness["checks"]["writer_plan_dry_run_only"] is True
assert readiness["writer_plan_summary"]["writes_executed"] is False
assert "readiness_checks_not_all_passed" not in readiness["blocked_reasons"]
@@ -1409,6 +1463,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
assert "/api/market_intel/mcp_activation_runbook" in readiness["production_smoke_targets"]
assert "/api/market_intel/mcp_fetch_gate" in readiness["production_smoke_targets"]
assert "/api/market_intel/scheduler_plan" in readiness["production_smoke_targets"]
+ assert "/api/market_intel/match_review_plan" in readiness["production_smoke_targets"]
assert readiness["write_approval_runbook"]["ready_for_real_write"] is False
assert readiness["write_approval_runbook"]["writes_executed"] is False
assert readiness["migration_blueprint"]["migration_executed"] is False
@@ -1430,6 +1485,9 @@ def test_deployment_readiness_reports_app_only_release_gate():
assert readiness["scheduler_plan"]["scheduler_registration_executed"] is False
assert readiness["scheduler_plan"]["crawler_job_started"] is False
assert readiness["scheduler_plan"]["database_write_executed"] is False
+ assert readiness["match_review_plan"]["review_queue_created"] is False
+ assert readiness["match_review_plan"]["auto_confirm_executed"] is False
+ assert readiness["match_review_plan"]["database_write_executed"] is False
def test_write_approval_runbook_is_read_only_and_blocks_real_write():