This commit is contained in:
@@ -108,6 +108,7 @@
|
||||
- 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。
|
||||
- Phase 50 manual sample review evaluate:新增 `/api/market_intel/manual_sample_review/evaluate` POST 與 UI JSON 審核入口,允許操作員貼入單筆 sample result 即時回傳 PASS/BLOCK;不保存 payload、不回吐完整 HTML、不寫 DB、不建立候選活動、不允許候選導入、不掛 scheduler;版本同步至 V10.219。
|
||||
- V10.220 補 Phase 50 UI POST CSRF header:`manual_sample_review/evaluate` 保持 CSRF 保護,頁面 fetch 送出 `X-CSRFToken`,不豁免安全檢查。
|
||||
- Phase 51 manual sample candidate handoff:新增 `/api/market_intel/manual_sample_review/candidate_handoff` POST 與 UI handoff 按鈕,將已通過審核的 sample result 轉成只讀候選活動 preview payload;不保存 handoff、不建立 review queue、不寫 market_*、不允許候選導入、不掛 scheduler;版本同步至 V10.222。
|
||||
- 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`。
|
||||
|
||||
@@ -320,7 +320,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
|
||||
# ==========================================
|
||||
# 系統版本與路徑
|
||||
# ==========================================
|
||||
SYSTEM_VERSION = "V10.221"
|
||||
SYSTEM_VERSION = "V10.222"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 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_* 寫入仍需後續獨立批准。
|
||||
- 2026-05-19 追加 manual sample review evaluate:`/api/market_intel/manual_sample_review/evaluate` 提供 POST-only 即時審核入口,操作員可貼入單筆 sample result JSON 取得 PASS/BLOCK 與 candidate preview readiness。此入口不保存 payload、不回吐完整 HTML、不連外、不寫 DB、不建立候選活動、不允許候選導入、不掛 scheduler;invalid JSON 只回診斷錯誤。
|
||||
- 2026-05-19 追加 manual sample candidate handoff:`/api/market_intel/manual_sample_review/candidate_handoff` 將已通過審核的 sample result 轉成只讀候選活動 handoff payload,包含 candidate key、平台、來源、URL、信心分級、排序與人工審核狀態。此入口保持 CSRF 保護,不保存 handoff、不建立 review queue、不寫 market_*、不允許候選導入、不掛 scheduler。
|
||||
|
||||
### 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 50 manual sample review evaluate | `/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/manual_sample_review/evaluate`, `/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 51 manual sample candidate handoff | `/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/manual_sample_review/evaluate`, `/api/market_intel/manual_sample_review/candidate_handoff`, `/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` |
|
||||
|
||||
@@ -192,6 +192,31 @@ def market_intel_manual_sample_review_evaluate():
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route(
|
||||
"/api/market_intel/manual_sample_review/candidate_handoff",
|
||||
methods=["POST"],
|
||||
)
|
||||
@login_required
|
||||
def market_intel_manual_sample_candidate_handoff():
|
||||
payload = request.get_json(silent=True)
|
||||
limit = request.args.get("limit", default=20, type=int)
|
||||
if not isinstance(payload, dict):
|
||||
data = _service().build_manual_sample_candidate_handoff(
|
||||
sample_result=None,
|
||||
payload_error="invalid_json_object",
|
||||
limit=limit,
|
||||
)
|
||||
return jsonify(data), 400
|
||||
|
||||
sample_result = payload.get("sample_result", payload)
|
||||
return jsonify(
|
||||
_service().build_manual_sample_candidate_handoff(
|
||||
sample_result=sample_result,
|
||||
limit=limit,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route("/api/market_intel/match_review_plan")
|
||||
@login_required
|
||||
def market_intel_match_review_plan():
|
||||
|
||||
@@ -24,6 +24,9 @@ def build_deployment_readiness_preview(
|
||||
manual_sample_review_evaluation = service.build_manual_sample_review_evaluation(
|
||||
sample_result={}
|
||||
)
|
||||
manual_sample_candidate_handoff = service.build_manual_sample_candidate_handoff(
|
||||
sample_result={}
|
||||
)
|
||||
match_review_plan = service.build_match_review_plan()
|
||||
opportunity_plan = service.build_opportunity_plan()
|
||||
opportunity_scoring_plan = service.build_opportunity_scoring_plan()
|
||||
@@ -121,6 +124,18 @@ def build_deployment_readiness_preview(
|
||||
and not manual_sample_review_evaluation["database_commit_executed"]
|
||||
and not manual_sample_review_evaluation["scheduler_attached"]
|
||||
),
|
||||
"manual_sample_candidate_handoff_post_safe": bool(
|
||||
manual_sample_candidate_handoff["mode"]
|
||||
== "manual_sample_candidate_handoff_preview"
|
||||
and manual_sample_candidate_handoff["payload_received"]
|
||||
and not manual_sample_candidate_handoff["payload_persisted"]
|
||||
and not manual_sample_candidate_handoff["candidate_handoff_persisted"]
|
||||
and not manual_sample_candidate_handoff["candidate_import_allowed"]
|
||||
and not manual_sample_candidate_handoff["external_network_executed"]
|
||||
and not manual_sample_candidate_handoff["database_write_executed"]
|
||||
and not manual_sample_candidate_handoff["database_commit_executed"]
|
||||
and not manual_sample_candidate_handoff["scheduler_attached"]
|
||||
),
|
||||
"match_review_plan_preview_safe": bool(
|
||||
match_review_plan["mode"] == "match_review_plan_preview"
|
||||
and not match_review_plan["review_queue_created"]
|
||||
@@ -363,6 +378,7 @@ def build_deployment_readiness_preview(
|
||||
"manual_sample_acceptance": manual_sample_acceptance,
|
||||
"manual_sample_review": manual_sample_review,
|
||||
"manual_sample_review_evaluation": manual_sample_review_evaluation,
|
||||
"manual_sample_candidate_handoff": manual_sample_candidate_handoff,
|
||||
"match_review_plan": match_review_plan,
|
||||
"opportunity_plan": opportunity_plan,
|
||||
"opportunity_scoring_plan": opportunity_scoring_plan,
|
||||
|
||||
@@ -345,3 +345,155 @@ def build_manual_sample_review_evaluation_preview(
|
||||
"do_not_persist_posted_review_payload",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _accepted_candidates_from_sample(sample_result, acceptance_contract, limit):
|
||||
diagnostics = sample_result.get("diagnostics") if isinstance(sample_result, dict) else {}
|
||||
diagnostics = diagnostics if isinstance(diagnostics, dict) else {}
|
||||
raw_candidates = diagnostics.get("campaign_link_candidates")
|
||||
raw_candidates = raw_candidates if isinstance(raw_candidates, list) else []
|
||||
accepted_bands = set(_thresholds(acceptance_contract)["accepted_candidate_bands"])
|
||||
normalized = [
|
||||
_normalize_candidate(item)
|
||||
for item in raw_candidates
|
||||
]
|
||||
return [
|
||||
item for item in normalized
|
||||
if item["confidence_band"] in accepted_bands
|
||||
][:limit]
|
||||
|
||||
|
||||
def build_manual_sample_candidate_handoff_preview(
|
||||
*,
|
||||
runtime_status,
|
||||
acceptance_contract,
|
||||
sample_result=None,
|
||||
payload_error=None,
|
||||
limit=20,
|
||||
):
|
||||
"""建立人工樣本候選活動 handoff;只產生 preview payload,不保存。"""
|
||||
safe_limit = max(1, min(_as_int(limit, 20), 50))
|
||||
review = build_manual_sample_review_evaluation_preview(
|
||||
runtime_status=runtime_status,
|
||||
acceptance_contract=acceptance_contract,
|
||||
sample_result=sample_result,
|
||||
payload_error=payload_error,
|
||||
)
|
||||
handoff_ready = bool(
|
||||
review["payload_valid_json_object"]
|
||||
and review["sample_result_accepted"]
|
||||
and review["ready_for_candidate_preview"]
|
||||
)
|
||||
candidates = []
|
||||
if handoff_ready:
|
||||
platform_code = str(sample_result.get("platform_code") or "")
|
||||
source_key = str(sample_result.get("source_key") or "")
|
||||
source_url = str(sample_result.get("source_url") or "")
|
||||
for index, candidate in enumerate(
|
||||
_accepted_candidates_from_sample(
|
||||
sample_result,
|
||||
acceptance_contract,
|
||||
safe_limit,
|
||||
),
|
||||
start=1,
|
||||
):
|
||||
candidates.append(
|
||||
{
|
||||
"candidate_key": (
|
||||
f"{platform_code}:{source_key}:{index}:"
|
||||
f"{candidate['confidence_band']}:{candidate['score']}"
|
||||
),
|
||||
"platform_code": platform_code,
|
||||
"source_key": source_key,
|
||||
"source_url": source_url,
|
||||
"candidate_url": candidate["url"],
|
||||
"candidate_text": candidate["text"],
|
||||
"confidence_band": candidate["confidence_band"],
|
||||
"score": candidate["score"],
|
||||
"rank_position": index,
|
||||
"review_status": "needs_operator_review",
|
||||
"write_status": "blocked_preview_only",
|
||||
"import_allowed": False,
|
||||
}
|
||||
)
|
||||
|
||||
blocked_reasons = list(review["blocked_reasons"])
|
||||
if not handoff_ready:
|
||||
blocked_reasons.append("candidate_handoff_not_ready")
|
||||
blocked_reasons.append("candidate_handoff_persist_still_blocked")
|
||||
|
||||
return {
|
||||
"mode": "manual_sample_candidate_handoff_preview",
|
||||
"review": {
|
||||
"mode": review["mode"],
|
||||
"review_result": review["review_result"],
|
||||
"sample_result_accepted": review["sample_result_accepted"],
|
||||
"ready_for_candidate_preview": review["ready_for_candidate_preview"],
|
||||
"review_findings": review["review_findings"],
|
||||
},
|
||||
"payload_received": review["payload_received"],
|
||||
"payload_valid_json_object": review["payload_valid_json_object"],
|
||||
"payload_error": review["payload_error"],
|
||||
"payload_persisted": False,
|
||||
"sample_result_persisted": False,
|
||||
"handoff_ready": handoff_ready,
|
||||
"candidate_handoff_created": bool(candidates),
|
||||
"candidate_handoff_persisted": False,
|
||||
"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,
|
||||
"blocked_reasons": blocked_reasons,
|
||||
"handoff_summary": {
|
||||
"candidate_count": len(candidates),
|
||||
"limit": safe_limit,
|
||||
"review_status": "needs_operator_review" if candidates else "blocked",
|
||||
"import_allowed": False,
|
||||
},
|
||||
"candidate_preview_contract": {
|
||||
"required_fields": [
|
||||
"candidate_key",
|
||||
"platform_code",
|
||||
"source_key",
|
||||
"source_url",
|
||||
"candidate_url",
|
||||
"candidate_text",
|
||||
"confidence_band",
|
||||
"score",
|
||||
"rank_position",
|
||||
"review_status",
|
||||
],
|
||||
"forbidden_actions": [
|
||||
"insert_market_campaigns",
|
||||
"insert_market_campaign_products",
|
||||
"create_crawler_run",
|
||||
"auto_import_candidates",
|
||||
],
|
||||
},
|
||||
"candidates": candidates,
|
||||
"operator_next_actions": [
|
||||
{
|
||||
"key": "review_candidate_urls",
|
||||
"label": "人工檢查候選活動 URL、文字與信心分級",
|
||||
"write_status": "blocked",
|
||||
},
|
||||
{
|
||||
"key": "promote_to_candidate_review_queue_later",
|
||||
"label": "後續需另行批准才可建立候選審核 queue",
|
||||
"write_status": "blocked",
|
||||
},
|
||||
],
|
||||
"safe_boundaries": [
|
||||
"do_not_fetch_external_pages_from_handoff_api",
|
||||
"do_not_persist_candidate_handoff_payload",
|
||||
"do_not_import_candidates_from_handoff_preview",
|
||||
"do_not_write_market_tables_from_handoff_preview",
|
||||
"do_not_attach_scheduler_from_handoff_preview",
|
||||
"do_not_touch_momo_db_lifecycle",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ from services.market_intel.manual_sample_acceptance import (
|
||||
build_manual_sample_acceptance_preview,
|
||||
)
|
||||
from services.market_intel.manual_sample_review import (
|
||||
build_manual_sample_candidate_handoff_preview,
|
||||
build_manual_sample_review_evaluation_preview,
|
||||
build_manual_sample_review_preview,
|
||||
)
|
||||
@@ -102,7 +103,7 @@ class MarketIntelRuntimeStatus:
|
||||
class MarketIntelService:
|
||||
"""市場情報入口服務,先集中 feature gate 與安全狀態。"""
|
||||
|
||||
phase = "phase_50_manual_sample_review_evaluate"
|
||||
phase = "phase_51_manual_sample_candidate_handoff"
|
||||
|
||||
def get_runtime_status(self) -> MarketIntelRuntimeStatus:
|
||||
return MarketIntelRuntimeStatus(
|
||||
@@ -476,6 +477,23 @@ class MarketIntelService:
|
||||
review["phase"] = self.phase
|
||||
return review
|
||||
|
||||
def build_manual_sample_candidate_handoff(
|
||||
self,
|
||||
sample_result=None,
|
||||
payload_error=None,
|
||||
limit=20,
|
||||
):
|
||||
"""回報人工樣本候選活動 handoff;只產生 preview,不寫 DB。"""
|
||||
handoff = build_manual_sample_candidate_handoff_preview(
|
||||
runtime_status=self.get_runtime_status(),
|
||||
acceptance_contract=self.build_manual_sample_acceptance(),
|
||||
sample_result=sample_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
)
|
||||
handoff["phase"] = self.phase
|
||||
return handoff
|
||||
|
||||
def build_match_review_plan(self):
|
||||
"""回報商品比對審核計畫;不建立 queue、不自動確認。"""
|
||||
schema_smoke = self.build_schema_smoke()
|
||||
|
||||
@@ -251,7 +251,7 @@
|
||||
align-items: stretch;
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -576,6 +576,9 @@
|
||||
<button class="market-intel-icon-button" type="button" title="審核 sample result JSON" data-market-intel-sample-review-evaluate>
|
||||
<i class="fas fa-check" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button class="market-intel-icon-button" type="button" title="產生候選活動 handoff" data-market-intel-sample-candidate-handoff>
|
||||
<i class="fas fa-arrow-right" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -900,8 +903,10 @@
|
||||
const sampleReviewRefresh = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-refresh]') : null;
|
||||
const sampleReviewInput = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-input]') : null;
|
||||
const sampleReviewEvaluate = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-review-evaluate]') : null;
|
||||
const sampleCandidateHandoff = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-handoff]') : null;
|
||||
const sampleReviewEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_review') }}";
|
||||
const sampleReviewEvaluateEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_review_evaluate') }}";
|
||||
const sampleCandidateHandoffEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_candidate_handoff') }}";
|
||||
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;
|
||||
@@ -2000,6 +2005,64 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateHandoff = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const summary = data.handoff_summary || {};
|
||||
const candidates = data.candidates || [];
|
||||
sampleReviewMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`handoff=${data.handoff_ready ? 'ready' : 'blocked'}`,
|
||||
`candidates=${summary.candidate_count || 0}`,
|
||||
`persisted=${data.candidate_handoff_persisted ? 'yes' : 'no'}`,
|
||||
`import=${data.candidate_import_allowed ? 'open' : 'blocked'}`
|
||||
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
|
||||
sampleReviewBody.innerHTML = `
|
||||
<div class="market-intel-empty mb-3">此卡只產生候選活動 handoff preview;不保存 payload、不建立活動、不寫 market_*。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
|
||||
<div class="market-intel-operation-list">${
|
||||
candidates.length
|
||||
? candidates.map(item => `
|
||||
<article class="market-intel-operation">
|
||||
<strong>${escapeHtml(item.candidate_text || item.candidate_url)}</strong>
|
||||
<small>${escapeHtml(item.platform_code)} / ${escapeHtml(item.confidence_band)} / score=${escapeHtml(item.score)} / ${escapeHtml(item.write_status)}</small>
|
||||
<small>${escapeHtml(item.candidate_url)}</small>
|
||||
</article>
|
||||
`).join('')
|
||||
: '<div class="market-intel-empty">目前沒有可交接候選;請先讓 sample result 通過審核。</div>'
|
||||
}</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const loadCandidateHandoff = async () => {
|
||||
if (!sampleReviewMeta || !sampleReviewBody || !sampleReviewInput) return;
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(sampleReviewInput.value || '{}');
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">json_error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">JSON 格式錯誤:${escapeHtml(error.message)}</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
sampleReviewBody.innerHTML = '<div class="market-intel-empty">產生候選 handoff 預覽中...</div>';
|
||||
try {
|
||||
const response = await fetch(sampleCandidateHandoffEndpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({ sample_result: parsed })
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok && !data.mode) throw new Error(`HTTP ${response.status}`);
|
||||
renderCandidateHandoff(data);
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">候選 handoff 產生失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderSchedulerMeta = data => {
|
||||
schedulerMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
@@ -3494,6 +3557,9 @@
|
||||
if (sampleReviewEvaluate) {
|
||||
sampleReviewEvaluate.addEventListener('click', evaluateSampleReview);
|
||||
}
|
||||
if (sampleCandidateHandoff) {
|
||||
sampleCandidateHandoff.addEventListener('click', loadCandidateHandoff);
|
||||
}
|
||||
if (schedulerRefresh) {
|
||||
schedulerRefresh.addEventListener('click', loadScheduler);
|
||||
}
|
||||
|
||||
@@ -518,6 +518,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
assert "data-market-intel-sample-review-boundaries" in template
|
||||
assert "data-market-intel-sample-review-input" in template
|
||||
assert "data-market-intel-sample-review-evaluate" in template
|
||||
assert "data-market-intel-sample-candidate-handoff" in template
|
||||
assert "data-market-intel-approval" in template
|
||||
assert "data-market-intel-approval-gates" in template
|
||||
assert "data-market-intel-deploy" in template
|
||||
@@ -537,6 +538,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
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_manual_sample_review_evaluate" in template
|
||||
assert "market_intel.market_intel_manual_sample_candidate_handoff" in template
|
||||
assert "X-CSRFToken" in template
|
||||
assert "market_intel.market_intel_scheduler_plan" in template
|
||||
assert "market_intel.market_intel_match_review_plan" in template
|
||||
@@ -573,7 +575,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_50_manual_sample_review_evaluate"
|
||||
assert bridge["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert bridge["execute_requested"] is False
|
||||
assert bridge["read_only_query_executed"] is False
|
||||
assert bridge["database_connection_opened"] is False
|
||||
@@ -731,7 +733,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_50_manual_sample_review_evaluate"
|
||||
assert contract["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert contract["caller"] == "market_intel"
|
||||
assert contract["contract_ready"] is True
|
||||
assert contract["blocked_reasons"] == []
|
||||
@@ -864,7 +866,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -877,7 +879,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_50_manual_sample_review_evaluate"
|
||||
assert gate["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert gate["fetch_requested"] is True
|
||||
assert gate["manual_fetch_gate_open"] is False
|
||||
assert gate["network_request_allowed"] is False
|
||||
@@ -947,7 +949,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["fetch_requested"] is False
|
||||
assert data["network_request_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -959,7 +961,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_manual_sample_fetch"] is False
|
||||
assert plan["sample_fetch_executed"] is False
|
||||
assert plan["external_network_executed"] is False
|
||||
@@ -1007,7 +1009,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["sample_fetch_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
@@ -1018,7 +1020,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_50_manual_sample_review_evaluate"
|
||||
assert acceptance["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert acceptance["contract_ready"] is True
|
||||
assert acceptance["sample_result_loaded"] is False
|
||||
assert acceptance["sample_result_accepted"] is False
|
||||
@@ -1060,7 +1062,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1072,7 +1074,7 @@ 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_50_manual_sample_review_evaluate"
|
||||
assert review["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert review["contract_ready"] is True
|
||||
assert review["sample_result_loaded"] is False
|
||||
assert review["sample_result_reviewed"] is False
|
||||
@@ -1183,7 +1185,7 @@ def test_manual_sample_review_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_review_preview"
|
||||
assert data["phase"] == "phase_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["sample_result_reviewed"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
@@ -1222,7 +1224,7 @@ def test_manual_sample_review_evaluation_preview_accepts_payload_without_persist
|
||||
)
|
||||
|
||||
assert review["mode"] == "manual_sample_review_evaluation_preview"
|
||||
assert review["phase"] == "phase_50_manual_sample_review_evaluate"
|
||||
assert review["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert review["review_request_type"] == "operator_posted_json"
|
||||
assert review["payload_received"] is True
|
||||
assert review["payload_valid_json_object"] is True
|
||||
@@ -1284,7 +1286,7 @@ def test_manual_sample_review_evaluate_route_is_post_only_and_no_write():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_review_evaluation_preview"
|
||||
assert data["phase"] == "phase_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["payload_received"] is True
|
||||
assert data["payload_valid_json_object"] is True
|
||||
assert data["payload_persisted"] is False
|
||||
@@ -1328,11 +1330,140 @@ def test_manual_sample_review_evaluate_rejects_invalid_json_without_write():
|
||||
assert "sample_result_payload_invalid" in data["blocked_reasons"]
|
||||
|
||||
|
||||
def test_manual_sample_candidate_handoff_preview_creates_candidates_without_persisting():
|
||||
sample_result = {
|
||||
"batch_id": "sample-batch-5",
|
||||
"platform_code": "pchome",
|
||||
"source_key": "homepage",
|
||||
"source_url": "https://24h.pchome.com.tw/",
|
||||
"status": "fetched",
|
||||
"status_code": 200,
|
||||
"content_length": 1500,
|
||||
"page_hash": "e" * 64,
|
||||
"title": "PChome 活動",
|
||||
"diagnostics": {
|
||||
"link_count": 3,
|
||||
"same_host_link_count": 2,
|
||||
"campaign_link_candidates": [
|
||||
{
|
||||
"confidence_band": "high",
|
||||
"score": 91,
|
||||
"url": "https://24h.pchome.com.tw/activity/sample",
|
||||
"text": "品牌活動",
|
||||
},
|
||||
{
|
||||
"confidence_band": "low",
|
||||
"score": 22,
|
||||
"url": "https://24h.pchome.com.tw/search/noise",
|
||||
"text": "低信心連結",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
handoff = MarketIntelService().build_manual_sample_candidate_handoff(
|
||||
sample_result=sample_result
|
||||
)
|
||||
|
||||
assert handoff["mode"] == "manual_sample_candidate_handoff_preview"
|
||||
assert handoff["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert handoff["payload_received"] is True
|
||||
assert handoff["payload_valid_json_object"] is True
|
||||
assert handoff["payload_persisted"] is False
|
||||
assert handoff["sample_result_persisted"] is False
|
||||
assert handoff["handoff_ready"] is True
|
||||
assert handoff["candidate_handoff_created"] is True
|
||||
assert handoff["candidate_handoff_persisted"] is False
|
||||
assert handoff["candidate_import_allowed"] is False
|
||||
assert handoff["external_network_executed"] is False
|
||||
assert handoff["database_connection_opened"] is False
|
||||
assert handoff["database_session_created"] is False
|
||||
assert handoff["database_write_executed"] is False
|
||||
assert handoff["database_commit_executed"] is False
|
||||
assert handoff["scheduler_attached"] is False
|
||||
assert handoff["handoff_summary"]["candidate_count"] == 1
|
||||
assert handoff["candidates"][0]["review_status"] == "needs_operator_review"
|
||||
assert handoff["candidates"][0]["write_status"] == "blocked_preview_only"
|
||||
assert handoff["candidates"][0]["import_allowed"] is False
|
||||
assert "do_not_persist_candidate_handoff_payload" in handoff["safe_boundaries"]
|
||||
|
||||
|
||||
def test_manual_sample_candidate_handoff_route_is_post_only_and_no_write():
|
||||
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.post(
|
||||
"/api/market_intel/manual_sample_review/candidate_handoff",
|
||||
json={
|
||||
"sample_result": {
|
||||
"batch_id": "sample-batch-6",
|
||||
"platform_code": "momo",
|
||||
"source_key": "homepage",
|
||||
"source_url": "https://www.momoshop.com.tw/",
|
||||
"status": "fetched",
|
||||
"status_code": 200,
|
||||
"content_length": 1600,
|
||||
"page_hash": "f" * 64,
|
||||
"title": "MOMO 活動",
|
||||
"diagnostics": {
|
||||
"link_count": 2,
|
||||
"same_host_link_count": 2,
|
||||
"campaign_link_candidates": [
|
||||
{
|
||||
"confidence_band": "medium",
|
||||
"score": 76,
|
||||
"url": "https://www.momoshop.com.tw/activity/sample",
|
||||
"text": "活動頁",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
data = response.get_json()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_candidate_handoff_preview"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["payload_received"] is True
|
||||
assert data["handoff_ready"] is True
|
||||
assert data["candidate_handoff_created"] is True
|
||||
assert data["candidate_handoff_persisted"] 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
|
||||
assert data["handoff_summary"]["candidate_count"] == 1
|
||||
|
||||
|
||||
def test_manual_sample_candidate_handoff_blocks_invalid_payload():
|
||||
handoff = MarketIntelService().build_manual_sample_candidate_handoff(
|
||||
sample_result=None,
|
||||
payload_error="invalid_json_object",
|
||||
)
|
||||
|
||||
assert handoff["mode"] == "manual_sample_candidate_handoff_preview"
|
||||
assert handoff["payload_received"] is False
|
||||
assert handoff["payload_valid_json_object"] is False
|
||||
assert handoff["handoff_ready"] is False
|
||||
assert handoff["candidate_handoff_created"] is False
|
||||
assert handoff["candidate_handoff_persisted"] is False
|
||||
assert handoff["candidate_import_allowed"] is False
|
||||
assert handoff["database_write_executed"] is False
|
||||
assert "candidate_handoff_not_ready" in handoff["blocked_reasons"]
|
||||
|
||||
|
||||
def test_scheduler_plan_preview_blocks_job_attachment():
|
||||
plan = MarketIntelService().build_scheduler_plan()
|
||||
|
||||
assert plan["mode"] == "scheduler_attach_plan_preview"
|
||||
assert plan["phase"] == "phase_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_to_attach_scheduler"] is False
|
||||
assert plan["scheduler_attached"] is False
|
||||
assert plan["scheduler_registration_executed"] is False
|
||||
@@ -1370,7 +1501,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["scheduler_registration_executed"] is False
|
||||
assert data["crawler_job_started"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1381,7 +1512,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_review_queue"] is False
|
||||
assert plan["review_queue_created"] is False
|
||||
assert plan["auto_match_executed"] is False
|
||||
@@ -1417,7 +1548,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["review_queue_created"] is False
|
||||
assert data["auto_confirm_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1428,7 +1559,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_opportunity_queue"] is False
|
||||
assert plan["opportunity_queue_created"] is False
|
||||
assert plan["threat_alert_dispatched"] is False
|
||||
@@ -1469,7 +1600,7 @@ def test_opportunity_plan_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "opportunity_plan_preview"
|
||||
assert data["phase"] == "phase_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["opportunity_queue_created"] is False
|
||||
assert data["threat_alert_dispatched"] is False
|
||||
assert data["ai_summary_generated"] is False
|
||||
@@ -1480,7 +1611,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_scoring_job"] is False
|
||||
assert plan["scoring_job_created"] is False
|
||||
assert plan["score_calculation_executed"] is False
|
||||
@@ -1528,7 +1659,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["scoring_job_created"] is False
|
||||
assert data["score_calculation_executed"] is False
|
||||
assert data["sample_scores_generated"] is False
|
||||
@@ -1540,7 +1671,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_evidence_bundle"] is False
|
||||
assert plan["evidence_bundle_created"] is False
|
||||
assert plan["evidence_query_executed"] is False
|
||||
@@ -1586,7 +1717,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["evidence_bundle_created"] is False
|
||||
assert data["evidence_query_executed"] is False
|
||||
assert data["sample_evidence_generated"] is False
|
||||
@@ -1599,7 +1730,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_50_manual_sample_review_evaluate"
|
||||
assert plan["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert plan["ready_for_alert_candidates"] is False
|
||||
assert plan["alert_candidate_created"] is False
|
||||
assert plan["alert_queue_created"] is False
|
||||
@@ -1684,7 +1815,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["alert_candidate_created"] is False
|
||||
assert data["alert_queue_created"] is False
|
||||
assert data["review_queue_created"] is False
|
||||
@@ -1762,7 +1893,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -1777,7 +1908,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_50_manual_sample_review_evaluate"
|
||||
assert readiness["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert readiness["execute_requested"] is False
|
||||
assert readiness["router_enabled"] is False
|
||||
assert readiness["external_mcp_complete"] is False
|
||||
@@ -2169,6 +2300,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
assert readiness["checks"]["manual_sample_acceptance_preview_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_review_preview_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_review_evaluation_post_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_candidate_handoff_post_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
|
||||
@@ -2286,6 +2418,29 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
is False
|
||||
)
|
||||
assert readiness["manual_sample_review_evaluation"]["scheduler_attached"] is False
|
||||
assert (
|
||||
readiness["manual_sample_candidate_handoff"]["mode"]
|
||||
== "manual_sample_candidate_handoff_preview"
|
||||
)
|
||||
assert readiness["manual_sample_candidate_handoff"]["payload_received"] is True
|
||||
assert readiness["manual_sample_candidate_handoff"]["payload_persisted"] is False
|
||||
assert (
|
||||
readiness["manual_sample_candidate_handoff"]["candidate_handoff_persisted"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_handoff"]["candidate_import_allowed"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_handoff"]["external_network_executed"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_handoff"]["database_write_executed"]
|
||||
is False
|
||||
)
|
||||
assert readiness["manual_sample_candidate_handoff"]["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
|
||||
@@ -2390,7 +2545,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_50_manual_sample_review_evaluate"
|
||||
assert drill["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert drill["execute_requested"] is False
|
||||
assert drill["schema_state"] == "planned_no_db_probe"
|
||||
assert drill["drill_ready_for_operator_review"] is True
|
||||
@@ -2505,7 +2660,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["migration_executed"] is False
|
||||
assert data["rollback_executed"] is False
|
||||
@@ -2517,7 +2672,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_50_manual_sample_review_evaluate"
|
||||
assert review["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert review["execute_requested"] is False
|
||||
assert review["catalog_state"] == "planned_no_probe"
|
||||
assert review["seed_state"] == "planned_no_probe"
|
||||
@@ -2632,7 +2787,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["catalog_state"] == "planned_no_probe"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -2645,7 +2800,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_50_manual_sample_review_evaluate"
|
||||
assert smoke["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert smoke["execute_requested"] is False
|
||||
assert smoke["smoke_result"] == "planned_no_execution"
|
||||
assert smoke["live_smoke_passed"] is False
|
||||
@@ -2707,7 +2862,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["smoke_result"] == "planned_no_execution"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -2720,7 +2875,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_50_manual_sample_review_evaluate"
|
||||
assert inventory["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
assert inventory["execute_requested"] is False
|
||||
assert inventory["read_only_query_executed"] is False
|
||||
assert inventory["database_connection_opened"] is False
|
||||
@@ -2864,7 +3019,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_50_manual_sample_review_evaluate"
|
||||
assert data["phase"] == "phase_51_manual_sample_candidate_handoff"
|
||||
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