bpmax-cli 0.1.44 → 0.2.1-beta.2
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 +52 -5
- package/dist/bin.js +12304 -1315
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/scripts/install-skills.mjs +98 -0
- package/skills/bpmax-ai-taskbook/SKILL.md +227 -0
- package/skills/bpmax-ai-taskbook/agents/openai.yaml +3 -0
- package/skills/bpmax-ai-taskbook/references/taskbook-template.md +68 -0
- 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-approval-matrix/SKILL.md +90 -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 +5 -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 +606 -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 +217 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +4 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +63 -0
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +551 -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/ai-test-suite.md +333 -0
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +41 -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 +24 -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 +109 -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 +83 -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 +121 -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 +1095 -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 +174 -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 +168 -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 +106 -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 +96 -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 +1113 -0
- package/skills/bpmax-form-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +203 -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 +91 -0
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +1762 -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 +1292 -0
- package/skills/bpmax-list-template-editor/SKILL.md +478 -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 +165 -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 +108 -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 +147 -0
- package/skills/bpmax-list-template-editor/references/special-formats.md +411 -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-memory-protocol/SKILL.md +72 -0
- package/skills/bpmax-nav-config-editor/SKILL.md +350 -0
- package/skills/bpmax-nav-config-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-nav-config-editor/references/api-workflow.md +70 -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 +51 -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-plugin-config/SKILL.md +42 -0
- package/skills/bpmax-project/SKILL.md +17 -3
- package/skills/bpmax-project-detail-template-editor/SKILL.md +355 -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 +120 -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/bpmax-user-mock-operator/SKILL.md +106 -0
- package/skills/bpmax-user-mock-operator/agents/openai.yaml +4 -0
- package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +37 -0
- package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +136 -0
- package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +138 -0
- package/skills/bpmax-workspace-editor/SKILL.md +78 -0
- package/skills/bpmax-workspace-editor/agents/openai.yaml +4 -0
- 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,964 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import copy
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import sys
|
|
10
|
+
import ssl
|
|
11
|
+
import urllib.error
|
|
12
|
+
import urllib.parse
|
|
13
|
+
import urllib.request
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
from difflib import unified_diff
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Dict, Iterable, Optional
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
SHARED_SKILL_ROOT = Path(__file__).resolve().parents[2] / "bpmax-builder-shared"
|
|
22
|
+
if str(SHARED_SKILL_ROOT) not in sys.path:
|
|
23
|
+
sys.path.insert(0, str(SHARED_SKILL_ROOT))
|
|
24
|
+
from base_url import DEFAULT_BASE_URL, resolve_base_url
|
|
25
|
+
|
|
26
|
+
DEFAULT_LANGUAGE = "zhCN"
|
|
27
|
+
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
28
|
+
TMP_ROOT = REPO_ROOT / ".codex" / "tmp" / "console-template-editor"
|
|
29
|
+
TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
|
|
30
|
+
SUBMIT_BASIC_KEYS = ("name", "desc", "data_set_id", "search_temp_id", "type")
|
|
31
|
+
EDIT_DETAIL_DROP_KEYS = (
|
|
32
|
+
"create_time",
|
|
33
|
+
"created_at",
|
|
34
|
+
"update_time",
|
|
35
|
+
"updated_at",
|
|
36
|
+
"deleted_at",
|
|
37
|
+
"is_del",
|
|
38
|
+
"organization_id",
|
|
39
|
+
"workspace",
|
|
40
|
+
)
|
|
41
|
+
CHART_REQUIRED_CONFIG_KEYS = ("title", "height", "dataSource", "config")
|
|
42
|
+
TABLE_REQUIRED_CONFIG_KEYS = ("title", "height", "page_size", "exportCount", "dataSource", "config")
|
|
43
|
+
OVERVIEW_REQUIRED_CONFIG_KEYS = ("title", "height", "dataSource", "config")
|
|
44
|
+
SUPPORTED_DATA_SOURCE_DRIVERS = ("es", "mysql", "customer", "custom_bpmax", "service")
|
|
45
|
+
OVERVIEW_SUPPORTED_ICONS = ("total", "finished", "delay_warning", "delay")
|
|
46
|
+
LINT_FORBIDDEN_PLACEHOLDERS = ("${page_size}", "${offset}")
|
|
47
|
+
|
|
48
|
+
from template_script_hard_rules import scan_named_script_surfaces
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def utc_now_iso() -> str:
|
|
52
|
+
return datetime.now(timezone.utc).isoformat()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ensure_tmp_dirs() -> None:
|
|
56
|
+
for part in TMP_SUBDIRS:
|
|
57
|
+
(TMP_ROOT / part).mkdir(parents=True, exist_ok=True)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def dump_json(path: Path, payload: Any) -> None:
|
|
61
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def load_json(path: Path) -> Any:
|
|
66
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def file_sha256(path: Path) -> str:
|
|
70
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def stable_json_lines(payload: Any) -> list[str]:
|
|
74
|
+
return (json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n").splitlines(keepends=True)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def write_diff(path: Path, before: Any, after: Any, before_label: str, after_label: str) -> None:
|
|
78
|
+
diff = unified_diff(
|
|
79
|
+
stable_json_lines(before),
|
|
80
|
+
stable_json_lines(after),
|
|
81
|
+
fromfile=before_label,
|
|
82
|
+
tofile=after_label,
|
|
83
|
+
)
|
|
84
|
+
text = "".join(diff)
|
|
85
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
86
|
+
path.write_text(text or "# no diff\n", encoding="utf-8")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def paths_for(stem: str) -> Dict[str, Path]:
|
|
90
|
+
ensure_tmp_dirs()
|
|
91
|
+
return {
|
|
92
|
+
"raw": TMP_ROOT / "raw" / f"{stem}.json",
|
|
93
|
+
"work": TMP_ROOT / "work" / f"{stem}.json",
|
|
94
|
+
"meta": TMP_ROOT / "meta" / f"{stem}.json",
|
|
95
|
+
"submit": TMP_ROOT / "submit" / f"{stem}.json",
|
|
96
|
+
"work_diff": TMP_ROOT / "diffs" / f"{stem}.work.diff.txt",
|
|
97
|
+
"submit_diff": TMP_ROOT / "diffs" / f"{stem}.submit.diff.txt",
|
|
98
|
+
"response": TMP_ROOT / "result" / f"{stem}.response.json",
|
|
99
|
+
"readback": TMP_ROOT / "result" / f"{stem}.readback.json",
|
|
100
|
+
"verify": TMP_ROOT / "result" / f"{stem}.verify.json",
|
|
101
|
+
"drift": TMP_ROOT / "result" / f"{stem}.drift.json",
|
|
102
|
+
"lint": TMP_ROOT / "result" / f"{stem}.lint.json",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def load_meta(path: Path) -> Dict[str, Any]:
|
|
107
|
+
if not path.exists():
|
|
108
|
+
return {}
|
|
109
|
+
payload = load_json(path)
|
|
110
|
+
if not isinstance(payload, dict):
|
|
111
|
+
raise SystemExit(f"invalid meta file: {path}")
|
|
112
|
+
return payload
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def save_meta(path: Path, payload: Dict[str, Any]) -> None:
|
|
116
|
+
dump_json(path, payload)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def extract_api_data(payload: Any) -> Any:
|
|
120
|
+
if isinstance(payload, dict) and "data" in payload:
|
|
121
|
+
return payload.get("data")
|
|
122
|
+
return payload
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def extract_template_id(value: Any) -> int | None:
|
|
126
|
+
if isinstance(value, bool):
|
|
127
|
+
return None
|
|
128
|
+
if isinstance(value, int):
|
|
129
|
+
return value
|
|
130
|
+
if isinstance(value, str) and value.isdigit():
|
|
131
|
+
return int(value)
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def type_name(value: Any) -> str:
|
|
136
|
+
if isinstance(value, dict):
|
|
137
|
+
return "dict"
|
|
138
|
+
if isinstance(value, list):
|
|
139
|
+
return "list"
|
|
140
|
+
return type(value).__name__
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def create_stem(workspace: str, sample_template_id: Any) -> str:
|
|
144
|
+
return f"create-{workspace}-{sample_template_id}"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def normalize_detail(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
148
|
+
if not isinstance(detail, dict):
|
|
149
|
+
raise SystemExit("console template detail must be a JSON object")
|
|
150
|
+
payload = copy.deepcopy(detail)
|
|
151
|
+
raw_content = payload.get("content")
|
|
152
|
+
if isinstance(raw_content, str):
|
|
153
|
+
text = raw_content.strip()
|
|
154
|
+
if text:
|
|
155
|
+
try:
|
|
156
|
+
payload["content"] = json.loads(text)
|
|
157
|
+
except json.JSONDecodeError as exc:
|
|
158
|
+
raise SystemExit(f"template content is not valid JSON: {exc}") from exc
|
|
159
|
+
else:
|
|
160
|
+
payload["content"] = {"column": 12, "layout": []}
|
|
161
|
+
elif raw_content is None:
|
|
162
|
+
payload["content"] = {"column": 12, "layout": []}
|
|
163
|
+
elif not isinstance(raw_content, dict):
|
|
164
|
+
raise SystemExit("template content must be a JSON string or object")
|
|
165
|
+
|
|
166
|
+
content = payload["content"]
|
|
167
|
+
if not isinstance(content.get("layout"), list):
|
|
168
|
+
raise SystemExit("template content.layout must be an array")
|
|
169
|
+
if content.get("column") in (None, ""):
|
|
170
|
+
content["column"] = 12
|
|
171
|
+
return payload
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def summarize_preserve(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
175
|
+
content = detail.get("content") if isinstance(detail.get("content"), dict) else {}
|
|
176
|
+
layout = content.get("layout") if isinstance(content.get("layout"), list) else []
|
|
177
|
+
return {
|
|
178
|
+
"topLevelKeys": sorted(detail.keys()),
|
|
179
|
+
"contentKeys": sorted(content.keys()) if isinstance(content, dict) else [],
|
|
180
|
+
"column": content.get("column") if isinstance(content, dict) else None,
|
|
181
|
+
"layoutCount": len(layout),
|
|
182
|
+
"layoutKeys": [canonical_layout_key(item.get("i")) for item in layout if isinstance(item, dict) and item.get("i") not in (None, "")],
|
|
183
|
+
"moduleNames": [item.get("name") for item in layout if isinstance(item, dict) and item.get("name")],
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def canonical_layout_key(value: Any) -> str:
|
|
188
|
+
if isinstance(value, bool):
|
|
189
|
+
raise SystemExit("layout key cannot be boolean")
|
|
190
|
+
if isinstance(value, int):
|
|
191
|
+
return str(value)
|
|
192
|
+
if isinstance(value, float):
|
|
193
|
+
if value.is_integer():
|
|
194
|
+
return str(int(value))
|
|
195
|
+
return format(value, "g")
|
|
196
|
+
if isinstance(value, str):
|
|
197
|
+
text = value.strip()
|
|
198
|
+
if text:
|
|
199
|
+
return text
|
|
200
|
+
raise SystemExit("layout key must be a non-empty string or number")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _copy_layout_items(value: Any) -> list[Dict[str, Any]]:
|
|
204
|
+
if value in (None, ""):
|
|
205
|
+
return []
|
|
206
|
+
if not isinstance(value, list):
|
|
207
|
+
raise SystemExit("layout items must be an array")
|
|
208
|
+
items: list[Dict[str, Any]] = []
|
|
209
|
+
for idx, item in enumerate(value):
|
|
210
|
+
if not isinstance(item, dict):
|
|
211
|
+
raise SystemExit(f"layout item at index {idx} is not an object")
|
|
212
|
+
items.append(copy.deepcopy(item))
|
|
213
|
+
return items
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _extract_basic(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
217
|
+
basic: Dict[str, Any] = {}
|
|
218
|
+
for key in SUBMIT_BASIC_KEYS:
|
|
219
|
+
if key == "type":
|
|
220
|
+
basic[key] = detail.get(key, 4)
|
|
221
|
+
else:
|
|
222
|
+
basic[key] = detail.get(key)
|
|
223
|
+
return basic
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def detail_to_work_payload(
|
|
227
|
+
detail: Dict[str, Any],
|
|
228
|
+
*,
|
|
229
|
+
workspace: str,
|
|
230
|
+
mode: str = "edit",
|
|
231
|
+
sample_template_id: int | None = None,
|
|
232
|
+
) -> Dict[str, Any]:
|
|
233
|
+
normalized = normalize_detail(detail)
|
|
234
|
+
content = copy.deepcopy(normalized["content"])
|
|
235
|
+
layout = _copy_layout_items(content.get("layout"))
|
|
236
|
+
content["layout"] = layout
|
|
237
|
+
template_id = extract_template_id(normalized.get("id"))
|
|
238
|
+
payload = {
|
|
239
|
+
"id": template_id if mode == "edit" else None,
|
|
240
|
+
"mode": mode,
|
|
241
|
+
"workspace": workspace,
|
|
242
|
+
"sampleTemplateId": sample_template_id,
|
|
243
|
+
"basic": _extract_basic(normalized),
|
|
244
|
+
"content": content,
|
|
245
|
+
"modules": copy.deepcopy(layout),
|
|
246
|
+
"keepLayoutItems": [],
|
|
247
|
+
"removedLayoutItems": [],
|
|
248
|
+
"preserve": summarize_preserve(normalized),
|
|
249
|
+
"notes": "",
|
|
250
|
+
}
|
|
251
|
+
if mode == "create":
|
|
252
|
+
payload["basic"]["type"] = 4
|
|
253
|
+
return payload
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def build_create_work_payload(detail: Dict[str, Any], *, workspace: str, sample_template_id: int) -> Dict[str, Any]:
|
|
257
|
+
work = detail_to_work_payload(detail, workspace=workspace, mode="create", sample_template_id=sample_template_id)
|
|
258
|
+
work["id"] = None
|
|
259
|
+
return work
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _removed_layout_keys(removed_items: Any) -> set[str]:
|
|
263
|
+
keys: set[str] = set()
|
|
264
|
+
if removed_items in (None, ""):
|
|
265
|
+
return keys
|
|
266
|
+
if not isinstance(removed_items, list):
|
|
267
|
+
raise SystemExit("removedLayoutItems must be an array")
|
|
268
|
+
for idx, item in enumerate(removed_items):
|
|
269
|
+
if isinstance(item, (str, int, float)) and not isinstance(item, bool):
|
|
270
|
+
keys.add(canonical_layout_key(item))
|
|
271
|
+
continue
|
|
272
|
+
if isinstance(item, dict):
|
|
273
|
+
keys.add(canonical_layout_key(item.get("i")))
|
|
274
|
+
continue
|
|
275
|
+
raise SystemExit(f"removedLayoutItems[{idx}] must be a layout key or object with i")
|
|
276
|
+
return keys
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _validate_layout_items(items: Iterable[Dict[str, Any]], label: str, errors: list[str], seen: set[str]) -> None:
|
|
280
|
+
for idx, item in enumerate(items):
|
|
281
|
+
if not isinstance(item, dict):
|
|
282
|
+
errors.append(f"{label}[{idx}] must be an object")
|
|
283
|
+
continue
|
|
284
|
+
layout_key = item.get("i")
|
|
285
|
+
if layout_key in (None, ""):
|
|
286
|
+
errors.append(f"{label}[{idx}] missing layout key i")
|
|
287
|
+
continue
|
|
288
|
+
try:
|
|
289
|
+
normalized_key = canonical_layout_key(layout_key)
|
|
290
|
+
except SystemExit as exc:
|
|
291
|
+
errors.append(f"{label}[{idx}].i invalid: {exc}")
|
|
292
|
+
continue
|
|
293
|
+
if normalized_key in seen:
|
|
294
|
+
errors.append(f"duplicate layout key detected: {normalized_key}")
|
|
295
|
+
continue
|
|
296
|
+
seen.add(normalized_key)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def lint_work_payload(work: Dict[str, Any], *, raw_payload: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
300
|
+
report: Dict[str, Any] = {"ok": True, "errors": [], "warnings": [], "checks": {}}
|
|
301
|
+
basic = work.get("basic")
|
|
302
|
+
content = work.get("content")
|
|
303
|
+
modules = work.get("modules")
|
|
304
|
+
keep_layout = work.get("keepLayoutItems")
|
|
305
|
+
removed_layout = work.get("removedLayoutItems")
|
|
306
|
+
mode = work.get("mode")
|
|
307
|
+
|
|
308
|
+
if mode not in ("edit", "create"):
|
|
309
|
+
report["errors"].append("mode must be edit or create")
|
|
310
|
+
if not isinstance(basic, dict):
|
|
311
|
+
report["errors"].append("basic must be an object")
|
|
312
|
+
if not isinstance(content, dict):
|
|
313
|
+
report["errors"].append("content must be an object")
|
|
314
|
+
if not isinstance(modules, list):
|
|
315
|
+
report["errors"].append("modules must be an array")
|
|
316
|
+
modules = []
|
|
317
|
+
if not isinstance(keep_layout, list):
|
|
318
|
+
report["errors"].append("keepLayoutItems must be an array")
|
|
319
|
+
keep_layout = []
|
|
320
|
+
if not isinstance(removed_layout, list):
|
|
321
|
+
report["errors"].append("removedLayoutItems must be an array")
|
|
322
|
+
removed_layout = []
|
|
323
|
+
|
|
324
|
+
if isinstance(basic, dict):
|
|
325
|
+
if not isinstance(basic.get("name"), str) or not basic.get("name", "").strip():
|
|
326
|
+
report["errors"].append("basic.name must be a non-empty string")
|
|
327
|
+
if basic.get("type") != 4:
|
|
328
|
+
report["errors"].append("basic.type must be 4 for console templates")
|
|
329
|
+
|
|
330
|
+
if isinstance(content, dict):
|
|
331
|
+
if not isinstance(content.get("layout"), list):
|
|
332
|
+
report["errors"].append("content.layout must be an array")
|
|
333
|
+
if content.get("column") in (None, ""):
|
|
334
|
+
report["warnings"].append("content.column is empty and will fall back to 12")
|
|
335
|
+
|
|
336
|
+
seen_layout_keys: set[str] = set()
|
|
337
|
+
_validate_layout_items(modules, "modules", report["errors"], seen_layout_keys)
|
|
338
|
+
_validate_layout_items(keep_layout, "keepLayoutItems", report["errors"], seen_layout_keys)
|
|
339
|
+
|
|
340
|
+
try:
|
|
341
|
+
removed_keys = _removed_layout_keys(removed_layout)
|
|
342
|
+
except SystemExit as exc:
|
|
343
|
+
report["errors"].append(str(exc))
|
|
344
|
+
removed_keys = set()
|
|
345
|
+
report["checks"]["removedLayoutKeys"] = sorted(removed_keys)
|
|
346
|
+
report["checks"]["moduleCount"] = len(modules)
|
|
347
|
+
report["checks"]["keepLayoutCount"] = len(keep_layout)
|
|
348
|
+
|
|
349
|
+
if raw_payload and isinstance(raw_payload, dict):
|
|
350
|
+
raw_content = raw_payload.get("content") if isinstance(raw_payload.get("content"), dict) else {}
|
|
351
|
+
raw_layout = raw_content.get("layout") if isinstance(raw_content.get("layout"), list) else []
|
|
352
|
+
if raw_layout and not modules and not keep_layout:
|
|
353
|
+
report["errors"].append("work layout is empty while raw payload contains layout items")
|
|
354
|
+
raw_layout_keys = set()
|
|
355
|
+
for item in raw_layout:
|
|
356
|
+
if isinstance(item, dict) and item.get("i") not in (None, ""):
|
|
357
|
+
try:
|
|
358
|
+
raw_layout_keys.add(canonical_layout_key(item.get("i")))
|
|
359
|
+
except SystemExit:
|
|
360
|
+
pass
|
|
361
|
+
unresolved_removed = sorted(key for key in removed_keys if key not in raw_layout_keys and key not in seen_layout_keys)
|
|
362
|
+
if unresolved_removed:
|
|
363
|
+
report["errors"].append(
|
|
364
|
+
"removedLayoutItems contains unknown layout keys: " + ", ".join(unresolved_removed)
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
report["ok"] = not report["errors"]
|
|
368
|
+
return report
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _compose_layout(work: Dict[str, Any]) -> list[Dict[str, Any]]:
|
|
372
|
+
modules = _copy_layout_items(work.get("modules"))
|
|
373
|
+
keep_layout = _copy_layout_items(work.get("keepLayoutItems"))
|
|
374
|
+
removed_keys = _removed_layout_keys(work.get("removedLayoutItems"))
|
|
375
|
+
final_layout: list[Dict[str, Any]] = []
|
|
376
|
+
seen: set[str] = set()
|
|
377
|
+
for item in modules + keep_layout:
|
|
378
|
+
key = canonical_layout_key(item.get("i"))
|
|
379
|
+
if key in removed_keys:
|
|
380
|
+
continue
|
|
381
|
+
if key in seen:
|
|
382
|
+
raise SystemExit(f"duplicate layout key in final layout: {key}")
|
|
383
|
+
seen.add(key)
|
|
384
|
+
final_layout.append(copy.deepcopy(item))
|
|
385
|
+
return final_layout
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def _has_ctx_config_fallback(script: str) -> bool:
|
|
389
|
+
compact = script.replace(" ", "").replace("\n", "")
|
|
390
|
+
patterns = (
|
|
391
|
+
"ctx.config||{}",
|
|
392
|
+
"ctx.config??{}",
|
|
393
|
+
"constcfg=ctx.config||{}",
|
|
394
|
+
"constcfg=ctx.config??{}",
|
|
395
|
+
"{config={}}=ctx",
|
|
396
|
+
"{config={}}=ctx||{}",
|
|
397
|
+
)
|
|
398
|
+
return any(pattern in compact for pattern in patterns)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _check_data_source_driver(script: Any, module_name: str, errors: list[str]) -> None:
|
|
402
|
+
if not isinstance(script, str):
|
|
403
|
+
return
|
|
404
|
+
if "raw-es-search" in script:
|
|
405
|
+
errors.append(
|
|
406
|
+
f"{module_name} dataSource uses unsupported driver raw-es-search; current console frontend supports "
|
|
407
|
+
"driver: 'es' for ES data sources"
|
|
408
|
+
)
|
|
409
|
+
for match in re.finditer(r"['\"]?driver['\"]?\s*:\s*['\"]([^'\"]+)['\"]", script):
|
|
410
|
+
driver = match.group(1)
|
|
411
|
+
if driver and driver not in SUPPORTED_DATA_SOURCE_DRIVERS:
|
|
412
|
+
errors.append(f"{module_name} dataSource uses unsupported driver: {driver}")
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _check_project_overview_script(script: Any, module_name: str, errors: list[str], warnings: list[str]) -> None:
|
|
416
|
+
if not isinstance(script, str):
|
|
417
|
+
return
|
|
418
|
+
compact = script.replace(" ", "").replace("\n", "")
|
|
419
|
+
if "return[" not in compact and "return [" not in script:
|
|
420
|
+
errors.append(f"{module_name} config script must return an array of KPI card objects")
|
|
421
|
+
for key in ("title", "amount", "icon"):
|
|
422
|
+
if key not in script:
|
|
423
|
+
errors.append(f"{module_name} config script should return card objects with {key}")
|
|
424
|
+
for icon in ("icon:", '"icon"'):
|
|
425
|
+
if icon in script:
|
|
426
|
+
break
|
|
427
|
+
else:
|
|
428
|
+
errors.append(f"{module_name} config script must set icon for each KPI card")
|
|
429
|
+
for unsupported_hint in ("echarts", "xAxis", "yAxis", "series"):
|
|
430
|
+
if unsupported_hint in script:
|
|
431
|
+
warnings.append(
|
|
432
|
+
f"{module_name} config script contains {unsupported_hint}; KPI overview should return card data, not ECharts options"
|
|
433
|
+
)
|
|
434
|
+
for token in ("icon: '", 'icon: "', '"icon": "'):
|
|
435
|
+
start = 0
|
|
436
|
+
while True:
|
|
437
|
+
idx = script.find(token, start)
|
|
438
|
+
if idx < 0:
|
|
439
|
+
break
|
|
440
|
+
quote = token[-1]
|
|
441
|
+
value_start = idx + len(token)
|
|
442
|
+
value_end = script.find(quote, value_start)
|
|
443
|
+
if value_end < 0:
|
|
444
|
+
break
|
|
445
|
+
icon = script[value_start:value_end]
|
|
446
|
+
if icon and icon not in OVERVIEW_SUPPORTED_ICONS:
|
|
447
|
+
errors.append(f"{module_name} uses unsupported ProjectOverviewSmart icon: {icon}")
|
|
448
|
+
start = value_end + 1
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _check_module_config(module: Dict[str, Any], errors: list[str], warnings: list[str], checks: Dict[str, Any]) -> None:
|
|
452
|
+
module_name = module.get("name") or "<unnamed>"
|
|
453
|
+
config = module.get("config")
|
|
454
|
+
if not isinstance(config, dict):
|
|
455
|
+
errors.append(f"{module_name} config must be an object")
|
|
456
|
+
return
|
|
457
|
+
|
|
458
|
+
module_id = canonical_layout_key(module.get("i"))
|
|
459
|
+
module_check = {"id": module_id, "name": module_name, "configKeys": sorted(config.keys())}
|
|
460
|
+
checks.setdefault("modules", []).append(module_check)
|
|
461
|
+
|
|
462
|
+
if module_name == "图表":
|
|
463
|
+
missing = [key for key in CHART_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
464
|
+
if missing:
|
|
465
|
+
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
466
|
+
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
467
|
+
chart_script = config.get("config")
|
|
468
|
+
if isinstance(chart_script, str) and "ctx.config" in chart_script and not _has_ctx_config_fallback(chart_script):
|
|
469
|
+
errors.append(f"{module_name} config script references ctx.config without fallback")
|
|
470
|
+
elif module_name == "一般表格":
|
|
471
|
+
missing = [key for key in TABLE_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
472
|
+
if missing:
|
|
473
|
+
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
474
|
+
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
475
|
+
table_script = config.get("config")
|
|
476
|
+
if isinstance(table_script, str):
|
|
477
|
+
compact_script = table_script.replace(" ", "").replace("\n", "")
|
|
478
|
+
if "cfg.page_size" in compact_script and "ctx.pageInfo" not in table_script and "allRows" not in table_script:
|
|
479
|
+
warnings.append(
|
|
480
|
+
f"{module_name} config script uses cfg.page_size without ctx.pageInfo/allRows export branch; "
|
|
481
|
+
"TableSmart export may only include the first page"
|
|
482
|
+
)
|
|
483
|
+
elif module_name == "数据概况":
|
|
484
|
+
missing = [key for key in OVERVIEW_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
485
|
+
if missing:
|
|
486
|
+
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
487
|
+
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
488
|
+
_check_project_overview_script(config.get("config"), module_name, errors, warnings)
|
|
489
|
+
|
|
490
|
+
serialized = json.dumps(config, ensure_ascii=False)
|
|
491
|
+
for placeholder in LINT_FORBIDDEN_PLACEHOLDERS:
|
|
492
|
+
if placeholder in serialized:
|
|
493
|
+
errors.append(f"{module_name} contains forbidden frontend placeholder: {placeholder}")
|
|
494
|
+
if "custom_bpmax" in serialized:
|
|
495
|
+
module_check["usesCustomBpmax"] = True
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def lint_template_semantics(
|
|
499
|
+
work_payload: Dict[str, Any],
|
|
500
|
+
*,
|
|
501
|
+
raw_payload: Optional[Dict[str, Any]] = None,
|
|
502
|
+
submit_payload: Optional[Dict[str, Any]] = None,
|
|
503
|
+
) -> Dict[str, Any]:
|
|
504
|
+
report: Dict[str, Any] = {"ok": True, "errors": [], "warnings": [], "checks": {"modules": []}}
|
|
505
|
+
lint_report = lint_work_payload(work_payload, raw_payload=raw_payload)
|
|
506
|
+
report["errors"].extend(lint_report["errors"])
|
|
507
|
+
report["warnings"].extend(lint_report["warnings"])
|
|
508
|
+
report["checks"].update(lint_report["checks"])
|
|
509
|
+
if report["errors"]:
|
|
510
|
+
report["ok"] = False
|
|
511
|
+
return report
|
|
512
|
+
|
|
513
|
+
try:
|
|
514
|
+
final_layout = _compose_layout(work_payload)
|
|
515
|
+
except SystemExit as exc:
|
|
516
|
+
report["errors"].append(str(exc))
|
|
517
|
+
report["ok"] = False
|
|
518
|
+
return report
|
|
519
|
+
|
|
520
|
+
report["checks"]["finalLayoutCount"] = len(final_layout)
|
|
521
|
+
report["checks"]["finalLayoutKeys"] = [canonical_layout_key(item.get("i")) for item in final_layout]
|
|
522
|
+
for module in final_layout:
|
|
523
|
+
_check_module_config(module, report["errors"], report["warnings"], report["checks"])
|
|
524
|
+
|
|
525
|
+
hard_rule_report = scan_named_script_surfaces(
|
|
526
|
+
[
|
|
527
|
+
{"path": "content.layout", "value": final_layout},
|
|
528
|
+
{"path": "content", "value": work_payload.get("content")},
|
|
529
|
+
]
|
|
530
|
+
)
|
|
531
|
+
report["checks"]["scriptHardRules"] = hard_rule_report["findings"]
|
|
532
|
+
report["errors"].extend(hard_rule_report["errors"])
|
|
533
|
+
|
|
534
|
+
if submit_payload:
|
|
535
|
+
if submit_payload.get("type") != 4:
|
|
536
|
+
report["errors"].append("submit.type must be 4")
|
|
537
|
+
if not isinstance(submit_payload.get("content"), str):
|
|
538
|
+
report["errors"].append("submit.content must be a JSON string")
|
|
539
|
+
flow_type = submit_payload.get("flow_type")
|
|
540
|
+
flow_key = submit_payload.get("flow_key")
|
|
541
|
+
report["checks"]["consoleListVisibility"] = {
|
|
542
|
+
"flow_type": flow_type,
|
|
543
|
+
"flow_key": flow_key,
|
|
544
|
+
"visibleInNoFlowConsoleList": flow_type is None and flow_key is None,
|
|
545
|
+
}
|
|
546
|
+
if flow_type == "" or flow_key == "":
|
|
547
|
+
report["errors"].append(
|
|
548
|
+
"submit flow_type/flow_key must be null for no-flow console templates; empty strings are hidden from /console_template list"
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
report["ok"] = not report["errors"]
|
|
552
|
+
return report
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def build_submit_payload(work: Dict[str, Any]) -> Dict[str, Any]:
|
|
556
|
+
lint = lint_work_payload(work)
|
|
557
|
+
if lint["errors"]:
|
|
558
|
+
raise SystemExit("invalid work payload: " + "; ".join(lint["errors"]))
|
|
559
|
+
|
|
560
|
+
basic = copy.deepcopy(work["basic"])
|
|
561
|
+
content = copy.deepcopy(work["content"])
|
|
562
|
+
content["layout"] = _compose_layout(work)
|
|
563
|
+
if content.get("column") in (None, ""):
|
|
564
|
+
content["column"] = 12
|
|
565
|
+
|
|
566
|
+
submit: Dict[str, Any] = {}
|
|
567
|
+
for key in SUBMIT_BASIC_KEYS:
|
|
568
|
+
submit[key] = basic.get(key)
|
|
569
|
+
if work.get("mode") == "create":
|
|
570
|
+
submit["status"] = 0
|
|
571
|
+
submit["content"] = json.dumps(content, ensure_ascii=False)
|
|
572
|
+
return submit
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def _normalize_for_compare(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
576
|
+
normalized = normalize_detail(payload)
|
|
577
|
+
basic = _extract_basic(normalized)
|
|
578
|
+
content = copy.deepcopy(normalized["content"])
|
|
579
|
+
return {
|
|
580
|
+
"id": extract_template_id(normalized.get("id")),
|
|
581
|
+
"basic": basic,
|
|
582
|
+
"content": content,
|
|
583
|
+
"layoutKeys": [canonical_layout_key(item.get("i")) for item in content.get("layout", []) if isinstance(item, dict) and item.get("i") not in (None, "")],
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def summarize_verification(submit_payload: Dict[str, Any], readback_detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
588
|
+
expected_content = normalize_detail({"content": submit_payload.get("content")})["content"]
|
|
589
|
+
expected = {
|
|
590
|
+
"basic": {key: submit_payload.get(key) for key in SUBMIT_BASIC_KEYS},
|
|
591
|
+
"content": expected_content,
|
|
592
|
+
}
|
|
593
|
+
actual = _normalize_for_compare(readback_detail)
|
|
594
|
+
checks = {
|
|
595
|
+
"name": {
|
|
596
|
+
"match": expected["basic"]["name"] == actual["basic"].get("name"),
|
|
597
|
+
"expected": expected["basic"]["name"],
|
|
598
|
+
"actual": actual["basic"].get("name"),
|
|
599
|
+
},
|
|
600
|
+
"desc": {
|
|
601
|
+
"match": expected["basic"]["desc"] == actual["basic"].get("desc"),
|
|
602
|
+
"expected": expected["basic"]["desc"],
|
|
603
|
+
"actual": actual["basic"].get("desc"),
|
|
604
|
+
},
|
|
605
|
+
"data_set_id": {
|
|
606
|
+
"match": expected["basic"]["data_set_id"] == actual["basic"].get("data_set_id"),
|
|
607
|
+
"expected": expected["basic"]["data_set_id"],
|
|
608
|
+
"actual": actual["basic"].get("data_set_id"),
|
|
609
|
+
},
|
|
610
|
+
"search_temp_id": {
|
|
611
|
+
"match": expected["basic"]["search_temp_id"] == actual["basic"].get("search_temp_id"),
|
|
612
|
+
"expected": expected["basic"]["search_temp_id"],
|
|
613
|
+
"actual": actual["basic"].get("search_temp_id"),
|
|
614
|
+
},
|
|
615
|
+
"type": {
|
|
616
|
+
"match": expected["basic"]["type"] == actual["basic"].get("type"),
|
|
617
|
+
"expected": expected["basic"]["type"],
|
|
618
|
+
"actual": actual["basic"].get("type"),
|
|
619
|
+
},
|
|
620
|
+
"content": {
|
|
621
|
+
"match": expected["content"] == actual["content"],
|
|
622
|
+
"expected": expected["content"],
|
|
623
|
+
"actual": actual["content"],
|
|
624
|
+
},
|
|
625
|
+
}
|
|
626
|
+
return {"ok": all(item["match"] for item in checks.values()), "checks": checks}
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
def build_drift_report(submit_payload: Dict[str, Any], readback_detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
630
|
+
verification = summarize_verification(submit_payload, readback_detail)
|
|
631
|
+
changes = {key: value for key, value in verification["checks"].items() if not value["match"]}
|
|
632
|
+
return {"ok": not changes, "submitToReadback": {"ok": not changes, "changes": changes}}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def ensure_meta_shape(meta: Dict[str, Any], stem: str) -> Dict[str, Any]:
|
|
636
|
+
payload = dict(meta)
|
|
637
|
+
payload.setdefault("stem", stem)
|
|
638
|
+
payload.setdefault("status", "exported")
|
|
639
|
+
payload.setdefault("notes", "")
|
|
640
|
+
payload.setdefault("createdTemplateId", None)
|
|
641
|
+
payload.setdefault("lintOk", None)
|
|
642
|
+
return payload
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
def write_export_meta(
|
|
646
|
+
path: Path,
|
|
647
|
+
*,
|
|
648
|
+
stem: str,
|
|
649
|
+
mode: str,
|
|
650
|
+
workspace: str,
|
|
651
|
+
template_id: int | None,
|
|
652
|
+
sample_template_id: int | None,
|
|
653
|
+
request_url: str,
|
|
654
|
+
raw_path: Path,
|
|
655
|
+
work_path: Path,
|
|
656
|
+
) -> Dict[str, Any]:
|
|
657
|
+
payload = ensure_meta_shape(load_meta(path), stem)
|
|
658
|
+
payload.update(
|
|
659
|
+
{
|
|
660
|
+
"mode": mode,
|
|
661
|
+
"workspace": workspace,
|
|
662
|
+
"templateId": template_id,
|
|
663
|
+
"sampleTemplateId": sample_template_id,
|
|
664
|
+
"requestUrl": request_url,
|
|
665
|
+
"rawSha256": file_sha256(raw_path),
|
|
666
|
+
"workSha256": file_sha256(work_path),
|
|
667
|
+
"submitSha256": None,
|
|
668
|
+
"lintSha256": None,
|
|
669
|
+
"lintWorkSha256": None,
|
|
670
|
+
"lintSubmitSha256": None,
|
|
671
|
+
"lintCheckedAt": None,
|
|
672
|
+
"lintOk": None,
|
|
673
|
+
"exportedAt": utc_now_iso(),
|
|
674
|
+
"submitBuiltAt": None,
|
|
675
|
+
"workConfirmedAt": None,
|
|
676
|
+
"workConfirmedBy": None,
|
|
677
|
+
"submitConfirmedAt": None,
|
|
678
|
+
"submitConfirmedBy": None,
|
|
679
|
+
"submittedAt": None,
|
|
680
|
+
"status": "exported",
|
|
681
|
+
}
|
|
682
|
+
)
|
|
683
|
+
save_meta(path, payload)
|
|
684
|
+
return payload
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def update_confirmation_state(
|
|
688
|
+
meta_path: Path,
|
|
689
|
+
*,
|
|
690
|
+
stem: str,
|
|
691
|
+
actor: str,
|
|
692
|
+
stage: str,
|
|
693
|
+
work_path: Path,
|
|
694
|
+
submit_path: Optional[Path] = None,
|
|
695
|
+
) -> Dict[str, Any]:
|
|
696
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
697
|
+
payload["workSha256"] = file_sha256(work_path)
|
|
698
|
+
now = utc_now_iso()
|
|
699
|
+
if stage == "work":
|
|
700
|
+
payload["workConfirmedAt"] = now
|
|
701
|
+
payload["workConfirmedBy"] = actor
|
|
702
|
+
payload["submitConfirmedAt"] = None
|
|
703
|
+
payload["submitConfirmedBy"] = None
|
|
704
|
+
payload["submitSha256"] = None
|
|
705
|
+
payload["submitBuiltAt"] = None
|
|
706
|
+
payload["lintSha256"] = None
|
|
707
|
+
payload["lintWorkSha256"] = None
|
|
708
|
+
payload["lintSubmitSha256"] = None
|
|
709
|
+
payload["lintCheckedAt"] = None
|
|
710
|
+
payload["lintOk"] = None
|
|
711
|
+
payload["submittedAt"] = None
|
|
712
|
+
payload["status"] = "work_confirmed"
|
|
713
|
+
elif stage == "submit":
|
|
714
|
+
if submit_path is None or not submit_path.exists():
|
|
715
|
+
raise SystemExit("submit confirmation requires existing submit file")
|
|
716
|
+
if payload.get("status") != "lint_passed":
|
|
717
|
+
raise SystemExit("submit confirmation requires lint_passed status")
|
|
718
|
+
if payload.get("workSha256") != file_sha256(work_path):
|
|
719
|
+
raise SystemExit("work file changed after confirmation; reconfirm work before submit")
|
|
720
|
+
current_submit_sha = file_sha256(submit_path)
|
|
721
|
+
if payload.get("submitSha256") != current_submit_sha:
|
|
722
|
+
raise SystemExit("submit file changed after lint; rerun lint before submit confirmation")
|
|
723
|
+
if payload.get("lintSubmitSha256") != current_submit_sha or payload.get("lintWorkSha256") != file_sha256(work_path):
|
|
724
|
+
raise SystemExit("lint result is stale; rerun lint before submit confirmation")
|
|
725
|
+
payload["submitConfirmedAt"] = now
|
|
726
|
+
payload["submitConfirmedBy"] = actor
|
|
727
|
+
payload["status"] = "submit_confirmed"
|
|
728
|
+
else:
|
|
729
|
+
raise SystemExit(f"unsupported confirmation stage: {stage}")
|
|
730
|
+
save_meta(meta_path, payload)
|
|
731
|
+
return payload
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def ensure_build_allowed(meta_path: Path, work_path: Path) -> Dict[str, Any]:
|
|
735
|
+
if not meta_path.exists():
|
|
736
|
+
raise SystemExit("missing meta confirmation file")
|
|
737
|
+
raw_meta = load_meta(meta_path)
|
|
738
|
+
meta = ensure_meta_shape(raw_meta, raw_meta.get("stem", "unknown"))
|
|
739
|
+
if meta.get("status") != "work_confirmed":
|
|
740
|
+
raise SystemExit("build blocked: work file is not confirmed")
|
|
741
|
+
current_work_sha = file_sha256(work_path)
|
|
742
|
+
if meta.get("workSha256") != current_work_sha:
|
|
743
|
+
raise SystemExit("build blocked: work file changed after confirmation")
|
|
744
|
+
return meta
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def update_build_meta(meta_path: Path, *, stem: str, work_path: Path, submit_path: Path) -> Dict[str, Any]:
|
|
748
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
749
|
+
previous_work_sha = payload.get("workSha256")
|
|
750
|
+
current_work_sha = file_sha256(work_path)
|
|
751
|
+
if payload.get("workConfirmedAt") and previous_work_sha != current_work_sha:
|
|
752
|
+
payload["workConfirmedAt"] = None
|
|
753
|
+
payload["workConfirmedBy"] = None
|
|
754
|
+
payload["workSha256"] = current_work_sha
|
|
755
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
756
|
+
payload["submitBuiltAt"] = utc_now_iso()
|
|
757
|
+
payload["submitConfirmedAt"] = None
|
|
758
|
+
payload["submitConfirmedBy"] = None
|
|
759
|
+
payload["lintSha256"] = None
|
|
760
|
+
payload["lintWorkSha256"] = None
|
|
761
|
+
payload["lintSubmitSha256"] = None
|
|
762
|
+
payload["lintCheckedAt"] = None
|
|
763
|
+
payload["lintOk"] = None
|
|
764
|
+
payload["submittedAt"] = None
|
|
765
|
+
payload["status"] = "submit_built"
|
|
766
|
+
save_meta(meta_path, payload)
|
|
767
|
+
return payload
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def ensure_lint_allowed(meta_path: Path, work_path: Path, submit_path: Path) -> Dict[str, Any]:
|
|
771
|
+
if not meta_path.exists():
|
|
772
|
+
raise SystemExit("missing meta confirmation file")
|
|
773
|
+
raw_meta = load_meta(meta_path)
|
|
774
|
+
meta = ensure_meta_shape(raw_meta, raw_meta.get("stem", "unknown"))
|
|
775
|
+
if meta.get("status") != "submit_built":
|
|
776
|
+
raise SystemExit("lint blocked: submit payload is not built")
|
|
777
|
+
if meta.get("workSha256") != file_sha256(work_path):
|
|
778
|
+
raise SystemExit("lint blocked: work file changed after build")
|
|
779
|
+
if meta.get("submitSha256") != file_sha256(submit_path):
|
|
780
|
+
raise SystemExit("lint blocked: submit file changed after build")
|
|
781
|
+
return meta
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def update_lint_meta(
|
|
785
|
+
meta_path: Path,
|
|
786
|
+
*,
|
|
787
|
+
stem: str,
|
|
788
|
+
work_path: Path,
|
|
789
|
+
submit_path: Path,
|
|
790
|
+
lint_path: Path,
|
|
791
|
+
lint_report: Dict[str, Any],
|
|
792
|
+
) -> Dict[str, Any]:
|
|
793
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
794
|
+
payload["workSha256"] = file_sha256(work_path)
|
|
795
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
796
|
+
payload["lintSha256"] = file_sha256(lint_path)
|
|
797
|
+
payload["lintWorkSha256"] = payload["workSha256"]
|
|
798
|
+
payload["lintSubmitSha256"] = payload["submitSha256"]
|
|
799
|
+
payload["lintCheckedAt"] = utc_now_iso()
|
|
800
|
+
payload["lintOk"] = bool(lint_report.get("ok"))
|
|
801
|
+
payload["submitConfirmedAt"] = None
|
|
802
|
+
payload["submitConfirmedBy"] = None
|
|
803
|
+
payload["status"] = "lint_passed" if lint_report.get("ok") else "lint_failed"
|
|
804
|
+
save_meta(meta_path, payload)
|
|
805
|
+
return payload
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def ensure_submission_allowed(meta_path: Path, work_path: Path, submit_path: Path, raw_path: Path, lint_path: Path) -> Dict[str, Any]:
|
|
809
|
+
if not meta_path.exists():
|
|
810
|
+
raise SystemExit("missing meta confirmation file")
|
|
811
|
+
raw_meta = load_meta(meta_path)
|
|
812
|
+
meta = ensure_meta_shape(raw_meta, raw_meta.get("stem", "unknown"))
|
|
813
|
+
required = (
|
|
814
|
+
"mode",
|
|
815
|
+
"workspace",
|
|
816
|
+
"workSha256",
|
|
817
|
+
"submitSha256",
|
|
818
|
+
"workConfirmedAt",
|
|
819
|
+
"submitConfirmedAt",
|
|
820
|
+
"status",
|
|
821
|
+
"lintCheckedAt",
|
|
822
|
+
)
|
|
823
|
+
missing = [key for key in required if not meta.get(key)]
|
|
824
|
+
if missing:
|
|
825
|
+
raise SystemExit(f"meta confirmation incomplete: missing {', '.join(missing)}")
|
|
826
|
+
if meta.get("status") != "submit_confirmed":
|
|
827
|
+
raise SystemExit("submission blocked: current status is not submit_confirmed")
|
|
828
|
+
current_work_sha = file_sha256(work_path)
|
|
829
|
+
current_submit_sha = file_sha256(submit_path)
|
|
830
|
+
if meta.get("workSha256") != current_work_sha:
|
|
831
|
+
raise SystemExit("submission blocked: work file changed after confirmation")
|
|
832
|
+
if meta.get("submitSha256") != current_submit_sha:
|
|
833
|
+
raise SystemExit("submission blocked: submit file changed after confirmation")
|
|
834
|
+
if meta.get("lintOk") is not True:
|
|
835
|
+
raise SystemExit("submission blocked: lint did not pass")
|
|
836
|
+
if meta.get("lintWorkSha256") != current_work_sha or meta.get("lintSubmitSha256") != current_submit_sha:
|
|
837
|
+
raise SystemExit("submission blocked: lint result is stale")
|
|
838
|
+
if not lint_path.exists():
|
|
839
|
+
raise SystemExit("submission blocked: missing lint result file")
|
|
840
|
+
submit_built_at = meta.get("submitBuiltAt")
|
|
841
|
+
lint_checked_at = meta.get("lintCheckedAt")
|
|
842
|
+
if submit_built_at and lint_checked_at and lint_checked_at < submit_built_at:
|
|
843
|
+
raise SystemExit("submission blocked: lint result predates submit build")
|
|
844
|
+
work_payload = load_json(work_path)
|
|
845
|
+
raw_payload = load_json(raw_path)
|
|
846
|
+
submit_payload = load_json(submit_path)
|
|
847
|
+
lint = lint_template_semantics(work_payload, raw_payload=raw_payload, submit_payload=submit_payload)
|
|
848
|
+
if lint["errors"]:
|
|
849
|
+
raise SystemExit("submission blocked by lint: " + "; ".join(lint["errors"]))
|
|
850
|
+
return meta
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
def app_base_url(base_url: str) -> str:
|
|
854
|
+
text = base_url.rstrip("/")
|
|
855
|
+
if text.endswith("/api"):
|
|
856
|
+
return text[:-4]
|
|
857
|
+
return text
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
def build_acceptance_urls(*, base_url: str, workspace: str, template_id: int) -> Dict[str, str]:
|
|
861
|
+
app_url = app_base_url(base_url)
|
|
862
|
+
return {
|
|
863
|
+
"editUrl": f"{app_url}/w:{workspace}/console_template/{template_id}",
|
|
864
|
+
"previewUrl": f"{app_url}/w:{workspace}/console?template_id={template_id}",
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
def record_submission_meta(
|
|
869
|
+
meta_path: Path,
|
|
870
|
+
*,
|
|
871
|
+
stem: str,
|
|
872
|
+
template_id: int,
|
|
873
|
+
acceptance_urls: Dict[str, str],
|
|
874
|
+
) -> Dict[str, Any]:
|
|
875
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
876
|
+
payload["createdTemplateId"] = template_id if payload.get("mode") == "create" else payload.get("createdTemplateId")
|
|
877
|
+
payload["templateId"] = template_id
|
|
878
|
+
payload["submittedAt"] = utc_now_iso()
|
|
879
|
+
payload["status"] = "submitted"
|
|
880
|
+
payload["editUrl"] = acceptance_urls.get("editUrl")
|
|
881
|
+
payload["previewUrl"] = acceptance_urls.get("previewUrl")
|
|
882
|
+
save_meta(meta_path, payload)
|
|
883
|
+
return payload
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
@dataclass
|
|
887
|
+
class ApiClient:
|
|
888
|
+
base_url: str
|
|
889
|
+
workspace: str
|
|
890
|
+
language: str
|
|
891
|
+
cookie_header: str
|
|
892
|
+
timeout: float
|
|
893
|
+
insecure: bool = False
|
|
894
|
+
|
|
895
|
+
def _build_url(self, path: str) -> str:
|
|
896
|
+
suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
|
|
897
|
+
joiner = "&" if "?" in path else "?"
|
|
898
|
+
return self.base_url.rstrip("/") + path + joiner + suffix
|
|
899
|
+
|
|
900
|
+
def request(self, method: str, path: str, body: Optional[dict] = None) -> dict:
|
|
901
|
+
headers = {
|
|
902
|
+
"content-type": "application/json",
|
|
903
|
+
"cookie": self.cookie_header,
|
|
904
|
+
"accept": "application/json, text/plain, */*",
|
|
905
|
+
}
|
|
906
|
+
data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
|
|
907
|
+
req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method)
|
|
908
|
+
context = ssl._create_unverified_context() if self.insecure else None
|
|
909
|
+
try:
|
|
910
|
+
with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
|
|
911
|
+
raw = resp.read().decode("utf-8", "replace")
|
|
912
|
+
except urllib.error.HTTPError as err:
|
|
913
|
+
raw = err.read().decode("utf-8", "replace")
|
|
914
|
+
raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
|
|
915
|
+
except urllib.error.URLError as err:
|
|
916
|
+
raise SystemExit(f"Request failed {path}: {err}") from err
|
|
917
|
+
payload = json.loads(raw)
|
|
918
|
+
if isinstance(payload, dict) and payload.get("code") not in (None, 0):
|
|
919
|
+
raise SystemExit(f"API error {path}: {payload}")
|
|
920
|
+
return payload
|
|
921
|
+
|
|
922
|
+
def get_template(self, template_id: int) -> dict:
|
|
923
|
+
return self.request("GET", f"/flow_page_template/{template_id}?skip_i18n=true")
|
|
924
|
+
|
|
925
|
+
def update_template(self, template_id: int, body: Dict[str, Any]) -> dict:
|
|
926
|
+
return self.request("PUT", f"/flow_page_template/{template_id}", body)
|
|
927
|
+
|
|
928
|
+
def create_template(self, body: Dict[str, Any]) -> dict:
|
|
929
|
+
return self.request("POST", "/flow_page_template", body)
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
def resolve_cookie_header(value: Optional[str]) -> str:
|
|
933
|
+
cookie = value or os.environ.get("BPMAX_COOKIE_HEADER", "")
|
|
934
|
+
if not cookie:
|
|
935
|
+
raise SystemExit("missing cookie header: pass --cookie-header or set BPMAX_COOKIE_HEADER")
|
|
936
|
+
return cookie
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
def resolve_workspace(value: Optional[str]) -> str:
|
|
940
|
+
workspace = value or os.environ.get("BPMAX_WORKSPACE", "")
|
|
941
|
+
if not workspace:
|
|
942
|
+
raise SystemExit("missing workspace: pass --workspace or set BPMAX_WORKSPACE")
|
|
943
|
+
return workspace
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
def build_client(args: Any) -> ApiClient:
|
|
947
|
+
return ApiClient(
|
|
948
|
+
base_url=resolve_base_url(getattr(args, "base_url", None)),
|
|
949
|
+
workspace=resolve_workspace(getattr(args, "workspace", None)),
|
|
950
|
+
language=getattr(args, "language", DEFAULT_LANGUAGE),
|
|
951
|
+
cookie_header=resolve_cookie_header(getattr(args, "cookie_header", None)),
|
|
952
|
+
timeout=float(getattr(args, "timeout", 30)),
|
|
953
|
+
insecure=bool(getattr(args, "insecure", False)),
|
|
954
|
+
)
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
def sanitize_create_detail(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
958
|
+
payload = copy.deepcopy(normalize_detail(detail))
|
|
959
|
+
payload["id"] = None
|
|
960
|
+
for key in EDIT_DETAIL_DROP_KEYS:
|
|
961
|
+
payload.pop(key, None)
|
|
962
|
+
payload["type"] = 4
|
|
963
|
+
payload["status"] = 0
|
|
964
|
+
return payload
|