This commit is contained in:
@@ -102,6 +102,7 @@
|
||||
- Phase 46 live DB inventory preview:新增 `/api/market_intel/live_db_inventory` 與 UI「正式 DB 庫存總覽」panel;預設 `execute=false` 不連 DB,人工 smoke 才可用 `execute=true` 對 `market_*` tables 做只讀 count / group by,建立平台、活動、商品、比對、告警與 crawler run 基準;版本同步至 V10.209。
|
||||
- Phase 47 manual sample fetch plan:新增 `/api/market_intel/manual_sample_plan` 與 UI「人工樣本 Fetch 計畫」panel;預設只輸出平台順序、每平台 1 個公開入口、MCP gate、操作員步驟與備援,不抓外站、不寫 DB、不建立 crawler run、不掛 scheduler;版本同步至 V10.214。
|
||||
- Phase 48 manual sample acceptance contract:新增 `/api/market_intel/manual_sample_acceptance` 與 UI「樣本結果驗收契約」panel;定義 sample result 必要欄位、diagnostics 欄位、驗收門檻、拒收條件、人工決策與升級順序,不載入 sample result、不抓外站、不允許候選導入、不寫 DB;版本同步至 V10.215。
|
||||
- Phase 49 manual sample result review:新增 `services/market_intel/manual_sample_review.py`、`/api/market_intel/manual_sample_review` 與 UI「樣本結果審核預覽」panel;以純函式評估人工 sample result 是否可進候選預覽,預設不載入結果、不抓外站、不存檔、不寫 DB、不允許候選導入、不掛 scheduler;版本同步至 V10.216。
|
||||
- Schema smoke:`tests/test_market_intel_skeleton.py` 檢查 `Base.metadata` 內含 ADR-035 八張 `market_*` tables。
|
||||
- Desktop UI QA:本機只註冊 `market_intel_bp` 的 Flask harness 載入 `/market_intel`,確認 Phase 15、候選預覽、writer preview、安全 flags、點陣暖紙視覺正常,console error 0。
|
||||
- API QA:`/api/market_intel/schema_smoke` 通過 7 張表與 `market_platforms` 必要欄位檢查;`/api/market_intel/platform_seed_writer_plan` 回傳 4 筆 dry-run upsert preview,`writes_executed=false`,四平台皆 `blocked_dry_run_only`。
|
||||
|
||||
@@ -174,6 +174,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 2026-05-18 追加 live DB inventory preview:`services.market_intel.live_db_inventory` 與 `/api/market_intel/live_db_inventory` 預設 `execute=false` 只回 planned,不連 DB;人工 smoke 可用 `execute=true` 對 `market_*` tables 執行只讀 count / group by,產生平台、活動狀態、商品活躍度、比對狀態、告警審核佇列與 crawler run 基準總覽。此探針不建立 ORM session、不寫 DB、不執行 migration、不連外、不掛 scheduler。
|
||||
- 2026-05-19 追加 manual sample fetch plan preview:`services.market_intel.manual_sample_plan` 與 `/api/market_intel/manual_sample_plan` 定義第一次人工 sample fetch 的平台順序、每平台 1 個公開入口、MCP fetch gate、正式 DB 庫存基準、操作員步驟與備援。此階段只產生計畫,不抓外部網站、不寫 DB、不建立 crawler run、不掛 scheduler、不繞反爬。
|
||||
- 2026-05-19 追加 manual sample acceptance contract:`services.market_intel.manual_sample_acceptance` 與 `/api/market_intel/manual_sample_acceptance` 定義 sample fetch 結果回來後的必要欄位、診斷欄位、驗收門檻、拒收條件、人工決策與升級順序。此階段不載入 sample result、不抓外部網站、不允許候選導入、不寫 DB、不掛 scheduler。
|
||||
- 2026-05-19 追加 manual sample result review:`services.market_intel.manual_sample_review` 與 `/api/market_intel/manual_sample_review` 以純函式評估操作員提供的 sample result 是否通過 Phase 48 驗收門檻並可進候選預覽。API/UI 預設不載入 sample result,不抓外站、不存檔、不寫 DB、不允許候選導入、不掛 scheduler;即使審核通過也只開 candidate preview gate,正式 market_* 寫入仍需後續獨立批准。
|
||||
|
||||
### Phase 4:Coupang / Shopee Adapter
|
||||
|
||||
|
||||
@@ -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 48 manual sample acceptance 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/manual_sample_plan`, `/api/market_intel/manual_sample_acceptance`, `/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/migration_apply_drill`, `/api/market_intel/migration_catalog_review`, `/api/market_intel/migration_live_smoke`, `/api/market_intel/live_db_inventory`, `/api/market_intel/seed_writer_cli_status`, `/api/market_intel/write_approval_runbook`, `/api/market_intel/deployment_readiness` |
|
||||
| `market_intel_routes.py` | 市場情報 Phase 49 manual sample result review | `/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/manual_sample_plan`, `/api/market_intel/manual_sample_acceptance`, `/api/market_intel/manual_sample_review`, `/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/migration_apply_drill`, `/api/market_intel/migration_catalog_review`, `/api/market_intel/migration_live_smoke`, `/api/market_intel/live_db_inventory`, `/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` |
|
||||
|
||||
@@ -169,6 +169,12 @@ def market_intel_manual_sample_acceptance():
|
||||
return jsonify(_service().build_manual_sample_acceptance())
|
||||
|
||||
|
||||
@market_intel_bp.route("/api/market_intel/manual_sample_review")
|
||||
@login_required
|
||||
def market_intel_manual_sample_review():
|
||||
return jsonify(_service().build_manual_sample_review())
|
||||
|
||||
|
||||
@market_intel_bp.route("/api/market_intel/match_review_plan")
|
||||
@login_required
|
||||
def market_intel_match_review_plan():
|
||||
|
||||
@@ -20,6 +20,7 @@ def build_deployment_readiness_preview(
|
||||
scheduler_plan = service.build_scheduler_plan()
|
||||
manual_sample_plan = service.build_manual_sample_plan()
|
||||
manual_sample_acceptance = service.build_manual_sample_acceptance()
|
||||
manual_sample_review = service.build_manual_sample_review()
|
||||
match_review_plan = service.build_match_review_plan()
|
||||
opportunity_plan = service.build_opportunity_plan()
|
||||
opportunity_scoring_plan = service.build_opportunity_scoring_plan()
|
||||
@@ -96,6 +97,15 @@ def build_deployment_readiness_preview(
|
||||
and not manual_sample_acceptance["database_commit_executed"]
|
||||
and not manual_sample_acceptance["scheduler_attached"]
|
||||
),
|
||||
"manual_sample_review_preview_safe": bool(
|
||||
manual_sample_review["mode"] == "manual_sample_review_preview"
|
||||
and not manual_sample_review["sample_result_loaded"]
|
||||
and not manual_sample_review["candidate_import_allowed"]
|
||||
and not manual_sample_review["external_network_executed"]
|
||||
and not manual_sample_review["database_write_executed"]
|
||||
and not manual_sample_review["database_commit_executed"]
|
||||
and not manual_sample_review["scheduler_attached"]
|
||||
),
|
||||
"match_review_plan_preview_safe": bool(
|
||||
match_review_plan["mode"] == "match_review_plan_preview"
|
||||
and not match_review_plan["review_queue_created"]
|
||||
@@ -300,6 +310,7 @@ def build_deployment_readiness_preview(
|
||||
"/api/market_intel/scheduler_plan",
|
||||
"/api/market_intel/manual_sample_plan",
|
||||
"/api/market_intel/manual_sample_acceptance",
|
||||
"/api/market_intel/manual_sample_review",
|
||||
"/api/market_intel/match_review_plan",
|
||||
"/api/market_intel/opportunity_plan",
|
||||
"/api/market_intel/opportunity_scoring_plan",
|
||||
@@ -335,6 +346,7 @@ def build_deployment_readiness_preview(
|
||||
"scheduler_plan": scheduler_plan,
|
||||
"manual_sample_plan": manual_sample_plan,
|
||||
"manual_sample_acceptance": manual_sample_acceptance,
|
||||
"manual_sample_review": manual_sample_review,
|
||||
"match_review_plan": match_review_plan,
|
||||
"opportunity_plan": opportunity_plan,
|
||||
"opportunity_scoring_plan": opportunity_scoring_plan,
|
||||
|
||||
297
services/market_intel/manual_sample_review.py
Normal file
297
services/market_intel/manual_sample_review.py
Normal file
@@ -0,0 +1,297 @@
|
||||
"""市場情報人工 sample result 審核預覽。
|
||||
|
||||
本模組只用純函式評估操作員提供的 sample result payload;
|
||||
不抓外部網站、不查 DB、不寫 DB、不建立候選活動、不掛排程。
|
||||
"""
|
||||
|
||||
from services.market_intel.manual_sample_acceptance import (
|
||||
REQUIRED_DIAGNOSTIC_FIELDS,
|
||||
REQUIRED_RESULT_FIELDS,
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_ACCEPTANCE_THRESHOLDS = {
|
||||
"http_status_min": 200,
|
||||
"http_status_max": 299,
|
||||
"minimum_content_length": 500,
|
||||
"page_hash_length": 64,
|
||||
"minimum_title_length": 2,
|
||||
"minimum_link_count": 1,
|
||||
"minimum_campaign_candidates": 1,
|
||||
"accepted_candidate_bands": ["high", "medium"],
|
||||
}
|
||||
|
||||
|
||||
def _as_int(value, default=0):
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
def _thresholds(acceptance_contract):
|
||||
configured = {}
|
||||
if isinstance(acceptance_contract, dict):
|
||||
configured = acceptance_contract.get("acceptance_thresholds") or {}
|
||||
return {
|
||||
**DEFAULT_ACCEPTANCE_THRESHOLDS,
|
||||
**configured,
|
||||
}
|
||||
|
||||
|
||||
def _normalize_candidate(candidate):
|
||||
if not isinstance(candidate, dict):
|
||||
return {
|
||||
"confidence_band": "unknown",
|
||||
"score": 0,
|
||||
"url": "",
|
||||
"text": "",
|
||||
}
|
||||
return {
|
||||
"confidence_band": str(candidate.get("confidence_band") or "unknown"),
|
||||
"score": _as_int(candidate.get("score"), 0),
|
||||
"url": str(candidate.get("url") or candidate.get("href") or ""),
|
||||
"text": str(candidate.get("text") or candidate.get("title") or ""),
|
||||
}
|
||||
|
||||
|
||||
def _build_check(key, label, passed, observed, expected):
|
||||
return {
|
||||
"key": key,
|
||||
"label": label,
|
||||
"status": "pass" if passed else "block",
|
||||
"passed": bool(passed),
|
||||
"observed": observed,
|
||||
"expected": expected,
|
||||
}
|
||||
|
||||
|
||||
def evaluate_manual_sample_result(sample_result, acceptance_contract):
|
||||
"""以驗收契約評估單一 sample result;不做任何 IO。"""
|
||||
thresholds = _thresholds(acceptance_contract)
|
||||
if not sample_result:
|
||||
return {
|
||||
"sample_result_loaded": False,
|
||||
"sample_result_reviewed": False,
|
||||
"sample_result_accepted": False,
|
||||
"ready_for_candidate_preview": False,
|
||||
"candidate_import_allowed": False,
|
||||
"review_result": "planned_no_sample_result",
|
||||
"review_checks": [],
|
||||
"review_findings": [
|
||||
{
|
||||
"key": "sample_result_not_loaded",
|
||||
"severity": "block",
|
||||
"label": "尚未載入人工樣本結果,維持預覽狀態",
|
||||
},
|
||||
],
|
||||
"candidate_summary": {
|
||||
"candidate_count": 0,
|
||||
"accepted_candidate_count": 0,
|
||||
"accepted_candidate_bands": thresholds["accepted_candidate_bands"],
|
||||
"top_candidates": [],
|
||||
},
|
||||
}
|
||||
|
||||
diagnostics = sample_result.get("diagnostics")
|
||||
diagnostics = diagnostics if isinstance(diagnostics, dict) else {}
|
||||
candidates = diagnostics.get("campaign_link_candidates")
|
||||
candidates = candidates if isinstance(candidates, list) else []
|
||||
normalized_candidates = [_normalize_candidate(item) for item in candidates]
|
||||
accepted_bands = set(thresholds["accepted_candidate_bands"])
|
||||
accepted_candidates = [
|
||||
item for item in normalized_candidates
|
||||
if item["confidence_band"] in accepted_bands
|
||||
]
|
||||
|
||||
missing_result_fields = [
|
||||
field for field in REQUIRED_RESULT_FIELDS
|
||||
if sample_result.get(field) in (None, "")
|
||||
]
|
||||
missing_diagnostic_fields = [
|
||||
field for field in REQUIRED_DIAGNOSTIC_FIELDS
|
||||
if diagnostics.get(field) in (None, "")
|
||||
]
|
||||
status_code = _as_int(sample_result.get("status_code"), 0)
|
||||
content_length = _as_int(sample_result.get("content_length"), 0)
|
||||
page_hash = str(sample_result.get("page_hash") or "")
|
||||
title = str(sample_result.get("title") or "")
|
||||
link_count = _as_int(diagnostics.get("link_count"), 0)
|
||||
|
||||
checks = [
|
||||
_build_check(
|
||||
"required_result_fields_present",
|
||||
"sample result 必須包含 Phase 48 定義的必要欄位",
|
||||
not missing_result_fields,
|
||||
missing_result_fields,
|
||||
list(REQUIRED_RESULT_FIELDS),
|
||||
),
|
||||
_build_check(
|
||||
"required_diagnostics_present",
|
||||
"diagnostics 必須包含連結與候選診斷欄位",
|
||||
not missing_diagnostic_fields,
|
||||
missing_diagnostic_fields,
|
||||
list(REQUIRED_DIAGNOSTIC_FIELDS),
|
||||
),
|
||||
_build_check(
|
||||
"http_status_ok",
|
||||
"HTTP status 必須落在允收區間",
|
||||
thresholds["http_status_min"]
|
||||
<= status_code
|
||||
<= thresholds["http_status_max"],
|
||||
status_code,
|
||||
f"{thresholds['http_status_min']}-{thresholds['http_status_max']}",
|
||||
),
|
||||
_build_check(
|
||||
"content_has_body",
|
||||
"content_length 必須超過最低門檻",
|
||||
content_length >= thresholds["minimum_content_length"],
|
||||
content_length,
|
||||
thresholds["minimum_content_length"],
|
||||
),
|
||||
_build_check(
|
||||
"page_fingerprint_present",
|
||||
"page_hash 必須符合固定長度,後續才能比對頁面變化",
|
||||
len(page_hash) == thresholds["page_hash_length"],
|
||||
len(page_hash),
|
||||
thresholds["page_hash_length"],
|
||||
),
|
||||
_build_check(
|
||||
"title_present",
|
||||
"title 必須能判斷頁面內容,不接受空白或挑戰頁",
|
||||
len(title.strip()) >= thresholds["minimum_title_length"],
|
||||
len(title.strip()),
|
||||
thresholds["minimum_title_length"],
|
||||
),
|
||||
_build_check(
|
||||
"link_count_present",
|
||||
"link_count 必須高於最低門檻,避免空頁或驗證頁",
|
||||
link_count >= thresholds["minimum_link_count"],
|
||||
link_count,
|
||||
thresholds["minimum_link_count"],
|
||||
),
|
||||
_build_check(
|
||||
"candidate_quality_reviewed",
|
||||
"至少需要一筆 high/medium 活動候選進入人工候選預覽",
|
||||
len(accepted_candidates) >= thresholds["minimum_campaign_candidates"],
|
||||
len(accepted_candidates),
|
||||
thresholds["minimum_campaign_candidates"],
|
||||
),
|
||||
]
|
||||
findings = [
|
||||
{
|
||||
"key": check["key"],
|
||||
"severity": "block",
|
||||
"label": check["label"],
|
||||
"observed": check["observed"],
|
||||
"expected": check["expected"],
|
||||
}
|
||||
for check in checks
|
||||
if not check["passed"]
|
||||
]
|
||||
accepted = all(check["passed"] for check in checks)
|
||||
return {
|
||||
"sample_result_loaded": True,
|
||||
"sample_result_reviewed": True,
|
||||
"sample_result_accepted": accepted,
|
||||
"ready_for_candidate_preview": accepted,
|
||||
"candidate_import_allowed": False,
|
||||
"review_result": (
|
||||
"accepted_for_candidate_preview"
|
||||
if accepted
|
||||
else "rejected_sample_result"
|
||||
),
|
||||
"review_checks": checks,
|
||||
"review_findings": findings,
|
||||
"candidate_summary": {
|
||||
"candidate_count": len(normalized_candidates),
|
||||
"accepted_candidate_count": len(accepted_candidates),
|
||||
"accepted_candidate_bands": thresholds["accepted_candidate_bands"],
|
||||
"top_candidates": accepted_candidates[:5],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def build_manual_sample_review_preview(
|
||||
*,
|
||||
runtime_status,
|
||||
acceptance_contract,
|
||||
sample_result=None,
|
||||
):
|
||||
"""建立人工樣本結果審核預覽;預設不載入 sample result。"""
|
||||
evaluation = evaluate_manual_sample_result(
|
||||
sample_result,
|
||||
acceptance_contract,
|
||||
)
|
||||
gate_checks = {
|
||||
"acceptance_contract_ready": bool(
|
||||
acceptance_contract
|
||||
and acceptance_contract.get("contract_ready")
|
||||
),
|
||||
"sample_review_is_pure_function": True,
|
||||
"external_network_blocked_in_review": True,
|
||||
"database_write_still_blocked": not bool(
|
||||
getattr(runtime_status, "database_write_allowed", False)
|
||||
),
|
||||
"scheduler_detached": not bool(
|
||||
getattr(runtime_status, "scheduler_attached", False)
|
||||
),
|
||||
}
|
||||
blocked_reasons = [
|
||||
key for key, passed in gate_checks.items()
|
||||
if not passed
|
||||
]
|
||||
if not evaluation["sample_result_loaded"]:
|
||||
blocked_reasons.append("sample_result_not_loaded")
|
||||
if not evaluation["ready_for_candidate_preview"]:
|
||||
blocked_reasons.append("candidate_preview_not_ready")
|
||||
blocked_reasons.append("candidate_import_still_blocked_until_operator_approval")
|
||||
|
||||
return {
|
||||
"mode": "manual_sample_review_preview",
|
||||
"contract_ready": bool(gate_checks["acceptance_contract_ready"]),
|
||||
"sample_result_loaded": evaluation["sample_result_loaded"],
|
||||
"sample_result_reviewed": evaluation["sample_result_reviewed"],
|
||||
"sample_result_accepted": evaluation["sample_result_accepted"],
|
||||
"ready_for_candidate_preview": evaluation["ready_for_candidate_preview"],
|
||||
"candidate_import_allowed": False,
|
||||
"external_network_executed": False,
|
||||
"database_connection_opened": False,
|
||||
"database_session_created": False,
|
||||
"database_write_executed": False,
|
||||
"database_commit_executed": False,
|
||||
"scheduler_attached": False,
|
||||
"writes_executed": False,
|
||||
"would_write_database": False,
|
||||
"gate_checks": gate_checks,
|
||||
"blocked_reasons": blocked_reasons,
|
||||
"review_result": evaluation["review_result"],
|
||||
"review_checks": evaluation["review_checks"],
|
||||
"review_findings": evaluation["review_findings"],
|
||||
"candidate_summary": evaluation["candidate_summary"],
|
||||
"operator_next_actions": [
|
||||
{
|
||||
"key": "load_single_sample_result_manually",
|
||||
"label": "由操作員提供單一平台 sample result JSON,再用純函式審核",
|
||||
"write_status": "blocked",
|
||||
},
|
||||
{
|
||||
"key": "open_candidate_preview_after_pass",
|
||||
"label": "審核通過後只開候選活動預覽,仍不得寫入 market_campaigns",
|
||||
"write_status": "blocked",
|
||||
},
|
||||
{
|
||||
"key": "revise_adapter_source_after_reject",
|
||||
"label": "審核未通過時調整 adapter source 或暫停該平台",
|
||||
"write_status": "blocked",
|
||||
},
|
||||
],
|
||||
"safe_boundaries": [
|
||||
"do_not_fetch_external_pages_from_review_api",
|
||||
"do_not_store_sample_result_from_review_preview",
|
||||
"do_not_import_candidates_from_review_preview",
|
||||
"do_not_write_market_tables_from_review_preview",
|
||||
"do_not_attach_scheduler_from_review_preview",
|
||||
"do_not_touch_momo_db_lifecycle",
|
||||
],
|
||||
}
|
||||
@@ -36,6 +36,9 @@ from services.market_intel.manual_sample_plan import (
|
||||
from services.market_intel.manual_sample_acceptance import (
|
||||
build_manual_sample_acceptance_preview,
|
||||
)
|
||||
from services.market_intel.manual_sample_review import (
|
||||
build_manual_sample_review_preview,
|
||||
)
|
||||
from services.market_intel.migration_blueprint import build_migration_blueprint
|
||||
from services.market_intel.migration_catalog_review import (
|
||||
build_migration_catalog_review_preview,
|
||||
@@ -98,7 +101,7 @@ class MarketIntelRuntimeStatus:
|
||||
class MarketIntelService:
|
||||
"""市場情報入口服務,先集中 feature gate 與安全狀態。"""
|
||||
|
||||
phase = "phase_48_manual_sample_acceptance_contract"
|
||||
phase = "phase_49_manual_sample_result_review"
|
||||
|
||||
def get_runtime_status(self) -> MarketIntelRuntimeStatus:
|
||||
return MarketIntelRuntimeStatus(
|
||||
@@ -447,6 +450,16 @@ class MarketIntelService:
|
||||
acceptance["phase"] = self.phase
|
||||
return acceptance
|
||||
|
||||
def build_manual_sample_review(self, sample_result=None):
|
||||
"""回報人工 sample result 審核預覽;預設不載入結果、不寫 DB。"""
|
||||
review = build_manual_sample_review_preview(
|
||||
runtime_status=self.get_runtime_status(),
|
||||
acceptance_contract=self.build_manual_sample_acceptance(),
|
||||
sample_result=sample_result,
|
||||
)
|
||||
review["phase"] = self.phase
|
||||
return review
|
||||
|
||||
def build_match_review_plan(self):
|
||||
"""回報商品比對審核計畫;不建立 queue、不自動確認。"""
|
||||
schema_smoke = self.build_schema_smoke()
|
||||
|
||||
@@ -522,6 +522,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="market-intel-panel" data-market-intel-sample-review>
|
||||
<div class="market-intel-preview-head">
|
||||
<div>
|
||||
<p class="market-intel-muted momo-mono mb-1">MANUAL SAMPLE / REVIEW</p>
|
||||
<h2 class="market-intel-preview-title">樣本結果審核預覽</h2>
|
||||
</div>
|
||||
<button class="market-intel-icon-button" type="button" title="重新整理樣本結果審核預覽" data-market-intel-sample-review-refresh>
|
||||
<i class="fas fa-rotate-right" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="market-intel-preview-meta" data-market-intel-sample-review-meta>
|
||||
<span class="market-intel-pill">loading</span>
|
||||
</div>
|
||||
<div data-market-intel-sample-review-body>
|
||||
<div class="market-intel-empty">讀取樣本結果審核預覽中...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="market-intel-panel" data-market-intel-scheduler>
|
||||
<div class="market-intel-preview-head">
|
||||
<div>
|
||||
@@ -773,6 +791,7 @@
|
||||
const mcpFetchGateRoot = document.querySelector('[data-market-intel-mcp-fetch-gate]');
|
||||
const manualSampleRoot = document.querySelector('[data-market-intel-manual-sample]');
|
||||
const sampleAcceptanceRoot = document.querySelector('[data-market-intel-sample-acceptance]');
|
||||
const sampleReviewRoot = document.querySelector('[data-market-intel-sample-review]');
|
||||
const schedulerRoot = document.querySelector('[data-market-intel-scheduler]');
|
||||
const matchReviewRoot = document.querySelector('[data-market-intel-match-review]');
|
||||
const opportunityRoot = document.querySelector('[data-market-intel-opportunity]');
|
||||
@@ -786,7 +805,7 @@
|
||||
const liveInventoryRoot = document.querySelector('[data-market-intel-live-inventory]');
|
||||
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 && !manualSampleRoot && !sampleAcceptanceRoot && !schedulerRoot && !matchReviewRoot && !opportunityRoot && !opportunityScoringRoot && !opportunityEvidenceRoot && !opportunityAlertRoot && !migrationRoot && !migrationDrillRoot && !catalogReviewRoot && !liveSmokeRoot && !liveInventoryRoot && !approvalRoot && !deployRoot) return;
|
||||
if (!root && !writerRoot && !cliRoot && !dbProbeRoot && !seedDiffRoot && !legacyBridgeRoot && !mcpReadinessRoot && !mcpPreflightRoot && !mcpActivationRoot && !mcpFetchGateRoot && !manualSampleRoot && !sampleAcceptanceRoot && !sampleReviewRoot && !schedulerRoot && !matchReviewRoot && !opportunityRoot && !opportunityScoringRoot && !opportunityEvidenceRoot && !opportunityAlertRoot && !migrationRoot && !migrationDrillRoot && !catalogReviewRoot && !liveSmokeRoot && !liveInventoryRoot && !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;
|
||||
@@ -836,6 +855,10 @@
|
||||
const sampleAcceptanceBody = sampleAcceptanceRoot ? sampleAcceptanceRoot.querySelector('[data-market-intel-sample-acceptance-body]') : null;
|
||||
const sampleAcceptanceRefresh = sampleAcceptanceRoot ? sampleAcceptanceRoot.querySelector('[data-market-intel-sample-acceptance-refresh]') : null;
|
||||
const sampleAcceptanceEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_acceptance') }}";
|
||||
const sampleReviewMeta = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-meta]') : null;
|
||||
const sampleReviewBody = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-body]') : null;
|
||||
const sampleReviewRefresh = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-refresh]') : null;
|
||||
const sampleReviewEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_review') }}";
|
||||
const schedulerMeta = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-meta]') : null;
|
||||
const schedulerBody = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-body]') : null;
|
||||
const schedulerRefresh = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-refresh]') : null;
|
||||
@@ -1809,6 +1832,99 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderSampleReviewMeta = data => {
|
||||
sampleReviewMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`loaded=${data.sample_result_loaded ? 'yes' : 'no'}`,
|
||||
`reviewed=${data.sample_result_reviewed ? 'yes' : 'no'}`,
|
||||
`result=${data.review_result || 'planned'}`,
|
||||
`import=${data.candidate_import_allowed ? 'open' : 'blocked'}`
|
||||
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
|
||||
};
|
||||
|
||||
const renderSampleReviewBody = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const checks = data.review_checks || [];
|
||||
const findings = data.review_findings || [];
|
||||
const candidates = data.candidate_summary || {};
|
||||
const actions = data.operator_next_actions || [];
|
||||
const boundaries = data.safe_boundaries || [];
|
||||
const renderCheck = item => `
|
||||
<div class="market-intel-check">
|
||||
<div>
|
||||
<strong>${escapeHtml(item.key || 'check')}</strong>
|
||||
<small>${escapeHtml(item.label || '')}</small>
|
||||
</div>
|
||||
<span>${escapeHtml(item.status || 'planned').toUpperCase()}</span>
|
||||
</div>
|
||||
`;
|
||||
const renderNamedItem = (item, status) => {
|
||||
const normalized = typeof item === 'string' ? { key: item, label: item } : (item || {});
|
||||
return `
|
||||
<div class="market-intel-check">
|
||||
<div>
|
||||
<strong>${escapeHtml(normalized.key || normalized.label || 'item')}</strong>
|
||||
<small>${escapeHtml(normalized.label || normalized.key || '')}</small>
|
||||
</div>
|
||||
<span>${escapeHtml(normalized.severity || normalized.write_status || status || 'blocked').toUpperCase()}</span>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
sampleReviewBody.innerHTML = `
|
||||
<div class="market-intel-empty mb-3">此卡只用純函式審核人工 sample result;目前預設不載入結果、不抓外站、不存檔、不寫 DB、不建立候選活動。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
|
||||
<div class="market-intel-empty mb-3">candidate_count=${escapeHtml(candidates.candidate_count || 0)} / accepted=${escapeHtml(candidates.accepted_candidate_count || 0)} / bands=${escapeHtml((candidates.accepted_candidate_bands || []).join('/'))}</div>
|
||||
<div class="market-intel-deploy-grid">
|
||||
<div data-market-intel-sample-review-checks>
|
||||
<p class="market-intel-deploy-section-title">REVIEW CHECKS</p>
|
||||
<div class="market-intel-check-list">${
|
||||
checks.length
|
||||
? checks.map(renderCheck).join('')
|
||||
: '<div class="market-intel-empty">尚未載入 sample result,審核檢查維持 planned。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div data-market-intel-sample-review-findings>
|
||||
<p class="market-intel-deploy-section-title">FINDINGS</p>
|
||||
<div class="market-intel-check-list">${
|
||||
findings.length
|
||||
? findings.map(item => renderNamedItem(item, 'block')).join('')
|
||||
: '<div class="market-intel-empty">目前沒有審核發現;尚未載入結果時代表未評估。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div data-market-intel-sample-review-actions>
|
||||
<p class="market-intel-deploy-section-title">NEXT ACTIONS</p>
|
||||
<div class="market-intel-check-list">${
|
||||
actions.length
|
||||
? actions.map(item => renderNamedItem(item, item.write_status || 'blocked')).join('')
|
||||
: '<div class="market-intel-empty">尚未提供下一步。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div data-market-intel-sample-review-boundaries>
|
||||
<p class="market-intel-deploy-section-title">BOUNDARIES</p>
|
||||
<div class="market-intel-check-list">${
|
||||
boundaries.length
|
||||
? boundaries.map(item => renderNamedItem(String(item), 'required')).join('')
|
||||
: '<div class="market-intel-empty">尚未提供安全邊界。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const loadSampleReview = async () => {
|
||||
if (!sampleReviewMeta || !sampleReviewBody) return;
|
||||
sampleReviewBody.innerHTML = '<div class="market-intel-empty">讀取樣本結果審核預覽中...</div>';
|
||||
try {
|
||||
const response = await fetch(sampleReviewEndpoint, { credentials: 'same-origin' });
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const data = await response.json();
|
||||
renderSampleReviewMeta(data);
|
||||
renderSampleReviewBody(data);
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">樣本結果審核預覽讀取失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderSchedulerMeta = data => {
|
||||
schedulerMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
@@ -3297,6 +3413,9 @@
|
||||
if (sampleAcceptanceRefresh) {
|
||||
sampleAcceptanceRefresh.addEventListener('click', loadSampleAcceptance);
|
||||
}
|
||||
if (sampleReviewRefresh) {
|
||||
sampleReviewRefresh.addEventListener('click', loadSampleReview);
|
||||
}
|
||||
if (schedulerRefresh) {
|
||||
schedulerRefresh.addEventListener('click', loadScheduler);
|
||||
}
|
||||
@@ -3348,6 +3467,7 @@
|
||||
loadMcpFetchGate();
|
||||
loadManualSample();
|
||||
loadSampleAcceptance();
|
||||
loadSampleReview();
|
||||
loadScheduler();
|
||||
loadMatchReview();
|
||||
loadOpportunity();
|
||||
|
||||
@@ -20,6 +20,7 @@ from services.market_intel.mcp_deploy_preflight import build_mcp_deploy_prefligh
|
||||
from services.market_intel.mcp_fetch_gate import build_mcp_fetch_gate_preview
|
||||
from services.market_intel.mcp_readiness import build_mcp_readiness_plan
|
||||
from services.market_intel.live_db_inventory import build_live_db_inventory_preview
|
||||
from services.market_intel.manual_sample_review import evaluate_manual_sample_result
|
||||
from services.market_intel.platform_seed_db_diff import build_platform_seed_db_diff_plan
|
||||
from services.market_intel.schema_db_probe import build_schema_db_probe_plan
|
||||
|
||||
@@ -510,6 +511,11 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
assert "data-market-intel-sample-acceptance-checks" in template
|
||||
assert "data-market-intel-sample-acceptance-fields" in template
|
||||
assert "data-market-intel-sample-acceptance-rules" in template
|
||||
assert "data-market-intel-sample-review" in template
|
||||
assert "data-market-intel-sample-review-checks" in template
|
||||
assert "data-market-intel-sample-review-findings" in template
|
||||
assert "data-market-intel-sample-review-actions" in template
|
||||
assert "data-market-intel-sample-review-boundaries" in template
|
||||
assert "data-market-intel-approval" in template
|
||||
assert "data-market-intel-approval-gates" in template
|
||||
assert "data-market-intel-deploy" in template
|
||||
@@ -527,6 +533,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
assert "market_intel.market_intel_mcp_fetch_gate" in template
|
||||
assert "market_intel.market_intel_manual_sample_plan" in template
|
||||
assert "market_intel.market_intel_manual_sample_acceptance" in template
|
||||
assert "market_intel.market_intel_manual_sample_review" 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_opportunity_plan" in template
|
||||
@@ -562,7 +569,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_48_manual_sample_acceptance_contract"
|
||||
assert bridge["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert bridge["execute_requested"] is False
|
||||
assert bridge["read_only_query_executed"] is False
|
||||
assert bridge["database_connection_opened"] is False
|
||||
@@ -720,7 +727,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_48_manual_sample_acceptance_contract"
|
||||
assert contract["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert contract["caller"] == "market_intel"
|
||||
assert contract["contract_ready"] is True
|
||||
assert contract["blocked_reasons"] == []
|
||||
@@ -853,7 +860,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -866,7 +873,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_48_manual_sample_acceptance_contract"
|
||||
assert gate["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert gate["fetch_requested"] is True
|
||||
assert gate["manual_fetch_gate_open"] is False
|
||||
assert gate["network_request_allowed"] is False
|
||||
@@ -936,7 +943,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["fetch_requested"] is False
|
||||
assert data["network_request_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -948,7 +955,7 @@ def test_manual_sample_plan_preview_blocks_fetch_and_write():
|
||||
plan = MarketIntelService().build_manual_sample_plan()
|
||||
|
||||
assert plan["mode"] == "manual_sample_fetch_plan_preview"
|
||||
assert plan["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_manual_sample_fetch"] is False
|
||||
assert plan["sample_fetch_executed"] is False
|
||||
assert plan["external_network_executed"] is False
|
||||
@@ -996,7 +1003,7 @@ def test_manual_sample_plan_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_fetch_plan_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["sample_fetch_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
@@ -1007,7 +1014,7 @@ def test_manual_sample_acceptance_preview_blocks_candidate_import():
|
||||
acceptance = MarketIntelService().build_manual_sample_acceptance()
|
||||
|
||||
assert acceptance["mode"] == "manual_sample_acceptance_preview"
|
||||
assert acceptance["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert acceptance["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert acceptance["contract_ready"] is True
|
||||
assert acceptance["sample_result_loaded"] is False
|
||||
assert acceptance["sample_result_accepted"] is False
|
||||
@@ -1049,7 +1056,7 @@ def test_manual_sample_acceptance_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_acceptance_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1057,11 +1064,135 @@ def test_manual_sample_acceptance_route_is_preview_only():
|
||||
assert data["scheduler_attached"] is False
|
||||
|
||||
|
||||
def test_manual_sample_review_preview_is_planned_until_result_loaded():
|
||||
review = MarketIntelService().build_manual_sample_review()
|
||||
|
||||
assert review["mode"] == "manual_sample_review_preview"
|
||||
assert review["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert review["contract_ready"] is True
|
||||
assert review["sample_result_loaded"] is False
|
||||
assert review["sample_result_reviewed"] is False
|
||||
assert review["sample_result_accepted"] is False
|
||||
assert review["ready_for_candidate_preview"] is False
|
||||
assert review["candidate_import_allowed"] is False
|
||||
assert review["external_network_executed"] is False
|
||||
assert review["database_connection_opened"] is False
|
||||
assert review["database_session_created"] is False
|
||||
assert review["database_write_executed"] is False
|
||||
assert review["database_commit_executed"] is False
|
||||
assert review["scheduler_attached"] is False
|
||||
assert review["writes_executed"] is False
|
||||
assert review["would_write_database"] is False
|
||||
assert review["review_result"] == "planned_no_sample_result"
|
||||
assert "sample_result_not_loaded" in review["blocked_reasons"]
|
||||
assert "candidate_import_still_blocked_until_operator_approval" in review["blocked_reasons"]
|
||||
assert "do_not_fetch_external_pages_from_review_api" in review["safe_boundaries"]
|
||||
assert "do_not_write_market_tables_from_review_preview" in review["safe_boundaries"]
|
||||
|
||||
|
||||
def test_manual_sample_review_evaluator_accepts_good_result_without_import():
|
||||
acceptance = MarketIntelService().build_manual_sample_acceptance()
|
||||
sample_result = {
|
||||
"batch_id": "sample-batch-1",
|
||||
"platform_code": "pchome",
|
||||
"source_key": "homepage",
|
||||
"source_url": "https://24h.pchome.com.tw/",
|
||||
"status": "fetched",
|
||||
"status_code": 200,
|
||||
"content_length": 1200,
|
||||
"page_hash": "a" * 64,
|
||||
"title": "PChome 活動",
|
||||
"diagnostics": {
|
||||
"link_count": 3,
|
||||
"same_host_link_count": 2,
|
||||
"campaign_link_candidates": [
|
||||
{
|
||||
"confidence_band": "high",
|
||||
"score": 82,
|
||||
"url": "https://24h.pchome.com.tw/activity/sample",
|
||||
"text": "品牌活動",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
result = evaluate_manual_sample_result(sample_result, acceptance)
|
||||
|
||||
assert result["sample_result_loaded"] is True
|
||||
assert result["sample_result_reviewed"] is True
|
||||
assert result["sample_result_accepted"] is True
|
||||
assert result["ready_for_candidate_preview"] is True
|
||||
assert result["candidate_import_allowed"] is False
|
||||
assert result["review_result"] == "accepted_for_candidate_preview"
|
||||
assert all(check["passed"] for check in result["review_checks"])
|
||||
assert result["review_findings"] == []
|
||||
assert result["candidate_summary"]["candidate_count"] == 1
|
||||
assert result["candidate_summary"]["accepted_candidate_count"] == 1
|
||||
|
||||
|
||||
def test_manual_sample_review_evaluator_rejects_bad_result():
|
||||
acceptance = MarketIntelService().build_manual_sample_acceptance()
|
||||
sample_result = {
|
||||
"batch_id": "sample-batch-2",
|
||||
"platform_code": "shopee",
|
||||
"source_key": "mall",
|
||||
"source_url": "https://shopee.tw/mall",
|
||||
"status": "blocked",
|
||||
"status_code": 403,
|
||||
"content_length": 120,
|
||||
"page_hash": "short",
|
||||
"title": "",
|
||||
"diagnostics": {
|
||||
"link_count": 0,
|
||||
"same_host_link_count": 0,
|
||||
"campaign_link_candidates": [],
|
||||
},
|
||||
}
|
||||
|
||||
result = evaluate_manual_sample_result(sample_result, acceptance)
|
||||
|
||||
assert result["sample_result_loaded"] is True
|
||||
assert result["sample_result_reviewed"] is True
|
||||
assert result["sample_result_accepted"] is False
|
||||
assert result["ready_for_candidate_preview"] is False
|
||||
assert result["candidate_import_allowed"] is False
|
||||
assert result["review_result"] == "rejected_sample_result"
|
||||
assert {item["key"] for item in result["review_findings"]} >= {
|
||||
"http_status_ok",
|
||||
"content_has_body",
|
||||
"candidate_quality_reviewed",
|
||||
}
|
||||
|
||||
|
||||
def test_manual_sample_review_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/manual_sample_review")
|
||||
data = response.get_json()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_review_preview"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["sample_result_reviewed"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
assert data["scheduler_attached"] is False
|
||||
|
||||
|
||||
def test_scheduler_plan_preview_blocks_job_attachment():
|
||||
plan = MarketIntelService().build_scheduler_plan()
|
||||
|
||||
assert plan["mode"] == "scheduler_attach_plan_preview"
|
||||
assert plan["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_to_attach_scheduler"] is False
|
||||
assert plan["scheduler_attached"] is False
|
||||
assert plan["scheduler_registration_executed"] is False
|
||||
@@ -1099,7 +1230,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["scheduler_registration_executed"] is False
|
||||
assert data["crawler_job_started"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1110,7 +1241,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_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_review_queue"] is False
|
||||
assert plan["review_queue_created"] is False
|
||||
assert plan["auto_match_executed"] is False
|
||||
@@ -1146,7 +1277,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["review_queue_created"] is False
|
||||
assert data["auto_confirm_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1157,7 +1288,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_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_opportunity_queue"] is False
|
||||
assert plan["opportunity_queue_created"] is False
|
||||
assert plan["threat_alert_dispatched"] is False
|
||||
@@ -1198,7 +1329,7 @@ def test_opportunity_plan_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "opportunity_plan_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["opportunity_queue_created"] is False
|
||||
assert data["threat_alert_dispatched"] is False
|
||||
assert data["ai_summary_generated"] is False
|
||||
@@ -1209,7 +1340,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_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_scoring_job"] is False
|
||||
assert plan["scoring_job_created"] is False
|
||||
assert plan["score_calculation_executed"] is False
|
||||
@@ -1257,7 +1388,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["scoring_job_created"] is False
|
||||
assert data["score_calculation_executed"] is False
|
||||
assert data["sample_scores_generated"] is False
|
||||
@@ -1269,7 +1400,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_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_evidence_bundle"] is False
|
||||
assert plan["evidence_bundle_created"] is False
|
||||
assert plan["evidence_query_executed"] is False
|
||||
@@ -1315,7 +1446,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["evidence_bundle_created"] is False
|
||||
assert data["evidence_query_executed"] is False
|
||||
assert data["sample_evidence_generated"] is False
|
||||
@@ -1328,7 +1459,7 @@ 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_48_manual_sample_acceptance_contract"
|
||||
assert plan["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert plan["ready_for_alert_candidates"] is False
|
||||
assert plan["alert_candidate_created"] is False
|
||||
assert plan["alert_queue_created"] is False
|
||||
@@ -1413,7 +1544,7 @@ 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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["alert_candidate_created"] is False
|
||||
assert data["alert_queue_created"] is False
|
||||
assert data["review_queue_created"] is False
|
||||
@@ -1491,7 +1622,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_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -1506,7 +1637,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_48_manual_sample_acceptance_contract"
|
||||
assert readiness["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert readiness["execute_requested"] is False
|
||||
assert readiness["router_enabled"] is False
|
||||
assert readiness["external_mcp_complete"] is False
|
||||
@@ -1896,6 +2027,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
assert readiness["checks"]["scheduler_plan_preview_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_plan_preview_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_acceptance_preview_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_review_preview_safe"] is True
|
||||
assert readiness["checks"]["match_review_plan_preview_safe"] is True
|
||||
assert readiness["checks"]["opportunity_plan_preview_safe"] is True
|
||||
assert readiness["checks"]["opportunity_scoring_plan_preview_safe"] is True
|
||||
@@ -1928,6 +2060,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
assert "/api/market_intel/scheduler_plan" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/manual_sample_plan" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/manual_sample_acceptance" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/manual_sample_review" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/match_review_plan" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/opportunity_plan" in readiness["production_smoke_targets"]
|
||||
assert "/api/market_intel/opportunity_scoring_plan" in readiness["production_smoke_targets"]
|
||||
@@ -1985,6 +2118,13 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
assert readiness["manual_sample_acceptance"]["external_network_executed"] is False
|
||||
assert readiness["manual_sample_acceptance"]["database_write_executed"] is False
|
||||
assert readiness["manual_sample_acceptance"]["scheduler_attached"] is False
|
||||
assert readiness["manual_sample_review"]["mode"] == "manual_sample_review_preview"
|
||||
assert readiness["manual_sample_review"]["sample_result_loaded"] is False
|
||||
assert readiness["manual_sample_review"]["sample_result_reviewed"] is False
|
||||
assert readiness["manual_sample_review"]["candidate_import_allowed"] is False
|
||||
assert readiness["manual_sample_review"]["external_network_executed"] is False
|
||||
assert readiness["manual_sample_review"]["database_write_executed"] is False
|
||||
assert readiness["manual_sample_review"]["scheduler_attached"] is False
|
||||
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
|
||||
@@ -2089,7 +2229,7 @@ def test_migration_apply_drill_planned_is_safe_and_manual_only():
|
||||
drill = MarketIntelService().build_migration_apply_drill()
|
||||
|
||||
assert drill["mode"] == "migration_apply_drill_preview"
|
||||
assert drill["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert drill["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert drill["execute_requested"] is False
|
||||
assert drill["schema_state"] == "planned_no_db_probe"
|
||||
assert drill["drill_ready_for_operator_review"] is True
|
||||
@@ -2204,7 +2344,7 @@ def test_migration_apply_drill_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "migration_apply_drill_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["migration_executed"] is False
|
||||
assert data["rollback_executed"] is False
|
||||
@@ -2216,7 +2356,7 @@ def test_migration_catalog_review_planned_is_safe_and_diagnostic():
|
||||
review = MarketIntelService().build_migration_catalog_review()
|
||||
|
||||
assert review["mode"] == "migration_catalog_review_preview"
|
||||
assert review["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert review["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert review["execute_requested"] is False
|
||||
assert review["catalog_state"] == "planned_no_probe"
|
||||
assert review["seed_state"] == "planned_no_probe"
|
||||
@@ -2331,7 +2471,7 @@ def test_migration_catalog_review_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "migration_catalog_review_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["catalog_state"] == "planned_no_probe"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -2344,7 +2484,7 @@ def test_migration_live_smoke_planned_is_preview_only():
|
||||
smoke = MarketIntelService().build_migration_live_smoke()
|
||||
|
||||
assert smoke["mode"] == "migration_live_smoke_preview"
|
||||
assert smoke["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert smoke["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert smoke["execute_requested"] is False
|
||||
assert smoke["smoke_result"] == "planned_no_execution"
|
||||
assert smoke["live_smoke_passed"] is False
|
||||
@@ -2406,7 +2546,7 @@ def test_migration_live_smoke_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "migration_live_smoke_preview"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["smoke_result"] == "planned_no_execution"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -2419,7 +2559,7 @@ def test_live_db_inventory_planned_is_preview_only():
|
||||
inventory = MarketIntelService().build_live_db_inventory()
|
||||
|
||||
assert inventory["mode"] == "live_db_inventory_planned"
|
||||
assert inventory["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert inventory["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert inventory["execute_requested"] is False
|
||||
assert inventory["read_only_query_executed"] is False
|
||||
assert inventory["database_connection_opened"] is False
|
||||
@@ -2563,7 +2703,7 @@ def test_live_db_inventory_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "live_db_inventory_planned"
|
||||
assert data["phase"] == "phase_48_manual_sample_acceptance_contract"
|
||||
assert data["phase"] == "phase_49_manual_sample_result_review"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["read_only_query_executed"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
|
||||
Reference in New Issue
Block a user