codeplain 0.4.2.dev55__tar.gz → 0.4.3.dev57__tar.gz

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 (207) hide show
  1. codeplain-0.4.3.dev57/.github/scripts/record-linear-release.cjs +178 -0
  2. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/publish-to-pypi.yml +45 -50
  3. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/PKG-INFO +1 -1
  4. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/docs/plain2code_cli.md +10 -1
  5. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code.py +2 -1
  6. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_arguments.py +11 -0
  7. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_state.py +5 -0
  8. codeplain-0.4.3.dev57/tests/test_exit_when_done.py +151 -0
  9. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_render_finished_report.py +37 -2
  10. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_terminal_attachment.py +1 -0
  11. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/components.py +11 -1
  12. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/plain2code_tui.py +18 -0
  13. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.claude/settings.json +0 -0
  14. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.flake8 +0 -0
  15. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/dependabot.yml +0 -0
  16. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/e2e.yml +0 -0
  17. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/lint-and-test.yml +0 -0
  18. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/lint-powershell.yml +0 -0
  19. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/notify-slack-on-main-merge.yml +0 -0
  20. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/publish-dev-to-pypi.yml +0 -0
  21. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.github/workflows/publish-install-script.yml +0 -0
  22. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.gitignore +0 -0
  23. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.vscode/launch.json +0 -0
  24. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/.vscode/settings.json +0 -0
  25. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/CLAUDE.md +0 -0
  26. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/CONTRIBUTING.md +0 -0
  27. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/LICENSE +0 -0
  28. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/README.md +0 -0
  29. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/change_detection.py +0 -0
  30. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/cli_output/__init__.py +0 -0
  31. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/cli_output/dry_run.py +0 -0
  32. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/cli_output/render_summary.py +0 -0
  33. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/cli_output/status.py +0 -0
  34. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/codeplain_REST_api.py +0 -0
  35. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/concept_utils.py +0 -0
  36. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/config/__init__.py +0 -0
  37. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/config/system_config.yaml +0 -0
  38. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/conformance_fix_journal.py +0 -0
  39. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/diff_utils.py +0 -0
  40. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/docs/generate_cli.py +0 -0
  41. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/docs/starting_a_plain_project_from_scratch.md +0 -0
  42. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/event_bus.py +0 -0
  43. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_golang/config.yaml +0 -0
  44. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_golang/harness_tests/hello_world_test.go +0 -0
  45. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_golang/hello_world_golang.plain +0 -0
  46. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_golang/run.sh +0 -0
  47. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_golang/tests/hello_world_golang/display-hello-world.plain +0 -0
  48. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_python/config.yaml +0 -0
  49. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_python/harness_tests/hello_world_display/test_hello_world.py +0 -0
  50. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_python/hello_world_python.plain +0 -0
  51. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_python/run.sh +0 -0
  52. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_python/tests/hello_world_python/display-hello-world.plain +0 -0
  53. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/config.yaml +0 -0
  54. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/harness_tests/hello_world_display/cypress/e2e/hello_world.cy.ts +0 -0
  55. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/harness_tests/hello_world_display/cypress/support/e2e.ts +0 -0
  56. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/harness_tests/hello_world_display/cypress.config.ts +0 -0
  57. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/harness_tests/hello_world_display/package.json +0 -0
  58. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/harness_tests/hello_world_display/tsconfig.json +0 -0
  59. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/hello_world_react.plain +0 -0
  60. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/run.sh +0 -0
  61. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/tests/hello_world_react/display-hello-world.plain +0 -0
  62. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/example_hello_world_react/tests/typescript-react-app-boilerplate/entry-point.plain +0 -0
  63. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/examples/run.sh +0 -0
  64. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/file_utils.py +0 -0
  65. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/git_preflight.py +0 -0
  66. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/git_utils.py +0 -0
  67. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/bash/examples.sh +0 -0
  68. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/bash/install.sh +0 -0
  69. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/bash/walkthrough.sh +0 -0
  70. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/powershell/examples.ps1 +0 -0
  71. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/powershell/install.ps1 +0 -0
  72. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/install/powershell/walkthrough.ps1 +0 -0
  73. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/memory_management.py +0 -0
  74. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/metadata_utils.py +0 -0
  75. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/module_renderer.py +0 -0
  76. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/partial_rendering.py +0 -0
  77. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/path_resolution.py +0 -0
  78. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_cli.md +0 -0
  79. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_console.py +0 -0
  80. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_events.py +0 -0
  81. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_exceptions.py +0 -0
  82. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_logger.py +0 -0
  83. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_nodes.py +0 -0
  84. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_read_config.py +0 -0
  85. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_telemetry.py +0 -0
  86. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain2code_utils.py +0 -0
  87. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain_file.py +0 -0
  88. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain_modules.py +0 -0
  89. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/plain_spec.py +0 -0
  90. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/pyproject.toml +0 -0
  91. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/pytest.ini +0 -0
  92. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/__init__.py +0 -0
  93. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/analyze_specification_ambiguity.py +0 -0
  94. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/base_action.py +0 -0
  95. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/commit_conformance_tests_changes.py +0 -0
  96. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/commit_implementation_code_changes.py +0 -0
  97. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/create_dist.py +0 -0
  98. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/distill_conformance_test_memory.py +0 -0
  99. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/exit_with_error.py +0 -0
  100. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/finish_functional_requirement.py +0 -0
  101. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/fix_conformance_test.py +0 -0
  102. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/fix_unit_tests.py +0 -0
  103. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/prepare_repositories.py +0 -0
  104. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/prepare_testing_environment.py +0 -0
  105. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/refactor_code.py +0 -0
  106. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/render_conformance_tests.py +0 -0
  107. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/render_functional_requirement.py +0 -0
  108. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/run_conformance_tests.py +0 -0
  109. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/run_unit_tests.py +0 -0
  110. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/actions/summarize_conformance_tests.py +0 -0
  111. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/agent_tools.py +0 -0
  112. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/code_renderer.py +0 -0
  113. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/conformance_tests.py +0 -0
  114. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/implementation_code_helpers.py +0 -0
  115. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/render_context.py +0 -0
  116. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/render_types.py +0 -0
  117. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/render_utils.py +0 -0
  118. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/state_machine_config.py +0 -0
  119. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/states.py +0 -0
  120. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/render_machine/triggers.py +0 -0
  121. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/requirements.txt +0 -0
  122. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/resources/codeplain_overview.png +0 -0
  123. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/resources/plain_example.png +0 -0
  124. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/standard_template_library/golang-console-app-template.plain +0 -0
  125. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/standard_template_library/python-console-app-template.plain +0 -0
  126. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/standard_template_library/typescript-react-app-boilerplate.plain +0 -0
  127. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/standard_template_library/typescript-react-app-template.plain +0 -0
  128. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/system_config.py +0 -0
  129. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_cypress.ps1 +0 -0
  130. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_cypress.sh +0 -0
  131. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_golang.ps1 +0 -0
  132. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_golang.sh +0 -0
  133. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_python.ps1 +0 -0
  134. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_conformance_tests_python.sh +0 -0
  135. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_flutter.ps1 +0 -0
  136. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_flutter.sh +0 -0
  137. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_golang.ps1 +0 -0
  138. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_golang.sh +0 -0
  139. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_python.ps1 +0 -0
  140. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_python.sh +0 -0
  141. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_react.ps1 +0 -0
  142. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/test_scripts/run_unittests_react.sh +0 -0
  143. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/__init__.py +0 -0
  144. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/conftest.py +0 -0
  145. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/acceptance_tests_warning/main_requiring_acceptance_tests.plain +0 -0
  146. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/acceptance_tests_warning/required_with_acceptance_tests.plain +0 -0
  147. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/acceptance_tests_warning/tests/required_with_acceptance_tests/entry-point.plain +0 -0
  148. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_code_var.plain +0 -0
  149. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_implement.plain +0 -0
  150. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_leaf.plain +0 -0
  151. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_middle.plain +0 -0
  152. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_root.plain +0 -0
  153. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/data/partial_rendering/pr_solo.plain +0 -0
  154. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/e2e/Dockerfile +0 -0
  155. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/e2e/conftest.py +0 -0
  156. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/e2e/test_hello_world_python.py +0 -0
  157. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/e2e/test_hello_world_python_windows.py +0 -0
  158. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_acceptance_scenario_rendered_once.py +0 -0
  159. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_acceptance_scenarios_after_a_code_fix.py +0 -0
  160. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_agent_tools.py +0 -0
  161. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_arg_provenance.py +0 -0
  162. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_change_detection.py +0 -0
  163. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_cli_output.py +0 -0
  164. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_conformance_fix_journal.py +0 -0
  165. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_console_log_styles.py +0 -0
  166. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_dependency_pins.py +0 -0
  167. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_distill_conformance_test_memory.py +0 -0
  168. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_dry_run_link_validation.py +0 -0
  169. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_file_utils.py +0 -0
  170. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_fix_unit_tests_action.py +0 -0
  171. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_fix_unit_tests_conformance_context.py +0 -0
  172. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_folder_path_resolution.py +0 -0
  173. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_frid_arguments.py +0 -0
  174. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_functionality_position.py +0 -0
  175. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_functionality_without_scenarios.py +0 -0
  176. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_git_preflight.py +0 -0
  177. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_git_utils.py +0 -0
  178. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_headless_logging.py +0 -0
  179. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_log_file_name_resolution.py +0 -0
  180. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_logging_config_path_resolution.py +0 -0
  181. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_partial_rendering.py +0 -0
  182. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_path_resolution.py +0 -0
  183. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_plain2code.py +0 -0
  184. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_plain2code_state.py +0 -0
  185. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_plain2code_utils.py +0 -0
  186. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_plain_modules.py +0 -0
  187. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_prepare_repositories_layout.py +0 -0
  188. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_render_range.py +0 -0
  189. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_render_stop_reason.py +0 -0
  190. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_resolve_config_file.py +0 -0
  191. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_script_path_resolution.py +0 -0
  192. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_system_config.py +0 -0
  193. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_telemetry.py +0 -0
  194. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_tests_folders.py +0 -0
  195. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_traceability_warnings.py +0 -0
  196. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_tui_components.py +0 -0
  197. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_tui_usage.py +0 -0
  198. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_usage_summary.py +0 -0
  199. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tests/test_user_error_message.py +0 -0
  200. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/__init__.py +0 -0
  201. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/models.py +0 -0
  202. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/plain_module_render_choice_tui.py +0 -0
  203. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/spinner.py +0 -0
  204. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/state_handlers.py +0 -0
  205. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/styles.css +0 -0
  206. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/tui/widget_helpers.py +0 -0
  207. {codeplain-0.4.2.dev55 → codeplain-0.4.3.dev57}/usage_summary.py +0 -0
