This commit is contained in:
@@ -113,6 +113,7 @@
|
||||
- V10.224 補 PPT 報表覆蓋矩陣:`/observability/ppt_audit_history` 將每個定義簡報同列串起 DB 寫入、線上預覽、視覺 QA 與交付狀態,並提供預覽、預熱、重跑操作,避免只顯示「目標已產生」。
|
||||
- Phase 53 manual sample candidate queue approval:新增 `/api/market_intel/manual_sample_review/candidate_queue_approval` POST 與 UI 送審 gate 按鈕,將 queue draft row preview 對齊既有 `market_alert_review_queue` 契約,檢查必填欄位、寫入 flags、備份與人工批准 gate;不建立 approval record、不寫 review queue、不開 DB transaction、不掛 scheduler;版本同步至 V10.225。
|
||||
- V10.226 補 PPT 視覺 QA runtime checklist:`/observability/ppt_audit_history` 在視覺模型未就緒時顯示 Feature Flag、LibreOffice、Vision Model 三段檢查與下一步操作,避免只看到「停用」而不知道卡在哪。
|
||||
- Phase 54 manual sample candidate queue transaction:新增 `/api/market_intel/manual_sample_review/candidate_queue_transaction` POST 與 UI transaction preview 按鈕,將 queue row preview 轉成 `market_alert_review_queue` idempotent insert statement、payload hash 與 rollback plan;不開 DB connection、不開 transaction、不 commit、不建立 approval record;版本同步至 V10.227。
|
||||
- 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.226"
|
||||
SYSTEM_VERSION = "V10.227"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 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。
|
||||
- 2026-05-19 追加 manual sample candidate queue draft:`services.market_intel.manual_sample_candidate_queue` 與 `/api/market_intel/manual_sample_review/candidate_queue_draft` 將 handoff 候選轉成只讀人工審核 queue draft,包含 queue item key、review priority、review state 與 approval_required。此入口保持 CSRF 保護,不建立正式 queue、不保存草案、不寫 market_*、不自動核准候選、不掛 scheduler。
|
||||
- 2026-05-19 追加 manual sample candidate queue approval:`/api/market_intel/manual_sample_review/candidate_queue_approval` 將 queue draft 對齊既有 `market_alert_review_queue` 契約,輸出 row preview、必填欄位 gate、寫入 flags、備份與人工批准 gate。此入口保持 CSRF 保護,不建立 approval record、不寫 review queue、不開 DB transaction、不掛 scheduler。
|
||||
- 2026-05-19 追加 manual sample candidate queue transaction:`/api/market_intel/manual_sample_review/candidate_queue_transaction` 將 queue row preview 轉成 idempotent insert statement preview、payload hash、runtime order 與 rollback plan。此入口保持 CSRF 保護,不開 DB connection、不開 transaction、不 commit、不建立 approval record、不寫 `market_alert_review_queue`。
|
||||
|
||||
### 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 53 manual sample candidate queue approval | `/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/manual_sample_review/candidate_queue_draft`, `/api/market_intel/manual_sample_review/candidate_queue_approval`, `/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 54 manual sample candidate queue transaction | `/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/manual_sample_review/candidate_queue_draft`, `/api/market_intel/manual_sample_review/candidate_queue_approval`, `/api/market_intel/manual_sample_review/candidate_queue_transaction`, `/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` |
|
||||
|
||||
@@ -267,6 +267,31 @@ def market_intel_manual_sample_candidate_queue_approval():
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route(
|
||||
"/api/market_intel/manual_sample_review/candidate_queue_transaction",
|
||||
methods=["POST"],
|
||||
)
|
||||
@login_required
|
||||
def market_intel_manual_sample_candidate_queue_transaction():
|
||||
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_queue_transaction(
|
||||
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_queue_transaction(
|
||||
sample_result=sample_result,
|
||||
limit=limit,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route("/api/market_intel/match_review_plan")
|
||||
@login_required
|
||||
def market_intel_match_review_plan():
|
||||
|
||||
@@ -33,6 +33,9 @@ def build_deployment_readiness_preview(
|
||||
manual_sample_candidate_queue_approval = (
|
||||
service.build_manual_sample_candidate_queue_approval(sample_result={})
|
||||
)
|
||||
manual_sample_candidate_queue_transaction = (
|
||||
service.build_manual_sample_candidate_queue_transaction(sample_result={})
|
||||
)
|
||||
match_review_plan = service.build_match_review_plan()
|
||||
opportunity_plan = service.build_opportunity_plan()
|
||||
opportunity_scoring_plan = service.build_opportunity_scoring_plan()
|
||||
@@ -171,6 +174,23 @@ def build_deployment_readiness_preview(
|
||||
and not manual_sample_candidate_queue_approval["database_commit_executed"]
|
||||
and not manual_sample_candidate_queue_approval["scheduler_attached"]
|
||||
),
|
||||
"manual_sample_candidate_queue_transaction_post_safe": bool(
|
||||
manual_sample_candidate_queue_transaction["mode"]
|
||||
== "manual_sample_candidate_queue_transaction_preview"
|
||||
and manual_sample_candidate_queue_transaction["payload_received"]
|
||||
and not manual_sample_candidate_queue_transaction["payload_persisted"]
|
||||
and not manual_sample_candidate_queue_transaction["transaction_ready"]
|
||||
and not manual_sample_candidate_queue_transaction["transaction_opened"]
|
||||
and not manual_sample_candidate_queue_transaction["transaction_committed"]
|
||||
and not manual_sample_candidate_queue_transaction["approval_record_written"]
|
||||
and not manual_sample_candidate_queue_transaction["review_queue_created"]
|
||||
and not manual_sample_candidate_queue_transaction["review_queue_persisted"]
|
||||
and not manual_sample_candidate_queue_transaction["candidate_import_allowed"]
|
||||
and not manual_sample_candidate_queue_transaction["external_network_executed"]
|
||||
and not manual_sample_candidate_queue_transaction["database_write_executed"]
|
||||
and not manual_sample_candidate_queue_transaction["database_commit_executed"]
|
||||
and not manual_sample_candidate_queue_transaction["scheduler_attached"]
|
||||
),
|
||||
"match_review_plan_preview_safe": bool(
|
||||
match_review_plan["mode"] == "match_review_plan_preview"
|
||||
and not match_review_plan["review_queue_created"]
|
||||
@@ -418,6 +438,9 @@ def build_deployment_readiness_preview(
|
||||
"manual_sample_candidate_queue_approval": (
|
||||
manual_sample_candidate_queue_approval
|
||||
),
|
||||
"manual_sample_candidate_queue_transaction": (
|
||||
manual_sample_candidate_queue_transaction
|
||||
),
|
||||
"match_review_plan": match_review_plan,
|
||||
"opportunity_plan": opportunity_plan,
|
||||
"opportunity_scoring_plan": opportunity_scoring_plan,
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
不建立正式 queue、不寫 DB、不掛 scheduler、不連外。
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
from services.market_intel.manual_sample_review import (
|
||||
build_manual_sample_candidate_handoff_preview,
|
||||
)
|
||||
@@ -342,3 +345,140 @@ def build_manual_sample_candidate_queue_approval_preview(
|
||||
"do_not_touch_momo_db_lifecycle",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
QUEUE_INSERT_SQL_SHAPE = (
|
||||
"INSERT INTO market_alert_review_queue (...) VALUES (...) "
|
||||
"ON CONFLICT(dedupe_key) DO NOTHING"
|
||||
)
|
||||
|
||||
|
||||
def _payload_hash(payload):
|
||||
encoded = json.dumps(payload, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
return hashlib.sha256(encoded).hexdigest()[:16]
|
||||
|
||||
|
||||
def _transaction_statements_from_rows(queue_rows):
|
||||
statements = []
|
||||
for index, row in enumerate(queue_rows, start=1):
|
||||
statements.append(
|
||||
{
|
||||
"index": index,
|
||||
"operation": "insert",
|
||||
"table": "market_alert_review_queue",
|
||||
"lookup": {"dedupe_key": row["dedupe_key"]},
|
||||
"sql_shape": QUEUE_INSERT_SQL_SHAPE,
|
||||
"parameter_keys": sorted(
|
||||
key for key in row if key != "write_status"
|
||||
),
|
||||
"parameter_payload_hash": _payload_hash(row),
|
||||
"idempotency_key": (
|
||||
f"market_alert_review_queue:{row['dedupe_key']}"
|
||||
),
|
||||
"write_status": "blocked_transaction_preview_only",
|
||||
}
|
||||
)
|
||||
return statements
|
||||
|
||||
|
||||
def build_manual_sample_candidate_queue_transaction_preview(
|
||||
*,
|
||||
runtime_status,
|
||||
acceptance_contract,
|
||||
sample_result=None,
|
||||
payload_error=None,
|
||||
limit=20,
|
||||
):
|
||||
"""建立候選審核 queue transaction preview;不開 transaction、不寫 DB。"""
|
||||
approval = build_manual_sample_candidate_queue_approval_preview(
|
||||
runtime_status=runtime_status,
|
||||
acceptance_contract=acceptance_contract,
|
||||
sample_result=sample_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
)
|
||||
queue_rows = approval.get("queue_write_preview", {}).get("rows", [])
|
||||
statements = _transaction_statements_from_rows(queue_rows)
|
||||
approval_gates_passed = all(
|
||||
gate.get("passed") for gate in approval.get("approval_gates", [])
|
||||
)
|
||||
transaction_preview_created = bool(statements)
|
||||
blocked_reasons = list(approval["blocked_reasons"])
|
||||
if not transaction_preview_created:
|
||||
blocked_reasons.append("queue_transaction_preview_not_ready")
|
||||
if not approval_gates_passed:
|
||||
blocked_reasons.append("queue_approval_gates_not_all_passed")
|
||||
blocked_reasons.append("queue_transaction_execution_still_blocked")
|
||||
|
||||
return {
|
||||
"mode": "manual_sample_candidate_queue_transaction_preview",
|
||||
"approval": {
|
||||
"mode": approval["mode"],
|
||||
"approval_preview_created": approval["approval_preview_created"],
|
||||
"approval_summary": approval["approval_summary"],
|
||||
},
|
||||
"payload_received": approval["payload_received"],
|
||||
"payload_valid_json_object": approval["payload_valid_json_object"],
|
||||
"payload_error": approval["payload_error"],
|
||||
"payload_persisted": False,
|
||||
"transaction_preview_created": transaction_preview_created,
|
||||
"transaction_ready": False,
|
||||
"transaction_opened": False,
|
||||
"transaction_committed": False,
|
||||
"transaction_rolled_back": False,
|
||||
"approval_request_created": False,
|
||||
"approval_record_written": False,
|
||||
"review_queue_write_allowed": False,
|
||||
"review_queue_created": False,
|
||||
"review_queue_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,
|
||||
"transaction_summary": {
|
||||
"target_table": "market_alert_review_queue",
|
||||
"statement_count": len(statements),
|
||||
"idempotency_key_count": len(
|
||||
{item["idempotency_key"] for item in statements}
|
||||
),
|
||||
"conflict_policy": "dedupe_key_do_nothing",
|
||||
"write_allowed": False,
|
||||
},
|
||||
"transaction_contract": {
|
||||
"target_table": "market_alert_review_queue",
|
||||
"sql_shape": QUEUE_INSERT_SQL_SHAPE,
|
||||
"required_runtime_order": [
|
||||
"backup_verified",
|
||||
"migration_live_smoke_passed",
|
||||
"runtime_write_flags_enabled",
|
||||
"manual_operator_approval",
|
||||
"one_time_queue_write_token_verified",
|
||||
"post_write_smoke",
|
||||
],
|
||||
},
|
||||
"statements": statements,
|
||||
"rollback_plan": [
|
||||
{
|
||||
"key": "transaction_not_opened_by_preview",
|
||||
"label": "本 preview 不開 transaction;若正式寫入失敗,必須由 CLI transaction rollback",
|
||||
},
|
||||
{
|
||||
"key": "dedupe_key_cleanup_review",
|
||||
"label": "若正式寫入後需回退,依 dedupe_key 人工審核清理",
|
||||
},
|
||||
],
|
||||
"safe_boundaries": [
|
||||
*approval["safe_boundaries"],
|
||||
"do_not_execute_queue_transaction_from_preview",
|
||||
"do_not_open_database_connection_from_transaction_preview",
|
||||
"do_not_commit_queue_transaction_from_preview",
|
||||
"do_not_create_approval_record_from_transaction_preview",
|
||||
"do_not_touch_momo_db_lifecycle",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ from services.market_intel.manual_sample_acceptance import (
|
||||
from services.market_intel.manual_sample_candidate_queue import (
|
||||
build_manual_sample_candidate_queue_approval_preview,
|
||||
build_manual_sample_candidate_queue_draft_preview,
|
||||
build_manual_sample_candidate_queue_transaction_preview,
|
||||
)
|
||||
from services.market_intel.manual_sample_review import (
|
||||
build_manual_sample_candidate_handoff_preview,
|
||||
@@ -107,7 +108,7 @@ class MarketIntelRuntimeStatus:
|
||||
class MarketIntelService:
|
||||
"""市場情報入口服務,先集中 feature gate 與安全狀態。"""
|
||||
|
||||
phase = "phase_53_manual_sample_candidate_queue_approval"
|
||||
phase = "phase_54_manual_sample_candidate_queue_transaction"
|
||||
|
||||
def get_runtime_status(self) -> MarketIntelRuntimeStatus:
|
||||
return MarketIntelRuntimeStatus(
|
||||
@@ -532,6 +533,18 @@ class MarketIntelService:
|
||||
approval["phase"] = self.phase
|
||||
return approval
|
||||
|
||||
def build_manual_sample_candidate_queue_transaction(self, sample_result=None, payload_error=None, limit=20):
|
||||
"""回報候選審核 queue transaction preview;不開 transaction、不寫 DB。"""
|
||||
transaction = build_manual_sample_candidate_queue_transaction_preview(
|
||||
runtime_status=self.get_runtime_status(),
|
||||
acceptance_contract=self.build_manual_sample_acceptance(),
|
||||
sample_result=sample_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
)
|
||||
transaction["phase"] = self.phase
|
||||
return transaction
|
||||
|
||||
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 auto auto auto;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto auto auto auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -585,6 +585,9 @@
|
||||
<button class="market-intel-icon-button" type="button" title="檢查 queue 寫入送審 gate" data-market-intel-sample-candidate-queue-approval>
|
||||
<i class="fas fa-shield-halved" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button class="market-intel-icon-button" type="button" title="產生 queue transaction preview" data-market-intel-sample-candidate-queue-transaction>
|
||||
<i class="fas fa-code" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -912,11 +915,13 @@
|
||||
const sampleCandidateHandoff = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-handoff]') : null;
|
||||
const sampleCandidateQueueDraft = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-draft]') : null;
|
||||
const sampleCandidateQueueApproval = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-approval]') : null;
|
||||
const sampleCandidateQueueTransaction = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-transaction]') : 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 sampleCandidateQueueDraftEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_candidate_queue_draft') }}";
|
||||
const sampleCandidateQueueApprovalEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_candidate_queue_approval') }}";
|
||||
const sampleCandidateQueueTransactionEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_candidate_queue_transaction') }}";
|
||||
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;
|
||||
@@ -2196,6 +2201,65 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateQueueTransaction = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const summary = data.transaction_summary || {};
|
||||
const statements = data.statements || [];
|
||||
sampleReviewMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`target=${summary.target_table || 'unknown'}`,
|
||||
`statements=${summary.statement_count || 0}`,
|
||||
`conflict=${summary.conflict_policy || 'none'}`,
|
||||
`ready=${data.transaction_ready ? 'yes' : 'no'}`
|
||||
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
|
||||
sampleReviewBody.innerHTML = `
|
||||
<div class="market-intel-empty mb-3">此卡只產生 transaction preview;不開 DB connection、不開 transaction、不 commit、不建立 approval record。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
|
||||
<div class="market-intel-operation-list">${
|
||||
statements.length
|
||||
? statements.map(item => `
|
||||
<article class="market-intel-operation">
|
||||
<strong>${escapeHtml(item.idempotency_key)}</strong>
|
||||
<small>${escapeHtml(item.operation)} / ${escapeHtml(item.table)} / ${escapeHtml(item.write_status)}</small>
|
||||
<small>${escapeHtml(item.sql_shape)}</small>
|
||||
<small>payload=${escapeHtml(item.parameter_payload_hash)}</small>
|
||||
</article>
|
||||
`).join('')
|
||||
: '<div class="market-intel-empty">目前沒有可檢查的 transaction statement。</div>'
|
||||
}</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const loadCandidateQueueTransaction = 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">產生 queue transaction preview 中...</div>';
|
||||
try {
|
||||
const response = await fetch(sampleCandidateQueueTransactionEndpoint, {
|
||||
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}`);
|
||||
renderCandidateQueueTransaction(data);
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">queue transaction preview 產生失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderSchedulerMeta = data => {
|
||||
schedulerMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
@@ -3699,6 +3763,9 @@
|
||||
if (sampleCandidateQueueApproval) {
|
||||
sampleCandidateQueueApproval.addEventListener('click', loadCandidateQueueApproval);
|
||||
}
|
||||
if (sampleCandidateQueueTransaction) {
|
||||
sampleCandidateQueueTransaction.addEventListener('click', loadCandidateQueueTransaction);
|
||||
}
|
||||
if (schedulerRefresh) {
|
||||
schedulerRefresh.addEventListener('click', loadScheduler);
|
||||
}
|
||||
|
||||
@@ -521,6 +521,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
assert "data-market-intel-sample-candidate-handoff" in template
|
||||
assert "data-market-intel-sample-candidate-queue-draft" in template
|
||||
assert "data-market-intel-sample-candidate-queue-approval" in template
|
||||
assert "data-market-intel-sample-candidate-queue-transaction" in template
|
||||
assert "data-market-intel-approval" in template
|
||||
assert "data-market-intel-approval-gates" in template
|
||||
assert "data-market-intel-deploy" in template
|
||||
@@ -543,6 +544,7 @@ def test_market_intel_preview_template_uses_safe_fetch_false_endpoint():
|
||||
assert "market_intel.market_intel_manual_sample_candidate_handoff" in template
|
||||
assert "market_intel.market_intel_manual_sample_candidate_queue_draft" in template
|
||||
assert "market_intel.market_intel_manual_sample_candidate_queue_approval" in template
|
||||
assert "market_intel.market_intel_manual_sample_candidate_queue_transaction" 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
|
||||
@@ -579,7 +581,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_53_manual_sample_candidate_queue_approval"
|
||||
assert bridge["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert bridge["execute_requested"] is False
|
||||
assert bridge["read_only_query_executed"] is False
|
||||
assert bridge["database_connection_opened"] is False
|
||||
@@ -737,7 +739,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_53_manual_sample_candidate_queue_approval"
|
||||
assert contract["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert contract["caller"] == "market_intel"
|
||||
assert contract["contract_ready"] is True
|
||||
assert contract["blocked_reasons"] == []
|
||||
@@ -870,7 +872,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -883,7 +885,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_53_manual_sample_candidate_queue_approval"
|
||||
assert gate["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert gate["fetch_requested"] is True
|
||||
assert gate["manual_fetch_gate_open"] is False
|
||||
assert gate["network_request_allowed"] is False
|
||||
@@ -953,7 +955,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["fetch_requested"] is False
|
||||
assert data["network_request_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -965,7 +967,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_manual_sample_fetch"] is False
|
||||
assert plan["sample_fetch_executed"] is False
|
||||
assert plan["external_network_executed"] is False
|
||||
@@ -1013,7 +1015,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["sample_fetch_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
@@ -1024,7 +1026,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_53_manual_sample_candidate_queue_approval"
|
||||
assert acceptance["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert acceptance["contract_ready"] is True
|
||||
assert acceptance["sample_result_loaded"] is False
|
||||
assert acceptance["sample_result_accepted"] is False
|
||||
@@ -1066,7 +1068,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1078,7 +1080,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_53_manual_sample_candidate_queue_approval"
|
||||
assert review["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert review["contract_ready"] is True
|
||||
assert review["sample_result_loaded"] is False
|
||||
assert review["sample_result_reviewed"] is False
|
||||
@@ -1189,7 +1191,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["sample_result_loaded"] is False
|
||||
assert data["sample_result_reviewed"] is False
|
||||
assert data["candidate_import_allowed"] is False
|
||||
@@ -1228,7 +1230,7 @@ def test_manual_sample_review_evaluation_preview_accepts_payload_without_persist
|
||||
)
|
||||
|
||||
assert review["mode"] == "manual_sample_review_evaluation_preview"
|
||||
assert review["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert review["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert review["review_request_type"] == "operator_posted_json"
|
||||
assert review["payload_received"] is True
|
||||
assert review["payload_valid_json_object"] is True
|
||||
@@ -1290,7 +1292,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["payload_received"] is True
|
||||
assert data["payload_valid_json_object"] is True
|
||||
assert data["payload_persisted"] is False
|
||||
@@ -1370,7 +1372,7 @@ def test_manual_sample_candidate_handoff_preview_creates_candidates_without_pers
|
||||
)
|
||||
|
||||
assert handoff["mode"] == "manual_sample_candidate_handoff_preview"
|
||||
assert handoff["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert handoff["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert handoff["payload_received"] is True
|
||||
assert handoff["payload_valid_json_object"] is True
|
||||
assert handoff["payload_persisted"] is False
|
||||
@@ -1434,7 +1436,7 @@ def test_manual_sample_candidate_handoff_route_is_post_only_and_no_write():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_candidate_handoff_preview"
|
||||
assert data["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["payload_received"] is True
|
||||
assert data["handoff_ready"] is True
|
||||
assert data["candidate_handoff_created"] is True
|
||||
@@ -1493,7 +1495,7 @@ def test_manual_sample_candidate_queue_draft_preview_builds_review_items_without
|
||||
)
|
||||
|
||||
assert queue_draft["mode"] == "manual_sample_candidate_queue_draft_preview"
|
||||
assert queue_draft["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert queue_draft["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert queue_draft["payload_received"] is True
|
||||
assert queue_draft["payload_valid_json_object"] is True
|
||||
assert queue_draft["payload_persisted"] is False
|
||||
@@ -1567,7 +1569,7 @@ def test_manual_sample_candidate_queue_draft_route_is_post_only_and_no_write():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_candidate_queue_draft_preview"
|
||||
assert data["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["payload_received"] is True
|
||||
assert data["handoff_ready"] is True
|
||||
assert data["queue_draft_ready"] is True
|
||||
@@ -1630,7 +1632,7 @@ def test_manual_sample_candidate_queue_approval_preview_blocks_write_and_maps_ro
|
||||
)
|
||||
|
||||
assert approval["mode"] == "manual_sample_candidate_queue_approval_preview"
|
||||
assert approval["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert approval["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert approval["payload_received"] is True
|
||||
assert approval["payload_valid_json_object"] is True
|
||||
assert approval["payload_persisted"] is False
|
||||
@@ -1708,7 +1710,7 @@ def test_manual_sample_candidate_queue_approval_route_is_post_only_and_no_write(
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_candidate_queue_approval_preview"
|
||||
assert data["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["payload_received"] is True
|
||||
assert data["approval_preview_created"] is True
|
||||
assert data["approval_request_created"] is False
|
||||
@@ -1741,11 +1743,152 @@ def test_manual_sample_candidate_queue_approval_blocks_invalid_payload():
|
||||
assert "review_queue_draft_not_ready" in approval["blocked_reasons"]
|
||||
|
||||
|
||||
def test_manual_sample_candidate_queue_transaction_preview_blocks_execution():
|
||||
sample_result = {
|
||||
"batch_id": "sample-batch-11",
|
||||
"platform_code": "momo",
|
||||
"source_key": "homepage",
|
||||
"source_url": "https://www.momoshop.com.tw/",
|
||||
"status": "fetched",
|
||||
"status_code": 200,
|
||||
"content_length": 1700,
|
||||
"page_hash": "e" * 64,
|
||||
"title": "MOMO 活動",
|
||||
"diagnostics": {
|
||||
"link_count": 2,
|
||||
"same_host_link_count": 2,
|
||||
"campaign_link_candidates": [
|
||||
{
|
||||
"confidence_band": "high",
|
||||
"score": 94,
|
||||
"url": "https://www.momoshop.com.tw/activity/sample",
|
||||
"text": "品牌活動",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
transaction = MarketIntelService().build_manual_sample_candidate_queue_transaction(
|
||||
sample_result=sample_result
|
||||
)
|
||||
|
||||
assert transaction["mode"] == "manual_sample_candidate_queue_transaction_preview"
|
||||
assert transaction["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert transaction["payload_received"] is True
|
||||
assert transaction["payload_valid_json_object"] is True
|
||||
assert transaction["payload_persisted"] is False
|
||||
assert transaction["transaction_preview_created"] is True
|
||||
assert transaction["transaction_ready"] is False
|
||||
assert transaction["transaction_opened"] is False
|
||||
assert transaction["transaction_committed"] is False
|
||||
assert transaction["approval_request_created"] is False
|
||||
assert transaction["approval_record_written"] is False
|
||||
assert transaction["review_queue_write_allowed"] is False
|
||||
assert transaction["review_queue_created"] is False
|
||||
assert transaction["review_queue_persisted"] is False
|
||||
assert transaction["candidate_import_allowed"] is False
|
||||
assert transaction["external_network_executed"] is False
|
||||
assert transaction["database_connection_opened"] is False
|
||||
assert transaction["database_session_created"] is False
|
||||
assert transaction["database_write_executed"] is False
|
||||
assert transaction["database_commit_executed"] is False
|
||||
assert transaction["scheduler_attached"] is False
|
||||
assert transaction["transaction_summary"]["target_table"] == "market_alert_review_queue"
|
||||
assert transaction["transaction_summary"]["statement_count"] == 1
|
||||
assert transaction["transaction_summary"]["conflict_policy"] == "dedupe_key_do_nothing"
|
||||
statement = transaction["statements"][0]
|
||||
assert statement["operation"] == "insert"
|
||||
assert statement["table"] == "market_alert_review_queue"
|
||||
assert statement["write_status"] == "blocked_transaction_preview_only"
|
||||
assert statement["idempotency_key"].startswith("market_alert_review_queue:")
|
||||
assert "queue_approval_gates_not_all_passed" in transaction["blocked_reasons"]
|
||||
assert "queue_transaction_execution_still_blocked" in transaction["blocked_reasons"]
|
||||
assert (
|
||||
"do_not_execute_queue_transaction_from_preview"
|
||||
in transaction["safe_boundaries"]
|
||||
)
|
||||
|
||||
|
||||
def test_manual_sample_candidate_queue_transaction_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_queue_transaction",
|
||||
json={
|
||||
"sample_result": {
|
||||
"batch_id": "sample-batch-12",
|
||||
"platform_code": "pchome",
|
||||
"source_key": "homepage",
|
||||
"source_url": "https://24h.pchome.com.tw/",
|
||||
"status": "fetched",
|
||||
"status_code": 200,
|
||||
"content_length": 1800,
|
||||
"page_hash": "f" * 64,
|
||||
"title": "PChome 活動",
|
||||
"diagnostics": {
|
||||
"link_count": 2,
|
||||
"same_host_link_count": 2,
|
||||
"campaign_link_candidates": [
|
||||
{
|
||||
"confidence_band": "medium",
|
||||
"score": 74,
|
||||
"url": "https://24h.pchome.com.tw/activity/sample",
|
||||
"text": "活動頁",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
data = response.get_json()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "manual_sample_candidate_queue_transaction_preview"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["payload_received"] is True
|
||||
assert data["transaction_preview_created"] is True
|
||||
assert data["transaction_ready"] is False
|
||||
assert data["transaction_opened"] is False
|
||||
assert data["transaction_committed"] is False
|
||||
assert data["approval_record_written"] is False
|
||||
assert data["review_queue_created"] is False
|
||||
assert data["review_queue_persisted"] is False
|
||||
assert data["database_write_executed"] is False
|
||||
assert data["scheduler_attached"] is False
|
||||
assert data["transaction_summary"]["statement_count"] == 1
|
||||
|
||||
|
||||
def test_manual_sample_candidate_queue_transaction_blocks_invalid_payload():
|
||||
transaction = MarketIntelService().build_manual_sample_candidate_queue_transaction(
|
||||
sample_result=None,
|
||||
payload_error="invalid_json_object",
|
||||
)
|
||||
|
||||
assert transaction["mode"] == "manual_sample_candidate_queue_transaction_preview"
|
||||
assert transaction["payload_received"] is False
|
||||
assert transaction["payload_valid_json_object"] is False
|
||||
assert transaction["transaction_preview_created"] is False
|
||||
assert transaction["transaction_ready"] is False
|
||||
assert transaction["transaction_opened"] is False
|
||||
assert transaction["transaction_committed"] is False
|
||||
assert transaction["approval_record_written"] is False
|
||||
assert transaction["review_queue_created"] is False
|
||||
assert transaction["database_write_executed"] is False
|
||||
assert "queue_transaction_preview_not_ready" in transaction["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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_to_attach_scheduler"] is False
|
||||
assert plan["scheduler_attached"] is False
|
||||
assert plan["scheduler_registration_executed"] is False
|
||||
@@ -1783,7 +1926,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["scheduler_registration_executed"] is False
|
||||
assert data["crawler_job_started"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1794,7 +1937,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_review_queue"] is False
|
||||
assert plan["review_queue_created"] is False
|
||||
assert plan["auto_match_executed"] is False
|
||||
@@ -1830,7 +1973,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["review_queue_created"] is False
|
||||
assert data["auto_confirm_executed"] is False
|
||||
assert data["external_network_executed"] is False
|
||||
@@ -1841,7 +1984,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_opportunity_queue"] is False
|
||||
assert plan["opportunity_queue_created"] is False
|
||||
assert plan["threat_alert_dispatched"] is False
|
||||
@@ -1882,7 +2025,7 @@ def test_opportunity_plan_route_is_preview_only():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data["mode"] == "opportunity_plan_preview"
|
||||
assert data["phase"] == "phase_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["opportunity_queue_created"] is False
|
||||
assert data["threat_alert_dispatched"] is False
|
||||
assert data["ai_summary_generated"] is False
|
||||
@@ -1893,7 +2036,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_scoring_job"] is False
|
||||
assert plan["scoring_job_created"] is False
|
||||
assert plan["score_calculation_executed"] is False
|
||||
@@ -1941,7 +2084,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["scoring_job_created"] is False
|
||||
assert data["score_calculation_executed"] is False
|
||||
assert data["sample_scores_generated"] is False
|
||||
@@ -1953,7 +2096,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_evidence_bundle"] is False
|
||||
assert plan["evidence_bundle_created"] is False
|
||||
assert plan["evidence_query_executed"] is False
|
||||
@@ -1999,7 +2142,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["evidence_bundle_created"] is False
|
||||
assert data["evidence_query_executed"] is False
|
||||
assert data["sample_evidence_generated"] is False
|
||||
@@ -2012,7 +2155,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_53_manual_sample_candidate_queue_approval"
|
||||
assert plan["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert plan["ready_for_alert_candidates"] is False
|
||||
assert plan["alert_candidate_created"] is False
|
||||
assert plan["alert_queue_created"] is False
|
||||
@@ -2097,7 +2240,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["alert_candidate_created"] is False
|
||||
assert data["alert_queue_created"] is False
|
||||
assert data["review_queue_created"] is False
|
||||
@@ -2175,7 +2318,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["deployment_actions_executed"] is False
|
||||
assert data["docker_command_executed"] is False
|
||||
assert data["ssh_command_executed"] is False
|
||||
@@ -2190,7 +2333,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_53_manual_sample_candidate_queue_approval"
|
||||
assert readiness["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert readiness["execute_requested"] is False
|
||||
assert readiness["router_enabled"] is False
|
||||
assert readiness["external_mcp_complete"] is False
|
||||
@@ -2585,6 +2728,7 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
assert readiness["checks"]["manual_sample_candidate_handoff_post_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_candidate_queue_draft_post_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_candidate_queue_approval_post_safe"] is True
|
||||
assert readiness["checks"]["manual_sample_candidate_queue_transaction_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
|
||||
@@ -2823,6 +2967,68 @@ def test_deployment_readiness_reports_app_only_release_gate():
|
||||
readiness["manual_sample_candidate_queue_approval"]["scheduler_attached"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["mode"]
|
||||
== "manual_sample_candidate_queue_transaction_preview"
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["payload_received"]
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["payload_persisted"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["transaction_ready"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["transaction_opened"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["transaction_committed"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"][
|
||||
"approval_record_written"
|
||||
]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["review_queue_created"]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"][
|
||||
"review_queue_persisted"
|
||||
]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"][
|
||||
"candidate_import_allowed"
|
||||
]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"][
|
||||
"external_network_executed"
|
||||
]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"][
|
||||
"database_write_executed"
|
||||
]
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
readiness["manual_sample_candidate_queue_transaction"]["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
|
||||
@@ -2927,7 +3133,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_53_manual_sample_candidate_queue_approval"
|
||||
assert drill["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert drill["execute_requested"] is False
|
||||
assert drill["schema_state"] == "planned_no_db_probe"
|
||||
assert drill["drill_ready_for_operator_review"] is True
|
||||
@@ -3042,7 +3248,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["migration_executed"] is False
|
||||
assert data["rollback_executed"] is False
|
||||
@@ -3054,7 +3260,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_53_manual_sample_candidate_queue_approval"
|
||||
assert review["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert review["execute_requested"] is False
|
||||
assert review["catalog_state"] == "planned_no_probe"
|
||||
assert review["seed_state"] == "planned_no_probe"
|
||||
@@ -3169,7 +3375,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["catalog_state"] == "planned_no_probe"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -3182,7 +3388,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_53_manual_sample_candidate_queue_approval"
|
||||
assert smoke["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert smoke["execute_requested"] is False
|
||||
assert smoke["smoke_result"] == "planned_no_execution"
|
||||
assert smoke["live_smoke_passed"] is False
|
||||
@@ -3244,7 +3450,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert data["execute_requested"] is False
|
||||
assert data["smoke_result"] == "planned_no_execution"
|
||||
assert data["migration_executed"] is False
|
||||
@@ -3257,7 +3463,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_53_manual_sample_candidate_queue_approval"
|
||||
assert inventory["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
assert inventory["execute_requested"] is False
|
||||
assert inventory["read_only_query_executed"] is False
|
||||
assert inventory["database_connection_opened"] is False
|
||||
@@ -3401,7 +3607,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_53_manual_sample_candidate_queue_approval"
|
||||
assert data["phase"] == "phase_54_manual_sample_candidate_queue_transaction"
|
||||
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