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.
Files changed (251) hide show
  1. package/README.md +3 -3
  2. package/dist/bin.js +3372 -453
  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,1303 @@
1
+ import hashlib
2
+ import json
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
+ import form_template_editor_common as common
15
+ import submit_form_template as submit_script
16
+ from form_template_editor_common import (
17
+ build_drift_report,
18
+ build_publish_safety_report,
19
+ build_runtime_acceptance_payload,
20
+ build_submit_payload,
21
+ detail_to_work_payload,
22
+ ensure_submission_allowed,
23
+ extract_template_id,
24
+ lint_form_template_semantics,
25
+ load_json,
26
+ summarize_verification,
27
+ update_build_meta,
28
+ update_confirmation_state,
29
+ )
30
+
31
+
32
+ def make_detail() -> dict:
33
+ return {
34
+ "id": 990702153,
35
+ "name": "经销商样机上架申请表单",
36
+ "desc": "请输入表单描述",
37
+ "category": "",
38
+ "option": {
39
+ "form": {"inline": False, "labelPosition": "top"},
40
+ "submitBtn": False,
41
+ "isTemplate": True,
42
+ "isPreview": False,
43
+ },
44
+ "rule": [
45
+ [
46
+ {
47
+ "field": "F1mymko1vmyub8c",
48
+ "type": "h_label",
49
+ "title": None,
50
+ "form_rule_id": 1001,
51
+ "form_template_id": 990702153,
52
+ "props": {"label": "经销商样机上架申请"},
53
+ }
54
+ ],
55
+ [
56
+ {
57
+ "field": "3q96an3nsvnu",
58
+ "type": "plugin_scan_input",
59
+ "title": "SN码",
60
+ "form_rule_id": 1002,
61
+ "form_template_id": 990702153,
62
+ "lambda": "return ctx.$FORM_KEY.sn;",
63
+ "lambdaFields": ["3q96an3nsvnu"],
64
+ "quickValue": True,
65
+ }
66
+ ],
67
+ ],
68
+ "value": [
69
+ {
70
+ "field": "F1mymko1vmyub8c",
71
+ "field_type": "h_label",
72
+ "key": None,
73
+ "value": {"type": "h_label"},
74
+ "template_id": 990702153,
75
+ },
76
+ {
77
+ "field": "3q96an3nsvnu",
78
+ "field_type": "plugin_scan_input",
79
+ "key": "sn",
80
+ "value": {"type": "plugin_scan_input", "value": ""},
81
+ "template_id": 990702153,
82
+ },
83
+ ],
84
+ }
85
+
86
+
87
+ class FormTemplateEditorCommonTests(unittest.TestCase):
88
+ @staticmethod
89
+ def _lint_meta() -> dict:
90
+ return {
91
+ "stem": "990702153",
92
+ "modelingGate": {
93
+ "minimalFormMode": "minimal",
94
+ "detailEntryMode": "single",
95
+ "longTermControl": "unknown",
96
+ "layoutReviewed": True,
97
+ },
98
+ }
99
+
100
+ def test_detail_maps_to_human_editable_work_payload(self) -> None:
101
+ detail = make_detail()
102
+
103
+ work = detail_to_work_payload(detail, mode="edit")
104
+
105
+ self.assertEqual(work["id"], 990702153)
106
+ self.assertEqual(work["mode"], "edit")
107
+ self.assertEqual(work["basic"]["name"], "经销商样机上架申请表单")
108
+ self.assertEqual(work["basic"]["category"], "")
109
+ self.assertEqual(work["layout"], [["F1mymko1vmyub8c"], ["3q96an3nsvnu"]])
110
+ self.assertEqual(
111
+ work["fields"]["3q96an3nsvnu"]["keepIds"]["rule"],
112
+ ["form_rule_id", "form_template_id"],
113
+ )
114
+ self.assertEqual(work["fields"]["3q96an3nsvnu"]["keepIds"]["value"], ["template_id"])
115
+
116
+ def test_create_mode_strips_backend_ids(self) -> None:
117
+ detail = make_detail()
118
+
119
+ work = detail_to_work_payload(detail, mode="create", sample_template_id=990702153)
120
+
121
+ self.assertIsNone(work["id"])
122
+ self.assertEqual(work["mode"], "create")
123
+ self.assertEqual(work["sampleTemplateId"], 990702153)
124
+ self.assertNotIn("form_rule_id", work["fields"]["3q96an3nsvnu"]["rule"])
125
+ self.assertNotIn("form_template_id", work["fields"]["3q96an3nsvnu"]["rule"])
126
+ self.assertNotIn("template_id", work["fields"]["3q96an3nsvnu"]["value"])
127
+
128
+ def test_build_submit_payload_preserves_ids_for_edit(self) -> None:
129
+ work = detail_to_work_payload(make_detail(), mode="edit")
130
+
131
+ submit = build_submit_payload(work)
132
+
133
+ self.assertEqual(submit["name"], "经销商样机上架申请表单")
134
+ self.assertEqual(submit["category"], "")
135
+ self.assertEqual(submit["rule"][1][0]["form_rule_id"], 1002)
136
+ self.assertEqual(submit["rule"][1][0]["form_template_id"], 990702153)
137
+ self.assertEqual(submit["value"][1]["template_id"], 990702153)
138
+
139
+ def test_build_submit_payload_drops_ids_for_create(self) -> None:
140
+ work = detail_to_work_payload(make_detail(), mode="create", sample_template_id=990702153)
141
+
142
+ submit = build_submit_payload(work)
143
+
144
+ self.assertEqual(submit["category"], "")
145
+ self.assertNotIn("form_rule_id", submit["rule"][1][0])
146
+ self.assertNotIn("form_template_id", submit["rule"][1][0])
147
+ self.assertNotIn("template_id", submit["value"][1])
148
+
149
+ def test_layout_and_fields_mismatch_fails(self) -> None:
150
+ work = detail_to_work_payload(make_detail(), mode="edit")
151
+ work["layout"] = [["missing-field"]]
152
+
153
+ with self.assertRaises(SystemExit):
154
+ build_submit_payload(work)
155
+
156
+ def test_lambda_requires_quick_value_true(self) -> None:
157
+ work = detail_to_work_payload(make_detail(), mode="edit")
158
+ work["fields"]["3q96an3nsvnu"]["rule"]["quickValue"] = False
159
+
160
+ with self.assertRaises(SystemExit):
161
+ build_submit_payload(work)
162
+
163
+ def test_semantic_lint_blocks_project_list_query(self) -> None:
164
+ work = detail_to_work_payload(make_detail(), mode="edit")
165
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = (
166
+ "return ctx.$axios.post('/bpmax/project/list?page=1', { flow_type: 'flow716', query: {} });"
167
+ )
168
+
169
+ report = lint_form_template_semantics(
170
+ work,
171
+ meta=self._lint_meta(),
172
+ )
173
+
174
+ self.assertFalse(report["ok"])
175
+ self.assertTrue(any("project/list" in err for err in report["errors"]))
176
+
177
+ def test_lint_blocks_editable_auto_filled_target_from_setvalue_helper(self) -> None:
178
+ detail = make_detail()
179
+ detail["rule"].append(
180
+ [
181
+ {
182
+ "field": "Freturndatex1",
183
+ "type": "bp-date-picker",
184
+ "title": "退货时间",
185
+ "form_rule_id": 1003,
186
+ "form_template_id": 990702153,
187
+ "props": {"type": "datetime", "disabled": False},
188
+ "hidden": False,
189
+ }
190
+ ]
191
+ )
192
+ detail["value"].append(
193
+ {
194
+ "field": "Freturndatex1",
195
+ "field_type": "bp-date-picker",
196
+ "key": "ex_time",
197
+ "value": {"type": "bp-date-picker", "value": ""},
198
+ "template_id": 990702153,
199
+ }
200
+ )
201
+ work = detail_to_work_payload(detail, mode="edit")
202
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = (
203
+ "{ const setValue = (payload) => ctx.$setValueByKeyToValue(payload); "
204
+ "const base = { ex_time: '2026-05-01 10:00:00' }; setValue({ ...base }); }"
205
+ )
206
+
207
+ report = lint_form_template_semantics(work, meta=self._lint_meta())
208
+
209
+ self.assertFalse(report["ok"])
210
+ self.assertTrue(any("Freturndatex1: auto-filled field key=ex_time" in err for err in report["errors"]))
211
+
212
+ def test_lint_allows_self_managed_i_input_lambda(self) -> None:
213
+ detail = make_detail()
214
+ detail["rule"][1][0]["type"] = "i_input"
215
+ detail["rule"][1][0]["lambda"] = "return ctx.$FORM_KEY.sn;"
216
+ detail["rule"][1][0]["quickValue"] = True
217
+ detail["value"][1]["field_type"] = "i_input"
218
+ detail["value"][1]["value"] = {"type": "i_input", "value": ""}
219
+
220
+ work = detail_to_work_payload(detail, mode="edit")
221
+ report = lint_form_template_semantics(work, meta=self._lint_meta())
222
+
223
+ self.assertTrue(report["ok"], report["errors"])
224
+ self.assertFalse(any("auto-filled field key=sn must be non-editable" in err for err in report["errors"]))
225
+
226
+ def test_lint_allows_raw_auto_filled_target_from_api_setvalue(self) -> None:
227
+ detail = make_detail()
228
+ detail["rule"].append(
229
+ [
230
+ {
231
+ "field": "Fsalepersonx1",
232
+ "type": "raw",
233
+ "title": "销售员",
234
+ "form_rule_id": 1003,
235
+ "form_template_id": 990702153,
236
+ "props": {"disabled": False},
237
+ "hidden": False,
238
+ }
239
+ ]
240
+ )
241
+ detail["value"].append(
242
+ {
243
+ "field": "Fsalepersonx1",
244
+ "field_type": "raw",
245
+ "key": "salesman",
246
+ "value": {"type": "raw", "value": ""},
247
+ "template_id": 990702153,
248
+ }
249
+ )
250
+ work = detail_to_work_payload(detail, mode="edit")
251
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = (
252
+ "{ ctx.$API.setValue('Fsalepersonx1', 'tester'); }"
253
+ )
254
+
255
+ report = lint_form_template_semantics(work, meta=self._lint_meta())
256
+
257
+ self.assertTrue(report["ok"])
258
+ self.assertTrue(report["checks"]["autoFilledFields"]["Fsalepersonx1"]["ok"])
259
+
260
+ def test_lint_blocks_input_auto_filled_target_from_api_setvalue(self) -> None:
261
+ detail = make_detail()
262
+ detail["rule"].append(
263
+ [
264
+ {
265
+ "field": "Fdealercode1",
266
+ "type": "i_input",
267
+ "title": "经销商编码",
268
+ "form_rule_id": 1003,
269
+ "form_template_id": 990702153,
270
+ "props": {"disabled": False},
271
+ "hidden": False,
272
+ }
273
+ ]
274
+ )
275
+ detail["value"].append(
276
+ {
277
+ "field": "Fdealercode1",
278
+ "field_type": "i_input",
279
+ "key": "dealer_code",
280
+ "value": {"type": "i_input", "value": ""},
281
+ "template_id": 990702153,
282
+ }
283
+ )
284
+ work = detail_to_work_payload(detail, mode="edit")
285
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = (
286
+ "{ ctx.$API.setValue('Fdealercode1', 'D001'); }"
287
+ )
288
+
289
+ report = lint_form_template_semantics(work, meta=self._lint_meta())
290
+
291
+ self.assertFalse(report["ok"])
292
+ self.assertTrue(any("Fdealercode1: auto-filled field must be non-editable" in err for err in report["errors"]))
293
+
294
+ def test_lint_does_not_misread_query_object_keys_as_autofill_targets(self) -> None:
295
+ detail = make_detail()
296
+ detail["rule"].append(
297
+ [
298
+ {
299
+ "field": "Freturndatex1",
300
+ "type": "bp-date-picker",
301
+ "title": "退货时间",
302
+ "form_rule_id": 1003,
303
+ "form_template_id": 990702153,
304
+ "props": {"type": "datetime", "disabled": False},
305
+ "hidden": False,
306
+ }
307
+ ]
308
+ )
309
+ detail["value"].append(
310
+ {
311
+ "field": "Freturndatex1",
312
+ "field_type": "bp-date-picker",
313
+ "key": "ex_time",
314
+ "value": {"type": "bp-date-picker", "value": ""},
315
+ "template_id": 990702153,
316
+ }
317
+ )
318
+ work = detail_to_work_payload(detail, mode="edit")
319
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = (
320
+ "{ const setValue = (payload) => { ctx.$setValueByKeyToValue(payload); }; "
321
+ "const query = { ex_time: { gte: '2026-01-01' } }; "
322
+ "setValue({ gate_status: 'ok' }); return query; }"
323
+ )
324
+
325
+ report = lint_form_template_semantics(work, meta=self._lint_meta())
326
+
327
+ self.assertTrue(report["ok"])
328
+ self.assertFalse(any("key=ex_time" in err for err in report["errors"]))
329
+ self.assertNotIn("ex_time", report["checks"]["autoFilledFields"])
330
+
331
+ def test_removed_fields_delete_from_rule_and_value(self) -> None:
332
+ work = detail_to_work_payload(make_detail(), mode="edit")
333
+ work["layout"] = [["3q96an3nsvnu"]]
334
+ work["removedFields"] = ["F1mymko1vmyub8c"]
335
+
336
+ submit = build_submit_payload(work)
337
+
338
+ self.assertEqual(len(submit["rule"]), 1)
339
+ self.assertEqual(len(submit["value"]), 1)
340
+ self.assertEqual(submit["value"][0]["field"], "3q96an3nsvnu")
341
+
342
+ def test_build_meta_resets_submit_confirmation_after_work_change(self) -> None:
343
+ with tempfile.TemporaryDirectory() as tmpdir:
344
+ root = Path(tmpdir)
345
+ work_path = root / "work.json"
346
+ submit_path = root / "submit.json"
347
+ meta_path = root / "meta.json"
348
+ work_path.write_text(json.dumps({"name": "v1"}, ensure_ascii=False), encoding="utf-8")
349
+ submit_path.write_text(json.dumps({"name": "s1"}, ensure_ascii=False), encoding="utf-8")
350
+ meta_path.write_text(
351
+ json.dumps(
352
+ {
353
+ "stem": "990702153",
354
+ "mode": "edit",
355
+ "workspace": "store_mgr",
356
+ "workSha256": hashlib.sha256(work_path.read_bytes()).hexdigest(),
357
+ "status": "work_confirmed",
358
+ "workConfirmedAt": "2026-04-21T00:00:00+00:00",
359
+ "workConfirmedBy": "tester",
360
+ "submitConfirmedAt": "2026-04-21T00:01:00+00:00",
361
+ "submitConfirmedBy": "tester",
362
+ },
363
+ ensure_ascii=False,
364
+ ),
365
+ encoding="utf-8",
366
+ )
367
+
368
+ work_path.write_text(json.dumps({"name": "v2"}, ensure_ascii=False), encoding="utf-8")
369
+ update_build_meta(meta_path, stem="990702153", work_path=work_path, submit_path=submit_path)
370
+ meta = load_json(meta_path)
371
+ self.assertIsNone(meta["workConfirmedAt"])
372
+ self.assertIsNone(meta["submitConfirmedAt"])
373
+ self.assertEqual(meta["status"], "submit_built")
374
+
375
+ def test_work_confirmation_persists_runtime_acceptance_requirements(self) -> None:
376
+ with tempfile.TemporaryDirectory() as tmpdir:
377
+ root = Path(tmpdir)
378
+ work_path = root / "work.json"
379
+ meta_path = root / "meta.json"
380
+ work_path.write_text(json.dumps({"name": "v1"}, ensure_ascii=False), encoding="utf-8")
381
+
382
+ update_confirmation_state(
383
+ meta_path,
384
+ stem="990702153",
385
+ actor="tester",
386
+ stage="work",
387
+ work_path=work_path,
388
+ modeling_gate={
389
+ "minimalFormMode": "minimal",
390
+ "detailEntryMode": "single",
391
+ "longTermControl": "unknown",
392
+ "layoutReviewed": True,
393
+ },
394
+ runtime_acceptance={
395
+ "required": True,
396
+ "flowType": "flow451422190",
397
+ "acceptancePage": "/w:store_mgr/apply/create",
398
+ "freshInstanceRequired": True,
399
+ },
400
+ )
401
+
402
+ meta = load_json(meta_path)
403
+ self.assertTrue(meta["runtimeAcceptance"]["required"])
404
+ self.assertEqual(meta["runtimeAcceptance"]["flowType"], "flow451422190")
405
+ self.assertTrue(meta["runtimeAcceptance"]["freshInstanceRequired"])
406
+
407
+ def test_work_confirmation_preserves_existing_runtime_acceptance_when_unspecified(self) -> None:
408
+ with tempfile.TemporaryDirectory() as tmpdir:
409
+ root = Path(tmpdir)
410
+ work_path = root / "work.json"
411
+ meta_path = root / "meta.json"
412
+ work_path.write_text(json.dumps({"name": "v1"}, ensure_ascii=False), encoding="utf-8")
413
+
414
+ modeling_gate = {
415
+ "minimalFormMode": "minimal",
416
+ "detailEntryMode": "single",
417
+ "longTermControl": "unknown",
418
+ "layoutReviewed": True,
419
+ }
420
+ update_confirmation_state(
421
+ meta_path,
422
+ stem="990702153",
423
+ actor="tester",
424
+ stage="work",
425
+ work_path=work_path,
426
+ modeling_gate=modeling_gate,
427
+ runtime_acceptance={
428
+ "required": True,
429
+ "flowType": "flow451422190",
430
+ "acceptancePage": "/w:store_mgr/apply/create",
431
+ "freshInstanceRequired": True,
432
+ },
433
+ )
434
+ first_meta = load_json(meta_path)
435
+
436
+ update_confirmation_state(
437
+ meta_path,
438
+ stem="990702153",
439
+ actor="tester-2",
440
+ stage="work",
441
+ work_path=work_path,
442
+ modeling_gate=modeling_gate,
443
+ runtime_acceptance=None,
444
+ )
445
+ meta = load_json(meta_path)
446
+ self.assertEqual(meta["runtimeAcceptance"], first_meta["runtimeAcceptance"])
447
+
448
+ def test_submission_gate_requires_confirmed_state_and_matching_hashes(self) -> None:
449
+ with tempfile.TemporaryDirectory() as tmpdir:
450
+ root = Path(tmpdir)
451
+ work_path = root / "work.json"
452
+ submit_path = root / "submit.json"
453
+ meta_path = root / "meta.json"
454
+ work_path.write_text(json.dumps({"name": "work-v1"}, ensure_ascii=False), encoding="utf-8")
455
+ submit_path.write_text(json.dumps({"name": "submit-v1"}, ensure_ascii=False), encoding="utf-8")
456
+ meta_path.write_text(
457
+ json.dumps({"stem": "990702153", "mode": "edit", "workspace": "store_mgr"}, ensure_ascii=False),
458
+ encoding="utf-8",
459
+ )
460
+
461
+ with self.assertRaises(SystemExit):
462
+ ensure_submission_allowed(meta_path, work_path, submit_path)
463
+
464
+ update_confirmation_state(
465
+ meta_path,
466
+ stem="990702153",
467
+ actor="tester",
468
+ stage="work",
469
+ work_path=work_path,
470
+ modeling_gate={
471
+ "minimalFormMode": "minimal",
472
+ "detailEntryMode": "single",
473
+ "longTermControl": "unknown",
474
+ "layoutReviewed": True,
475
+ },
476
+ runtime_acceptance={
477
+ "required": True,
478
+ "flowType": "flow352878207",
479
+ "acceptancePage": "/w:store_mgr/apply/create",
480
+ "freshInstanceRequired": True,
481
+ },
482
+ )
483
+ with self.assertRaises(SystemExit):
484
+ ensure_submission_allowed(meta_path, work_path, submit_path)
485
+
486
+ update_build_meta(meta_path, stem="990702153", work_path=work_path, submit_path=submit_path)
487
+ with self.assertRaises(SystemExit):
488
+ ensure_submission_allowed(meta_path, work_path, submit_path)
489
+
490
+ update_confirmation_state(
491
+ meta_path,
492
+ stem="990702153",
493
+ actor="tester",
494
+ stage="work",
495
+ work_path=work_path,
496
+ submit_path=submit_path,
497
+ modeling_gate={
498
+ "minimalFormMode": "minimal",
499
+ "detailEntryMode": "single",
500
+ "longTermControl": "unknown",
501
+ "layoutReviewed": True,
502
+ },
503
+ runtime_acceptance={
504
+ "required": False,
505
+ "flowType": None,
506
+ "acceptancePage": None,
507
+ "freshInstanceRequired": False,
508
+ },
509
+ )
510
+ with self.assertRaises(SystemExit):
511
+ ensure_submission_allowed(meta_path, work_path, submit_path)
512
+
513
+ update_build_meta(meta_path, stem="990702153", work_path=work_path, submit_path=submit_path)
514
+ update_confirmation_state(
515
+ meta_path,
516
+ stem="990702153",
517
+ actor="tester",
518
+ stage="submit",
519
+ work_path=work_path,
520
+ submit_path=submit_path,
521
+ )
522
+
523
+ ensure_submission_allowed(meta_path, work_path, submit_path)
524
+ submit_path.write_text(json.dumps({"name": "submit-v2"}, ensure_ascii=False), encoding="utf-8")
525
+ with self.assertRaises(SystemExit):
526
+ ensure_submission_allowed(meta_path, work_path, submit_path)
527
+
528
+ def test_verification_tracks_field_level_runtime_keys(self) -> None:
529
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), mode="edit"))
530
+ readback = make_detail()
531
+
532
+ verify = summarize_verification(submit, readback)
533
+
534
+ self.assertTrue(verify["ok"])
535
+ self.assertEqual(verify["checks"]["category"]["expected"], "")
536
+ self.assertEqual(verify["fields"]["3q96an3nsvnu"]["actual"]["quickValue"], True)
537
+ self.assertEqual(verify["checks"]["rowShapes"]["expected"], [1, 1])
538
+
539
+ def test_verification_detects_field_mismatch(self) -> None:
540
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), mode="edit"))
541
+ readback = make_detail()
542
+ readback["value"][1]["key"] = "sn_code"
543
+
544
+ verify = summarize_verification(submit, readback)
545
+
546
+ self.assertFalse(verify["ok"])
547
+ self.assertEqual(verify["fields"]["3q96an3nsvnu"]["expected"]["key"], "sn")
548
+ self.assertEqual(verify["fields"]["3q96an3nsvnu"]["actual"]["key"], "sn_code")
549
+
550
+ def test_verification_detects_category_mismatch(self) -> None:
551
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), mode="edit"))
552
+ readback = make_detail()
553
+ readback["category"] = "sample-category"
554
+
555
+ verify = summarize_verification(submit, readback)
556
+
557
+ self.assertFalse(verify["ok"])
558
+ self.assertEqual(verify["checks"]["category"]["expected"], "")
559
+ self.assertEqual(verify["checks"]["category"]["actual"], "sample-category")
560
+
561
+ def test_lint_blocks_ctx_esquery_in_ordinary_lambda(self) -> None:
562
+ work = detail_to_work_payload(make_detail(), mode="edit")
563
+ work["fields"]["3q96an3nsvnu"]["rule"]["lambda"] = "return ctx.$esQuery({});"
564
+ submit = build_submit_payload(work)
565
+
566
+ report = lint_form_template_semantics(
567
+ work,
568
+ meta={
569
+ "stem": "990702153",
570
+ "modelingGate": {
571
+ "minimalFormMode": "minimal",
572
+ "detailEntryMode": "single",
573
+ "longTermControl": "unknown",
574
+ "layoutReviewed": True,
575
+ },
576
+ },
577
+ submit_payload=submit,
578
+ )
579
+
580
+ self.assertFalse(report["ok"])
581
+ self.assertTrue(any("ctx.$esQuery" in message for message in report["errors"]))
582
+
583
+ def test_lint_blocks_incomplete_custome_validate(self) -> None:
584
+ work = detail_to_work_payload(make_detail(), mode="edit")
585
+ work["fields"]["3q96an3nsvnu"]["rule"]["customeValidate"] = {"content": "return true;"}
586
+ submit = build_submit_payload(work)
587
+
588
+ report = lint_form_template_semantics(
589
+ work,
590
+ meta={
591
+ "stem": "990702153",
592
+ "modelingGate": {
593
+ "minimalFormMode": "minimal",
594
+ "detailEntryMode": "single",
595
+ "longTermControl": "unknown",
596
+ "layoutReviewed": True,
597
+ },
598
+ },
599
+ submit_payload=submit,
600
+ )
601
+
602
+ self.assertFalse(report["ok"])
603
+ self.assertTrue(any("shouldValidate" in message for message in report["errors"]))
604
+ self.assertTrue(any("trigger" in message for message in report["errors"]))
605
+
606
+ def test_lint_warns_on_risky_raw_shape(self) -> None:
607
+ detail = make_detail()
608
+ detail["rule"].append(
609
+ [
610
+ {
611
+ "field": "raw-field",
612
+ "type": "raw",
613
+ "title": "回显字段",
614
+ "hidden": False,
615
+ "props": {"disabled": True},
616
+ }
617
+ ]
618
+ )
619
+ detail["value"].append(
620
+ {
621
+ "field": "raw-field",
622
+ "field_type": "raw",
623
+ "key": "rawDisplay",
624
+ "value": {"type": "raw"},
625
+ }
626
+ )
627
+ work = detail_to_work_payload(detail, mode="edit")
628
+ submit = build_submit_payload(work)
629
+
630
+ report = lint_form_template_semantics(
631
+ work,
632
+ meta={
633
+ "stem": "990702153",
634
+ "modelingGate": {
635
+ "minimalFormMode": "rich",
636
+ "detailEntryMode": "single",
637
+ "longTermControl": "unknown",
638
+ "layoutReviewed": True,
639
+ },
640
+ },
641
+ submit_payload=submit,
642
+ )
643
+
644
+ self.assertTrue(any("raw field uses always-visible disabled shape" in message for message in report["warnings"]))
645
+
646
+ def test_lint_blocks_visible_lambda_init_raw_autofill_when_editable(self) -> None:
647
+ detail = make_detail()
648
+ detail["rule"].append(
649
+ [
650
+ {
651
+ "field": "auto-salesman",
652
+ "type": "raw",
653
+ "title": "销售员",
654
+ "hidden": False,
655
+ "lambda": "return ctx?.userInfo?.name || '';",
656
+ "lambdaInit": True,
657
+ "quickValue": True,
658
+ "props": {"disabled": False},
659
+ }
660
+ ]
661
+ )
662
+ detail["value"].append(
663
+ {
664
+ "field": "auto-salesman",
665
+ "field_type": "raw",
666
+ "key": "salesman",
667
+ "value": {"type": "raw"},
668
+ }
669
+ )
670
+ work = detail_to_work_payload(detail, mode="edit")
671
+ submit = build_submit_payload(work)
672
+
673
+ report = lint_form_template_semantics(
674
+ work,
675
+ meta={
676
+ "stem": "990702153",
677
+ "modelingGate": {
678
+ "minimalFormMode": "minimal",
679
+ "detailEntryMode": "single",
680
+ "longTermControl": "unknown",
681
+ "layoutReviewed": True,
682
+ },
683
+ },
684
+ submit_payload=submit,
685
+ )
686
+
687
+ self.assertFalse(report["ok"])
688
+ self.assertTrue(any("visible auto-filled raw/data field must be disabled" in message for message in report["errors"]))
689
+
690
+ def test_lint_blocks_visible_script_owned_datetime_when_editable(self) -> None:
691
+ detail = make_detail()
692
+ detail["rule"].extend(
693
+ [
694
+ [
695
+ {
696
+ "field": "auto-driver",
697
+ "type": "raw",
698
+ "title": "回填驱动",
699
+ "hidden": True,
700
+ "lambda": "ctx.$setValueByKeyToValue({ ex_time: '2026-05-01 10:00:00' }); return '';",
701
+ "quickValue": True,
702
+ }
703
+ ],
704
+ [
705
+ {
706
+ "field": "visible-time",
707
+ "type": "bp-date-picker",
708
+ "title": "退换货时间",
709
+ "hidden": False,
710
+ "props": {"type": "datetime", "disabled": False},
711
+ }
712
+ ],
713
+ ]
714
+ )
715
+ detail["value"].extend(
716
+ [
717
+ {
718
+ "field": "auto-driver",
719
+ "field_type": "raw",
720
+ "key": "auto_driver",
721
+ "value": {"type": "raw"},
722
+ },
723
+ {
724
+ "field": "visible-time",
725
+ "field_type": "bp-date-picker",
726
+ "key": "ex_time",
727
+ "value": {"type": "bp-date-picker", "value": ""},
728
+ },
729
+ ]
730
+ )
731
+ work = detail_to_work_payload(detail, mode="edit")
732
+ submit = build_submit_payload(work)
733
+
734
+ report = lint_form_template_semantics(
735
+ work,
736
+ meta={
737
+ "stem": "990702153",
738
+ "modelingGate": {
739
+ "minimalFormMode": "minimal",
740
+ "detailEntryMode": "single",
741
+ "longTermControl": "unknown",
742
+ "layoutReviewed": True,
743
+ },
744
+ },
745
+ submit_payload=submit,
746
+ )
747
+
748
+ self.assertFalse(report["ok"])
749
+ self.assertTrue(any("key=ex_time must be non-editable" in message for message in report["errors"]))
750
+
751
+ def test_lint_blocks_visible_script_owned_input_when_editable(self) -> None:
752
+ detail = make_detail()
753
+ detail["rule"].extend(
754
+ [
755
+ [
756
+ {
757
+ "field": "auto-driver",
758
+ "type": "raw",
759
+ "title": "回填驱动",
760
+ "hidden": True,
761
+ "lambda": "ctx.$setValueByKeyToValue({ sku: 'SKU-001' }); return '';",
762
+ "quickValue": True,
763
+ }
764
+ ],
765
+ [
766
+ {
767
+ "field": "visible-sku",
768
+ "type": "i_input",
769
+ "title": "SKU",
770
+ "hidden": False,
771
+ "props": {"disabled": False},
772
+ }
773
+ ],
774
+ ]
775
+ )
776
+ detail["value"].extend(
777
+ [
778
+ {
779
+ "field": "auto-driver",
780
+ "field_type": "raw",
781
+ "key": "auto_driver",
782
+ "value": {"type": "raw"},
783
+ },
784
+ {
785
+ "field": "visible-sku",
786
+ "field_type": "i_input",
787
+ "key": "sku",
788
+ "value": {"type": "i_input", "value": ""},
789
+ },
790
+ ]
791
+ )
792
+ work = detail_to_work_payload(detail, mode="edit")
793
+ submit = build_submit_payload(work)
794
+
795
+ report = lint_form_template_semantics(
796
+ work,
797
+ meta=self._lint_meta(),
798
+ submit_payload=submit,
799
+ )
800
+
801
+ self.assertFalse(report["ok"])
802
+ self.assertTrue(any("key=sku must be non-editable" in message for message in report["errors"]))
803
+
804
+ def test_lint_does_not_block_manual_scan_input_synced_by_script(self) -> None:
805
+ detail = make_detail()
806
+ detail["rule"].append(
807
+ [
808
+ {
809
+ "field": "choice-driver",
810
+ "type": "raw",
811
+ "title": "候选驱动",
812
+ "hidden": True,
813
+ "lambda": "ctx.$setValueByKeyToValue({ sn: 'SN001' }); return '';",
814
+ "quickValue": True,
815
+ }
816
+ ]
817
+ )
818
+ detail["value"].append(
819
+ {
820
+ "field": "choice-driver",
821
+ "field_type": "raw",
822
+ "key": "choice_driver",
823
+ "value": {"type": "raw"},
824
+ }
825
+ )
826
+ work = detail_to_work_payload(detail, mode="edit")
827
+ submit = build_submit_payload(work)
828
+
829
+ report = lint_form_template_semantics(
830
+ work,
831
+ meta={
832
+ "stem": "990702153",
833
+ "modelingGate": {
834
+ "minimalFormMode": "minimal",
835
+ "detailEntryMode": "single",
836
+ "longTermControl": "unknown",
837
+ "layoutReviewed": True,
838
+ },
839
+ },
840
+ submit_payload=submit,
841
+ )
842
+
843
+ self.assertTrue(report["ok"])
844
+ self.assertFalse(any("visible script-owned field must be disabled" in message for message in report["errors"]))
845
+
846
+ def test_lint_blocks_visible_meta_hint_auto_readonly_key_when_editable(self) -> None:
847
+ detail = make_detail()
848
+ detail["rule"].append(
849
+ [
850
+ {
851
+ "field": "dealer-code",
852
+ "type": "i_input",
853
+ "title": "经销商编码",
854
+ "hidden": False,
855
+ "props": {"disabled": False},
856
+ }
857
+ ]
858
+ )
859
+ detail["value"].append(
860
+ {
861
+ "field": "dealer-code",
862
+ "field_type": "i_input",
863
+ "key": "robo_salechannelcode",
864
+ "value": {"type": "i_input"},
865
+ }
866
+ )
867
+ work = detail_to_work_payload(detail, mode="edit")
868
+ submit = build_submit_payload(work)
869
+
870
+ report = lint_form_template_semantics(
871
+ work,
872
+ meta={
873
+ "stem": "990702153",
874
+ "modelingGate": {
875
+ "minimalFormMode": "minimal",
876
+ "detailEntryMode": "single",
877
+ "longTermControl": "unknown",
878
+ "layoutReviewed": True,
879
+ },
880
+ "lintHints": {
881
+ "autoReadonlyKeys": ["robo_salechannelcode"],
882
+ },
883
+ },
884
+ submit_payload=submit,
885
+ )
886
+
887
+ self.assertFalse(report["ok"])
888
+ self.assertTrue(
889
+ any(
890
+ "auto-filled field key=robo_salechannelcode must be non-editable" in message
891
+ for message in report["errors"]
892
+ )
893
+ )
894
+
895
+ def test_lint_accepts_disabled_meta_hint_auto_readonly_key(self) -> None:
896
+ detail = make_detail()
897
+ detail["rule"].append(
898
+ [
899
+ {
900
+ "field": "dealer-code",
901
+ "type": "i_input",
902
+ "title": "经销商编码",
903
+ "hidden": False,
904
+ "props": {"disabled": True},
905
+ }
906
+ ]
907
+ )
908
+ detail["value"].append(
909
+ {
910
+ "field": "dealer-code",
911
+ "field_type": "i_input",
912
+ "key": "robo_salechannelcode",
913
+ "value": {"type": "i_input"},
914
+ }
915
+ )
916
+ work = detail_to_work_payload(detail, mode="edit")
917
+ submit = build_submit_payload(work)
918
+
919
+ report = lint_form_template_semantics(
920
+ work,
921
+ meta={
922
+ "stem": "990702153",
923
+ "modelingGate": {
924
+ "minimalFormMode": "minimal",
925
+ "detailEntryMode": "single",
926
+ "longTermControl": "unknown",
927
+ "layoutReviewed": True,
928
+ },
929
+ "lintHints": {
930
+ "autoReadonlyKeys": ["robo_salechannelcode"],
931
+ },
932
+ },
933
+ submit_payload=submit,
934
+ )
935
+
936
+ self.assertTrue(report["ok"])
937
+ self.assertFalse(
938
+ any(
939
+ "auto-filled field key=robo_salechannelcode must be non-editable" in message
940
+ for message in report["errors"]
941
+ )
942
+ )
943
+
944
+ def test_lint_blocks_hidden_self_lambda_input_without_disabled(self) -> None:
945
+ detail = make_detail()
946
+ detail["rule"].append(
947
+ [
948
+ {
949
+ "field": "dealer-sap",
950
+ "type": "i_input",
951
+ "title": "经销商SAP编码",
952
+ "hidden": True,
953
+ "quickValue": True,
954
+ "lambda": "{ return 'SAP2026-4'; }",
955
+ "lambdaFields": ["3q96an3nsvnu"],
956
+ "props": {"disabled": False},
957
+ }
958
+ ]
959
+ )
960
+ detail["value"].append(
961
+ {
962
+ "field": "dealer-sap",
963
+ "field_type": "i_input",
964
+ "key": "dealer_sap_code",
965
+ "value": {"type": "i_input"},
966
+ }
967
+ )
968
+ work = detail_to_work_payload(detail, mode="edit")
969
+ submit = build_submit_payload(work)
970
+
971
+ report = lint_form_template_semantics(work, meta=self._lint_meta(), submit_payload=submit)
972
+
973
+ self.assertFalse(report["ok"])
974
+ self.assertTrue(
975
+ any(
976
+ "auto-filled field key=dealer_sap_code must be non-editable" in message
977
+ for message in report["errors"]
978
+ )
979
+ )
980
+
981
+ def test_lint_accepts_hidden_self_lambda_input_when_disabled(self) -> None:
982
+ detail = make_detail()
983
+ detail["rule"].append(
984
+ [
985
+ {
986
+ "field": "dealer-sap",
987
+ "type": "i_input",
988
+ "title": "经销商SAP编码",
989
+ "hidden": True,
990
+ "quickValue": True,
991
+ "lambda": "{ return 'SAP2026-4'; }",
992
+ "lambdaFields": ["3q96an3nsvnu"],
993
+ "props": {"disabled": True},
994
+ }
995
+ ]
996
+ )
997
+ detail["value"].append(
998
+ {
999
+ "field": "dealer-sap",
1000
+ "field_type": "i_input",
1001
+ "key": "dealer_sap_code",
1002
+ "value": {"type": "i_input"},
1003
+ }
1004
+ )
1005
+ work = detail_to_work_payload(detail, mode="edit")
1006
+ submit = build_submit_payload(work)
1007
+
1008
+ report = lint_form_template_semantics(work, meta=self._lint_meta(), submit_payload=submit)
1009
+
1010
+ self.assertTrue(report["ok"])
1011
+
1012
+ def test_lint_blocks_missing_meta_hint_auto_readonly_key(self) -> None:
1013
+ work = detail_to_work_payload(make_detail(), mode="edit")
1014
+ submit = build_submit_payload(work)
1015
+
1016
+ report = lint_form_template_semantics(
1017
+ work,
1018
+ meta={
1019
+ **self._lint_meta(),
1020
+ "lintHints": {
1021
+ "autoReadonlyKeys": ["missing_auto_readonly_key"],
1022
+ },
1023
+ },
1024
+ submit_payload=submit,
1025
+ )
1026
+
1027
+ self.assertFalse(report["ok"])
1028
+ self.assertTrue(
1029
+ any(
1030
+ "auto-filled key missing_auto_readonly_key from meta.lintHints.autoReadonlyKeys not found in submit payload"
1031
+ in message
1032
+ for message in report["errors"]
1033
+ )
1034
+ )
1035
+
1036
+ def test_lint_blocks_when_sub_form_is_required_but_missing(self) -> None:
1037
+ work = detail_to_work_payload(make_detail(), mode="edit")
1038
+ submit = build_submit_payload(work)
1039
+
1040
+ report = lint_form_template_semantics(
1041
+ work,
1042
+ meta={
1043
+ "stem": "990702153",
1044
+ "modelingGate": {
1045
+ "minimalFormMode": "minimal",
1046
+ "detailEntryMode": "sub_form_required",
1047
+ "longTermControl": "unknown",
1048
+ "layoutReviewed": True,
1049
+ },
1050
+ },
1051
+ submit_payload=submit,
1052
+ )
1053
+
1054
+ self.assertFalse(report["ok"])
1055
+ self.assertTrue(any("requires sub_form" in message for message in report["errors"]))
1056
+
1057
+ def test_lint_blocks_sub_form_binding_draft_child(self) -> None:
1058
+ detail = make_detail()
1059
+ detail["rule"].append(
1060
+ [
1061
+ {
1062
+ "field": "sub-form-field",
1063
+ "type": "sub_form",
1064
+ "title": "SN明细",
1065
+ "props": {
1066
+ "mode": "table",
1067
+ "form_template": {"id": 100, "origin_template_id": 0, "status": 0},
1068
+ },
1069
+ }
1070
+ ]
1071
+ )
1072
+ detail["value"].append(
1073
+ {
1074
+ "field": "sub-form-field",
1075
+ "field_type": "sub_form",
1076
+ "key": "list",
1077
+ "value": {"type": "sub_form"},
1078
+ }
1079
+ )
1080
+ work = detail_to_work_payload(detail, mode="edit")
1081
+ submit = build_submit_payload(work)
1082
+
1083
+ report = lint_form_template_semantics(
1084
+ work,
1085
+ meta={
1086
+ "stem": "990702153",
1087
+ "modelingGate": {
1088
+ "minimalFormMode": "minimal",
1089
+ "detailEntryMode": "sub_form_required",
1090
+ "longTermControl": "unknown",
1091
+ "layoutReviewed": True,
1092
+ },
1093
+ },
1094
+ submit_payload=submit,
1095
+ )
1096
+
1097
+ self.assertFalse(report["ok"])
1098
+ self.assertTrue(any("draft child template id" in message for message in report["errors"]))
1099
+
1100
+ def test_submission_gate_requires_modeling_decisions(self) -> None:
1101
+ with tempfile.TemporaryDirectory() as tmpdir:
1102
+ root = Path(tmpdir)
1103
+ work_path = root / "work.json"
1104
+ submit_path = root / "submit.json"
1105
+ meta_path = root / "meta.json"
1106
+ work_payload = detail_to_work_payload(make_detail(), mode="edit")
1107
+ submit_payload = build_submit_payload(work_payload)
1108
+ work_path.write_text(json.dumps(work_payload, ensure_ascii=False), encoding="utf-8")
1109
+ submit_path.write_text(json.dumps(submit_payload, ensure_ascii=False), encoding="utf-8")
1110
+ meta_path.write_text(
1111
+ json.dumps(
1112
+ {
1113
+ "stem": "990702153",
1114
+ "mode": "edit",
1115
+ "workspace": "store_mgr",
1116
+ "workSha256": hashlib.sha256(work_path.read_bytes()).hexdigest(),
1117
+ "submitSha256": hashlib.sha256(submit_path.read_bytes()).hexdigest(),
1118
+ "workConfirmedAt": "2026-04-21T00:00:00+00:00",
1119
+ "submitConfirmedAt": "2026-04-21T00:01:00+00:00",
1120
+ "submitBuiltAt": "2026-04-21T00:00:30+00:00",
1121
+ "status": "submit_confirmed",
1122
+ "modelingGatePassed": False,
1123
+ },
1124
+ ensure_ascii=False,
1125
+ ),
1126
+ encoding="utf-8",
1127
+ )
1128
+
1129
+ with self.assertRaises(SystemExit):
1130
+ ensure_submission_allowed(meta_path, work_path, submit_path)
1131
+
1132
+ def test_publish_safety_blocks_missing_published_runtime_fields(self) -> None:
1133
+ work = detail_to_work_payload(make_detail(), mode="edit")
1134
+ submit = build_submit_payload(work)
1135
+ submit["rule"][1][0]["lambda"] = ""
1136
+ submit["rule"][1][0]["quickValue"] = False
1137
+
1138
+ with tempfile.TemporaryDirectory() as tmpdir:
1139
+ repo_root = Path(tmpdir)
1140
+ published_dir = (
1141
+ repo_root
1142
+ / "think_form_template"
1143
+ / "uuid'test-uuid___is_del'0___origin_template_id'!0"
1144
+ / "think_form_rule"
1145
+ / "field'3q96an3nsvnu"
1146
+ )
1147
+ published_dir.mkdir(parents=True)
1148
+ published_rule = {
1149
+ "field": "3q96an3nsvnu",
1150
+ "type": "plugin_scan_input",
1151
+ "key": "sn",
1152
+ "lambda": "return 1;",
1153
+ "quickValue": True,
1154
+ "lambdaFields": ["3q96an3nsvnu"],
1155
+ }
1156
+ (published_dir / "form_rule.rule").write_text(
1157
+ json.dumps(published_rule, ensure_ascii=False),
1158
+ encoding="utf-8",
1159
+ )
1160
+
1161
+ with mock.patch.object(common, "REPO_ROOT", repo_root):
1162
+ report = build_publish_safety_report(submit, "test-uuid")
1163
+
1164
+ self.assertFalse(report["ok"])
1165
+ self.assertTrue(any("drops published lambda" in message for message in report["errors"]))
1166
+ self.assertTrue(any("quickValue" in message for message in report["errors"]))
1167
+
1168
+ def test_build_drift_report_tracks_editor_writeback_changes(self) -> None:
1169
+ submit = build_submit_payload(detail_to_work_payload(make_detail(), mode="edit"))
1170
+ draft_readback = make_detail()
1171
+ draft_readback["rule"][1][0]["quickValue"] = False
1172
+ published_readback = make_detail()
1173
+ published_readback["rule"][1][0]["props"] = {
1174
+ "mode": "table",
1175
+ "form_template": {"id": 777},
1176
+ }
1177
+ published_readback["rule"][1][0]["type"] = "sub_form"
1178
+ published_readback["value"][1]["field_type"] = "sub_form"
1179
+
1180
+ drift = build_drift_report(submit, draft_readback, published_readback)
1181
+
1182
+ self.assertFalse(drift["ok"])
1183
+ self.assertIn("3q96an3nsvnu", drift["submitToDraft"]["changedFields"])
1184
+ self.assertIn("quickValue", drift["submitToDraft"]["changedFields"]["3q96an3nsvnu"])
1185
+ self.assertIn("subFormTemplateId", drift["draftToPublished"]["changedFields"]["3q96an3nsvnu"])
1186
+
1187
+ def test_runtime_acceptance_payload_is_pending_when_required_but_unverified(self) -> None:
1188
+ payload = build_runtime_acceptance_payload(
1189
+ required=True,
1190
+ flow_type="flow352878207",
1191
+ expected_draft_id=990702161,
1192
+ expected_published_id=990702162,
1193
+ acceptance_page="/w:store_mgr/apply/create",
1194
+ fresh_instance_required=True,
1195
+ acceptance_level="runtime_live",
1196
+ )
1197
+
1198
+ self.assertFalse(payload["ok"])
1199
+ self.assertEqual(payload["status"], "pending")
1200
+ self.assertIsNone(payload["checks"]["flowReferenceMatchesPublished"])
1201
+ self.assertIsNone(payload["checks"]["runtimeLoadMatchesPublished"])
1202
+ self.assertEqual(payload["acceptanceLevel"], "runtime_live")
1203
+
1204
+ def test_runtime_acceptance_payload_accepts_when_all_runtime_checks_match(self) -> None:
1205
+ payload = build_runtime_acceptance_payload(
1206
+ required=True,
1207
+ flow_type="flow352878207",
1208
+ expected_draft_id=990702161,
1209
+ expected_published_id=990702162,
1210
+ flow_live_form_template_id=990702162,
1211
+ flow_draft_form_template_id=990702161,
1212
+ actual_runtime_form_template_id=990702162,
1213
+ acceptance_page="/w:store_mgr/apply/create",
1214
+ used_fresh_instance=True,
1215
+ fresh_instance_required=True,
1216
+ acceptance_level="runtime_live",
1217
+ runtime_reference_source="flow_live_api",
1218
+ )
1219
+
1220
+ self.assertTrue(payload["ok"])
1221
+ self.assertEqual(payload["status"], "accepted")
1222
+ self.assertEqual(payload["flowLiveFormTemplateId"], 990702162)
1223
+ self.assertEqual(payload["flowDraftFormTemplateId"], 990702161)
1224
+ self.assertEqual(payload["runtimeReferenceSource"], "flow_live_api")
1225
+
1226
+ def test_submit_script_resolves_origin_template_as_edit_target_when_present(self) -> None:
1227
+ class FakeClient:
1228
+ def get_form_template(self, template_id):
1229
+ return {"data": {"id": template_id, "origin_template_id": 990702142}}
1230
+
1231
+ draft_id, detail = submit_script.resolve_edit_target_ids(FakeClient(), 990702161)
1232
+ self.assertEqual(draft_id, 990702142)
1233
+ self.assertEqual(detail["id"], 990702161)
1234
+
1235
+ def test_submit_script_uses_requested_id_as_edit_target_when_origin_missing(self) -> None:
1236
+ class FakeClient:
1237
+ def get_form_template(self, template_id):
1238
+ return {"data": {"id": template_id, "origin_template_id": 0}}
1239
+
1240
+ draft_id, detail = submit_script.resolve_edit_target_ids(FakeClient(), 990702161)
1241
+ self.assertEqual(draft_id, 990702161)
1242
+ self.assertEqual(detail["id"], 990702161)
1243
+
1244
+ def test_runtime_acceptance_payload_accepts_browser_runtime_without_flow_live_reference(self) -> None:
1245
+ payload = build_runtime_acceptance_payload(
1246
+ required=True,
1247
+ flow_type="flow352878207",
1248
+ expected_draft_id=990702161,
1249
+ expected_published_id=990702162,
1250
+ actual_runtime_form_template_id=990702162,
1251
+ acceptance_page="/w:store_mgr/project/create?flow_type=flow352878207",
1252
+ used_fresh_instance=False,
1253
+ fresh_instance_required=False,
1254
+ acceptance_level="runtime_live",
1255
+ runtime_reference_source="browser_runtime",
1256
+ )
1257
+
1258
+ self.assertTrue(payload["ok"])
1259
+ self.assertEqual(payload["status"], "accepted")
1260
+ self.assertIsNone(payload["checks"]["flowReferenceMatchesPublished"])
1261
+ self.assertTrue(payload["checks"]["runtimeLoadMatchesPublished"])
1262
+ self.assertEqual(payload["runtimeReferenceSource"], "browser_runtime")
1263
+
1264
+ def test_runtime_acceptance_payload_marks_not_required_tasks(self) -> None:
1265
+ payload = build_runtime_acceptance_payload(
1266
+ required=False,
1267
+ flow_type=None,
1268
+ expected_draft_id=990702161,
1269
+ expected_published_id=990702162,
1270
+ acceptance_level="template_only",
1271
+ )
1272
+
1273
+ self.assertTrue(payload["ok"])
1274
+ self.assertEqual(payload["status"], "not_required")
1275
+ self.assertEqual(payload["acceptanceLevel"], "template_only")
1276
+
1277
+ def test_runtime_acceptance_payload_supports_runtime_diagnosis(self) -> None:
1278
+ payload = build_runtime_acceptance_payload(
1279
+ required=True,
1280
+ flow_type="flow451422190",
1281
+ expected_draft_id=990702291,
1282
+ expected_published_id=990702292,
1283
+ flow_live_form_template_id=990702290,
1284
+ flow_draft_form_template_id=990702292,
1285
+ acceptance_level="runtime_diagnosis",
1286
+ runtime_reference_source="flow_draft_api",
1287
+ )
1288
+
1289
+ self.assertFalse(payload["ok"])
1290
+ self.assertEqual(payload["status"], "failed")
1291
+ self.assertEqual(payload["flowLiveFormTemplateId"], 990702290)
1292
+ self.assertEqual(payload["flowDraftFormTemplateId"], 990702292)
1293
+ self.assertEqual(payload["runtimeReferenceSource"], "flow_draft_api")
1294
+
1295
+ def test_extract_template_id_handles_common_response_shapes(self) -> None:
1296
+ self.assertEqual(extract_template_id({"data": {"id": 123}}), 123)
1297
+ self.assertEqual(extract_template_id({"id": "456"}), 456)
1298
+ self.assertEqual(extract_template_id(789), 789)
1299
+ self.assertIsNone(extract_template_id({"data": {}}))
1300
+
1301
+
1302
+ if __name__ == "__main__":
1303
+ unittest.main()