@@ -0,0 +1,178 @@
1
+ // Records a deploy or a release as a Linear release. Run it from actions/github-script:
2
+ //
3
+ // script: return require('./.github/scripts/record-linear-release.cjs')({ github, context, core })
4
+ //
5
+ // Environment:
6
+ // LINEAR_ACCESS_KEY The pipeline's access key. Without one, nothing is recorded.
7
+ // LINEAR_RELEASE_MODE "live" records the release. Anything else only logs what would be sent.
8
+ // RELEASE_SHA The commit that was deployed or tagged.
9
+ // RELEASE_VERSION The release tag, or for a deploy its short SHA (the default).
10
+ // RELEASE_BRANCH The branch PRs merge into. Defaults to main.
11
+ // RELEASE_NOTES "prs" (the default) lists the PRs. "github-release" copies the body of
12
+ // the GitHub release tagged RELEASE_VERSION.
13
+ //
14
+ // Output: release-url, the release's page in Linear. It stays empty when the release is only logged.
15
+ 'use strict';
16
+
17
+ const LINEAR_API = 'https://api.linear.app/graphql';
18
+ const MAX_BASE_CANDIDATES = 20;
19
+
20
+ // On GitHub, "#12" is a PR or issue of the same repo. Linear matches a bare "#12" against every
21
+ // repo it knows, so it can link a PR from another repo. Every reference is therefore written out
22
+ // as a full link, except in code (fenced or inline), existing links and URLs. GitHub redirects
23
+ // /pull/N to /issues/N when N is an issue.
24
+ function linkReferences(text, owner, repo) {
25
+ const untouched = /(```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`|\[[^\]\n]*\]\([^)\n]*\)|<[^>\n]*>|https?:\/\/[^\s)]+)/;
26
+ return text
27
+ .split(untouched)
28
+ .map((part, i) =>
29
+ i % 2
30
+ ? part
31
+ : part
32
+ .replace(
33
+ /(^|[^\w/#&])([\w.-]+)\/([\w.-]+)#(\d+)\b/g,
34
+ (_, pre, o, r, n) => `${pre}[${o}/${r}#${n}](https://github.com/${o}/${r}/pull/${n})`,
35
+ )
36
+ .replace(
37
+ /(^|[^\w/#&[]|\bPR ?)#(\d+)\b/g,
38
+ (_, pre, n) => `${pre}[#${n}](https://github.com/${owner}/${repo}/pull/${n})`,
39
+ ),
40
+ )
41
+ .join('');
42
+ }
43
+
44
+ function prNotes(prs, owner, repo) {
45
+ const link = (n) => `[#${n}](https://github.com/${owner}/${repo}/pull/${n})`;
46
+ const dependabot = prs.filter((pr) => pr.user.login === 'dependabot[bot]');
47
+ const lines = prs
48
+ .filter((pr) => !dependabot.includes(pr))
49
+ .map((pr) => `- ${link(pr.number)} ${linkReferences(pr.title, owner, repo)} · ${pr.user.login}`);
50
+ if (dependabot.length) {
51
+ const s = dependabot.length > 1 ? 's' : '';
52
+ lines.push(`- ${dependabot.length} Dependabot update${s}: ${dependabot.map((pr) => link(pr.number)).join(', ')}`);
53
+ }
54
+ return lines.join('\n');
55
+ }
56
+
57
+ // The PRs merged into `branch` since the newest earlier release in this pipeline.
58
+ async function pullRequestsSince({ github, owner, repo, branch, head, version, releases }) {
59
+ const compare = async (base, target, page = 1, perPage = 1) =>
60
+ (await github.rest.repos.compareCommitsWithBasehead({ owner, repo, basehead: `${base}...${target}`, page, per_page: perPage }))
61
+ .data;
62
+
63
+ // Testing can be deployed from a branch. Such a deploy gets no PRs; they count once they reach the branch.
64
+ if (!['ahead', 'identical'].includes((await compare(head, branch)).status)) {
65
+ return { prs: [], reason: `${head.slice(0, 7)} is not on ${branch}` };
66
+ }
67
+
68
+ // Sorted by completion time, since an older release whose notes were edited can be listed first.
69
+ // A release that is not on the branch is a branch deploy and is never a base. This release itself
70
+ // (a re-run) is skipped, but another version at the same commit is a base, and leaves no new PRs.
71
+ const candidates = releases
72
+ .filter((r) => r.commitSha && r.version !== version)
73
+ .sort((a, b) => Date.parse(b.completedAt || b.createdAt) - Date.parse(a.completedAt || a.createdAt))
74
+ .slice(0, MAX_BASE_CANDIDATES);
75
+ let base;
76
+ for (const release of candidates) {
77
+ const { status } = await compare(release.commitSha, head);
78
+ if (status === 'diverged') continue;
79
+ // "behind": the newest release is ahead of this commit, so this deploy is a rollback.
80
+ if (status === 'behind') return { prs: [], reason: `rollback: ${release.version} is newer` };
81
+ base = release;
82
+ break;
83
+ }
84
+ if (!base) return { prs: [], reason: 'no earlier release on the branch' };
85
+
86
+ const commits = [];
87
+ for (let page = 1; ; page++) {
88
+ const data = await compare(base.commitSha, head, page, 100);
89
+ commits.push(...data.commits);
90
+ if (data.commits.length < 100 || commits.length >= data.total_commits) break;
91
+ }
92
+
93
+ // GitHub knows each commit's PR, whatever the merge method.
94
+ const prs = new Map();
95
+ for (const { sha } of commits) {
96
+ const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ owner, repo, commit_sha: sha });
97
+ for (const pr of data) {
98
+ if (pr.merged_at && pr.base.ref === branch && !prs.has(pr.number)) prs.set(pr.number, pr);
99
+ }
100
+ }
101
+ return { prs: [...prs.values()], base };
102
+ }
103
+
104
+ module.exports = async ({ github, context, core }) => {
105
+ const key = process.env.LINEAR_ACCESS_KEY;
106
+ const live = process.env.LINEAR_RELEASE_MODE === 'live';
107
+ if (!key) {
108
+ if (live) throw new Error('LINEAR_RELEASE_MODE is live, but this pipeline has no Linear access key');
109
+ core.notice('No Linear access key for this pipeline, so the release is not recorded.');
110
+ return;
111
+ }
112
+ const required = (name) => {
113
+ if (!process.env[name]) throw new Error(`${name} is not set`);
114
+ return process.env[name];
115
+ };
116
+ const head = required('RELEASE_SHA');
117
+ const version = process.env.RELEASE_VERSION || head.slice(0, 7);
118
+ const branch = process.env.RELEASE_BRANCH || 'main';
119
+ const { owner, repo } = context.repo;
120
+
121
+ const linear = async (query, variables) => {
122
+ const res = await fetch(LINEAR_API, {
123
+ method: 'POST',
124
+ headers: { 'Content-Type': 'application/json', Authorization: key },
125
+ body: JSON.stringify({ query, variables }),
126
+ signal: AbortSignal.timeout(30_000),
127
+ });
128
+ const body = await res.json().catch(() => ({}));
129
+ if (!res.ok || body.errors) throw new Error(`Linear API ${res.status}: ${JSON.stringify(body.errors || body)}`);
130
+ return body.data;
131
+ };
132
+
133
+ const { recentReleasesByAccessKey: releases } = await linear(
134
+ 'query { recentReleasesByAccessKey(limit: 50) { commitSha version completedAt createdAt } }',
135
+ );
136
+ const { prs, base, reason } = await pullRequestsSince({ github, owner, repo, branch, head, version, releases });
137
+
138
+ const links = [{ label: 'GitHub run', url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}` }];
139
+ let notes;
140
+ if (process.env.RELEASE_NOTES === 'github-release') {
141
+ const { data } = await github.rest.repos.getReleaseByTag({ owner, repo, tag: version });
142
+ notes = linkReferences((data.body || '').replace(/\r\n/g, '\n').trim(), owner, repo);
143
+ links.unshift({ label: 'GitHub release', url: data.html_url });
144
+ } else {
145
+ notes = prNotes(prs, owner, repo);
146
+ }
147
+
148
+ const input = {
149
+ name: version,
150
+ version,
151
+ commitSha: head,
152
+ repository: { owner, name: repo, provider: 'github', url: `https://github.com/${owner}/${repo}` },
153
+ pullRequestReferences: prs.map((pr) => ({ repositoryOwner: owner, repositoryName: repo, number: pr.number })),
154
+ links,
155
+ ...(notes ? { releaseNotes: { title: version, content: notes } } : {}),
156
+ };
157
+
158
+ const since = base ? `since ${base.version}` : `none (${reason})`;
159
+ core.info(`PRs ${since}: ${prs.map((pr) => `#${pr.number}`).join(', ') || '-'}`);
160
+ if (!live) {
161
+ core.notice(`Log-only: ${version} would be recorded in Linear with ${prs.length} PRs. Set LINEAR_RELEASE_MODE=live to record it.`);
162
+ core.info(JSON.stringify(input, null, 2));
163
+ return;
164
+ }
165
+
166
+ const { releaseSyncByAccessKey: result } = await linear(
167
+ 'mutation ($input: ReleaseSyncInputBase!) { releaseSyncByAccessKey(input: $input) { success release { url } } }',
168
+ { input },
169
+ );
170
+ // Linear can report a failed sync with HTTP 200.
171
+ if (!result.success || !result.release) throw new Error(`Linear did not record ${version}: ${JSON.stringify(result)}`);
172
+ core.setOutput('release-url', result.release.url);
173
+ core.notice(`Recorded ${version} in Linear: ${result.release.url}`);
174
+ };
175
+
176
+ module.exports.linkReferences = linkReferences;
177
+ module.exports.prNotes = prNotes;
178
+ module.exports.pullRequestsSince = pullRequestsSince;
@@ -93,7 +93,8 @@ jobs:
93
93
  # re-posts without publishing again.
94
94
  notify:
95
95
  name: Notify Slack
96
- needs: [build, publish-to-pypi]
96
+ # linear-release is skipped for pre-releases and failed publishes; this job still runs.
97
+ needs: [build, publish-to-pypi, linear-release]
97
98
  if: ${{ !cancelled() && vars.SLACK_CHANNEL_ID != '' }}
98
99
  runs-on: ubuntu-latest
99
100
 
@@ -163,6 +164,9 @@ jobs:
163
164
 
164
165
  - name: Notify Slack (release published)
165
166
  if: ${{ needs.publish-to-pypi.result == 'success' && !github.event.release.prerelease }}
167
+ env:
168
+ # Empty while the release step only logs, or when it failed.
169
+ RELEASE_URL: ${{ needs.linear-release.outputs.release-url }}
166
170
  uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
167
171
  with:
168
172
  method: chat.postMessage
@@ -173,7 +177,7 @@ jobs:
173
177
  thread_ts: ${{ env.THREAD_TS }}
174
178
  text: >-
175
179
  *Codeplain Client*: `${{ github.ref_name }}` published to PyPI :white_check_mark:.
176
- Install with `pip install --upgrade codeplain`.
180
+ Install with `pip install --upgrade codeplain`.${{ env.RELEASE_URL != '' && format(' <{0}|View release>.', env.RELEASE_URL) || (needs.linear-release.result == 'failure' || needs.linear-release.outputs.outcome == 'failure') && ' Recording it in Linear failed :warning:.' || '' }}
177
181
 
178
182
  # Success also puts a ✅ on the start notice, so the result shows in the
179
183
  # channel without another message. Needs the app's reactions:write scope.
@@ -191,51 +195,42 @@ jobs:
191
195
  timestamp: ${{ env.THREAD_TS }}
192
196
  name: white_check_mark
193
197
 
194
- # Release pipelines to be turned on only after the rest of the infrastructure
195
- # is ready.
196
- #
197
- # # Runs only after the package is on PyPI. Kept as its own job so the publish job
198
- # # keeps its minimal permissions and no checkout.
199
- # linear-release:
200
- # name: Record release in Linear
201
- # needs: [build, publish-to-pypi]
202
- # runs-on: ubuntu-latest
203
- #
204
- # permissions:
205
- # contents: read
206
- #
207
- # steps:
208
- # - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
209
- # with:
210
- # # The scan needs full history.
211
- # fetch-depth: 0
212
- #
213
- # # Non-fatal: the package is already published.
214
- # - name: Record release in Linear
215
- # id: linear
216
- # continue-on-error: true
217
- # uses: linear/linear-release-action@0a25abab892a91062ebf42260dbb2ce6277aa205 # v0.16.0
218
- # with:
219
- # access_key: ${{ secrets.LINEAR_ACCESS_KEY }}
220
- # version: ${{ github.ref_name }}
221
- # # Pin the CLI the action downloads, not just the action.
222
- # cli_version: v0.16.0
223
- #
224
- # # continue-on-error keeps the job green, so this checks the step's own
225
- # # outcome — `failure()` would never fire.
226
- # - name: Notify Slack (release not recorded)
227
- # if: ${{ steps.linear.outcome == 'failure' && vars.SLACK_CHANNEL_ID != '' }}
228
- # env:
229
- # # See the notify job.
230
- # THREAD_TS: ${{ needs.build.outputs.slack-ts && format('"{0}"', needs.build.outputs.slack-ts) || 'null' }}
231
- # uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
232
- # with:
233
- # method: chat.postMessage
234
- # token: ${{ secrets.SLACK_BOT_TOKEN }}
235
- # errors: true
236
- # payload: |
237
- # channel: ${{ vars.SLACK_CHANNEL_ID }}
238
- # thread_ts: ${{ env.THREAD_TS }}
239
- # text: >-
240
- # *Codeplain Client*: `${{ github.ref_name }}` is on PyPI, but recording it in Linear FAILED :warning:.
241
- # See <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the run log>.
198
+ # Stable releases only; pre-releases stay out of the Linear pipeline. Its own
199
+ # job, after the package is on PyPI, so the publish job keeps its minimal
200
+ # permissions and no checkout.
201
+ linear-release:
202
+ name: Record release in Linear
203
+ needs: publish-to-pypi
204
+ if: ${{ !github.event.release.prerelease }}
205
+ runs-on: ubuntu-latest
206
+ # pull-requests lets the step look up each commit's PR.
207
+ permissions:
208
+ contents: read
209
+ pull-requests: read
210
+ outputs:
211
+ # The notify job links the release, or says recording it failed.
212
+ release-url: ${{ steps.linear.outputs.release-url }}
213
+ outcome: ${{ steps.linear.outcome }}
214
+
215
+ steps:
216
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
217
+ with:
218
+ persist-credentials: false
219
+
220
+ # The release gets the PRs merged since the previous one, and the GitHub
221
+ # release text as notes; a re-run updates it. Log-only until
222
+ # LINEAR_RELEASE_MODE is "live". Non-fatal: the package is already published.
223
+ - name: Record release in Linear
224
+ id: linear
225
+ continue-on-error: true
226
+ # A hung API call must not hold up the Slack notice.
227
+ timeout-minutes: 10
228
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
229
+ env:
230
+ LINEAR_ACCESS_KEY: ${{ secrets.LINEAR_ACCESS_KEY }}
231
+ LINEAR_RELEASE_MODE: ${{ vars.LINEAR_RELEASE_MODE }}
232
+ RELEASE_VERSION: ${{ github.event.release.tag_name }}
233
+ RELEASE_SHA: ${{ github.sha }}
234
+ RELEASE_NOTES: github-release
235
+ with:
236
+ script: return require('./.github/scripts/record-linear-release.cjs')({ github, context, core })
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeplain
3
- Version: 0.4.2.dev55
3
+ Version: 0.4.3.dev57
4
4
  Summary: Transform plain language specifications into working code
5
5
  License-File: LICENSE
6
6
  Classifier: Environment :: Console
@@ -19,7 +19,8 @@ usage: generate_cli.py [-h] [--verbose] [--base-folder BASE_FOLDER]
19
19
  [--conformance-tests-dest CONFORMANCE_TESTS_DEST]
20
20
  [--render-machine-graph]
21
21
  [--logging-config-path LOGGING_CONFIG_PATH]
22
- [--headless] [--status] [--version]
22
+ [--headless] [--exit-when-done | --no-exit-when-done]
23
+ [--status] [--version]
23
24
  [filename]
24
25
 
25
26
  Render plain code to target code. Path arguments resolve based on where they
@@ -131,6 +132,14 @@ options:
131
132
  specification text itself stays in the log file only.
132
133
  Used automatically when stdin, stdout or stderr is not
133
134
  a terminal.
135
+ --exit-when-done, --no-exit-when-done
136
+ Close the terminal interface as soon as rendering
137
+ stops, instead of keeping it open until you press
138
+ Enter. The render summary is printed to the terminal
139
+ as usual. Use --no-exit-when-done to keep the
140
+ interface open when config.yaml turns this on.
141
+ Headless rendering always ends by itself, so the
142
+ option changes nothing there.
134
143
  --status Display account status including user information, API
135
144
  key label, and rendering credits. Does not render any
136
145
  code.
@@ -453,6 +453,7 @@ def render( # noqa: C901
453
453
  enter_pause_event=enter_pause_event,
454
454
  on_cancel=run_state.set_render_cancelled,
455
455
  default_log_level=default_log_level,
456
+ exit_when_done=args.exit_when_done,
456
457
  css_path="styles.css",
457
458
  )
458
459
  app.run()
@@ -591,7 +592,7 @@ def main(): # noqa: C901
591
592
  print_exit_summary(
592
593
  run_state,
593
594
  args.filename,
594
- error_message=error_message,
595
+ error_message=error_message or run_state.render_error_message,
595
596
  )
596
597
  # Remove any scratch extractions created for archive-only ("<module>.module") modules.
597
598
  for module in plain_module.all_required_modules + [plain_module]:
@@ -511,6 +511,17 @@ def create_parser():
511
511
  "Used automatically when stdin, stdout or stderr is not a terminal.",
512
512
  )
513
513
 
514
+ _add_arg(
515
+ parser,
516
+ "--exit-when-done",
517
+ action=argparse.BooleanOptionalAction,
518
+ default=False,
519
+ help="Close the terminal interface as soon as rendering stops, instead of keeping it open "
520
+ "until you press Enter. The render summary is printed to the terminal as usual. "
521
+ "Use --no-exit-when-done to keep the interface open when config.yaml turns this on. "
522
+ "Headless rendering always ends by itself, so the option changes nothing there.",
523
+ )
524
+
514
525
  parser.add_argument(
515
526
  "--status",
516
527
  action="store_true",
@@ -12,6 +12,8 @@ class RunState:
12
12
  self.replay: bool = replay_with is not None
13
13
  self.render_succeeded: bool = False
14
14
  self.render_cancelled: bool = False
15
+ # Why the render failed, as the TUI showed it; printed in the summary after the TUI closes.
16
+ self.render_error_message: Optional[str] = None
15
17
  self.render_generated_code_path: Optional[str] = None
16
18
  self.rendered_functionalities: int = 0
17
19
  if replay_with:
@@ -39,6 +41,9 @@ class RunState:
39
41
  def set_render_succeeded(self, succeeded: bool):
40
42
  self.render_succeeded = succeeded
41
43
 
44
+ def set_render_error_message(self, error_message: str):
45
+ self.render_error_message = error_message
46
+
42
47
  def set_render_cancelled(self):
43
48
  self.render_cancelled = True
44
49
 
@@ -0,0 +1,151 @@
1
+ """Tests for --exit-when-done: the TUI closes by itself once rendering has stopped."""
2
+
3
+ import asyncio
4
+ import threading
5
+
6
+ import pytest
7
+
8
+ from event_bus import EventBus
9
+ from plain2code_arguments import create_parser, parse_arguments
10
+ from plain2code_events import LogMessageEmitted, RenderCompleted, RenderFailed
11
+ from plain2code_state import RunState
12
+ from tui.plain2code_tui import Plain2CodeTUI
13
+
14
+
15
+ def _make_app(run_state: RunState, event_bus: EventBus, exit_when_done: bool, on_ready=lambda: None) -> Plain2CodeTUI:
16
+ return Plain2CodeTUI(
17
+ event_bus=event_bus,
18
+ run_state=run_state,
19
+ on_ready=on_ready,
20
+ render_id="test-render-id",
21
+ unittests_script=None,
22
+ conformance_tests_script=None,
23
+ prepare_environment_script=None,
24
+ state_machine_version="0.0.0",
25
+ exit_when_done=exit_when_done,
26
+ css_path="styles.css",
27
+ )
28
+
29
+
30
+ def _run(exit_when_done: bool, event) -> bool:
31
+ """Publish ``event`` to a mounted TUI and report whether the TUI closed itself."""
32
+
33
+ async def scenario() -> bool:
34
+ event_bus = EventBus()
35
+ run_state = RunState(spec_filename="x.plain")
36
+ app = _make_app(run_state, event_bus, exit_when_done)
37
+ async with app.run_test() as pilot:
38
+ event_bus.publish(event)
39
+ await pilot.pause()
40
+ return app._exit
41
+
42
+ return asyncio.run(scenario())
43
+
44
+
45
+ def test_tui_closes_itself_when_rendering_completes():
46
+ assert _run(True, RenderCompleted(rendered_code_path="plain_modules/x/")) is True
47
+
48
+
49
+ def test_tui_closes_itself_when_rendering_fails():
50
+ assert _run(True, RenderFailed(error_message="Conformance tests failed")) is True
51
+
52
+
53
+ def test_tui_keeps_the_failure_reason_for_the_summary():
54
+ """The TUI closes right away, so the reason it showed must survive on the run state."""
55
+
56
+ async def scenario() -> RunState:
57
+ event_bus = EventBus()
58
+ run_state = RunState(spec_filename="x.plain")
59
+ app = _make_app(run_state, event_bus, True)
60
+ async with app.run_test() as pilot:
61
+ event_bus.publish(RenderFailed(error_message="Conformance tests failed"))
62
+ await pilot.pause()
63
+ return run_state
64
+
65
+ assert asyncio.run(scenario()).render_error_message == "Conformance tests failed"
66
+
67
+
68
+ def test_tui_waits_for_the_user_without_the_option():
69
+ assert _run(False, RenderCompleted(rendered_code_path="plain_modules/x/")) is False
70
+ assert _run(False, RenderFailed(error_message="Conformance tests failed")) is False
71
+
72
+
73
+ def test_tui_closes_itself_when_the_render_thread_reports_completion():
74
+ """The render runs in its own thread, so the completion event reaches the TUI from there."""
75
+
76
+ async def scenario() -> bool:
77
+ event_bus = EventBus()
78
+ run_state = RunState(spec_filename="x.plain")
79
+ app = _make_app(run_state, event_bus, True)
80
+ async with app.run_test() as pilot:
81
+ thread = threading.Thread(
82
+ target=lambda: event_bus.publish(RenderCompleted(rendered_code_path="plain_modules/x/"))
83
+ )
84
+ thread.start()
85
+ thread.join()
86
+ await pilot.pause()
87
+ return app._exit
88
+
89
+ assert asyncio.run(scenario()) is True
90
+
91
+
92
+ def _log(message: str) -> LogMessageEmitted:
93
+ return LogMessageEmitted(logger_name="codeplain", level="INFO", message=message, timestamp="00:00:01")
94
+
95
+
96
+ @pytest.mark.parametrize(
97
+ "event", [RenderCompleted(rendered_code_path="plain_modules/x/"), RenderFailed(error_message="x")]
98
+ )
99
+ def test_tui_closes_cleanly_while_log_lines_are_still_arriving(event):
100
+ """Log lines reach the TUI from the render thread right up to (and past) the final event.
101
+
102
+ Entries still waiting to be drawn when the TUI closes must not crash it: before the fix,
103
+ mounting them into the torn-down log view raised MountError, which run_test re-raises.
104
+ """
105
+
106
+ async def scenario() -> bool:
107
+ event_bus = EventBus()
108
+ run_state = RunState(spec_filename="x.plain")
109
+
110
+ def render():
111
+ for i in range(20):
112
+ event_bus.publish(_log(f"step {i}"))
113
+ event_bus.publish(event)
114
+ for i in range(20):
115
+ event_bus.publish(_log(f"after {i}"))
116
+
117
+ # Started from on_ready, exactly as plain2code.render() starts the render thread.
118
+ render_thread = threading.Thread(target=render, daemon=True)
119
+ app = _make_app(run_state, event_bus, True, on_ready=render_thread.start)
120
+ async with app.run_test() as pilot:
121
+ for _ in range(100):
122
+ if app._exit and not render_thread.is_alive():
123
+ break
124
+ await pilot.pause(0.01)
125
+ return app._exit
126
+
127
+ assert asyncio.run(scenario()) is True
128
+
129
+
130
+ def test_option_is_off_by_default():
131
+ args = create_parser().parse_args(["x.plain"])
132
+ assert args.exit_when_done is False
133
+
134
+
135
+ def test_option_turns_on_from_the_command_line():
136
+ args = create_parser().parse_args(["x.plain", "--exit-when-done"])
137
+ assert args.exit_when_done is True
138
+
139
+
140
+ def test_option_turns_off_from_the_command_line():
141
+ args = create_parser().parse_args(["x.plain", "--no-exit-when-done"])
142
+ assert args.exit_when_done is False
143
+
144
+
145
+ def test_command_line_turns_off_an_exit_configured_in_config_yaml(tmp_path, monkeypatch):
146
+ (tmp_path / "x.plain").write_text("")
147
+ (tmp_path / "config.yaml").write_text("exit-when-done: true\n")
148
+ monkeypatch.chdir(tmp_path)
149
+
150
+ assert parse_arguments([str(tmp_path / "x.plain")]).exit_when_done is True
151
+ assert parse_arguments([str(tmp_path / "x.plain"), "--no-exit-when-done"]).exit_when_done is False
@@ -108,7 +108,7 @@ def make_args(api_key="test-key", headless=False):
108
108
  )
109
109
 
110
110
 
111
- def run_main(render_side_effect=None, api_key="test-key"):
111
+ def run_main(render_side_effect=None, api_key="test-key", print_exit_summary=None):
112
112
  """Drive main() with everything but the reporting path stubbed out.
113
113
 
114
114
  render() is replaced, so the stub is what decides how the render "ended" -
@@ -134,7 +134,7 @@ def run_main(render_side_effect=None, api_key="test-key"):
134
134
  patch("plain2code.setup_logging", return_value="INFO"),
135
135
  patch("plain2code.initialize_telemetry"),
136
136
  patch("plain2code.stop_narrating"),
137
- patch("plain2code.print_exit_summary"),
137
+ patch("plain2code.print_exit_summary", print_exit_summary or MagicMock()),
138
138
  patch("plain2code.dump_crash_logs"),
139
139
  patch("plain2code.capture_crash"),
140
140
  patch("plain2code.codeplain_api.CodeplainAPI", return_value=api),
@@ -204,3 +204,38 @@ class TestMainReportsEveryEnding:
204
204
  api = run_main(api_key=None)
205
205
 
206
206
  api.render_finished.assert_not_called()
207
+
208
+
209
+ class TestSummaryShowsWhyTheRenderFailed:
210
+ """A failure inside the render machine reaches main() only through the run state.
211
+
212
+ The state machine publishes RenderFailed without raising, so render() returns normally
213
+ and main() has no error of its own. The TUI keeps the reason on the run state; with
214
+ --exit-when-done the summary is the only place the user still sees it.
215
+ """
216
+
217
+ def test_the_reason_the_tui_kept_is_printed(self):
218
+ def fail_inside_the_render_machine(run_state):
219
+ run_state.set_render_succeeded(False)
220
+ run_state.set_render_error_message("Conformance tests still fail after 20 attempts.")
221
+
222
+ summary = MagicMock()
223
+ run_main(fail_inside_the_render_machine, print_exit_summary=summary)
224
+
225
+ assert summary.call_args.kwargs["error_message"] == "Conformance tests still fail after 20 attempts."
226
+
227
+ def test_a_raised_error_still_wins(self):
228
+ def fail(run_state):
229
+ run_state.set_render_error_message("reason the TUI kept")
230
+ raise Exception("rendering blew up")
231
+
232
+ summary = MagicMock()
233
+ run_main(fail, print_exit_summary=summary)
234
+
235
+ assert summary.call_args.kwargs["error_message"] == "rendering blew up"
236
+
237
+ def test_a_successful_render_has_no_error_message(self):
238
+ summary = MagicMock()
239
+ run_main(lambda run_state: run_state.set_render_succeeded(True), print_exit_summary=summary)
240
+
241
+ assert summary.call_args.kwargs["error_message"] is None
@@ -84,6 +84,7 @@ def make_args():
84
84
  render_from=None,
85
85
  force_render=False,
86
86
  headless=False,
87
+ exit_when_done=False,
87
88
  replay_with=None,
88
89
  job_tag=None,
89
90
  log_to_file=False,
@@ -624,12 +624,20 @@ class StructuredLogView(VerticalScroll):
624
624
  async def add_log(
625
625
  self, logger_name: str, level: str, message: str, timestamp: str = "", log_color: Optional[str] = None
626
626
  ):
627
- """Add a new log entry."""
627
+ """Add a new log entry.
628
+
629
+ Log entries are scheduled from the render thread, so one can still be pending when the
630
+ TUI closes (e.g. with --exit-when-done). Once the view is detached from the DOM the entry
631
+ is dropped instead of mounted, since mounting into a detached widget raises MountError.
632
+ The check runs right before each mount because the view can detach while awaiting.
633
+ """
628
634
  # Check if this is a success message that should have spacing before it
629
635
  is_success_message = any(keyword in message.lower() for keyword in LogEntry.SUCCESS_KEYWORDS)
630
636
 
631
637
  # Add empty line before success messages
632
638
  if is_success_message:
639
+ if not self.is_attached:
640
+ return
633
641
  spacer = Static("", classes="log-spacer")
634
642
  await self.mount(spacer)
635
643
 
@@ -639,6 +647,8 @@ class StructuredLogView(VerticalScroll):
639
647
  if not self._should_show_log(level):
640
648
  entry.display = False
641
649
 
650
+ if not self.is_attached:
651
+ return
642
652
  await self.mount(entry)
643
653
  # Auto-scroll to bottom to show latest logs
644
654
  self.scroll_end(animate=False)