bpmax-cli 0.1.43 → 0.1.44-beta.0
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 +3372 -453
- 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,341 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Dict, List, Optional
|
|
6
|
+
|
|
7
|
+
import e2e_state
|
|
8
|
+
from bpmax_session import ApiClient, BpmaxApiError, build_client, field_values_by_key, load_json, read_json_input, save_json
|
|
9
|
+
from flow_test_profile import FlowTestProfile, resolve_profile
|
|
10
|
+
from flow_filter_fields import build_report as build_filter_report
|
|
11
|
+
from flow_form_runtime import build_create_skeleton, build_step_skeleton
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
ROOT = Path(__file__).resolve().parents[4]
|
|
15
|
+
TMP_DIR = ROOT / ".codex" / "tmp" / "api_flow_runner"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def merge_sample_into_create_payload(payload: Dict[str, Any], sample: Dict[str, Any]) -> Dict[str, Any]:
|
|
19
|
+
result = json.loads(json.dumps(payload, ensure_ascii=False))
|
|
20
|
+
fields = result.get("projectForm", {}).get("value", [])
|
|
21
|
+
for item in fields:
|
|
22
|
+
key = item.get("key")
|
|
23
|
+
field = item.get("field")
|
|
24
|
+
title = item.get("title")
|
|
25
|
+
for candidate in (key, field, title):
|
|
26
|
+
if candidate and candidate in sample:
|
|
27
|
+
item["value"] = {"value": sample[candidate], "type": item.get("field_type")}
|
|
28
|
+
break
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def artifact_prefix(profile: FlowTestProfile) -> str:
|
|
33
|
+
return profile.flow_type or profile.name
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def save_artifact(profile: FlowTestProfile, name: str, data: Any) -> str:
|
|
37
|
+
path = TMP_DIR / f"{name}.json"
|
|
38
|
+
save_json(path, data)
|
|
39
|
+
return str(path)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def active_step_from_detail(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
43
|
+
data = detail.get("data", detail)
|
|
44
|
+
for item in data.get("steps", []) or data.get("flow_step_list", []) or []:
|
|
45
|
+
if str(item.get("status")) == "2":
|
|
46
|
+
return {
|
|
47
|
+
"step_id": item.get("id") or item.get("step_id"),
|
|
48
|
+
"flow_step_id": item.get("flow_step_id"),
|
|
49
|
+
"name": item.get("name"),
|
|
50
|
+
}
|
|
51
|
+
current_flow_step_id = data.get("current_flow_step_id")
|
|
52
|
+
if current_flow_step_id:
|
|
53
|
+
for item in data.get("steps", []) or data.get("flow_step_list", []) or []:
|
|
54
|
+
if str(item.get("flow_step_id")) == str(current_flow_step_id):
|
|
55
|
+
return {
|
|
56
|
+
"step_id": item.get("id") or item.get("step_id"),
|
|
57
|
+
"flow_step_id": item.get("flow_step_id"),
|
|
58
|
+
"name": item.get("name"),
|
|
59
|
+
}
|
|
60
|
+
for item in data.get("step_owner_list", []) or []:
|
|
61
|
+
if str(item.get("status")) in {"1", "2"} and item.get("step_id"):
|
|
62
|
+
return item
|
|
63
|
+
return {
|
|
64
|
+
"step_id": data.get("current_step_id"),
|
|
65
|
+
"flow_step_id": data.get("current_flow_step_id"),
|
|
66
|
+
"name": data.get("current_flow_step_name"),
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def append_state_artifacts(state_id: Optional[str], *, artifacts=None, endpoint_calls=None, browser_only_steps=None, runtime_bindings=None) -> None:
|
|
71
|
+
if not state_id:
|
|
72
|
+
return
|
|
73
|
+
if artifacts:
|
|
74
|
+
e2e_state.record_artifacts(state_id, artifacts)
|
|
75
|
+
if endpoint_calls:
|
|
76
|
+
e2e_state.record_endpoint_calls(state_id, endpoint_calls)
|
|
77
|
+
if browser_only_steps:
|
|
78
|
+
e2e_state.record_browser_only_steps(state_id, browser_only_steps)
|
|
79
|
+
if runtime_bindings:
|
|
80
|
+
e2e_state.record_runtime_bindings(state_id, runtime_bindings)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def record_state_scenario(state_id: Optional[str], scenario: str, status: str, note: str = "", sample: str = "") -> None:
|
|
84
|
+
if not state_id:
|
|
85
|
+
return
|
|
86
|
+
args = type(
|
|
87
|
+
"StateRecordArgs",
|
|
88
|
+
(),
|
|
89
|
+
{
|
|
90
|
+
"id": state_id,
|
|
91
|
+
"scenario": scenario,
|
|
92
|
+
"title": scenario,
|
|
93
|
+
"status": status,
|
|
94
|
+
"sample": sample,
|
|
95
|
+
"note": note,
|
|
96
|
+
},
|
|
97
|
+
)
|
|
98
|
+
e2e_state.cmd_record(args)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def scenario_note(result: Dict[str, Any]) -> str:
|
|
102
|
+
parts = []
|
|
103
|
+
if result.get("project_id"):
|
|
104
|
+
parts.append(f"project_id={result['project_id']}")
|
|
105
|
+
if result.get("step_id"):
|
|
106
|
+
parts.append(f"step_id={result['step_id']}")
|
|
107
|
+
if result.get("current_step"):
|
|
108
|
+
parts.append(f"current_step={result['current_step']}")
|
|
109
|
+
if result.get("count") is not None:
|
|
110
|
+
parts.append(f"count={result['count']}")
|
|
111
|
+
return ", ".join(parts)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def cmd_list(args: argparse.Namespace, client: ApiClient, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
115
|
+
query = read_json_input(args.query) or {}
|
|
116
|
+
payload = client.post_project_list(
|
|
117
|
+
{
|
|
118
|
+
"flow_type": profile.flow_type,
|
|
119
|
+
"data_set_id": args.data_set_id,
|
|
120
|
+
"query": query,
|
|
121
|
+
},
|
|
122
|
+
page_size=args.page_size,
|
|
123
|
+
)
|
|
124
|
+
rows = payload.get("data", {}).get("data", [])
|
|
125
|
+
result = {"scenario": "list", "count": len(rows), "rows": rows}
|
|
126
|
+
artifact = save_artifact(profile, f"{artifact_prefix(profile)}_list", result)
|
|
127
|
+
append_state_artifacts(args.state_id, artifacts=[{"kind": "list_result", "path": artifact}], endpoint_calls=client.endpoint_calls)
|
|
128
|
+
return result
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def cmd_detail(args: argparse.Namespace, client: ApiClient, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
132
|
+
detail = client.get_project(args.project_id, steps=True)
|
|
133
|
+
data = detail.get("data", detail)
|
|
134
|
+
current = active_step_from_detail(detail)
|
|
135
|
+
result = {
|
|
136
|
+
"scenario": "detail",
|
|
137
|
+
"project_id": data.get("id"),
|
|
138
|
+
"name": data.get("name"),
|
|
139
|
+
"current_step": current.get("name") or data.get("current_flow_step_name"),
|
|
140
|
+
"current_flow_step_id": current.get("flow_step_id") or data.get("current_flow_step_id"),
|
|
141
|
+
"field_values": field_values_by_key((data.get("metaForm") or {}).get("value", [])),
|
|
142
|
+
"detail": detail,
|
|
143
|
+
}
|
|
144
|
+
artifact = save_artifact(profile, f"{artifact_prefix(profile)}_detail_{args.project_id}", result)
|
|
145
|
+
append_state_artifacts(
|
|
146
|
+
args.state_id,
|
|
147
|
+
artifacts=[{"kind": "project_detail", "path": artifact, "project_id": args.project_id}],
|
|
148
|
+
endpoint_calls=client.endpoint_calls,
|
|
149
|
+
runtime_bindings={"last_detail_project_id": args.project_id},
|
|
150
|
+
)
|
|
151
|
+
return result
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def cmd_create(args: argparse.Namespace, client: ApiClient, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
155
|
+
payload = read_json_input(args.payload_file) if args.payload_file else build_create_skeleton(profile=profile)
|
|
156
|
+
sample = read_json_input(args.sample_file) if args.sample_file else None
|
|
157
|
+
if isinstance(sample, dict):
|
|
158
|
+
payload = merge_sample_into_create_payload(payload, sample)
|
|
159
|
+
created = client.create_project(payload)
|
|
160
|
+
project_id = created.get("data", {}).get("id") or created.get("id")
|
|
161
|
+
detail = client.get_project(project_id, steps=True) if project_id else {}
|
|
162
|
+
data = detail.get("data", detail) if detail else {}
|
|
163
|
+
current = active_step_from_detail(detail) if detail else {}
|
|
164
|
+
result = {
|
|
165
|
+
"scenario": "create",
|
|
166
|
+
"project_id": project_id,
|
|
167
|
+
"current_step": current.get("name") or data.get("current_flow_step_name"),
|
|
168
|
+
"current_flow_step_id": current.get("flow_step_id") or data.get("current_flow_step_id"),
|
|
169
|
+
"field_values": field_values_by_key((data.get("metaForm") or {}).get("value", [])),
|
|
170
|
+
"payload": payload,
|
|
171
|
+
}
|
|
172
|
+
artifact = save_artifact(profile, f"{artifact_prefix(profile)}_create_{project_id or 'unknown'}", result)
|
|
173
|
+
append_state_artifacts(
|
|
174
|
+
args.state_id,
|
|
175
|
+
artifacts=[{"kind": "create_result", "path": artifact, "project_id": project_id}],
|
|
176
|
+
endpoint_calls=client.endpoint_calls,
|
|
177
|
+
runtime_bindings={"last_created_project_id": project_id},
|
|
178
|
+
)
|
|
179
|
+
return result
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _perform_step_action(args: argparse.Namespace, client: ApiClient, action: str, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
183
|
+
detail = client.get_project(args.project_id, steps=True)
|
|
184
|
+
step_payload_wrapper = read_json_input(args.payload_file) if args.payload_file else build_step_skeleton(detail, args.step_id, action, profile)
|
|
185
|
+
payload = step_payload_wrapper.get("payload", step_payload_wrapper)
|
|
186
|
+
step_id = args.step_id or step_payload_wrapper.get("step_id") or payload.get("id")
|
|
187
|
+
if not step_id:
|
|
188
|
+
raise SystemExit("unable to resolve step_id; pass --step-id or --payload-file")
|
|
189
|
+
response = client.put_step_action(step_id, action, payload)
|
|
190
|
+
readback = client.get_project(args.project_id, steps=True)
|
|
191
|
+
data = readback.get("data", readback)
|
|
192
|
+
current = active_step_from_detail(readback)
|
|
193
|
+
result = {
|
|
194
|
+
"scenario": action,
|
|
195
|
+
"project_id": args.project_id,
|
|
196
|
+
"step_id": step_id,
|
|
197
|
+
"response": response,
|
|
198
|
+
"current_step": current.get("name") or data.get("current_flow_step_name"),
|
|
199
|
+
"current_flow_step_id": current.get("flow_step_id") or data.get("current_flow_step_id"),
|
|
200
|
+
}
|
|
201
|
+
artifact = save_artifact(profile, f"{artifact_prefix(profile)}_{action}_{args.project_id}_{step_id}", result)
|
|
202
|
+
append_state_artifacts(
|
|
203
|
+
args.state_id,
|
|
204
|
+
artifacts=[{"kind": f"step_{action}", "path": artifact, "project_id": args.project_id, "step_id": step_id}],
|
|
205
|
+
endpoint_calls=client.endpoint_calls,
|
|
206
|
+
)
|
|
207
|
+
return result
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def cmd_filter(args: argparse.Namespace, client: ApiClient, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
211
|
+
runtime_payload = client.post_project_list(
|
|
212
|
+
{
|
|
213
|
+
"flow_type": profile.flow_type,
|
|
214
|
+
"data_set_id": args.data_set_id,
|
|
215
|
+
"query": read_json_input(args.query) or {},
|
|
216
|
+
},
|
|
217
|
+
page_size=min(args.page_size, 20),
|
|
218
|
+
)
|
|
219
|
+
report = build_filter_report(runtime_payload, profile)
|
|
220
|
+
artifact = save_artifact(profile, f"{artifact_prefix(profile)}_filter_fields", report)
|
|
221
|
+
append_state_artifacts(args.state_id, artifacts=[{"kind": "filter_fields", "path": artifact}], endpoint_calls=client.endpoint_calls)
|
|
222
|
+
return report
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def cmd_full(args: argparse.Namespace, client: ApiClient, profile: FlowTestProfile) -> Dict[str, Any]:
|
|
226
|
+
summary: Dict[str, Any] = {"scenario": "full", "steps": []}
|
|
227
|
+
create_result = cmd_create(args, client, profile)
|
|
228
|
+
project_id = create_result.get("project_id")
|
|
229
|
+
summary["steps"].append(create_result)
|
|
230
|
+
args.project_id = project_id
|
|
231
|
+
summary["steps"].append(cmd_detail(args, client, profile))
|
|
232
|
+
for _ in range(args.max_approvals):
|
|
233
|
+
try:
|
|
234
|
+
step_result = _perform_step_action(args, client, "approve", profile)
|
|
235
|
+
except BpmaxApiError as err:
|
|
236
|
+
summary["steps"].append({"scenario": "approve", "error": str(err)})
|
|
237
|
+
break
|
|
238
|
+
summary["steps"].append(step_result)
|
|
239
|
+
if step_result.get("current_step") in set(profile.terminal_step_names):
|
|
240
|
+
break
|
|
241
|
+
summary["filter"] = cmd_filter(args, client, profile)
|
|
242
|
+
summary["project_id"] = project_id
|
|
243
|
+
summary["terminal_reached"] = any(
|
|
244
|
+
item.get("current_step") in set(profile.terminal_step_names)
|
|
245
|
+
for item in summary["steps"]
|
|
246
|
+
if isinstance(item, dict)
|
|
247
|
+
)
|
|
248
|
+
return summary
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
252
|
+
p = argparse.ArgumentParser(description="Run API-first flow e2e scenarios.")
|
|
253
|
+
p.add_argument("--profile", default="negative_sale")
|
|
254
|
+
p.add_argument("--profile-file")
|
|
255
|
+
p.add_argument("--cookie-header")
|
|
256
|
+
p.add_argument("--header-file")
|
|
257
|
+
p.add_argument("--workspace")
|
|
258
|
+
p.add_argument("--flow-type")
|
|
259
|
+
p.add_argument("--data-set-uuid")
|
|
260
|
+
p.add_argument("--list-template-uuid")
|
|
261
|
+
p.add_argument("--filter-template-uuid")
|
|
262
|
+
p.add_argument("--form-template-uuid")
|
|
263
|
+
p.add_argument("--form-template-name")
|
|
264
|
+
p.add_argument("--data-set-id", type=int, default=0)
|
|
265
|
+
p.add_argument("--base-url")
|
|
266
|
+
p.add_argument("--language", default="zhCN")
|
|
267
|
+
p.add_argument("--timeout", default=30)
|
|
268
|
+
p.add_argument("--insecure", action="store_true")
|
|
269
|
+
p.add_argument("--state-id")
|
|
270
|
+
p.add_argument("--output")
|
|
271
|
+
p.add_argument("--project-id")
|
|
272
|
+
p.add_argument("--step-id")
|
|
273
|
+
p.add_argument("--payload-file")
|
|
274
|
+
p.add_argument("--sample-file")
|
|
275
|
+
p.add_argument("--query")
|
|
276
|
+
p.add_argument("--page-size", type=int, default=20)
|
|
277
|
+
p.add_argument("--max-approvals", type=int, default=8)
|
|
278
|
+
|
|
279
|
+
sub = p.add_subparsers(dest="scenario", required=True)
|
|
280
|
+
for name in ("list", "create", "detail", "approve", "reject", "filter", "full"):
|
|
281
|
+
sub.add_parser(name)
|
|
282
|
+
return p
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def main() -> None:
|
|
286
|
+
args = build_parser().parse_args()
|
|
287
|
+
client = build_client(args)
|
|
288
|
+
profile = resolve_profile(
|
|
289
|
+
args.profile,
|
|
290
|
+
profile_file=args.profile_file,
|
|
291
|
+
workspace=args.workspace,
|
|
292
|
+
flow_type=args.flow_type,
|
|
293
|
+
data_set_uuid=args.data_set_uuid,
|
|
294
|
+
list_template_uuid=args.list_template_uuid,
|
|
295
|
+
filter_template_uuid=args.filter_template_uuid,
|
|
296
|
+
form_template_uuid=args.form_template_uuid,
|
|
297
|
+
form_template_name=args.form_template_name,
|
|
298
|
+
)
|
|
299
|
+
append_state_artifacts(args.state_id, browser_only_steps=profile.browser_only_steps)
|
|
300
|
+
try:
|
|
301
|
+
if args.scenario == "list":
|
|
302
|
+
result = cmd_list(args, client, profile)
|
|
303
|
+
elif args.scenario == "create":
|
|
304
|
+
result = cmd_create(args, client, profile)
|
|
305
|
+
elif args.scenario == "detail":
|
|
306
|
+
if not args.project_id:
|
|
307
|
+
raise SystemExit("detail requires --project-id")
|
|
308
|
+
result = cmd_detail(args, client, profile)
|
|
309
|
+
elif args.scenario == "approve":
|
|
310
|
+
if not args.project_id:
|
|
311
|
+
raise SystemExit("approve requires --project-id")
|
|
312
|
+
result = _perform_step_action(args, client, "approve", profile)
|
|
313
|
+
elif args.scenario == "reject":
|
|
314
|
+
if not args.project_id:
|
|
315
|
+
raise SystemExit("reject requires --project-id")
|
|
316
|
+
result = _perform_step_action(args, client, "refuse", profile)
|
|
317
|
+
elif args.scenario == "filter":
|
|
318
|
+
result = cmd_filter(args, client, profile)
|
|
319
|
+
else:
|
|
320
|
+
result = cmd_full(args, client, profile)
|
|
321
|
+
except BpmaxApiError as err:
|
|
322
|
+
append_state_artifacts(args.state_id, endpoint_calls=client.endpoint_calls)
|
|
323
|
+
record_state_scenario(args.state_id, args.scenario.upper(), "fail", note=str(err))
|
|
324
|
+
raise SystemExit(str(err)) from err
|
|
325
|
+
except SystemExit as err:
|
|
326
|
+
if args.state_id and getattr(err, "code", 0) not in (0, None):
|
|
327
|
+
record_state_scenario(args.state_id, args.scenario.upper(), "fail", note=str(err))
|
|
328
|
+
raise
|
|
329
|
+
status = "pass"
|
|
330
|
+
note = scenario_note(result)
|
|
331
|
+
if args.scenario == "full" and not result.get("terminal_reached"):
|
|
332
|
+
status = "fail"
|
|
333
|
+
note = (note + ", " if note else "") + "terminal step not reached"
|
|
334
|
+
record_state_scenario(args.state_id, args.scenario.upper(), status, note=note, sample=str(result.get("project_id") or ""))
|
|
335
|
+
if args.output:
|
|
336
|
+
save_json(Path(args.output), result)
|
|
337
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
if __name__ == "__main__":
|
|
341
|
+
main()
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from dataclasses import dataclass, field, replace
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
ROOT = Path(__file__).resolve().parents[4]
|
|
11
|
+
SKILL_DIR = Path(__file__).resolve().parents[1]
|
|
12
|
+
PROFILE_DIR = SKILL_DIR / "profiles"
|
|
13
|
+
REQUIRED_PROFILE_KEYS = (
|
|
14
|
+
"workspace",
|
|
15
|
+
"flow_type",
|
|
16
|
+
"data_set_uuid",
|
|
17
|
+
"list_template_uuid",
|
|
18
|
+
"filter_template_uuid",
|
|
19
|
+
"form_template_uuid",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class FlowTestProfile:
|
|
25
|
+
name: str
|
|
26
|
+
workspace: str
|
|
27
|
+
flow_type: str
|
|
28
|
+
flow_name: str = ""
|
|
29
|
+
data_set_uuid: str = ""
|
|
30
|
+
list_template_uuid: str = ""
|
|
31
|
+
filter_template_uuid: str = ""
|
|
32
|
+
form_template_uuid: str = ""
|
|
33
|
+
form_template_name: str = ""
|
|
34
|
+
default_qualification: str = ""
|
|
35
|
+
default_status: int = 0
|
|
36
|
+
terminal_step_names: List[str] = field(default_factory=list)
|
|
37
|
+
priority_filter_fields: List[str] = field(default_factory=list)
|
|
38
|
+
node_chain_ids: List[str] = field(default_factory=list)
|
|
39
|
+
default_create_values: Dict[str, Any] = field(default_factory=dict)
|
|
40
|
+
endpoint_overrides: Dict[str, Any] = field(default_factory=dict)
|
|
41
|
+
field_mappers: Dict[str, Any] = field(default_factory=dict)
|
|
42
|
+
browser_only_steps: List[Dict[str, Any]] = field(default_factory=list)
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def from_mapping(cls, payload: Dict[str, Any], *, default_name: str = "profile") -> "FlowTestProfile":
|
|
46
|
+
return cls(
|
|
47
|
+
name=str(payload.get("name") or default_name),
|
|
48
|
+
workspace=str(payload.get("workspace") or ""),
|
|
49
|
+
flow_type=str(payload.get("flow_type") or ""),
|
|
50
|
+
flow_name=str(payload.get("flow_name") or ""),
|
|
51
|
+
data_set_uuid=str(payload.get("data_set_uuid") or ""),
|
|
52
|
+
list_template_uuid=str(payload.get("list_template_uuid") or ""),
|
|
53
|
+
filter_template_uuid=str(payload.get("filter_template_uuid") or ""),
|
|
54
|
+
form_template_uuid=str(payload.get("form_template_uuid") or ""),
|
|
55
|
+
form_template_name=str(payload.get("form_template_name") or ""),
|
|
56
|
+
default_qualification=str(payload.get("default_qualification") or ""),
|
|
57
|
+
default_status=int(payload.get("default_status", 0) or 0),
|
|
58
|
+
terminal_step_names=[str(item) for item in payload.get("terminal_step_names", []) or []],
|
|
59
|
+
priority_filter_fields=[str(item) for item in payload.get("priority_filter_fields", []) or []],
|
|
60
|
+
node_chain_ids=[str(item) for item in payload.get("node_chain_ids", []) or []],
|
|
61
|
+
default_create_values=dict(payload.get("default_create_values", {}) or {}),
|
|
62
|
+
endpoint_overrides=dict(payload.get("endpoint_overrides", {}) or {}),
|
|
63
|
+
field_mappers=dict(payload.get("field_mappers", {}) or {}),
|
|
64
|
+
browser_only_steps=list(payload.get("browser_only_steps", []) or []),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def with_overrides(
|
|
68
|
+
self,
|
|
69
|
+
*,
|
|
70
|
+
workspace: Optional[str] = None,
|
|
71
|
+
flow_type: Optional[str] = None,
|
|
72
|
+
data_set_uuid: Optional[str] = None,
|
|
73
|
+
list_template_uuid: Optional[str] = None,
|
|
74
|
+
filter_template_uuid: Optional[str] = None,
|
|
75
|
+
form_template_uuid: Optional[str] = None,
|
|
76
|
+
form_template_name: Optional[str] = None,
|
|
77
|
+
) -> "FlowTestProfile":
|
|
78
|
+
return replace(
|
|
79
|
+
self,
|
|
80
|
+
workspace=workspace or self.workspace,
|
|
81
|
+
flow_type=flow_type or self.flow_type,
|
|
82
|
+
data_set_uuid=data_set_uuid or self.data_set_uuid,
|
|
83
|
+
list_template_uuid=list_template_uuid or self.list_template_uuid,
|
|
84
|
+
filter_template_uuid=filter_template_uuid or self.filter_template_uuid,
|
|
85
|
+
form_template_uuid=form_template_uuid or self.form_template_uuid,
|
|
86
|
+
form_template_name=form_template_name or self.form_template_name,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _parse_yaml_path(path: Path) -> Dict[str, Any]:
|
|
91
|
+
try:
|
|
92
|
+
import yaml # type: ignore
|
|
93
|
+
except Exception as err: # pragma: no cover
|
|
94
|
+
raise SystemExit(f"yaml profile requires PyYAML: {path}") from err
|
|
95
|
+
data = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
96
|
+
if not isinstance(data, dict):
|
|
97
|
+
raise SystemExit(f"profile must be an object: {path}")
|
|
98
|
+
return data
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def load_profile_mapping(path: Path) -> Dict[str, Any]:
|
|
102
|
+
suffix = path.suffix.lower()
|
|
103
|
+
if suffix == ".json":
|
|
104
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
105
|
+
elif suffix in {".yml", ".yaml"}:
|
|
106
|
+
data = _parse_yaml_path(path)
|
|
107
|
+
else:
|
|
108
|
+
raise SystemExit(f"unsupported profile format: {path}")
|
|
109
|
+
if not isinstance(data, dict):
|
|
110
|
+
raise SystemExit(f"profile must be an object: {path}")
|
|
111
|
+
return data
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def validate_profile_mapping(payload: Dict[str, Any], *, source: str) -> None:
|
|
115
|
+
missing = [key for key in REQUIRED_PROFILE_KEYS if not payload.get(key)]
|
|
116
|
+
if missing:
|
|
117
|
+
raise SystemExit(f"profile missing required keys from {source}: {', '.join(missing)}")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def profile_path_for_name(profile_name: str) -> Path:
|
|
121
|
+
for suffix in (".json", ".yaml", ".yml"):
|
|
122
|
+
candidate = PROFILE_DIR / f"{profile_name}{suffix}"
|
|
123
|
+
if candidate.exists():
|
|
124
|
+
return candidate
|
|
125
|
+
raise SystemExit(f"profile not found: {profile_name} (searched under {PROFILE_DIR})")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def resolve_profile_path(profile_name: Optional[str] = None, profile_file: Optional[str] = None) -> Path:
|
|
129
|
+
if profile_file:
|
|
130
|
+
path = Path(profile_file)
|
|
131
|
+
if not path.is_absolute():
|
|
132
|
+
path = (Path.cwd() / path).resolve()
|
|
133
|
+
if not path.exists():
|
|
134
|
+
raise SystemExit(f"profile file not found: {path}")
|
|
135
|
+
return path
|
|
136
|
+
return profile_path_for_name(profile_name or "negative_sale")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def load_profile(profile_name: str = "negative_sale", *, profile_file: Optional[str] = None) -> FlowTestProfile:
|
|
140
|
+
path = resolve_profile_path(profile_name, profile_file)
|
|
141
|
+
payload = load_profile_mapping(path)
|
|
142
|
+
validate_profile_mapping(payload, source=str(path))
|
|
143
|
+
return FlowTestProfile.from_mapping(payload, default_name=path.stem)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def resolve_profile(
|
|
147
|
+
profile_name: str = "negative_sale",
|
|
148
|
+
*,
|
|
149
|
+
profile_file: Optional[str] = None,
|
|
150
|
+
workspace: Optional[str] = None,
|
|
151
|
+
flow_type: Optional[str] = None,
|
|
152
|
+
data_set_uuid: Optional[str] = None,
|
|
153
|
+
list_template_uuid: Optional[str] = None,
|
|
154
|
+
filter_template_uuid: Optional[str] = None,
|
|
155
|
+
form_template_uuid: Optional[str] = None,
|
|
156
|
+
form_template_name: Optional[str] = None,
|
|
157
|
+
) -> FlowTestProfile:
|
|
158
|
+
base = load_profile(profile_name, profile_file=profile_file)
|
|
159
|
+
return base.with_overrides(
|
|
160
|
+
workspace=workspace,
|
|
161
|
+
flow_type=flow_type,
|
|
162
|
+
data_set_uuid=data_set_uuid,
|
|
163
|
+
list_template_uuid=list_template_uuid,
|
|
164
|
+
filter_template_uuid=filter_template_uuid,
|
|
165
|
+
form_template_uuid=form_template_uuid,
|
|
166
|
+
form_template_name=form_template_name,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def find_uuid_dir(base_dir: str, uuid: str) -> Path:
|
|
171
|
+
if not uuid:
|
|
172
|
+
raise FileNotFoundError(f"missing uuid for {base_dir}")
|
|
173
|
+
root = ROOT / base_dir
|
|
174
|
+
matches = sorted(root.glob(f"uuid'{uuid}*"))
|
|
175
|
+
if not matches:
|
|
176
|
+
raise FileNotFoundError(f"unable to locate {base_dir} for uuid {uuid}")
|
|
177
|
+
return matches[0]
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def find_flow_dir(flow_type: str) -> Path:
|
|
181
|
+
root = ROOT / "think_flow"
|
|
182
|
+
matches = sorted(root.glob(f"flow_type'{flow_type}*"))
|
|
183
|
+
if not matches:
|
|
184
|
+
raise FileNotFoundError(f"unable to locate flow for flow_type {flow_type}")
|
|
185
|
+
return matches[0]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
|
|
10
|
+
if str(SCRIPT_DIR) not in sys.path:
|
|
11
|
+
sys.path.insert(0, str(SCRIPT_DIR))
|
|
12
|
+
|
|
13
|
+
import e2e_state # noqa: E402
|
|
14
|
+
from bpmax_session import resolve_extra_headers # noqa: E402
|
|
15
|
+
from flow_test_profile import FlowTestProfile, load_profile, resolve_profile # noqa: E402
|
|
16
|
+
from flow_api_matrix import build_matrix # noqa: E402
|
|
17
|
+
from flow_filter_fields import build_report as build_filter_report # noqa: E402
|
|
18
|
+
from flow_form_runtime import build_create_skeleton, infer_transition # noqa: E402
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class NegativeSaleApiToolsTests(unittest.TestCase):
|
|
22
|
+
def test_build_create_skeleton_from_local_template(self) -> None:
|
|
23
|
+
profile = resolve_profile()
|
|
24
|
+
payload = build_create_skeleton(profile=profile)
|
|
25
|
+
self.assertEqual(payload["flow_type"], "flow288204142")
|
|
26
|
+
self.assertTrue(payload["projectForm"]["value"])
|
|
27
|
+
keys = {item.get("key") for item in payload["projectForm"]["value"]}
|
|
28
|
+
self.assertIn("negativeQuota", keys)
|
|
29
|
+
self.assertIn("seller", keys)
|
|
30
|
+
|
|
31
|
+
def test_filter_field_report_contains_expected_sources(self) -> None:
|
|
32
|
+
report = build_filter_report(None, resolve_profile())
|
|
33
|
+
recommended = report["recommended_fields"]
|
|
34
|
+
self.assertIn("name", recommended)
|
|
35
|
+
self.assertIn("seller", recommended)
|
|
36
|
+
self.assertIn("product", recommended)
|
|
37
|
+
self.assertIn("status", recommended)
|
|
38
|
+
|
|
39
|
+
def test_api_matrix_contains_step_endpoints(self) -> None:
|
|
40
|
+
matrix = build_matrix(resolve_profile())
|
|
41
|
+
endpoint_names = {item["name"] for item in matrix["endpoints"]}
|
|
42
|
+
self.assertIn("create_project", endpoint_names)
|
|
43
|
+
self.assertIn("step_detail", endpoint_names)
|
|
44
|
+
self.assertIn("step_approve", endpoint_names)
|
|
45
|
+
self.assertIn("step_reject", endpoint_names)
|
|
46
|
+
self.assertTrue(matrix["browser_only_steps"])
|
|
47
|
+
|
|
48
|
+
def test_infer_transition_reads_flow_chain(self) -> None:
|
|
49
|
+
profile = resolve_profile()
|
|
50
|
+
approve = infer_transition("1777001001001", "approve", profile)
|
|
51
|
+
refuse = infer_transition("1777001001001", "refuse", profile)
|
|
52
|
+
self.assertEqual(approve["target_step"], "1777001001002")
|
|
53
|
+
self.assertEqual(refuse["target_step"], "1775123074529")
|
|
54
|
+
|
|
55
|
+
def test_e2e_state_extended_fields_roundtrip(self) -> None:
|
|
56
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
57
|
+
state_dir = Path(tmpdir)
|
|
58
|
+
original = e2e_state.STATE_DIR
|
|
59
|
+
e2e_state.STATE_DIR = state_dir
|
|
60
|
+
try:
|
|
61
|
+
args = type("Args", (), {"id": "neg", "title": "负卖", "workspace": "store_mgr", "flow_type": "flow288204142", "dep": []})
|
|
62
|
+
e2e_state.cmd_init(args)
|
|
63
|
+
e2e_state.record_artifacts("neg", [{"kind": "matrix", "path": "/tmp/matrix.json"}])
|
|
64
|
+
e2e_state.record_endpoint_calls("neg", [{"method": "POST", "path": "/api/project"}])
|
|
65
|
+
e2e_state.record_browser_only_steps("neg", [{"title": "页面验真"}])
|
|
66
|
+
e2e_state.record_runtime_bindings("neg", {"last_created_project_id": 1})
|
|
67
|
+
data = json.loads((state_dir / "neg.json").read_text(encoding="utf-8"))
|
|
68
|
+
self.assertIn("artifacts", data)
|
|
69
|
+
self.assertIn("endpoint_calls", data)
|
|
70
|
+
self.assertIn("browser_only_steps", data)
|
|
71
|
+
self.assertEqual(data["runtime_bindings"]["last_created_project_id"], 1)
|
|
72
|
+
finally:
|
|
73
|
+
e2e_state.STATE_DIR = original
|
|
74
|
+
|
|
75
|
+
def test_profile_file_requires_mandatory_bindings(self) -> None:
|
|
76
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
77
|
+
profile_path = Path(tmpdir) / "broken.json"
|
|
78
|
+
profile_path.write_text(json.dumps({"name": "broken", "workspace": "store_mgr"}, ensure_ascii=False), encoding="utf-8")
|
|
79
|
+
with self.assertRaises(SystemExit) as ctx:
|
|
80
|
+
load_profile(profile_file=str(profile_path))
|
|
81
|
+
self.assertIn("profile missing required keys", str(ctx.exception))
|
|
82
|
+
|
|
83
|
+
def test_runtime_merge_uses_profile_mapper_and_drops_display_fields(self) -> None:
|
|
84
|
+
base = resolve_profile()
|
|
85
|
+
profile = FlowTestProfile(
|
|
86
|
+
name="custom",
|
|
87
|
+
workspace=base.workspace,
|
|
88
|
+
flow_type=base.flow_type,
|
|
89
|
+
data_set_uuid=base.data_set_uuid,
|
|
90
|
+
list_template_uuid=base.list_template_uuid,
|
|
91
|
+
filter_template_uuid=base.filter_template_uuid,
|
|
92
|
+
form_template_uuid=base.form_template_uuid,
|
|
93
|
+
form_template_name=base.form_template_name,
|
|
94
|
+
field_mappers={"create": {"by_key": {"seller": {"source": "search_value_json"}}}},
|
|
95
|
+
)
|
|
96
|
+
detail = {
|
|
97
|
+
"data": {
|
|
98
|
+
"qualification": "兴盛",
|
|
99
|
+
"metaForm": {
|
|
100
|
+
"value": [
|
|
101
|
+
{
|
|
102
|
+
"key": "seller",
|
|
103
|
+
"field": "seller",
|
|
104
|
+
"title": "经销商团队",
|
|
105
|
+
"field_type": "group_select",
|
|
106
|
+
"value": {"value": "展示态文案", "type": "group_select"},
|
|
107
|
+
"fieldPreview": "不应进入创建请求",
|
|
108
|
+
"search_value_json": "{\"id\": 7, \"name\": \"测试团队\"}",
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
payload = build_create_skeleton(project_detail=detail, profile=profile)
|
|
115
|
+
seller = next(item for item in payload["projectForm"]["value"] if item.get("key") == "seller")
|
|
116
|
+
self.assertEqual(seller["value"]["value"], {"id": 7, "name": "测试团队"})
|
|
117
|
+
self.assertNotIn("fieldPreview", seller)
|
|
118
|
+
|
|
119
|
+
def test_resolve_extra_headers_merges_file_and_env(self) -> None:
|
|
120
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
121
|
+
header_path = Path(tmpdir) / "headers.json"
|
|
122
|
+
header_path.write_text(json.dumps({"x-trace-id": "file-trace"}, ensure_ascii=False), encoding="utf-8")
|
|
123
|
+
original = os.environ.get("BPMAX_EXTRA_HEADERS_JSON")
|
|
124
|
+
os.environ["BPMAX_EXTRA_HEADERS_JSON"] = json.dumps({"x-request-from": "env", "x-trace-id": "env-trace"})
|
|
125
|
+
try:
|
|
126
|
+
args = type("Args", (), {"header_file": str(header_path)})
|
|
127
|
+
headers = resolve_extra_headers(args)
|
|
128
|
+
finally:
|
|
129
|
+
if original is None:
|
|
130
|
+
os.environ.pop("BPMAX_EXTRA_HEADERS_JSON", None)
|
|
131
|
+
else:
|
|
132
|
+
os.environ["BPMAX_EXTRA_HEADERS_JSON"] = original
|
|
133
|
+
self.assertEqual(headers["x-trace-id"], "env-trace")
|
|
134
|
+
self.assertEqual(headers["x-request-from"], "env")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__ == "__main__":
|
|
138
|
+
unittest.main()
|