bpmax-cli 0.1.42 → 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.
Files changed (251) hide show
  1. package/README.md +3 -3
  2. package/dist/bin.js +3967 -533
  3. package/dist/bin.js.map +1 -1
  4. package/package.json +1 -1
  5. package/skills/bpmax-api-platform-editor/SKILL.md +321 -0
  6. package/skills/bpmax-api-platform-editor/agents/openai.yaml +4 -0
  7. package/skills/bpmax-api-platform-editor/references/api-doc-debug-workflow.md +34 -0
  8. package/skills/bpmax-api-platform-editor/references/api-proxy-shape.md +41 -0
  9. package/skills/bpmax-api-platform-editor/references/instance-config-shape.md +41 -0
  10. package/skills/bpmax-api-platform-editor/references/platform-api-map.md +52 -0
  11. package/skills/bpmax-api-platform-editor/references/runtime-workflow.md +32 -0
  12. package/skills/bpmax-api-platform-editor/scripts/api_platform_editor_common.py +1276 -0
  13. package/skills/bpmax-api-platform-editor/scripts/build_submit_payload.py +64 -0
  14. package/skills/bpmax-api-platform-editor/scripts/capture_write_contract.py +40 -0
  15. package/skills/bpmax-api-platform-editor/scripts/export_layer_bundle.py +212 -0
  16. package/skills/bpmax-api-platform-editor/scripts/record_doc_debug_acceptance.py +62 -0
  17. package/skills/bpmax-api-platform-editor/scripts/submit_and_verify_layer.py +75 -0
  18. package/skills/bpmax-api-platform-editor/tests/test_api_platform_editor.py +287 -0
  19. package/skills/bpmax-auth/SKILL.md +6 -17
  20. package/skills/bpmax-builder-shared/SKILL.md +44 -0
  21. package/skills/bpmax-builder-shared/base_url.py +81 -0
  22. package/skills/bpmax-builder-shared/runtime-script-site-matrix.json +71 -0
  23. package/skills/bpmax-builder-shared/runtime-script-site-matrix.md +34 -0
  24. package/skills/bpmax-builder-shared/runtime-script-template-catalog.md +123 -0
  25. package/skills/bpmax-builder-shared/runtime_script_rules.py +272 -0
  26. package/skills/bpmax-builder-shared/skill_audit.py +374 -0
  27. package/skills/bpmax-builder-shared/template_script_hard_rules.py +280 -0
  28. package/skills/bpmax-builder-shared/tests/test_base_url.py +80 -0
  29. package/skills/bpmax-builder-shared/tests/test_runtime_script_rules.py +115 -0
  30. package/skills/bpmax-builder-shared/tests/test_skill_audit.py +231 -0
  31. package/skills/bpmax-builder-shared/tests/test_template_script_hard_rules.py +281 -0
  32. package/skills/bpmax-cli/SKILL.md +2 -0
  33. package/skills/bpmax-config-latest/SKILL.md +71 -0
  34. package/skills/bpmax-console-template-editor/SKILL.md +536 -0
  35. package/skills/bpmax-console-template-editor/agents/openai.yaml +4 -0
  36. package/skills/bpmax-console-template-editor/references/filter-integration.md +60 -0
  37. package/skills/bpmax-console-template-editor/references/lessons-from-resume-dashboard.md +114 -0
  38. package/skills/bpmax-console-template-editor/references/local-temp-workflow.md +69 -0
  39. package/skills/bpmax-console-template-editor/references/module-catalog.md +100 -0
  40. package/skills/bpmax-console-template-editor/references/runtime-page-shape.md +91 -0
  41. package/skills/bpmax-console-template-editor/references/template-shape.md +149 -0
  42. package/skills/bpmax-console-template-editor/scripts/build_submit_payload.py +38 -0
  43. package/skills/bpmax-console-template-editor/scripts/confirm_console_template.py +33 -0
  44. package/skills/bpmax-console-template-editor/scripts/console_template_editor_common.py +964 -0
  45. package/skills/bpmax-console-template-editor/scripts/export_console_template.py +99 -0
  46. package/skills/bpmax-console-template-editor/scripts/lint_console_template.py +46 -0
  47. package/skills/bpmax-console-template-editor/scripts/submit_console_template.py +99 -0
  48. package/skills/bpmax-console-template-editor/tests/test_console_template_editor.py +383 -0
  49. package/skills/bpmax-dataset-field-template-editor/SKILL.md +600 -0
  50. package/skills/bpmax-dataset-field-template-editor/references/create-request-gotchas.md +25 -0
  51. package/skills/bpmax-dataset-field-template-editor/references/field-classify-mapping.md +35 -0
  52. package/skills/bpmax-dataset-field-template-editor/references/nested-field-patterns.md +24 -0
  53. package/skills/bpmax-dataset-field-template-editor/references/runtime-verified-field-page-shape.md +61 -0
  54. package/skills/bpmax-dataset-field-template-editor/references/virtual-field-patterns.md +27 -0
  55. package/skills/bpmax-dataset-field-template-editor/references/work-file-to-submit-mapping.md +127 -0
  56. package/skills/bpmax-dataset-field-template-editor/scripts/build_submit_payload.py +67 -0
  57. package/skills/bpmax-dataset-field-template-editor/scripts/confirm_dataset_field.py +37 -0
  58. package/skills/bpmax-dataset-field-template-editor/scripts/dataset_field_editor_common.py +784 -0
  59. package/skills/bpmax-dataset-field-template-editor/scripts/export_dataset_field.py +62 -0
  60. package/skills/bpmax-dataset-field-template-editor/scripts/init_create_dataset_field.py +104 -0
  61. package/skills/bpmax-dataset-field-template-editor/scripts/inspect_dataset_field_runtime.py +83 -0
  62. package/skills/bpmax-dataset-field-template-editor/scripts/lint_dataset_field_semantics.py +35 -0
  63. package/skills/bpmax-dataset-field-template-editor/scripts/submit_dataset_field.py +95 -0
  64. package/skills/bpmax-dataset-field-template-editor/tests/test_dataset_field_editor.py +709 -0
  65. package/skills/bpmax-dataset-field-template-editor/tests/test_init_create_dataset_field.py +59 -0
  66. package/skills/bpmax-dataset-template-editor/SKILL.md +779 -0
  67. package/skills/bpmax-dataset-template-editor/references/custom-key-usage-patterns.md +18 -0
  68. package/skills/bpmax-dataset-template-editor/references/dataset-script-runtime-matrix.md +73 -0
  69. package/skills/bpmax-dataset-template-editor/references/pre-process-script-authoring-guide.md +186 -0
  70. package/skills/bpmax-dataset-template-editor/references/pre-process-script-example-catalog.md +106 -0
  71. package/skills/bpmax-dataset-template-editor/references/runtime-gotchas.md +28 -0
  72. package/skills/bpmax-dataset-template-editor/references/runtime-verified-dataset-page-shape.md +47 -0
  73. package/skills/bpmax-dataset-template-editor/references/ui-to-backend-field-map.md +23 -0
  74. package/skills/bpmax-dataset-template-editor/references/work-file-to-submit-mapping.md +97 -0
  75. package/skills/bpmax-dataset-template-editor/scripts/basic_table_audit.py +65 -0
  76. package/skills/bpmax-dataset-template-editor/scripts/build_submit_payload.py +38 -0
  77. package/skills/bpmax-dataset-template-editor/scripts/dataset_editor_common.py +650 -0
  78. package/skills/bpmax-dataset-template-editor/scripts/export_dataset.py +155 -0
  79. package/skills/bpmax-dataset-template-editor/scripts/lint_dataset_template.py +42 -0
  80. package/skills/bpmax-dataset-template-editor/scripts/resolve_dataset.py +43 -0
  81. package/skills/bpmax-dataset-template-editor/scripts/scan_custom_key_references.py +27 -0
  82. package/skills/bpmax-dataset-template-editor/scripts/submit_dataset.py +115 -0
  83. package/skills/bpmax-dataset-template-editor/scripts/verify_dataset_list.py +52 -0
  84. package/skills/bpmax-dataset-template-editor/scripts/verify_publish_health.py +39 -0
  85. package/skills/bpmax-dataset-template-editor/tests/test_dataset_editor.py +373 -0
  86. package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +151 -0
  87. package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +4 -0
  88. package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +60 -0
  89. package/skills/bpmax-e2e-flow-test-operator/SKILL.md +371 -0
  90. package/skills/bpmax-e2e-flow-test-operator/agents/openai.yaml +5 -0
  91. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale.json +97 -0
  92. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_final_v2.json +105 -0
  93. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_main.json +36 -0
  94. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_region.json +40 -0
  95. package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +33 -0
  96. package/skills/bpmax-e2e-flow-test-operator/references/failure-update-loop.md +17 -0
  97. package/skills/bpmax-e2e-flow-test-operator/references/filter-field-discovery.md +40 -0
  98. package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +19 -0
  99. package/skills/bpmax-e2e-flow-test-operator/references/negative-sale-api-matrix.md +75 -0
  100. package/skills/bpmax-e2e-flow-test-operator/references/profile-schema.md +107 -0
  101. package/skills/bpmax-e2e-flow-test-operator/references/skill-experience-coverage-matrix.md +29 -0
  102. package/skills/bpmax-e2e-flow-test-operator/references/stale-runtime-and-clean-sample-rules.md +54 -0
  103. package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +58 -0
  104. package/skills/bpmax-e2e-flow-test-operator/scripts/bpmax_session.py +287 -0
  105. package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_plan.json +59 -0
  106. package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_runner.py +687 -0
  107. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +95 -0
  108. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_state.py +288 -0
  109. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_api_matrix.py +161 -0
  110. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_filter_fields.py +138 -0
  111. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_form_runtime.py +396 -0
  112. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_runner.py +341 -0
  113. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_test_profile.py +185 -0
  114. package/skills/bpmax-e2e-flow-test-operator/tests/test_negative_sale_api_tools.py +138 -0
  115. package/skills/bpmax-feishu-chat-flow-plugin-editor/SKILL.md +69 -0
  116. package/skills/bpmax-feishu-chat-flow-plugin-editor/agents/openai.yaml +4 -0
  117. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-checklist.md +42 -0
  118. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-recipes.md +38 -0
  119. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-shape.md +86 -0
  120. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/gate-lint.md +68 -0
  121. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/hoocoo-patterns.md +39 -0
  122. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/runtime-behavior.md +41 -0
  123. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/script-authoring.md +110 -0
  124. package/skills/bpmax-feishu-chat-flow-plugin-editor/scripts/lint_feishu_chat_plugin.py +278 -0
  125. package/skills/bpmax-feishu-chat-flow-plugin-editor/tests/test_lint_feishu_chat_plugin.py +203 -0
  126. package/skills/bpmax-filter-template-editor/SKILL.md +564 -0
  127. package/skills/bpmax-filter-template-editor/references/experience-coverage-matrix.md +38 -0
  128. package/skills/bpmax-filter-template-editor/references/filter-and-flow-binding.md +57 -0
  129. package/skills/bpmax-filter-template-editor/references/filter-content-schema.md +141 -0
  130. package/skills/bpmax-filter-template-editor/references/filter-request-shape.md +287 -0
  131. package/skills/bpmax-filter-template-editor/references/filter-runtime-patterns.md +115 -0
  132. package/skills/bpmax-filter-template-editor/references/runtime-verified-filter-page-shape.md +94 -0
  133. package/skills/bpmax-filter-template-editor/scripts/build_submit_payload.py +25 -0
  134. package/skills/bpmax-filter-template-editor/scripts/confirm_filter_template.py +22 -0
  135. package/skills/bpmax-filter-template-editor/scripts/export_filter_template.py +57 -0
  136. package/skills/bpmax-filter-template-editor/scripts/filter_template_editor_common.py +348 -0
  137. package/skills/bpmax-filter-template-editor/scripts/init_create_filter_template.py +8 -0
  138. package/skills/bpmax-filter-template-editor/scripts/lint_filter_template_semantics.py +26 -0
  139. package/skills/bpmax-filter-template-editor/scripts/submit_filter_template.py +62 -0
  140. package/skills/bpmax-filter-template-editor/tests/test_filter_template_editor.py +231 -0
  141. package/skills/bpmax-flow-template-editor/SKILL.md +1043 -0
  142. package/skills/bpmax-flow-template-editor/agents/openai.yaml +4 -0
  143. package/skills/bpmax-flow-template-editor/references/before-next-step-script-runtime-gotchas.md +62 -0
  144. package/skills/bpmax-flow-template-editor/references/config-surfaces-and-placeholders.md +270 -0
  145. package/skills/bpmax-flow-template-editor/references/diff-strategy.md +67 -0
  146. package/skills/bpmax-flow-template-editor/references/editor-runtime-vs-draft.md +25 -0
  147. package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +159 -0
  148. package/skills/bpmax-flow-template-editor/references/intent-model.md +117 -0
  149. package/skills/bpmax-flow-template-editor/references/lessons-from-price-plan-flow.md +147 -0
  150. package/skills/bpmax-flow-template-editor/references/local-temp-workflow.md +97 -0
  151. package/skills/bpmax-flow-template-editor/references/matrix-flow-form-nav-collaboration.md +163 -0
  152. package/skills/bpmax-flow-template-editor/references/payload-checklist.md +133 -0
  153. package/skills/bpmax-flow-template-editor/references/project-create-runtime-gotchas.md +54 -0
  154. package/skills/bpmax-flow-template-editor/references/requirement-to-node-mapping.md +149 -0
  155. package/skills/bpmax-flow-template-editor/references/runtime-verified-flow-detail-shape.md +41 -0
  156. package/skills/bpmax-flow-template-editor/references/runtime-verified-meta-fields.md +155 -0
  157. package/skills/bpmax-flow-template-editor/references/runtime-verified-node-fields.md +179 -0
  158. package/skills/bpmax-flow-template-editor/references/save-draft-request-shape.md +91 -0
  159. package/skills/bpmax-flow-template-editor/references/script-review-hard-rules.md +93 -0
  160. package/skills/bpmax-flow-template-editor/references/work-file-to-submit-mapping.md +57 -0
  161. package/skills/bpmax-flow-template-editor/scripts/build_submit_payload.py +69 -0
  162. package/skills/bpmax-flow-template-editor/scripts/confirm_flow_template.py +52 -0
  163. package/skills/bpmax-flow-template-editor/scripts/export_flow_template.py +114 -0
  164. package/skills/bpmax-flow-template-editor/scripts/flow_template_editor_common.py +1084 -0
  165. package/skills/bpmax-flow-template-editor/scripts/submit_flow_template.py +159 -0
  166. package/skills/bpmax-flow-template-editor/tests/test_flow_template_editor.py +636 -0
  167. package/skills/bpmax-form-template-editor/SKILL.md +1074 -0
  168. package/skills/bpmax-form-template-editor/agents/openai.yaml +4 -0
  169. package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +193 -0
  170. package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +125 -0
  171. package/skills/bpmax-form-template-editor/references/payload-checklist.md +77 -0
  172. package/skills/bpmax-form-template-editor/references/sub-form-patterns.md +49 -0
  173. package/skills/bpmax-form-template-editor/scripts/build_submit_payload.py +37 -0
  174. package/skills/bpmax-form-template-editor/scripts/check_form_template_consistency.py +145 -0
  175. package/skills/bpmax-form-template-editor/scripts/confirm_form_template.py +67 -0
  176. package/skills/bpmax-form-template-editor/scripts/export_form_template.py +89 -0
  177. package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +1745 -0
  178. package/skills/bpmax-form-template-editor/scripts/lint_form_template_semantics.py +30 -0
  179. package/skills/bpmax-form-template-editor/scripts/record_runtime_acceptance.py +67 -0
  180. package/skills/bpmax-form-template-editor/scripts/submit_form_template.py +163 -0
  181. package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +1303 -0
  182. package/skills/bpmax-list-template-editor/SKILL.md +468 -0
  183. package/skills/bpmax-list-template-editor/agents/openai.yaml +4 -0
  184. package/skills/bpmax-list-template-editor/references/browser-page-contract.md +81 -0
  185. package/skills/bpmax-list-template-editor/references/content-config-shape.md +148 -0
  186. package/skills/bpmax-list-template-editor/references/dataset-field-mapping.md +60 -0
  187. package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +103 -0
  188. package/skills/bpmax-list-template-editor/references/local-temp-workflow.md +102 -0
  189. package/skills/bpmax-list-template-editor/references/payload-checklist.md +47 -0
  190. package/skills/bpmax-list-template-editor/references/runtime-verified-workflow.md +140 -0
  191. package/skills/bpmax-list-template-editor/references/special-formats.md +394 -0
  192. package/skills/bpmax-list-template-editor/scripts/build_submit_payload.py +37 -0
  193. package/skills/bpmax-list-template-editor/scripts/confirm_list_template.py +33 -0
  194. package/skills/bpmax-list-template-editor/scripts/export_list_template.py +89 -0
  195. package/skills/bpmax-list-template-editor/scripts/fetch_data_set.py +34 -0
  196. package/skills/bpmax-list-template-editor/scripts/lint_list_template_semantics.py +54 -0
  197. package/skills/bpmax-list-template-editor/scripts/list_template_editor_common.py +955 -0
  198. package/skills/bpmax-list-template-editor/scripts/record_acceptance.py +55 -0
  199. package/skills/bpmax-list-template-editor/scripts/submit_list_template.py +117 -0
  200. package/skills/bpmax-list-template-editor/tests/test_list_template_editor_common.py +441 -0
  201. package/skills/bpmax-nav-config-editor/SKILL.md +347 -0
  202. package/skills/bpmax-nav-config-editor/agents/openai.yaml +4 -0
  203. package/skills/bpmax-nav-config-editor/references/api-workflow.md +68 -0
  204. package/skills/bpmax-nav-config-editor/references/config-shape.md +78 -0
  205. package/skills/bpmax-nav-config-editor/references/icon-selection.md +83 -0
  206. package/skills/bpmax-nav-config-editor/references/path-mapping-rules.md +46 -0
  207. package/skills/bpmax-nav-config-editor/references/payload-checklist.md +41 -0
  208. package/skills/bpmax-nav-config-editor/references/runtime-probing.md +47 -0
  209. package/skills/bpmax-nav-config-editor/scripts/build_submit_payload.py +34 -0
  210. package/skills/bpmax-nav-config-editor/scripts/confirm_nav_config.py +32 -0
  211. package/skills/bpmax-nav-config-editor/scripts/export_nav_config.py +56 -0
  212. package/skills/bpmax-nav-config-editor/scripts/lint_nav_config_semantics.py +33 -0
  213. package/skills/bpmax-nav-config-editor/scripts/nav_config_editor_common.py +812 -0
  214. package/skills/bpmax-nav-config-editor/scripts/submit_nav_config.py +44 -0
  215. package/skills/bpmax-nav-config-editor/scripts/verify_nav_config.py +33 -0
  216. package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor.py +358 -0
  217. package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor_common.py +138 -0
  218. package/skills/bpmax-nav-config-editor/tests/test_nav_config_lint.py +58 -0
  219. package/skills/bpmax-nav-config-editor/tests/test_nav_config_submit_verify.py +51 -0
  220. package/skills/bpmax-project/SKILL.md +1 -1
  221. package/skills/bpmax-project-detail-template-editor/SKILL.md +329 -0
  222. package/skills/bpmax-project-detail-template-editor/agents/openai.yaml +4 -0
  223. package/skills/bpmax-project-detail-template-editor/references/local-temp-workflow.md +59 -0
  224. package/skills/bpmax-project-detail-template-editor/references/module-catalog-and-config-notes.md +47 -0
  225. package/skills/bpmax-project-detail-template-editor/references/payload-checklist.md +33 -0
  226. package/skills/bpmax-project-detail-template-editor/references/project-detail-template-api-workflow.md +44 -0
  227. package/skills/bpmax-project-detail-template-editor/scripts/build_submit_payload.py +30 -0
  228. package/skills/bpmax-project-detail-template-editor/scripts/confirm_project_detail_template.py +33 -0
  229. package/skills/bpmax-project-detail-template-editor/scripts/export_project_detail_template.py +87 -0
  230. package/skills/bpmax-project-detail-template-editor/scripts/lint_project_detail_template_semantics.py +37 -0
  231. package/skills/bpmax-project-detail-template-editor/scripts/project_detail_template_editor_common.py +507 -0
  232. package/skills/bpmax-project-detail-template-editor/scripts/submit_project_detail_template.py +120 -0
  233. package/skills/bpmax-project-detail-template-editor/tests/test_project_detail_template_editor.py +369 -0
  234. package/skills/bpmax-role-editor/SKILL.md +251 -0
  235. package/skills/bpmax-role-editor/references/api-workflow.md +30 -0
  236. package/skills/bpmax-role-editor/references/runtime-page-shape.md +18 -0
  237. package/skills/bpmax-role-editor/references/work-file-mapping.md +32 -0
  238. package/skills/bpmax-role-editor/scripts/build_submit_payload.py +38 -0
  239. package/skills/bpmax-role-editor/scripts/confirm_role.py +33 -0
  240. package/skills/bpmax-role-editor/scripts/export_role.py +163 -0
  241. package/skills/bpmax-role-editor/scripts/lint_role_semantics.py +38 -0
  242. package/skills/bpmax-role-editor/scripts/role_editor_common.py +1231 -0
  243. package/skills/bpmax-role-editor/scripts/submit_role.py +144 -0
  244. package/skills/bpmax-role-editor/tests/test_role_editor.py +343 -0
  245. package/skills/bpmax-shared/SKILL.md +1 -1
  246. package/skills/form-control-library/SKILL.md +82 -0
  247. package/skills/form-control-library/agents/openai.yaml +4 -0
  248. package/skills/form-control-library/references/form-controls.md +199 -0
  249. package/skills/form-control-library/references/form-template-submit-schema.md +180 -0
  250. package/skills/form-control-library/references/group-select-runtime.md +191 -0
  251. package/skills/form-control-library/scripts/rebuild_form_control_library.py +55 -0
