bpmax-cli 0.1.43 → 0.1.44-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bin.js +3397 -433
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-api-platform-editor/SKILL.md +321 -0
- package/skills/bpmax-api-platform-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-api-platform-editor/references/api-doc-debug-workflow.md +34 -0
- package/skills/bpmax-api-platform-editor/references/api-proxy-shape.md +41 -0
- package/skills/bpmax-api-platform-editor/references/instance-config-shape.md +41 -0
- package/skills/bpmax-api-platform-editor/references/platform-api-map.md +52 -0
- package/skills/bpmax-api-platform-editor/references/runtime-workflow.md +32 -0
- package/skills/bpmax-api-platform-editor/scripts/api_platform_editor_common.py +1276 -0
- package/skills/bpmax-api-platform-editor/scripts/build_submit_payload.py +64 -0
- package/skills/bpmax-api-platform-editor/scripts/capture_write_contract.py +40 -0
- package/skills/bpmax-api-platform-editor/scripts/export_layer_bundle.py +212 -0
- package/skills/bpmax-api-platform-editor/scripts/record_doc_debug_acceptance.py +62 -0
- package/skills/bpmax-api-platform-editor/scripts/submit_and_verify_layer.py +75 -0
- package/skills/bpmax-api-platform-editor/tests/test_api_platform_editor.py +287 -0
- package/skills/bpmax-auth/SKILL.md +6 -17
- package/skills/bpmax-builder-shared/SKILL.md +44 -0
- package/skills/bpmax-builder-shared/base_url.py +81 -0
- package/skills/bpmax-builder-shared/runtime-script-site-matrix.json +71 -0
- package/skills/bpmax-builder-shared/runtime-script-site-matrix.md +34 -0
- package/skills/bpmax-builder-shared/runtime-script-template-catalog.md +123 -0
- package/skills/bpmax-builder-shared/runtime_script_rules.py +272 -0
- package/skills/bpmax-builder-shared/skill_audit.py +374 -0
- package/skills/bpmax-builder-shared/template_script_hard_rules.py +280 -0
- package/skills/bpmax-builder-shared/tests/test_base_url.py +80 -0
- package/skills/bpmax-builder-shared/tests/test_runtime_script_rules.py +115 -0
- package/skills/bpmax-builder-shared/tests/test_skill_audit.py +231 -0
- package/skills/bpmax-builder-shared/tests/test_template_script_hard_rules.py +281 -0
- package/skills/bpmax-cli/SKILL.md +2 -0
- package/skills/bpmax-config-latest/SKILL.md +71 -0
- package/skills/bpmax-console-template-editor/SKILL.md +536 -0
- package/skills/bpmax-console-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-console-template-editor/references/filter-integration.md +60 -0
- package/skills/bpmax-console-template-editor/references/lessons-from-resume-dashboard.md +114 -0
- package/skills/bpmax-console-template-editor/references/local-temp-workflow.md +69 -0
- package/skills/bpmax-console-template-editor/references/module-catalog.md +100 -0
- package/skills/bpmax-console-template-editor/references/runtime-page-shape.md +91 -0
- package/skills/bpmax-console-template-editor/references/template-shape.md +149 -0
- package/skills/bpmax-console-template-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-console-template-editor/scripts/confirm_console_template.py +33 -0
- package/skills/bpmax-console-template-editor/scripts/console_template_editor_common.py +964 -0
- package/skills/bpmax-console-template-editor/scripts/export_console_template.py +99 -0
- package/skills/bpmax-console-template-editor/scripts/lint_console_template.py +46 -0
- package/skills/bpmax-console-template-editor/scripts/submit_console_template.py +99 -0
- package/skills/bpmax-console-template-editor/tests/test_console_template_editor.py +383 -0
- package/skills/bpmax-dataset-field-template-editor/SKILL.md +600 -0
- package/skills/bpmax-dataset-field-template-editor/references/create-request-gotchas.md +25 -0
- package/skills/bpmax-dataset-field-template-editor/references/field-classify-mapping.md +35 -0
- package/skills/bpmax-dataset-field-template-editor/references/nested-field-patterns.md +24 -0
- package/skills/bpmax-dataset-field-template-editor/references/runtime-verified-field-page-shape.md +61 -0
- package/skills/bpmax-dataset-field-template-editor/references/virtual-field-patterns.md +27 -0
- package/skills/bpmax-dataset-field-template-editor/references/work-file-to-submit-mapping.md +127 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/build_submit_payload.py +67 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/confirm_dataset_field.py +37 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/dataset_field_editor_common.py +784 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/export_dataset_field.py +62 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/init_create_dataset_field.py +104 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/inspect_dataset_field_runtime.py +83 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/lint_dataset_field_semantics.py +35 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/submit_dataset_field.py +95 -0
- package/skills/bpmax-dataset-field-template-editor/tests/test_dataset_field_editor.py +709 -0
- package/skills/bpmax-dataset-field-template-editor/tests/test_init_create_dataset_field.py +59 -0
- package/skills/bpmax-dataset-template-editor/SKILL.md +779 -0
- package/skills/bpmax-dataset-template-editor/references/custom-key-usage-patterns.md +18 -0
- package/skills/bpmax-dataset-template-editor/references/dataset-script-runtime-matrix.md +73 -0
- package/skills/bpmax-dataset-template-editor/references/pre-process-script-authoring-guide.md +186 -0
- package/skills/bpmax-dataset-template-editor/references/pre-process-script-example-catalog.md +106 -0
- package/skills/bpmax-dataset-template-editor/references/runtime-gotchas.md +28 -0
- package/skills/bpmax-dataset-template-editor/references/runtime-verified-dataset-page-shape.md +47 -0
- package/skills/bpmax-dataset-template-editor/references/ui-to-backend-field-map.md +23 -0
- package/skills/bpmax-dataset-template-editor/references/work-file-to-submit-mapping.md +97 -0
- package/skills/bpmax-dataset-template-editor/scripts/basic_table_audit.py +65 -0
- package/skills/bpmax-dataset-template-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-dataset-template-editor/scripts/dataset_editor_common.py +650 -0
- package/skills/bpmax-dataset-template-editor/scripts/export_dataset.py +155 -0
- package/skills/bpmax-dataset-template-editor/scripts/lint_dataset_template.py +42 -0
- package/skills/bpmax-dataset-template-editor/scripts/resolve_dataset.py +43 -0
- package/skills/bpmax-dataset-template-editor/scripts/scan_custom_key_references.py +27 -0
- package/skills/bpmax-dataset-template-editor/scripts/submit_dataset.py +115 -0
- package/skills/bpmax-dataset-template-editor/scripts/verify_dataset_list.py +52 -0
- package/skills/bpmax-dataset-template-editor/scripts/verify_publish_health.py +39 -0
- package/skills/bpmax-dataset-template-editor/tests/test_dataset_editor.py +373 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +151 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +4 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +60 -0
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +371 -0
- package/skills/bpmax-e2e-flow-test-operator/agents/openai.yaml +5 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale.json +97 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_final_v2.json +105 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_main.json +36 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_region.json +40 -0
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +33 -0
- package/skills/bpmax-e2e-flow-test-operator/references/failure-update-loop.md +17 -0
- package/skills/bpmax-e2e-flow-test-operator/references/filter-field-discovery.md +40 -0
- package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +19 -0
- package/skills/bpmax-e2e-flow-test-operator/references/negative-sale-api-matrix.md +75 -0
- package/skills/bpmax-e2e-flow-test-operator/references/profile-schema.md +107 -0
- package/skills/bpmax-e2e-flow-test-operator/references/skill-experience-coverage-matrix.md +29 -0
- package/skills/bpmax-e2e-flow-test-operator/references/stale-runtime-and-clean-sample-rules.md +54 -0
- package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +58 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/bpmax_session.py +287 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_plan.json +59 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_runner.py +687 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +95 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_state.py +288 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_api_matrix.py +161 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_filter_fields.py +138 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_form_runtime.py +396 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_runner.py +341 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_test_profile.py +185 -0
- package/skills/bpmax-e2e-flow-test-operator/tests/test_negative_sale_api_tools.py +138 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/SKILL.md +69 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-checklist.md +42 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-recipes.md +38 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-shape.md +86 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/gate-lint.md +68 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/hoocoo-patterns.md +39 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/runtime-behavior.md +41 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/script-authoring.md +110 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/scripts/lint_feishu_chat_plugin.py +278 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/tests/test_lint_feishu_chat_plugin.py +203 -0
- package/skills/bpmax-filter-template-editor/SKILL.md +564 -0
- package/skills/bpmax-filter-template-editor/references/experience-coverage-matrix.md +38 -0
- package/skills/bpmax-filter-template-editor/references/filter-and-flow-binding.md +57 -0
- package/skills/bpmax-filter-template-editor/references/filter-content-schema.md +141 -0
- package/skills/bpmax-filter-template-editor/references/filter-request-shape.md +287 -0
- package/skills/bpmax-filter-template-editor/references/filter-runtime-patterns.md +115 -0
- package/skills/bpmax-filter-template-editor/references/runtime-verified-filter-page-shape.md +94 -0
- package/skills/bpmax-filter-template-editor/scripts/build_submit_payload.py +25 -0
- package/skills/bpmax-filter-template-editor/scripts/confirm_filter_template.py +22 -0
- package/skills/bpmax-filter-template-editor/scripts/export_filter_template.py +57 -0
- package/skills/bpmax-filter-template-editor/scripts/filter_template_editor_common.py +348 -0
- package/skills/bpmax-filter-template-editor/scripts/init_create_filter_template.py +8 -0
- package/skills/bpmax-filter-template-editor/scripts/lint_filter_template_semantics.py +26 -0
- package/skills/bpmax-filter-template-editor/scripts/submit_filter_template.py +62 -0
- package/skills/bpmax-filter-template-editor/tests/test_filter_template_editor.py +231 -0
- package/skills/bpmax-flow-template-editor/SKILL.md +1043 -0
- package/skills/bpmax-flow-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-flow-template-editor/references/before-next-step-script-runtime-gotchas.md +62 -0
- package/skills/bpmax-flow-template-editor/references/config-surfaces-and-placeholders.md +270 -0
- package/skills/bpmax-flow-template-editor/references/diff-strategy.md +67 -0
- package/skills/bpmax-flow-template-editor/references/editor-runtime-vs-draft.md +25 -0
- package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +159 -0
- package/skills/bpmax-flow-template-editor/references/intent-model.md +117 -0
- package/skills/bpmax-flow-template-editor/references/lessons-from-price-plan-flow.md +147 -0
- package/skills/bpmax-flow-template-editor/references/local-temp-workflow.md +97 -0
- package/skills/bpmax-flow-template-editor/references/matrix-flow-form-nav-collaboration.md +163 -0
- package/skills/bpmax-flow-template-editor/references/payload-checklist.md +133 -0
- package/skills/bpmax-flow-template-editor/references/project-create-runtime-gotchas.md +54 -0
- package/skills/bpmax-flow-template-editor/references/requirement-to-node-mapping.md +149 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-flow-detail-shape.md +41 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-meta-fields.md +155 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-node-fields.md +179 -0
- package/skills/bpmax-flow-template-editor/references/save-draft-request-shape.md +91 -0
- package/skills/bpmax-flow-template-editor/references/script-review-hard-rules.md +93 -0
- package/skills/bpmax-flow-template-editor/references/work-file-to-submit-mapping.md +57 -0
- package/skills/bpmax-flow-template-editor/scripts/build_submit_payload.py +69 -0
- package/skills/bpmax-flow-template-editor/scripts/confirm_flow_template.py +52 -0
- package/skills/bpmax-flow-template-editor/scripts/export_flow_template.py +114 -0
- package/skills/bpmax-flow-template-editor/scripts/flow_template_editor_common.py +1084 -0
- package/skills/bpmax-flow-template-editor/scripts/submit_flow_template.py +159 -0
- package/skills/bpmax-flow-template-editor/tests/test_flow_template_editor.py +636 -0
- package/skills/bpmax-form-template-editor/SKILL.md +1074 -0
- package/skills/bpmax-form-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +193 -0
- package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +125 -0
- package/skills/bpmax-form-template-editor/references/payload-checklist.md +77 -0
- package/skills/bpmax-form-template-editor/references/sub-form-patterns.md +49 -0
- package/skills/bpmax-form-template-editor/scripts/build_submit_payload.py +37 -0
- package/skills/bpmax-form-template-editor/scripts/check_form_template_consistency.py +145 -0
- package/skills/bpmax-form-template-editor/scripts/confirm_form_template.py +67 -0
- package/skills/bpmax-form-template-editor/scripts/export_form_template.py +89 -0
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +1745 -0
- package/skills/bpmax-form-template-editor/scripts/lint_form_template_semantics.py +30 -0
- package/skills/bpmax-form-template-editor/scripts/record_runtime_acceptance.py +67 -0
- package/skills/bpmax-form-template-editor/scripts/submit_form_template.py +163 -0
- package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +1303 -0
- package/skills/bpmax-list-template-editor/SKILL.md +468 -0
- package/skills/bpmax-list-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-list-template-editor/references/browser-page-contract.md +81 -0
- package/skills/bpmax-list-template-editor/references/content-config-shape.md +148 -0
- package/skills/bpmax-list-template-editor/references/dataset-field-mapping.md +60 -0
- package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +103 -0
- package/skills/bpmax-list-template-editor/references/local-temp-workflow.md +102 -0
- package/skills/bpmax-list-template-editor/references/payload-checklist.md +47 -0
- package/skills/bpmax-list-template-editor/references/runtime-verified-workflow.md +140 -0
- package/skills/bpmax-list-template-editor/references/special-formats.md +394 -0
- package/skills/bpmax-list-template-editor/scripts/build_submit_payload.py +37 -0
- package/skills/bpmax-list-template-editor/scripts/confirm_list_template.py +33 -0
- package/skills/bpmax-list-template-editor/scripts/export_list_template.py +89 -0
- package/skills/bpmax-list-template-editor/scripts/fetch_data_set.py +34 -0
- package/skills/bpmax-list-template-editor/scripts/lint_list_template_semantics.py +54 -0
- package/skills/bpmax-list-template-editor/scripts/list_template_editor_common.py +955 -0
- package/skills/bpmax-list-template-editor/scripts/record_acceptance.py +55 -0
- package/skills/bpmax-list-template-editor/scripts/submit_list_template.py +117 -0
- package/skills/bpmax-list-template-editor/tests/test_list_template_editor_common.py +441 -0
- package/skills/bpmax-nav-config-editor/SKILL.md +347 -0
- package/skills/bpmax-nav-config-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-nav-config-editor/references/api-workflow.md +68 -0
- package/skills/bpmax-nav-config-editor/references/config-shape.md +78 -0
- package/skills/bpmax-nav-config-editor/references/icon-selection.md +83 -0
- package/skills/bpmax-nav-config-editor/references/path-mapping-rules.md +46 -0
- package/skills/bpmax-nav-config-editor/references/payload-checklist.md +41 -0
- package/skills/bpmax-nav-config-editor/references/runtime-probing.md +47 -0
- package/skills/bpmax-nav-config-editor/scripts/build_submit_payload.py +34 -0
- package/skills/bpmax-nav-config-editor/scripts/confirm_nav_config.py +32 -0
- package/skills/bpmax-nav-config-editor/scripts/export_nav_config.py +56 -0
- package/skills/bpmax-nav-config-editor/scripts/lint_nav_config_semantics.py +33 -0
- package/skills/bpmax-nav-config-editor/scripts/nav_config_editor_common.py +812 -0
- package/skills/bpmax-nav-config-editor/scripts/submit_nav_config.py +44 -0
- package/skills/bpmax-nav-config-editor/scripts/verify_nav_config.py +33 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor.py +358 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor_common.py +138 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_lint.py +58 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_submit_verify.py +51 -0
- package/skills/bpmax-project/SKILL.md +1 -1
- package/skills/bpmax-project-detail-template-editor/SKILL.md +329 -0
- package/skills/bpmax-project-detail-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-project-detail-template-editor/references/local-temp-workflow.md +59 -0
- package/skills/bpmax-project-detail-template-editor/references/module-catalog-and-config-notes.md +47 -0
- package/skills/bpmax-project-detail-template-editor/references/payload-checklist.md +33 -0
- package/skills/bpmax-project-detail-template-editor/references/project-detail-template-api-workflow.md +44 -0
- package/skills/bpmax-project-detail-template-editor/scripts/build_submit_payload.py +30 -0
- package/skills/bpmax-project-detail-template-editor/scripts/confirm_project_detail_template.py +33 -0
- package/skills/bpmax-project-detail-template-editor/scripts/export_project_detail_template.py +87 -0
- package/skills/bpmax-project-detail-template-editor/scripts/lint_project_detail_template_semantics.py +37 -0
- package/skills/bpmax-project-detail-template-editor/scripts/project_detail_template_editor_common.py +507 -0
- package/skills/bpmax-project-detail-template-editor/scripts/submit_project_detail_template.py +120 -0
- package/skills/bpmax-project-detail-template-editor/tests/test_project_detail_template_editor.py +369 -0
- package/skills/bpmax-role-editor/SKILL.md +251 -0
- package/skills/bpmax-role-editor/references/api-workflow.md +30 -0
- package/skills/bpmax-role-editor/references/runtime-page-shape.md +18 -0
- package/skills/bpmax-role-editor/references/work-file-mapping.md +32 -0
- package/skills/bpmax-role-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-role-editor/scripts/confirm_role.py +33 -0
- package/skills/bpmax-role-editor/scripts/export_role.py +163 -0
- package/skills/bpmax-role-editor/scripts/lint_role_semantics.py +38 -0
- package/skills/bpmax-role-editor/scripts/role_editor_common.py +1231 -0
- package/skills/bpmax-role-editor/scripts/submit_role.py +144 -0
- package/skills/bpmax-role-editor/tests/test_role_editor.py +343 -0
- package/skills/bpmax-shared/SKILL.md +1 -1
- package/skills/form-control-library/SKILL.md +82 -0
- package/skills/form-control-library/agents/openai.yaml +4 -0
- package/skills/form-control-library/references/form-controls.md +199 -0
- package/skills/form-control-library/references/form-template-submit-schema.md +180 -0
- package/skills/form-control-library/references/group-select-runtime.md +191 -0
- package/skills/form-control-library/scripts/rebuild_form_control_library.py +55 -0
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import ssl
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.parse
|
|
10
|
+
import urllib.request
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from datetime import datetime, timezone
|
|
13
|
+
from difflib import unified_diff
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any, Dict, Optional
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
SHARED_SKILL_ROOT = Path(__file__).resolve().parents[2] / "bpmax-builder-shared"
|
|
19
|
+
if str(SHARED_SKILL_ROOT) not in sys.path:
|
|
20
|
+
sys.path.insert(0, str(SHARED_SKILL_ROOT))
|
|
21
|
+
from base_url import DEFAULT_BASE_URL, resolve_base_url
|
|
22
|
+
|
|
23
|
+
DEFAULT_LANGUAGE = "zhCN"
|
|
24
|
+
DEFAULT_CONFIRM_TOKEN = "SUBMIT_CONFIRMED"
|
|
25
|
+
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
26
|
+
TMP_ROOT = REPO_ROOT / ".codex" / "tmp" / "dataset-editor"
|
|
27
|
+
TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
|
|
28
|
+
DEFAULT_LIST_PAGE_SIZE = 100
|
|
29
|
+
DEFAULT_REFRESH_SETTING = {
|
|
30
|
+
"replace_strategy": "full_refresh",
|
|
31
|
+
"stop_refresh": 0,
|
|
32
|
+
"stop_refresh_time": "",
|
|
33
|
+
"stop_refresh_count": 0,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
from template_script_hard_rules import scan_named_script_surfaces
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def utc_now_iso() -> str:
|
|
40
|
+
return datetime.now(timezone.utc).isoformat()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def ensure_tmp_dirs() -> None:
|
|
44
|
+
for part in TMP_SUBDIRS:
|
|
45
|
+
(TMP_ROOT / part).mkdir(parents=True, exist_ok=True)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def slugify_flow_key(flow_key: str) -> str:
|
|
49
|
+
text = flow_key.strip() if flow_key else ""
|
|
50
|
+
return text or "default"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def create_stem(flow_type: str, flow_key: str) -> str:
|
|
54
|
+
return f"create-{flow_type}-{slugify_flow_key(flow_key)}"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def paths_for(stem: Any) -> Dict[str, Path]:
|
|
58
|
+
ensure_tmp_dirs()
|
|
59
|
+
key = str(stem)
|
|
60
|
+
return {
|
|
61
|
+
"raw": TMP_ROOT / "raw" / f"{key}.json",
|
|
62
|
+
"work": TMP_ROOT / "work" / f"{key}.json",
|
|
63
|
+
"meta": TMP_ROOT / "meta" / f"{key}.json",
|
|
64
|
+
"submit": TMP_ROOT / "submit" / f"{key}.json",
|
|
65
|
+
"work_diff": TMP_ROOT / "diffs" / f"{key}.work.diff.txt",
|
|
66
|
+
"submit_diff": TMP_ROOT / "diffs" / f"{key}.submit.diff.txt",
|
|
67
|
+
"response": TMP_ROOT / "result" / f"{key}.response.json",
|
|
68
|
+
"readback": TMP_ROOT / "result" / f"{key}.readback.json",
|
|
69
|
+
"verify": TMP_ROOT / "result" / f"{key}.verify.json",
|
|
70
|
+
"lint": TMP_ROOT / "result" / f"{key}.lint.json",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def dump_json(path: Path, payload: Any) -> None:
|
|
75
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def load_json(path: Path) -> Any:
|
|
80
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def stable_json_lines(payload: Any) -> list[str]:
|
|
84
|
+
return (json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n").splitlines(keepends=True)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def write_diff(path: Path, before: Any, after: Any, before_label: str, after_label: str) -> None:
|
|
88
|
+
diff = unified_diff(
|
|
89
|
+
stable_json_lines(before),
|
|
90
|
+
stable_json_lines(after),
|
|
91
|
+
fromfile=before_label,
|
|
92
|
+
tofile=after_label,
|
|
93
|
+
)
|
|
94
|
+
text = "".join(diff)
|
|
95
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
96
|
+
path.write_text(text or "# no diff\n", encoding="utf-8")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def normalize_text(value: Any) -> str:
|
|
100
|
+
if value is None:
|
|
101
|
+
return ""
|
|
102
|
+
if isinstance(value, str):
|
|
103
|
+
return value
|
|
104
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def normalize_int(value: Any) -> int:
|
|
108
|
+
if value in (None, ""):
|
|
109
|
+
return 0
|
|
110
|
+
return int(value)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def normalize_refresh_setting(value: Any) -> Dict[str, Any]:
|
|
114
|
+
data = dict(DEFAULT_REFRESH_SETTING)
|
|
115
|
+
if isinstance(value, dict):
|
|
116
|
+
data.update(value)
|
|
117
|
+
return {
|
|
118
|
+
"replace_strategy": normalize_text(data.get("replace_strategy", DEFAULT_REFRESH_SETTING["replace_strategy"])),
|
|
119
|
+
"stop_refresh": normalize_int(data.get("stop_refresh", DEFAULT_REFRESH_SETTING["stop_refresh"])),
|
|
120
|
+
"stop_refresh_time": normalize_text(data.get("stop_refresh_time", DEFAULT_REFRESH_SETTING["stop_refresh_time"])),
|
|
121
|
+
"stop_refresh_count": normalize_int(data.get("stop_refresh_count", DEFAULT_REFRESH_SETTING["stop_refresh_count"])),
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def refresh_setting_to_work(value: Any) -> Dict[str, Any]:
|
|
126
|
+
data = normalize_refresh_setting(value)
|
|
127
|
+
return {
|
|
128
|
+
"replaceStrategy": data["replace_strategy"],
|
|
129
|
+
"stopRefresh": data["stop_refresh"],
|
|
130
|
+
"stopRefreshTime": data["stop_refresh_time"],
|
|
131
|
+
"stopRefreshCount": data["stop_refresh_count"],
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def refresh_setting_to_submit(value: Any) -> Dict[str, Any]:
|
|
136
|
+
if not isinstance(value, dict):
|
|
137
|
+
return dict(DEFAULT_REFRESH_SETTING)
|
|
138
|
+
return normalize_refresh_setting(
|
|
139
|
+
{
|
|
140
|
+
"replace_strategy": value.get("replaceStrategy", value.get("replace_strategy")),
|
|
141
|
+
"stop_refresh": value.get("stopRefresh", value.get("stop_refresh")),
|
|
142
|
+
"stop_refresh_time": value.get("stopRefreshTime", value.get("stop_refresh_time")),
|
|
143
|
+
"stop_refresh_count": value.get("stopRefreshCount", value.get("stop_refresh_count")),
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def simplify_field(item: Dict[str, Any]) -> Dict[str, Any]:
|
|
149
|
+
return {
|
|
150
|
+
"id": item.get("id"),
|
|
151
|
+
"key": item.get("key", ""),
|
|
152
|
+
"name": item.get("name", ""),
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def field_summary(items: list[Dict[str, Any]]) -> Dict[str, Any]:
|
|
157
|
+
normalized = [simplify_field(item) for item in items]
|
|
158
|
+
return {
|
|
159
|
+
"count": len(normalized),
|
|
160
|
+
"items": normalized,
|
|
161
|
+
"ids": [item["id"] for item in normalized if item.get("id") is not None],
|
|
162
|
+
"keys": [item["key"] for item in normalized if item.get("key")],
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def detail_to_work_payload(detail: Dict[str, Any], available_fields: Optional[list[Dict[str, Any]]] = None) -> Dict[str, Any]:
|
|
167
|
+
selected_fields = [simplify_field(item) for item in detail.get("dataSetFields") or detail.get("fields") or []]
|
|
168
|
+
available = [simplify_field(item) for item in (available_fields or [])]
|
|
169
|
+
selected_ids = {item.get("id") for item in selected_fields}
|
|
170
|
+
available = [item for item in available if item.get("id") not in selected_ids]
|
|
171
|
+
return {
|
|
172
|
+
"id": detail.get("id"),
|
|
173
|
+
"mode": "edit",
|
|
174
|
+
"flowType": detail.get("flow_type", ""),
|
|
175
|
+
"flowKey": detail.get("flow_key", ""),
|
|
176
|
+
"status": detail.get("status"),
|
|
177
|
+
"basic": {
|
|
178
|
+
"name": detail.get("name", ""),
|
|
179
|
+
"basicTable": detail.get("basic_table", ""),
|
|
180
|
+
"customKey": normalize_text(detail.get("custom_key", "")),
|
|
181
|
+
"nonBlock": normalize_int(detail.get("non_block", 0)),
|
|
182
|
+
"isDefault": normalize_int(detail.get("is_default", 0)),
|
|
183
|
+
},
|
|
184
|
+
"scripts": {
|
|
185
|
+
"postScript": normalize_text(detail.get("post_script", "")),
|
|
186
|
+
"postEsMapping": normalize_text(detail.get("post_es_mapping", "")),
|
|
187
|
+
"refreshProjectScript": normalize_text(detail.get("refresh_project_script", "")),
|
|
188
|
+
},
|
|
189
|
+
"search": {
|
|
190
|
+
"preProcessScript": normalize_text(detail.get("pre_process_script", "")),
|
|
191
|
+
"postProcessScript": normalize_text(detail.get("post_process_script", "")),
|
|
192
|
+
"tag": normalize_int(detail.get("process_script_tag", 0)),
|
|
193
|
+
},
|
|
194
|
+
"refreshSetting": refresh_setting_to_work(detail.get("refresh_setting")),
|
|
195
|
+
"fields": {
|
|
196
|
+
"selected": selected_fields,
|
|
197
|
+
"selectedKeys": [item["key"] for item in selected_fields if item.get("key")],
|
|
198
|
+
"available": available,
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def build_create_skeleton(
|
|
204
|
+
flow_type: str,
|
|
205
|
+
flow_key: str = "",
|
|
206
|
+
basic_table: str = "",
|
|
207
|
+
defaults: Optional[Dict[str, Any]] = None,
|
|
208
|
+
field_options: Optional[list[Dict[str, Any]]] = None,
|
|
209
|
+
) -> Dict[str, Any]:
|
|
210
|
+
defaults = defaults or {}
|
|
211
|
+
return {
|
|
212
|
+
"id": None,
|
|
213
|
+
"mode": "create",
|
|
214
|
+
"flowType": flow_type,
|
|
215
|
+
"flowKey": flow_key,
|
|
216
|
+
"status": None,
|
|
217
|
+
"basic": {
|
|
218
|
+
"name": defaults.get("name", ""),
|
|
219
|
+
"basicTable": defaults.get("basicTable", basic_table),
|
|
220
|
+
"customKey": defaults.get("customKey", ""),
|
|
221
|
+
"nonBlock": normalize_int(defaults.get("nonBlock", 0)),
|
|
222
|
+
"isDefault": normalize_int(defaults.get("isDefault", 0)),
|
|
223
|
+
},
|
|
224
|
+
"scripts": {
|
|
225
|
+
"postScript": normalize_text(defaults.get("postScript", "")),
|
|
226
|
+
"postEsMapping": normalize_text(defaults.get("postEsMapping", "")),
|
|
227
|
+
"refreshProjectScript": normalize_text(defaults.get("refreshProjectScript", "")),
|
|
228
|
+
},
|
|
229
|
+
"search": {
|
|
230
|
+
"preProcessScript": normalize_text(defaults.get("preProcessScript", "")),
|
|
231
|
+
"postProcessScript": normalize_text(defaults.get("postProcessScript", "")),
|
|
232
|
+
"tag": normalize_int(defaults.get("tag", 0)),
|
|
233
|
+
},
|
|
234
|
+
"refreshSetting": refresh_setting_to_work(defaults.get("refreshSetting")),
|
|
235
|
+
"fields": {
|
|
236
|
+
"selected": [simplify_field(item) for item in defaults.get("selectedFields", [])],
|
|
237
|
+
"selectedKeys": [item["key"] for item in defaults.get("selectedFields", []) if item.get("key")],
|
|
238
|
+
"available": [simplify_field(item) for item in (field_options or [])],
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def build_submit_payload(work: Dict[str, Any]) -> Dict[str, Any]:
|
|
244
|
+
basic = work.get("basic") or {}
|
|
245
|
+
scripts = work.get("scripts") or {}
|
|
246
|
+
search = work.get("search") or {}
|
|
247
|
+
selected_fields = (work.get("fields") or {}).get("selected") or []
|
|
248
|
+
payload: Dict[str, Any] = {
|
|
249
|
+
"name": basic.get("name", ""),
|
|
250
|
+
"basic_table": basic.get("basicTable", ""),
|
|
251
|
+
"custom_key": normalize_text(basic.get("customKey", "")),
|
|
252
|
+
"non_block": normalize_int(basic.get("nonBlock", 0)),
|
|
253
|
+
"is_default": normalize_int(basic.get("isDefault", 0)),
|
|
254
|
+
"flow_type": work.get("flowType", ""),
|
|
255
|
+
"post_script": normalize_text(scripts.get("postScript", "")),
|
|
256
|
+
"post_es_mapping": normalize_text(scripts.get("postEsMapping", "")),
|
|
257
|
+
"refresh_project_script": normalize_text(scripts.get("refreshProjectScript", "")),
|
|
258
|
+
"pre_process_script": normalize_text(search.get("preProcessScript", "")),
|
|
259
|
+
"post_process_script": normalize_text(search.get("postProcessScript", "")),
|
|
260
|
+
"process_script_tag": normalize_int(search.get("tag", 0)),
|
|
261
|
+
"refresh_setting": refresh_setting_to_submit(work.get("refreshSetting")),
|
|
262
|
+
"fields": [item["key"] for item in selected_fields if item.get("key")],
|
|
263
|
+
}
|
|
264
|
+
if work.get("flowKey", "") not in ("", None):
|
|
265
|
+
payload["flow_key"] = work["flowKey"]
|
|
266
|
+
if work.get("id") not in (None, ""):
|
|
267
|
+
payload["id"] = work["id"]
|
|
268
|
+
return payload
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def load_repo_dataset_snapshots(
|
|
272
|
+
flow_type: str,
|
|
273
|
+
flow_key: str = "",
|
|
274
|
+
repo_root: Path = REPO_ROOT,
|
|
275
|
+
) -> list[Dict[str, Any]]:
|
|
276
|
+
base = repo_root / "think_data_set"
|
|
277
|
+
snapshots: list[Dict[str, Any]] = []
|
|
278
|
+
if not base.exists():
|
|
279
|
+
return snapshots
|
|
280
|
+
for path in base.rglob("data_set"):
|
|
281
|
+
try:
|
|
282
|
+
payload = load_json(path)
|
|
283
|
+
except (json.JSONDecodeError, OSError):
|
|
284
|
+
continue
|
|
285
|
+
if payload.get("flow_type") != flow_type:
|
|
286
|
+
continue
|
|
287
|
+
if normalize_text(payload.get("flow_key", "")) != normalize_text(flow_key):
|
|
288
|
+
continue
|
|
289
|
+
snapshots.append(
|
|
290
|
+
{
|
|
291
|
+
"path": str(path.relative_to(repo_root)),
|
|
292
|
+
"id": payload.get("id"),
|
|
293
|
+
"name": payload.get("name", ""),
|
|
294
|
+
"basic_table": payload.get("basic_table", ""),
|
|
295
|
+
"custom_key": normalize_text(payload.get("custom_key", "")),
|
|
296
|
+
"status": payload.get("status"),
|
|
297
|
+
}
|
|
298
|
+
)
|
|
299
|
+
return snapshots
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def summarize_basic_table_audit(
|
|
303
|
+
detail: Dict[str, Any],
|
|
304
|
+
peer_items: Optional[list[Dict[str, Any]]] = None,
|
|
305
|
+
repo_items: Optional[list[Dict[str, Any]]] = None,
|
|
306
|
+
preferred_basic_tables: Optional[list[str]] = None,
|
|
307
|
+
) -> Dict[str, Any]:
|
|
308
|
+
actual = normalize_text(detail.get("basic_table", ""))
|
|
309
|
+
preferred = [normalize_text(item) for item in (preferred_basic_tables or []) if normalize_text(item)]
|
|
310
|
+
peer_tables = sorted(
|
|
311
|
+
{
|
|
312
|
+
normalize_text(item.get("basic_table", ""))
|
|
313
|
+
for item in (peer_items or [])
|
|
314
|
+
if normalize_text(item.get("basic_table", ""))
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
repo_tables = sorted(
|
|
318
|
+
{
|
|
319
|
+
normalize_text(item.get("basic_table", ""))
|
|
320
|
+
for item in (repo_items or [])
|
|
321
|
+
if normalize_text(item.get("basic_table", ""))
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
recommended = preferred or peer_tables or repo_tables
|
|
325
|
+
reasons: list[str] = []
|
|
326
|
+
suspicious = False
|
|
327
|
+
if not actual:
|
|
328
|
+
suspicious = True
|
|
329
|
+
reasons.append("basic_table is empty")
|
|
330
|
+
if actual == "project" and "think_project" in recommended:
|
|
331
|
+
suspicious = True
|
|
332
|
+
reasons.append("project conflicts with recommended think_project")
|
|
333
|
+
if recommended and actual and actual not in recommended:
|
|
334
|
+
suspicious = True
|
|
335
|
+
reasons.append("basic_table differs from same-flow defaults")
|
|
336
|
+
return {
|
|
337
|
+
"ok": not suspicious,
|
|
338
|
+
"severity": "blocker" if suspicious else "ok",
|
|
339
|
+
"actual": actual,
|
|
340
|
+
"recommended": recommended,
|
|
341
|
+
"reasons": reasons,
|
|
342
|
+
"peerSummary": {
|
|
343
|
+
"count": len(peer_items or []),
|
|
344
|
+
"basicTables": peer_tables,
|
|
345
|
+
},
|
|
346
|
+
"repoSummary": {
|
|
347
|
+
"count": len(repo_items or []),
|
|
348
|
+
"basicTables": repo_tables,
|
|
349
|
+
},
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def summarize_publish_health(detail: Dict[str, Any], es_data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
354
|
+
status = detail.get("status")
|
|
355
|
+
batch = {
|
|
356
|
+
"current_batch_id": normalize_text(detail.get("current_batch_id", "")),
|
|
357
|
+
"current_batch_count": detail.get("current_batch_count"),
|
|
358
|
+
"current_batch_create_time": normalize_text(detail.get("current_batch_create_time", "")),
|
|
359
|
+
}
|
|
360
|
+
batch_missing = (
|
|
361
|
+
batch["current_batch_id"] == ""
|
|
362
|
+
and batch["current_batch_count"] in (None, "")
|
|
363
|
+
and batch["current_batch_create_time"] == ""
|
|
364
|
+
)
|
|
365
|
+
reasons: list[str] = []
|
|
366
|
+
suspicious = False
|
|
367
|
+
if status == 3 and batch_missing:
|
|
368
|
+
suspicious = True
|
|
369
|
+
reasons.append("status=3 while current_batch_* is empty")
|
|
370
|
+
es_summary: Dict[str, Any] = {"available": es_data is not None}
|
|
371
|
+
if isinstance(es_data, dict):
|
|
372
|
+
docs = es_data.get("docs") or es_data.get("data") or es_data.get("rows")
|
|
373
|
+
if isinstance(docs, list):
|
|
374
|
+
es_summary["docCount"] = len(docs)
|
|
375
|
+
elif isinstance(docs, dict):
|
|
376
|
+
es_summary["docCount"] = len(docs)
|
|
377
|
+
else:
|
|
378
|
+
es_summary["docCount"] = 0 if docs in (None, "") else 1
|
|
379
|
+
return {
|
|
380
|
+
"ok": not suspicious,
|
|
381
|
+
"severity": "blocker" if suspicious else "ok",
|
|
382
|
+
"status": status,
|
|
383
|
+
"batch": batch,
|
|
384
|
+
"esData": es_summary,
|
|
385
|
+
"reasons": reasons,
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def summarize_list_verification(
|
|
390
|
+
submit_payload: Dict[str, Any],
|
|
391
|
+
readback_detail: Dict[str, Any],
|
|
392
|
+
list_item: Optional[Dict[str, Any]],
|
|
393
|
+
) -> Dict[str, Any]:
|
|
394
|
+
expected_fields = [item for item in submit_payload.get("fields", []) if item]
|
|
395
|
+
checks = {
|
|
396
|
+
"found": bool(list_item),
|
|
397
|
+
"name": False,
|
|
398
|
+
"custom_key": False,
|
|
399
|
+
"status": False,
|
|
400
|
+
"field_count": False,
|
|
401
|
+
}
|
|
402
|
+
actual = {
|
|
403
|
+
"list": list_item or {},
|
|
404
|
+
"detail": {
|
|
405
|
+
"fieldCount": len((readback_detail.get("dataSetFields") or readback_detail.get("fields") or [])),
|
|
406
|
+
},
|
|
407
|
+
}
|
|
408
|
+
expected = {
|
|
409
|
+
"name": submit_payload.get("name", ""),
|
|
410
|
+
"custom_key": normalize_text(submit_payload.get("custom_key", "")),
|
|
411
|
+
"status": readback_detail.get("status"),
|
|
412
|
+
"fieldCount": len(expected_fields),
|
|
413
|
+
}
|
|
414
|
+
if list_item:
|
|
415
|
+
checks["name"] = normalize_text(list_item.get("name", "")) == expected["name"]
|
|
416
|
+
checks["custom_key"] = normalize_text(list_item.get("custom_key", "")) == expected["custom_key"]
|
|
417
|
+
checks["status"] = list_item.get("status") == expected["status"]
|
|
418
|
+
checks["field_count"] = actual["detail"]["fieldCount"] == expected["fieldCount"]
|
|
419
|
+
return {
|
|
420
|
+
"ok": all(checks.values()),
|
|
421
|
+
"checks": checks,
|
|
422
|
+
"expected": expected,
|
|
423
|
+
"actual": actual,
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def build_dataset_lint_report(
|
|
428
|
+
work_payload: Dict[str, Any],
|
|
429
|
+
*,
|
|
430
|
+
meta: Optional[Dict[str, Any]] = None,
|
|
431
|
+
submit_payload: Optional[Dict[str, Any]] = None,
|
|
432
|
+
) -> Dict[str, Any]:
|
|
433
|
+
report: Dict[str, Any] = {"ok": True, "errors": [], "warnings": [], "checks": {}}
|
|
434
|
+
normalized_meta = dict(meta or {})
|
|
435
|
+
basic_table_audit = normalized_meta.get("basicTableAudit")
|
|
436
|
+
if isinstance(basic_table_audit, dict):
|
|
437
|
+
report["checks"]["basicTableAudit"] = basic_table_audit
|
|
438
|
+
if basic_table_audit.get("severity") == "blocker":
|
|
439
|
+
report["errors"].append("basicTableAudit blocker: " + "; ".join(basic_table_audit.get("reasons") or ["unknown"]))
|
|
440
|
+
|
|
441
|
+
payload = submit_payload or build_submit_payload(work_payload)
|
|
442
|
+
script_surfaces = [
|
|
443
|
+
{"path": "scripts.postScript", "script": payload.get("post_script")},
|
|
444
|
+
{"path": "scripts.postEsMapping", "script": payload.get("post_es_mapping")},
|
|
445
|
+
{"path": "scripts.refreshProjectScript", "script": payload.get("refresh_project_script")},
|
|
446
|
+
{"path": "search.preProcessScript", "script": payload.get("pre_process_script")},
|
|
447
|
+
{"path": "search.postProcessScript", "script": payload.get("post_process_script")},
|
|
448
|
+
]
|
|
449
|
+
hard_rule_report = scan_named_script_surfaces(script_surfaces)
|
|
450
|
+
report["checks"]["scriptHardRules"] = hard_rule_report["findings"]
|
|
451
|
+
report["errors"].extend(hard_rule_report["errors"])
|
|
452
|
+
report["ok"] = not report["errors"]
|
|
453
|
+
return report
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def scan_custom_key_references(custom_key: str, repo_root: Path = REPO_ROOT) -> Dict[str, Any]:
|
|
457
|
+
needle = normalize_text(custom_key).strip()
|
|
458
|
+
if not needle:
|
|
459
|
+
return {"ok": True, "customKey": needle, "count": 0, "matches": [], "warning": False}
|
|
460
|
+
cmd = [
|
|
461
|
+
"rg",
|
|
462
|
+
"-n",
|
|
463
|
+
"-F",
|
|
464
|
+
"--glob",
|
|
465
|
+
"!think_data_set/**",
|
|
466
|
+
needle,
|
|
467
|
+
str(repo_root / "think_flow_page_template"),
|
|
468
|
+
str(repo_root / "think_configuration"),
|
|
469
|
+
str(repo_root / "think_flow"),
|
|
470
|
+
]
|
|
471
|
+
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
|
472
|
+
matches: list[Dict[str, Any]] = []
|
|
473
|
+
if result.returncode in (0, 1):
|
|
474
|
+
for line in result.stdout.splitlines():
|
|
475
|
+
path_text, line_no, snippet = (line.split(":", 2) + ["", ""])[:3]
|
|
476
|
+
path = Path(path_text)
|
|
477
|
+
try:
|
|
478
|
+
relative = str(path.relative_to(repo_root))
|
|
479
|
+
except ValueError:
|
|
480
|
+
relative = path_text
|
|
481
|
+
matches.append({"path": relative, "line": int(line_no), "snippet": snippet.strip()})
|
|
482
|
+
else:
|
|
483
|
+
raise SystemExit(f"rg failed while scanning custom_key references: {result.stderr.strip()}")
|
|
484
|
+
return {
|
|
485
|
+
"ok": True,
|
|
486
|
+
"customKey": needle,
|
|
487
|
+
"count": len(matches),
|
|
488
|
+
"matches": matches[:50],
|
|
489
|
+
"warning": bool(matches),
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def resolve_dataset_candidates(
|
|
494
|
+
list_rows: list[Dict[str, Any]],
|
|
495
|
+
*,
|
|
496
|
+
name: str = "",
|
|
497
|
+
custom_key: str = "",
|
|
498
|
+
) -> Dict[str, Any]:
|
|
499
|
+
target_name = normalize_text(name).strip()
|
|
500
|
+
target_key = normalize_text(custom_key).strip()
|
|
501
|
+
candidates: list[Dict[str, Any]] = []
|
|
502
|
+
for item in list_rows:
|
|
503
|
+
matches_name = not target_name or normalize_text(item.get("name", "")).strip() == target_name
|
|
504
|
+
matches_key = not target_key or normalize_text(item.get("custom_key", "")).strip() == target_key
|
|
505
|
+
if matches_name and matches_key:
|
|
506
|
+
candidates.append(item)
|
|
507
|
+
return {
|
|
508
|
+
"ok": len(candidates) == 1,
|
|
509
|
+
"count": len(candidates),
|
|
510
|
+
"candidates": candidates,
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def summarize_verification(submit_payload: Dict[str, Any], readback_detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
515
|
+
checks: Dict[str, Dict[str, Any]] = {}
|
|
516
|
+
ok = True
|
|
517
|
+
simple_mapping = {
|
|
518
|
+
"name": "name",
|
|
519
|
+
"basic_table": "basic_table",
|
|
520
|
+
"custom_key": "custom_key",
|
|
521
|
+
"non_block": "non_block",
|
|
522
|
+
"is_default": "is_default",
|
|
523
|
+
"post_script": "post_script",
|
|
524
|
+
"post_es_mapping": "post_es_mapping",
|
|
525
|
+
"refresh_project_script": "refresh_project_script",
|
|
526
|
+
"pre_process_script": "pre_process_script",
|
|
527
|
+
"post_process_script": "post_process_script",
|
|
528
|
+
"process_script_tag": "process_script_tag",
|
|
529
|
+
"refresh_setting": "refresh_setting",
|
|
530
|
+
}
|
|
531
|
+
for submit_key, readback_key in simple_mapping.items():
|
|
532
|
+
expected = normalize_text(submit_payload.get(submit_key, ""))
|
|
533
|
+
actual = normalize_text(readback_detail.get(readback_key, ""))
|
|
534
|
+
match = expected == actual
|
|
535
|
+
ok = ok and match
|
|
536
|
+
checks[submit_key] = {"match": match, "expected": expected, "actual": actual}
|
|
537
|
+
|
|
538
|
+
expected_fields = [item for item in submit_payload.get("fields", []) if item]
|
|
539
|
+
readback_fields = readback_detail.get("dataSetFields") or readback_detail.get("fields") or []
|
|
540
|
+
actual_summary = field_summary(readback_fields)
|
|
541
|
+
expected_summary = {
|
|
542
|
+
"count": len(expected_fields),
|
|
543
|
+
"ids": [item.get("id") for item in readback_fields if item.get("key") in set(expected_fields)],
|
|
544
|
+
"keys": expected_fields,
|
|
545
|
+
}
|
|
546
|
+
fields_match = expected_summary["keys"] == actual_summary["keys"]
|
|
547
|
+
ok = ok and fields_match
|
|
548
|
+
checks["fields"] = {
|
|
549
|
+
"match": fields_match,
|
|
550
|
+
"expected": expected_summary,
|
|
551
|
+
"actual": actual_summary,
|
|
552
|
+
}
|
|
553
|
+
return {"ok": ok, "checks": checks}
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def require_confirm_token(token: str) -> None:
|
|
557
|
+
if token != DEFAULT_CONFIRM_TOKEN:
|
|
558
|
+
raise SystemExit(f"refusing to submit: --confirm-token must equal {DEFAULT_CONFIRM_TOKEN}")
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
@dataclass
|
|
562
|
+
class ApiClient:
|
|
563
|
+
base_url: str
|
|
564
|
+
workspace: str
|
|
565
|
+
language: str
|
|
566
|
+
cookie_header: str
|
|
567
|
+
timeout: float
|
|
568
|
+
insecure: bool = False
|
|
569
|
+
|
|
570
|
+
def _build_url(self, path: str) -> str:
|
|
571
|
+
suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
|
|
572
|
+
joiner = "&" if "?" in path else "?"
|
|
573
|
+
return self.base_url.rstrip("/") + path + joiner + suffix
|
|
574
|
+
|
|
575
|
+
def request(self, method: str, path: str, body: Optional[dict] = None) -> dict:
|
|
576
|
+
headers = {
|
|
577
|
+
"content-type": "application/json",
|
|
578
|
+
"cookie": self.cookie_header,
|
|
579
|
+
"accept": "application/json, text/plain, */*",
|
|
580
|
+
}
|
|
581
|
+
data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
|
|
582
|
+
req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method)
|
|
583
|
+
context = ssl._create_unverified_context() if self.insecure else None
|
|
584
|
+
try:
|
|
585
|
+
with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
|
|
586
|
+
raw = resp.read().decode("utf-8", "replace")
|
|
587
|
+
except urllib.error.HTTPError as err:
|
|
588
|
+
raw = err.read().decode("utf-8", "replace")
|
|
589
|
+
raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
|
|
590
|
+
except urllib.error.URLError as err:
|
|
591
|
+
raise SystemExit(f"Request failed {path}: {err}") from err
|
|
592
|
+
payload = json.loads(raw)
|
|
593
|
+
if payload.get("code") != 0:
|
|
594
|
+
raise SystemExit(f"API error {path}: {raw}")
|
|
595
|
+
return payload
|
|
596
|
+
|
|
597
|
+
def get_dataset(self, dataset_id: int) -> dict:
|
|
598
|
+
return self.request("GET", f"/bpmax/data-set/{dataset_id}")
|
|
599
|
+
|
|
600
|
+
def list_datasets(
|
|
601
|
+
self,
|
|
602
|
+
flow_type: str,
|
|
603
|
+
flow_key: str = "",
|
|
604
|
+
*,
|
|
605
|
+
page: int = 1,
|
|
606
|
+
page_size: int = DEFAULT_LIST_PAGE_SIZE,
|
|
607
|
+
include_relations: bool = True,
|
|
608
|
+
include_progress: bool = True,
|
|
609
|
+
is_del: int = 0,
|
|
610
|
+
) -> dict:
|
|
611
|
+
payload: Dict[str, Any] = {
|
|
612
|
+
"is_del": is_del,
|
|
613
|
+
"flow_type": flow_type,
|
|
614
|
+
"flow_key": flow_key,
|
|
615
|
+
"includeRelations": include_relations,
|
|
616
|
+
"includeProgress": include_progress,
|
|
617
|
+
}
|
|
618
|
+
return self.request("POST", f"/bpmax/data-set/list?page_size={page_size}&page={page}", payload)
|
|
619
|
+
|
|
620
|
+
def create_dataset(self, payload: dict) -> dict:
|
|
621
|
+
return self.request("POST", "/bpmax/data-set", payload)
|
|
622
|
+
|
|
623
|
+
def update_dataset_relation_fields(self, dataset_id: int, payload: dict) -> dict:
|
|
624
|
+
return self.request("POST", f"/bpmax/data-set/relationFields/{dataset_id}", payload)
|
|
625
|
+
|
|
626
|
+
def get_flow_fields(self, flow_type: str, flow_key: str = "") -> dict:
|
|
627
|
+
query = f"/bpmax/data-set-field/getBatchByFlow?flow_type={urllib.parse.quote(flow_type)}"
|
|
628
|
+
if flow_key not in ("", None):
|
|
629
|
+
query += f"&flow_key={urllib.parse.quote(flow_key)}"
|
|
630
|
+
return self.request("GET", query)
|
|
631
|
+
|
|
632
|
+
def get_dataset_es_data(self, dataset_id: int) -> dict:
|
|
633
|
+
return self.request("GET", f"/bpmax/data-set/esData/{dataset_id}")
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
def build_client(args: Any) -> ApiClient:
|
|
637
|
+
workspace = getattr(args, "workspace", None)
|
|
638
|
+
cookie_header = getattr(args, "cookie_header", None)
|
|
639
|
+
if not workspace:
|
|
640
|
+
raise SystemExit("--workspace is required")
|
|
641
|
+
if not cookie_header:
|
|
642
|
+
raise SystemExit("--cookie-header is required")
|
|
643
|
+
return ApiClient(
|
|
644
|
+
base_url=resolve_base_url(getattr(args, "base_url", None)),
|
|
645
|
+
workspace=workspace,
|
|
646
|
+
language=getattr(args, "language", None) or DEFAULT_LANGUAGE,
|
|
647
|
+
cookie_header=cookie_header,
|
|
648
|
+
timeout=float(getattr(args, "timeout", 30)),
|
|
649
|
+
insecure=bool(getattr(args, "insecure", False)),
|
|
650
|
+
)
|