@@ -0,0 +1,636 @@
1
+ import json
2
+ import os
3
+ import sys
4
+ import tempfile
5
+ import unittest
6
+ from pathlib import Path
7
+ from unittest import mock
8
+
9
+
10
+ SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
11
+ if str(SCRIPT_DIR) not in sys.path:
12
+ sys.path.insert(0, str(SCRIPT_DIR))
13
+
14
+ from flow_template_editor_common import ( # noqa: E402
15
+ ApiClient,
16
+ build_client,
17
+ build_drift_report,
18
+ build_submit_payload,
19
+ detail_to_work_payload,
20
+ evaluate_lints,
21
+ ensure_submission_allowed,
22
+ lint_work_payload,
23
+ lint_flow_semantics,
24
+ load_json,
25
+ normalize_flow_detail,
26
+ resolve_export_detail,
27
+ summarize_verification,
28
+ update_build_meta,
29
+ update_confirmation_state,
30
+ )
31
+
32
+
33
+ def make_detail() -> dict:
34
+ return {
35
+ "name": "ST销售出库",
36
+ "flow_type": "flow352878207",
37
+ "update_time": "2026-04-02 20:48:50",
38
+ "data": {
39
+ "periods": ["销售出库", "归档"],
40
+ "nodes": [
41
+ {
42
+ "id": "1775218151534",
43
+ "name": "提交申请",
44
+ "period": "销售出库",
45
+ "approve_to_step": "1776676101001",
46
+ "approve_fail": "",
47
+ "form_template": 990702287,
48
+ "need_confirm": False,
49
+ "owner_is_creater": True,
50
+ "owner_roles": [],
51
+ "enableBeforeNextStepScript": True,
52
+ "beforeNextStepScript": "return true;",
53
+ "condational_nodes": [],
54
+ },
55
+ {
56
+ "id": "1776676101001",
57
+ "name": "主管审批",
58
+ "period": "销售出库",
59
+ "approve_to_step": "",
60
+ "approve_fail": "1775218151534",
61
+ "need_confirm": False,
62
+ "owner_is_creater": True,
63
+ "owner_roles": [],
64
+ "condational_nodes": [],
65
+ },
66
+ ],
67
+ "meta": {
68
+ "isMeta": True,
69
+ "name": "开始",
70
+ "form_template": 990702239,
71
+ "project_name_template": "return 'ST销售出库';",
72
+ },
73
+ "group": [],
74
+ },
75
+ }
76
+
77
+
78
+ def make_runtime_submit_data() -> dict:
79
+ return copy_for_runtime(make_detail()["data"])
80
+
81
+
82
+ def copy_for_runtime(data: dict) -> dict:
83
+ return json.loads(json.dumps(data, ensure_ascii=False))
84
+
85
+
86
+ def make_semantic_work() -> dict:
87
+ return detail_to_work_payload(make_detail(), workspace="store_mgr")
88
+
89
+
90
+ class FlowTemplateEditorCommonTests(unittest.TestCase):
91
+ def test_detail_to_work_payload_maps_real_shape(self) -> None:
92
+ work = detail_to_work_payload(make_detail(), workspace="store_mgr")
93
+ self.assertEqual(work["mode"], "edit")
94
+ self.assertEqual(work["identity"]["scope"], "main")
95
+ self.assertEqual(work["basic"]["name"], "ST销售出库")
96
+ self.assertEqual(work["basic"]["updateTime"], "2026-04-02 20:48:50")
97
+ self.assertEqual(work["data"]["periods"][0], "销售出库")
98
+ self.assertEqual(work["preserve"]["nodeCount"], 2)
99
+
100
+ def test_build_submit_payload_preserves_full_data_shape(self) -> None:
101
+ work = detail_to_work_payload(make_detail(), workspace="store_mgr")
102
+ submit = build_submit_payload(work)
103
+ self.assertEqual(set(submit.keys()), {"name", "data"})
104
+ self.assertEqual(submit["name"], "ST销售出库")
105
+ self.assertEqual(submit["data"], work["data"])
106
+
107
+ def test_build_submit_payload_rejects_missing_node_target(self) -> None:
108
+ work = detail_to_work_payload(make_detail(), workspace="store_mgr")
109
+ work["data"]["nodes"][0]["approve_to_step"] = "不存在的节点"
110
+ with self.assertRaises(SystemExit):
111
+ build_submit_payload(work)
112
+
113
+ def test_evaluate_lints_can_ignore_preexisting_raw_errors_only(self) -> None:
114
+ raw_detail = make_detail()
115
+ raw_detail["data"]["nodes"][0]["approve_to_step"] = "[source]"
116
+ work = detail_to_work_payload(raw_detail, workspace="store_mgr")
117
+
118
+ structure_lint, semantic_lint = evaluate_lints(
119
+ work,
120
+ raw_payload=raw_detail,
121
+ allow_preexisting_lint_errors=True,
122
+ )
123
+
124
+ self.assertTrue(structure_lint["ok"])
125
+ self.assertFalse(structure_lint["errors"])
126
+ self.assertTrue(structure_lint["ignoredPreexistingErrors"])
127
+ self.assertTrue(semantic_lint["ok"])
128
+
129
+ work["data"]["nodes"][1]["approve_fail"] = "新坏节点"
130
+ structure_lint, _ = evaluate_lints(
131
+ work,
132
+ raw_payload=raw_detail,
133
+ allow_preexisting_lint_errors=True,
134
+ )
135
+ self.assertFalse(structure_lint["ok"])
136
+ self.assertTrue(any("新坏节点" in err for err in structure_lint["errors"]))
137
+
138
+ def test_runtime_fallback_accepts_bare_get_submit_data_shape(self) -> None:
139
+ runtime_detail = make_runtime_submit_data()
140
+ work = detail_to_work_payload(
141
+ runtime_detail,
142
+ workspace="store_mgr",
143
+ flow_type="flow352878207",
144
+ source="runtime_fallback",
145
+ )
146
+ self.assertEqual(work["basic"]["flowType"], "flow352878207")
147
+ self.assertEqual(work["data"]["group"], [])
148
+
149
+ def test_semantic_lint_requires_before_next_step_enable_flag(self) -> None:
150
+ work = make_semantic_work()
151
+ work["data"]["nodes"][0]["enableBeforeNextStepScript"] = False
152
+ report = lint_flow_semantics(work)
153
+ self.assertFalse(report["ok"])
154
+ self.assertTrue(any("enableBeforeNextStepScript" in err for err in report["errors"]))
155
+
156
+ def test_work_lint_requires_group_array(self) -> None:
157
+ work = make_semantic_work()
158
+ work["data"]["group"] = {}
159
+ report = lint_work_payload(work)
160
+ self.assertFalse(report["ok"])
161
+ self.assertTrue(any("data.group must be an array" in err for err in report["errors"]))
162
+
163
+ def test_semantic_lint_rejects_object_shaped_group(self) -> None:
164
+ work = make_semantic_work()
165
+ work["data"]["group"] = {}
166
+ report = lint_flow_semantics(work)
167
+ self.assertFalse(report["ok"])
168
+ self.assertTrue(any("FlowMap rendering" in err for err in report["errors"]))
169
+
170
+ def test_semantic_lint_rejects_bare_auto_trigger_flow_form(self) -> None:
171
+ work = make_semantic_work()
172
+ work["data"]["nodes"][0]["auto_trigger_flows"] = {
173
+ "flows": [
174
+ {
175
+ "create_rule": "return [{ form: { robo_serialno: sn } }];"
176
+ }
177
+ ]
178
+ }
179
+ report = lint_flow_semantics(work)
180
+ self.assertFalse(report["ok"])
181
+ self.assertTrue(any("bare form object" in err for err in report["errors"]))
182
+
183
+ def test_semantic_lint_rejects_approval_count_on_non_approval_step(self) -> None:
184
+ work = make_semantic_work()
185
+ work["data"]["nodes"][0]["name"] = "成员评分"
186
+ work["data"]["nodes"][0]["approve_count_required"] = 1
187
+
188
+ report = lint_flow_semantics(work)
189
+
190
+ self.assertFalse(report["ok"])
191
+ self.assertTrue(any("non-approval steps must use 0" in err for err in report["errors"]))
192
+
193
+ def test_semantic_lint_rejects_approval_step_without_explicit_reject_target(self) -> None:
194
+ work = make_semantic_work()
195
+ work["data"]["nodes"][1]["name"] = "评分确认"
196
+ work["data"]["nodes"][1]["approve_count_required"] = 1
197
+ work["data"]["nodes"][1]["approve_to_step"] = "1775218151534"
198
+ work["data"]["nodes"][1]["approve_fail"] = ""
199
+ work["data"]["nodes"][1]["approve_fail_actions"] = []
200
+
201
+ report = lint_flow_semantics(work)
202
+
203
+ self.assertFalse(report["ok"])
204
+ self.assertTrue(any("no explicit reject target" in err for err in report["errors"]))
205
+
206
+ def test_semantic_lint_rejects_approval_and_reject_to_same_target(self) -> None:
207
+ work = make_semantic_work()
208
+ work["data"]["nodes"][1]["name"] = "评分确认"
209
+ work["data"]["nodes"][1]["approve_count_required"] = 1
210
+ work["data"]["nodes"][1]["approve_to_step"] = "1775218151534"
211
+ work["data"]["nodes"][1]["approve_fail"] = "1775218151534"
212
+
213
+ report = lint_flow_semantics(work)
214
+
215
+ self.assertFalse(report["ok"])
216
+ self.assertTrue(any("approval and reject routing target the same node" in err for err in report["errors"]))
217
+
218
+ def test_semantic_lint_rejects_non_numeric_form_template_refs(self) -> None:
219
+ work = make_semantic_work()
220
+ work["data"]["nodes"][0]["form_template"] = "uuid'abc'"
221
+ work["data"]["meta"]["form_template"] = "uuid'def'"
222
+ report = lint_flow_semantics(work)
223
+ self.assertFalse(report["ok"])
224
+ self.assertGreaterEqual(len(report["errors"]), 2)
225
+ self.assertGreaterEqual(len(report["hardErrors"]), 2)
226
+
227
+ def test_semantic_lint_rejects_non_numeric_online_template_refs(self) -> None:
228
+ work = make_semantic_work()
229
+ work["data"]["meta"]["table_list_template"] = "uuid'list'"
230
+ work["data"]["meta"]["table_filter_template"] = "uuid'filter'"
231
+ work["data"]["meta"]["step_detail_id"] = "uuid'meta-detail'"
232
+ work["data"]["nodes"][0]["step_detail_id"] = "uuid'node-detail'"
233
+
234
+ report = lint_flow_semantics(work)
235
+
236
+ self.assertFalse(report["ok"])
237
+ self.assertTrue(any("meta.table_list_template" in err for err in report["errors"]))
238
+ self.assertTrue(any("meta.table_filter_template" in err for err in report["errors"]))
239
+ self.assertTrue(any("meta.step_detail_id" in err for err in report["errors"]))
240
+ self.assertTrue(any("提交申请.step_detail_id" in err for err in report["errors"]))
241
+ self.assertEqual(len(report["hardErrors"]), 4)
242
+
243
+ def test_evaluate_lints_does_not_ignore_preexisting_online_template_ref_errors(self) -> None:
244
+ raw_detail = make_detail()
245
+ raw_detail["data"]["meta"]["table_list_template"] = "uuid'legacy-list'"
246
+ work = detail_to_work_payload(raw_detail, workspace="store_mgr")
247
+
248
+ structure_lint, semantic_lint = evaluate_lints(
249
+ work,
250
+ raw_payload=raw_detail,
251
+ allow_preexisting_lint_errors=True,
252
+ )
253
+
254
+ self.assertTrue(structure_lint["ok"])
255
+ self.assertFalse(semantic_lint["ok"])
256
+ self.assertTrue(any("meta.table_list_template" in err for err in semantic_lint["errors"]))
257
+ self.assertFalse(semantic_lint["ignoredPreexistingErrors"])
258
+
259
+ def test_semantic_lint_blocks_project_list_query(self) -> None:
260
+ work = make_semantic_work()
261
+ work["data"]["nodes"][0]["beforeNextStepScript"] = (
262
+ "return ctx.$axios.post('/bpmax/project/list?page=1', { flow_type: 'flow716', query: {} });"
263
+ )
264
+
265
+ report = lint_flow_semantics(work)
266
+
267
+ self.assertFalse(report["ok"])
268
+ self.assertTrue(any("project/list" in err for err in report["errors"]))
269
+
270
+ def test_build_submit_payload_blocks_hard_template_ref_errors(self) -> None:
271
+ work = make_semantic_work()
272
+ work["data"]["meta"]["table_list_template"] = "uuid'bad'"
273
+
274
+ with self.assertRaises(SystemExit):
275
+ build_submit_payload(work)
276
+
277
+ def test_build_meta_resets_submit_confirmation_after_work_change(self) -> None:
278
+ with tempfile.TemporaryDirectory() as tmpdir:
279
+ root = Path(tmpdir)
280
+ work_path = root / "work.json"
281
+ submit_path = root / "submit.json"
282
+ meta_path = root / "meta.json"
283
+ work_path.write_text(json.dumps({"name": "v1"}, ensure_ascii=False), encoding="utf-8")
284
+ submit_path.write_text(json.dumps({"name": "s1"}, ensure_ascii=False), encoding="utf-8")
285
+ meta_path.write_text(
286
+ json.dumps(
287
+ {
288
+ "stem": "flow352878207",
289
+ "mode": "edit",
290
+ "workspace": "store_mgr",
291
+ "workSha256": "old",
292
+ "status": "submit_confirmed",
293
+ "workConfirmedAt": "2026-04-21T00:00:00+00:00",
294
+ "submitConfirmedAt": "2026-04-21T00:01:00+00:00",
295
+ },
296
+ ensure_ascii=False,
297
+ ),
298
+ encoding="utf-8",
299
+ )
300
+ update_build_meta(meta_path, stem="flow352878207", work_path=work_path, submit_path=submit_path)
301
+ meta = load_json(meta_path)
302
+ self.assertIsNone(meta["workConfirmedAt"])
303
+ self.assertIsNone(meta["submitConfirmedAt"])
304
+ self.assertEqual(meta["status"], "submit_built")
305
+
306
+ def test_update_build_meta_persists_allow_preexisting_lint_errors_flag(self) -> None:
307
+ with tempfile.TemporaryDirectory() as tmpdir:
308
+ root = Path(tmpdir)
309
+ work_path = root / "work.json"
310
+ submit_path = root / "submit.json"
311
+ meta_path = root / "meta.json"
312
+ work_path.write_text(json.dumps({"name": "v1"}, ensure_ascii=False), encoding="utf-8")
313
+ submit_path.write_text(json.dumps({"name": "s1"}, ensure_ascii=False), encoding="utf-8")
314
+ update_build_meta(
315
+ meta_path,
316
+ stem="flow352878207",
317
+ work_path=work_path,
318
+ submit_path=submit_path,
319
+ allow_preexisting_lint_errors=True,
320
+ )
321
+ meta = load_json(meta_path)
322
+ self.assertTrue(meta["allowPreexistingLintErrors"])
323
+
324
+ def test_confirm_flow_template_handles_two_stage_confirmation(self) -> None:
325
+ with tempfile.TemporaryDirectory() as tmpdir:
326
+ root = Path(tmpdir)
327
+ work_path = root / "work.json"
328
+ submit_path = root / "submit.json"
329
+ meta_path = root / "meta.json"
330
+ work_path.write_text(json.dumps(detail_to_work_payload(make_detail(), workspace="store_mgr"), ensure_ascii=False), encoding="utf-8")
331
+ submit_path.write_text(json.dumps({"name": "ST销售出库", "data": {}}, ensure_ascii=False), encoding="utf-8")
332
+ update_confirmation_state(meta_path, stem="flow352878207", actor="tester", stage="work", work_path=work_path, submit_path=submit_path)
333
+ meta = load_json(meta_path)
334
+ self.assertEqual(meta["status"], "work_confirmed")
335
+ update_confirmation_state(meta_path, stem="flow352878207", actor="tester", stage="submit", work_path=work_path, submit_path=submit_path)
336
+ meta = load_json(meta_path)
337
+ self.assertEqual(meta["status"], "submit_confirmed")
338
+
339
+ def test_work_confirmation_persists_runtime_acceptance_requirements(self) -> None:
340
+ with tempfile.TemporaryDirectory() as tmpdir:
341
+ root = Path(tmpdir)
342
+ work_path = root / "work.json"
343
+ meta_path = root / "meta.json"
344
+ work_path.write_text(json.dumps(detail_to_work_payload(make_detail(), workspace="store_mgr"), ensure_ascii=False), encoding="utf-8")
345
+
346
+ update_confirmation_state(
347
+ meta_path,
348
+ stem="flow352878207",
349
+ actor="tester",
350
+ stage="work",
351
+ work_path=work_path,
352
+ runtime_acceptance={
353
+ "required": True,
354
+ "flowType": "flow352878207",
355
+ "acceptancePage": "/w:store_mgr/project/create?flow_type=flow352878207",
356
+ "freshInstanceRequired": True,
357
+ },
358
+ )
359
+
360
+ meta = load_json(meta_path)
361
+ self.assertTrue(meta["runtimeAcceptance"]["required"])
362
+ self.assertEqual(meta["runtimeAcceptance"]["flowType"], "flow352878207")
363
+ self.assertTrue(meta["runtimeAcceptance"]["freshInstanceRequired"])
364
+
365
+ def test_work_confirmation_preserves_existing_runtime_acceptance_when_unspecified(self) -> None:
366
+ with tempfile.TemporaryDirectory() as tmpdir:
367
+ root = Path(tmpdir)
368
+ work_path = root / "work.json"
369
+ meta_path = root / "meta.json"
370
+ work_path.write_text(json.dumps(detail_to_work_payload(make_detail(), workspace="store_mgr"), ensure_ascii=False), encoding="utf-8")
371
+
372
+ update_confirmation_state(
373
+ meta_path,
374
+ stem="flow352878207",
375
+ actor="tester",
376
+ stage="work",
377
+ work_path=work_path,
378
+ runtime_acceptance={
379
+ "required": True,
380
+ "flowType": "flow352878207",
381
+ "acceptancePage": "/w:store_mgr/project/create?flow_type=flow352878207",
382
+ "freshInstanceRequired": True,
383
+ },
384
+ )
385
+ first_meta = load_json(meta_path)
386
+
387
+ update_confirmation_state(
388
+ meta_path,
389
+ stem="flow352878207",
390
+ actor="tester-2",
391
+ stage="work",
392
+ work_path=work_path,
393
+ runtime_acceptance=None,
394
+ )
395
+ meta = load_json(meta_path)
396
+ self.assertEqual(meta["runtimeAcceptance"], first_meta["runtimeAcceptance"])
397
+
398
+ def test_work_file_change_invalidates_submit_gate(self) -> None:
399
+ with tempfile.TemporaryDirectory() as tmpdir:
400
+ root = Path(tmpdir)
401
+ raw_path = root / "raw.json"
402
+ work_path = root / "work.json"
403
+ submit_path = root / "submit.json"
404
+ meta_path = root / "meta.json"
405
+ raw_detail = make_detail()
406
+ work = detail_to_work_payload(raw_detail, workspace="store_mgr")
407
+ submit = build_submit_payload(work)
408
+ raw_path.write_text(json.dumps(raw_detail, ensure_ascii=False), encoding="utf-8")
409
+ work_path.write_text(json.dumps(work, ensure_ascii=False), encoding="utf-8")
410
+ submit_path.write_text(json.dumps(submit, ensure_ascii=False), encoding="utf-8")
411
+ update_confirmation_state(meta_path, stem="flow352878207", actor="tester", stage="work", work_path=work_path, submit_path=submit_path)
412
+ update_confirmation_state(meta_path, stem="flow352878207", actor="tester", stage="submit", work_path=work_path, submit_path=submit_path)
413
+ meta = load_json(meta_path)
414
+ meta.update(
415
+ {
416
+ "mode": "edit",
417
+ "workspace": "store_mgr",
418
+ "updateTime": "2026-04-02 20:48:50",
419
+ "flowType": "flow352878207",
420
+ "workSha256": meta["workSha256"],
421
+ "submitSha256": meta["submitSha256"],
422
+ }
423
+ )
424
+ meta_path.write_text(json.dumps(meta, ensure_ascii=False), encoding="utf-8")
425
+ work["data"]["periods"].append("新增阶段")
426
+ work_path.write_text(json.dumps(work, ensure_ascii=False), encoding="utf-8")
427
+ with self.assertRaises(SystemExit):
428
+ ensure_submission_allowed(meta_path, work_path, submit_path, raw_path)
429
+
430
+ def test_submit_gate_allows_preexisting_raw_errors_when_flag_enabled(self) -> None:
431
+ with tempfile.TemporaryDirectory() as tmpdir:
432
+ root = Path(tmpdir)
433
+ raw_path = root / "raw.json"
434
+ work_path = root / "work.json"
435
+ submit_path = root / "submit.json"
436
+ meta_path = root / "meta.json"
437
+ raw_detail = make_detail()
438
+ raw_detail["data"]["nodes"][0]["approve_to_step"] = "[source]"
439
+ work = detail_to_work_payload(raw_detail, workspace="store_mgr")
440
+ submit = build_submit_payload(
441
+ work,
442
+ raw_payload=raw_detail,
443
+ allow_preexisting_lint_errors=True,
444
+ )
445
+ raw_path.write_text(json.dumps(raw_detail, ensure_ascii=False), encoding="utf-8")
446
+ work_path.write_text(json.dumps(work, ensure_ascii=False), encoding="utf-8")
447
+ submit_path.write_text(json.dumps(submit, ensure_ascii=False), encoding="utf-8")
448
+ meta_path.write_text(
449
+ json.dumps(
450
+ {
451
+ "stem": "flow352878207",
452
+ "mode": "edit",
453
+ "workspace": "store_mgr",
454
+ "flowType": "flow352878207",
455
+ "updateTime": "2026-04-02 20:48:50",
456
+ "workSha256": __import__("hashlib").sha256(work_path.read_bytes()).hexdigest(),
457
+ "submitSha256": __import__("hashlib").sha256(submit_path.read_bytes()).hexdigest(),
458
+ "workConfirmedAt": "2026-04-21T00:00:00+00:00",
459
+ "submitConfirmedAt": "2026-04-21T00:01:00+00:00",
460
+ "allowPreexistingLintErrors": True,
461
+ "status": "submit_confirmed",
462
+ },
463
+ ensure_ascii=False,
464
+ ),
465
+ encoding="utf-8",
466
+ )
467
+ meta = ensure_submission_allowed(meta_path, work_path, submit_path, raw_path)
468
+ self.assertTrue(meta["allowPreexistingLintErrors"])
469
+
470
+ def test_submit_gate_blocks_obvious_structure_regression(self) -> None:
471
+ with tempfile.TemporaryDirectory() as tmpdir:
472
+ root = Path(tmpdir)
473
+ raw_path = root / "raw.json"
474
+ work_path = root / "work.json"
475
+ submit_path = root / "submit.json"
476
+ meta_path = root / "meta.json"
477
+ raw_detail = make_detail()
478
+ work = detail_to_work_payload(raw_detail, workspace="store_mgr")
479
+ work["data"]["nodes"] = []
480
+ submit = {"name": work["basic"]["name"], "data": work["data"]}
481
+ raw_path.write_text(json.dumps(raw_detail, ensure_ascii=False), encoding="utf-8")
482
+ work_path.write_text(json.dumps(work, ensure_ascii=False), encoding="utf-8")
483
+ submit_path.write_text(json.dumps(submit, ensure_ascii=False), encoding="utf-8")
484
+ meta_path.write_text(
485
+ json.dumps(
486
+ {
487
+ "stem": "flow352878207",
488
+ "mode": "edit",
489
+ "workspace": "store_mgr",
490
+ "flowType": "flow352878207",
491
+ "updateTime": "2026-04-02 20:48:50",
492
+ "workSha256": __import__("hashlib").sha256(work_path.read_bytes()).hexdigest(),
493
+ "submitSha256": __import__("hashlib").sha256(submit_path.read_bytes()).hexdigest(),
494
+ "workConfirmedAt": "2026-04-21T00:00:00+00:00",
495
+ "submitConfirmedAt": "2026-04-21T00:01:00+00:00",
496
+ "status": "submit_confirmed",
497
+ },
498
+ ensure_ascii=False,
499
+ ),
500
+ encoding="utf-8",
501
+ )
502
+ with self.assertRaises(SystemExit):
503
+ ensure_submission_allowed(meta_path, work_path, submit_path, raw_path)
504
+
505
+ def test_verification_detects_drift_in_readback(self) -> None:
506
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), workspace="store_mgr"))
507
+ readback = make_detail()
508
+ readback["data"]["nodes"][1]["approve_fail"] = ""
509
+ verify = summarize_verification(submit, readback)
510
+ self.assertFalse(verify["ok"])
511
+ self.assertFalse(verify["checks"]["nodeSummaries"]["match"])
512
+
513
+ def test_drift_report_highlights_submit_to_draft_change(self) -> None:
514
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), workspace="store_mgr"))
515
+ readback = make_detail()
516
+ readback["data"]["meta"] = {}
517
+ drift = build_drift_report(submit, readback)
518
+ self.assertFalse(drift["ok"])
519
+ self.assertIn("metaKeys", drift["submitToDraft"]["changes"])
520
+
521
+ def test_empty_api_flow_can_fallback_to_runtime_skeleton(self) -> None:
522
+ api_detail = {"name": "未命名的流程", "data": {}}
523
+ runtime_detail = make_runtime_submit_data()
524
+ resolved, source = resolve_export_detail(api_detail, runtime_detail)
525
+ self.assertEqual(source, "runtime_fallback")
526
+ self.assertEqual(resolved["periods"][0], "销售出库")
527
+
528
+ def test_runtime_fallback_normalize_can_fill_name_and_update_time_from_live(self) -> None:
529
+ runtime_detail = make_runtime_submit_data()
530
+ normalized = normalize_flow_detail(
531
+ runtime_detail,
532
+ flow_type="flow352878207",
533
+ name="ST销售出库",
534
+ update_time="2026-04-22 16:58:41",
535
+ )
536
+ self.assertEqual(normalized["name"], "ST销售出库")
537
+ self.assertEqual(normalized["update_time"], "2026-04-22 16:58:41")
538
+
539
+ def test_flow_api_url_matches_live_editor(self) -> None:
540
+ client = ApiClient(
541
+ base_url="https://bpmax.example.com",
542
+ workspace="store_mgr",
543
+ language="zhCN",
544
+ cookie_header="token=demo",
545
+ timeout=30,
546
+ )
547
+ self.assertEqual(
548
+ client._build_url("/api/flow?flow_type=flow352878207&draft=1&skip_i18n=true"),
549
+ "https://bpmax.example.com/api/flow?flow_type=flow352878207&draft=1&skip_i18n=true&$workspace=store_mgr&$language=zhCN",
550
+ )
551
+
552
+ def test_publish_flow_uses_publish_1_endpoint(self) -> None:
553
+ client = ApiClient(
554
+ base_url="https://bpmax.example.com",
555
+ workspace="store_mgr",
556
+ language="zhCN",
557
+ cookie_header="token=demo",
558
+ timeout=30,
559
+ )
560
+ with mock.patch.object(client, "request", return_value={"code": 0}) as request:
561
+ client.publish_flow(
562
+ flow_type="flow352878207",
563
+ update_time="2026-04-02 20:48:50",
564
+ body={"name": "ST销售出库", "data": {}},
565
+ )
566
+ request.assert_called_once()
567
+ self.assertIn("publish=1", request.call_args.args[1])
568
+
569
+ def test_legacy_submit_script_is_disabled(self) -> None:
570
+ with self.assertRaises(SystemExit) as ctx:
571
+ __import__("submit_flow_template")
572
+ self.assertEqual(ctx.exception.code, 2)
573
+
574
+ def test_build_client_uses_environment_base_url(self) -> None:
575
+ args = type(
576
+ "Args",
577
+ (),
578
+ {
579
+ "base_url": None,
580
+ "workspace": "store_mgr",
581
+ "language": "zhCN",
582
+ "cookie_header": "token=demo",
583
+ "timeout": 30,
584
+ "insecure": False,
585
+ },
586
+ )()
587
+ with mock.patch.dict(os.environ, {"BPMAX_BASE_URL": "https://bpmax.example.com/"}, clear=False):
588
+ client = build_client(args)
589
+ self.assertEqual(client.base_url, "https://bpmax.example.com")
590
+
591
+ def test_build_client_requires_runtime_origin_when_not_explicitly_configured(self) -> None:
592
+ args = type(
593
+ "Args",
594
+ (),
595
+ {
596
+ "base_url": None,
597
+ "workspace": "store_mgr",
598
+ "language": "zhCN",
599
+ "cookie_header": "token=demo",
600
+ "timeout": 30,
601
+ "insecure": False,
602
+ },
603
+ )()
604
+ with mock.patch.dict(os.environ, {}, clear=True):
605
+ with self.assertRaises(SystemExit) as ctx:
606
+ build_client(args)
607
+ self.assertIn("BPMAX_BASE_URL", str(ctx.exception))
608
+
609
+ def test_skill_references_exist(self) -> None:
610
+ skill_path = Path(__file__).resolve().parents[1] / "SKILL.md"
611
+ content = skill_path.read_text(encoding="utf-8")
612
+ expected = [
613
+ "scripts/export_flow_template.py",
614
+ "scripts/build_submit_payload.py",
615
+ "scripts/confirm_flow_template.py",
616
+ "scripts/submit_flow_template.py",
617
+ "references/local-temp-workflow.md",
618
+ "references/work-file-to-submit-mapping.md",
619
+ ".codex/tmp/flow-template-editor/",
620
+ "semantic-lint.json",
621
+ "runtime-acceptance.json",
622
+ "已自动化",
623
+ "仍需人工确认",
624
+ ]
625
+ for item in expected:
626
+ self.assertIn(item, content)
627
+ for relative in [
628
+ "references/local-temp-workflow.md",
629
+ "references/work-file-to-submit-mapping.md",
630
+ "references/runtime-verified-flow-detail-shape.md",
631
+ ]:
632
+ self.assertTrue((skill_path.parent / relative).exists(), relative)
633
+
634
+
635
+ if __name__ == "__main__":
636
+ unittest.main()