codeplain 0.3.13.dev48__py3-none-any.whl → 0.3.14.dev50__py3-none-any.whl

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 (49) hide show
  1. change_detection.py +65 -94
  2. cli_output/dry_run.py +7 -3
  3. {codeplain-0.3.13.dev48.dist-info → codeplain-0.3.14.dev50.dist-info}/METADATA +1 -1
  4. {codeplain-0.3.13.dev48.dist-info → codeplain-0.3.14.dev50.dist-info}/RECORD +49 -43
  5. codeplain_REST_api.py +9 -14
  6. docs/generate_cli.py +3 -2
  7. partial_rendering.py +32 -2
  8. plain2code.py +42 -14
  9. plain2code_arguments.py +69 -12
  10. plain2code_telemetry.py +2 -1
  11. plain2code_utils.py +14 -0
  12. plain_modules.py +73 -14
  13. render_machine/actions/analyze_specification_ambiguity.py +5 -3
  14. render_machine/actions/distill_conformance_test_memory.py +3 -1
  15. render_machine/actions/fix_conformance_test.py +4 -4
  16. render_machine/actions/fix_unit_tests.py +3 -1
  17. render_machine/actions/refactor_code.py +6 -1
  18. render_machine/actions/render_conformance_tests.py +52 -20
  19. render_machine/actions/render_functional_requirement.py +5 -2
  20. render_machine/actions/run_conformance_tests.py +3 -2
  21. render_machine/actions/summarize_conformance_tests.py +3 -1
  22. render_machine/render_context.py +59 -20
  23. render_machine/render_types.py +6 -15
  24. standard_template_library/typescript-react-app-boilerplate.plain +2 -1
  25. tests/test_acceptance_scenario_rendered_once.py +169 -0
  26. tests/test_acceptance_scenarios_after_a_code_fix.py +110 -0
  27. tests/test_change_detection.py +138 -127
  28. tests/test_conformance_fix_journal.py +46 -46
  29. tests/test_dry_run_link_validation.py +2 -1
  30. tests/test_fix_unit_tests_action.py +1 -1
  31. tests/test_frid_arguments.py +40 -0
  32. tests/test_functionality_without_scenarios.py +88 -0
  33. tests/test_git_utils.py +13 -13
  34. tests/test_partial_rendering.py +82 -47
  35. tests/test_plain2code.py +39 -41
  36. tests/test_plain2code_utils.py +12 -1
  37. tests/test_plain_modules.py +50 -44
  38. tests/test_render_finished_report.py +2 -0
  39. tests/test_render_range.py +18 -9
  40. tests/test_render_stop_reason.py +5 -5
  41. tests/test_telemetry.py +2 -2
  42. tests/test_terminal_attachment.py +2 -1
  43. tests/test_tests_folders.py +91 -0
  44. tests/test_traceability_warnings.py +69 -0
  45. tui/plain_module_render_choice_tui.py +4 -6
  46. tui/state_handlers.py +19 -28
  47. {codeplain-0.3.13.dev48.dist-info → codeplain-0.3.14.dev50.dist-info}/WHEEL +0 -0
  48. {codeplain-0.3.13.dev48.dist-info → codeplain-0.3.14.dev50.dist-info}/entry_points.txt +0 -0
  49. {codeplain-0.3.13.dev48.dist-info → codeplain-0.3.14.dev50.dist-info}/licenses/LICENSE +0 -0
@@ -55,6 +55,11 @@ def code_var_module(fixtures_dir, tmp_build_folder):
55
55
  return PlainModule("pr_code_var.plain", tmp_build_folder, [fixtures_dir])
56
56
 
57
57
 
58
+ def _stored(*frids: str) -> list[dict[str, str]]:
59
+ """Metadata entries for the given func-ids, as the module stores them."""
60
+ return [{"id": frid, "markdown": f"{frid} markdown."} for frid in frids]
61
+
62
+
58
63
  def _write_metadata(module: PlainModule, metadata: dict) -> None:
59
64
  folder = module.get_codeplain_folder()
60
65
  os.makedirs(folder, exist_ok=True)
@@ -220,24 +225,23 @@ def test_get_next_module_raises_when_module_not_found(root_module):
220
225
 
221
226
 
222
227
  def test_get_next_frid_within_same_module(root_module):
223
- # Each fixture module has FRIDs ["1", "2"].
224
- next_frid, next_module = root_module.get_next_frid("1", "pr_leaf")
225
- assert next_frid == "2"
228
+ next_frid, next_module = root_module.get_next_frid("leaf-one", "pr_leaf")
229
+ assert next_frid == "leaf-two"
226
230
  assert next_module.module_name == "pr_leaf"
227
231
 
228
232
 
229
233
  def test_get_next_frid_crosses_module_boundary(root_module):
230
234
  # After pr_leaf's last FRID, progress to pr_middle's first.
231
- next_frid, next_module = root_module.get_next_frid("2", "pr_leaf")
235
+ next_frid, next_module = root_module.get_next_frid("leaf-two", "pr_leaf")
232
236
  assert next_module.module_name == "pr_middle"
233
- assert next_frid == "1"
237
+ assert next_frid == "middle-one"
234
238
 
235
239
 
236
240
  def test_get_next_frid_from_last_required_module_progresses_to_root(root_module):
237
241
  # After pr_middle's last FRID, progress to the root's first FRID.
238
- next_frid, next_module = root_module.get_next_frid("2", "pr_middle")
242
+ next_frid, next_module = root_module.get_next_frid("middle-two", "pr_middle")
239
243
  assert next_module is root_module
240
- assert next_frid == "1"
244
+ assert next_frid == "root-one"
241
245
 
242
246
 
243
247
  # --------------------------------------------------------------------------
@@ -293,13 +297,13 @@ def test_is_module_fully_rendered_false_when_nothing_rendered(solo_module):
293
297
 
294
298
 
295
299
  def test_is_module_fully_rendered_false_when_only_first_frid_rendered(solo_module):
296
- _init_build_repo_with_finished_frid(solo_module, "1")
300
+ _init_build_repo_with_finished_frid(solo_module, "solo-one")
297
301
  assert solo_module.is_module_fully_rendered() is False
298
302
 
299
303
 
300
304
  def test_is_module_fully_rendered_true_when_last_frid_rendered(solo_module):
301
- # solo module has FRIDs ["1", "2", "3"]; "3" is the last.
302
- _init_build_repo_with_finished_frid(solo_module, "3")
305
+ # solo module has FRIDs ["solo-one", "solo-two", "solo-three"]; the last one is "solo-three".
306
+ _init_build_repo_with_finished_frid(solo_module, "solo-three")
303
307
  assert solo_module.is_module_fully_rendered() is True
304
308
 
305
309
 
@@ -314,16 +318,16 @@ def test_update_frid_stores_raw_markdown_not_rendered_text(code_var_module):
314
318
  rendered text (code variable substituted) would make every later diff report
315
319
  a spurious edit for that FRID."""
316
320
  raw = code_var_module._get_module_functional_requirements()
317
- # Sanity: FRID 2 really does carry an unsubstituted placeholder.
318
- assert "{{ variable_name }}" in raw[1]
321
+ # Sanity: implement-configurable really does carry an unsubstituted placeholder.
322
+ assert "{{ variable_name }}" in raw[1]["markdown"]
319
323
 
320
- code_var_module.update_frid_in_module_metadata("1")
321
- code_var_module.update_frid_in_module_metadata("2")
324
+ code_var_module.update_frid_in_module_metadata("plain-one")
325
+ code_var_module.update_frid_in_module_metadata("implement-configurable")
322
326
 
323
327
  metadata = code_var_module.load_module_metadata()
324
328
  assert metadata["functionalities"] == raw
325
329
  # The substituted value must NOT leak into the stored baseline.
326
- assert "configurable-value" not in metadata["functionalities"][1]
330
+ assert "configurable-value" not in metadata["functionalities"][1]["markdown"]
327
331
 
328
332
 
329
333
  def test_code_variable_frid_not_flagged_as_change(code_var_module):
@@ -336,8 +340,8 @@ def test_code_variable_frid_not_flagged_as_change(code_var_module):
336
340
  code_var_module,
337
341
  {"non_functional_source_hash": code_var_module.get_module_non_functional_source_hash()},
338
342
  )
339
- code_var_module.update_frid_in_module_metadata("1")
340
- code_var_module.update_frid_in_module_metadata("2")
343
+ code_var_module.update_frid_in_module_metadata("plain-one")
344
+ code_var_module.update_frid_in_module_metadata("implement-configurable")
341
345
 
342
346
  assert determine_partial_render_start(code_var_module) is None
343
347
 
@@ -651,26 +655,28 @@ def test_seed_module_metadata_overwrites_stale_functionalities(solo_module):
651
655
 
652
656
 
653
657
  def test_truncate_metadata_functionalities_no_metadata_is_noop(solo_module):
654
- solo_module.truncate_metadata_functionalities("1")
658
+ solo_module.truncate_metadata_functionalities("solo-one")
655
659
  assert solo_module.load_module_metadata() is None
656
660
 
657
661
 
658
662
  def test_truncate_metadata_functionalities_shortens_list_and_keeps_hashes(solo_module):
659
- _write_metadata(solo_module, {"source_hash": "abc", "functionalities": ["fr1", "fr2", "fr3"]})
660
- solo_module.truncate_metadata_functionalities("1")
663
+ _write_metadata(
664
+ solo_module, {"source_hash": "abc", "functionalities": _stored("solo-one", "solo-two", "solo-three")}
665
+ )
666
+ solo_module.truncate_metadata_functionalities("solo-one")
661
667
  metadata = solo_module.load_module_metadata()
662
- assert metadata["functionalities"] == ["fr1"]
668
+ assert metadata["functionalities"] == _stored("solo-one")
663
669
  assert metadata["source_hash"] == "abc"
664
670
 
665
671
 
666
672
  def test_truncate_metadata_functionalities_noop_when_list_short_enough(solo_module):
667
- _write_metadata(solo_module, {"functionalities": ["fr1"]})
668
- solo_module.truncate_metadata_functionalities("2")
669
- assert solo_module.load_module_metadata()["functionalities"] == ["fr1"]
673
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one")})
674
+ solo_module.truncate_metadata_functionalities("solo-two")
675
+ assert solo_module.load_module_metadata()["functionalities"] == _stored("solo-one")
670
676
 
671
677
 
672
678
  def test_truncate_metadata_functionalities_none_frid_empties_list(solo_module):
673
- _write_metadata(solo_module, {"functionalities": ["fr1", "fr2"]})
679
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one", "solo-two")})
674
680
  solo_module.truncate_metadata_functionalities(None)
675
681
  assert solo_module.load_module_metadata()["functionalities"] == []
676
682
 
@@ -694,16 +700,16 @@ def _commit_finished_frid(module: PlainModule, frid: str) -> None:
694
700
  def test_revert_code_to_frid_reverts_repo_and_trims_metadata(solo_module):
695
701
  os.makedirs(solo_module.module_build_folder)
696
702
  init_git_repo(solo_module.module_build_folder, module_name=solo_module.module_name)
697
- _commit_finished_frid(solo_module, "1")
698
- _commit_finished_frid(solo_module, "2")
699
- _write_metadata(solo_module, {"source_hash": "abc", "functionalities": ["fr1", "fr2"]})
703
+ _commit_finished_frid(solo_module, "solo-one")
704
+ _commit_finished_frid(solo_module, "solo-two")
705
+ _write_metadata(solo_module, {"source_hash": "abc", "functionalities": _stored("solo-one", "solo-two")})
700
706
 
701
- solo_module.revert_code_to_frid("1")
707
+ solo_module.revert_code_to_frid("solo-one")
702
708
 
703
- assert os.path.exists(os.path.join(solo_module.module_build_folder, "frid_1.txt"))
704
- assert not os.path.exists(os.path.join(solo_module.module_build_folder, "frid_2.txt"))
709
+ assert os.path.exists(os.path.join(solo_module.module_build_folder, "frid_solo-one.txt"))
710
+ assert not os.path.exists(os.path.join(solo_module.module_build_folder, "frid_solo-two.txt"))
705
711
  metadata = solo_module.load_module_metadata()
706
- assert metadata["functionalities"] == ["fr1"]
712
+ assert metadata["functionalities"] == _stored("solo-one")
707
713
  assert metadata["source_hash"] == "abc"
708
714
  # The metadata folder lives outside the code repo and must survive the revert.
709
715
  assert os.path.exists(solo_module.get_codeplain_folder())
@@ -712,12 +718,12 @@ def test_revert_code_to_frid_reverts_repo_and_trims_metadata(solo_module):
712
718
  def test_revert_code_to_frid_none_reverts_to_initial_state(solo_module):
713
719
  os.makedirs(solo_module.module_build_folder)
714
720
  init_git_repo(solo_module.module_build_folder, module_name=solo_module.module_name)
715
- _commit_finished_frid(solo_module, "1")
716
- _write_metadata(solo_module, {"functionalities": ["fr1"]})
721
+ _commit_finished_frid(solo_module, "solo-one")
722
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one")})
717
723
 
718
724
  solo_module.revert_code_to_frid(None)
719
725
 
720
- assert not os.path.exists(os.path.join(solo_module.module_build_folder, "frid_1.txt"))
726
+ assert not os.path.exists(os.path.join(solo_module.module_build_folder, "frid_solo-one.txt"))
721
727
  assert solo_module.load_module_metadata()["functionalities"] == []
722
728
 
723
729
 
@@ -730,13 +736,13 @@ def test_reconcile_metadata_with_git_trims_metadata_ahead_of_git(solo_module):
730
736
  # Simulates the crash window: metadata records FR 2 but git only committed FR 1.
731
737
  os.makedirs(solo_module.module_build_folder)
732
738
  init_git_repo(solo_module.module_build_folder, module_name=solo_module.module_name)
733
- _commit_finished_frid(solo_module, "1")
734
- _write_metadata(solo_module, {"source_hash": "abc", "functionalities": ["fr1", "fr2"]})
739
+ _commit_finished_frid(solo_module, "solo-one")
740
+ _write_metadata(solo_module, {"source_hash": "abc", "functionalities": _stored("solo-one", "solo-two")})
735
741
 
736
742
  solo_module.reconcile_metadata_with_git()
737
743
 
738
744
  metadata = solo_module.load_module_metadata()
739
- assert metadata["functionalities"] == ["fr1"]
745
+ assert metadata["functionalities"] == _stored("solo-one")
740
746
  # Only the functionalities baseline is trimmed; the hashes are left untouched.
741
747
  assert metadata["source_hash"] == "abc"
742
748
 
@@ -744,20 +750,20 @@ def test_reconcile_metadata_with_git_trims_metadata_ahead_of_git(solo_module):
744
750
  def test_reconcile_metadata_with_git_in_sync_is_noop(solo_module):
745
751
  os.makedirs(solo_module.module_build_folder)
746
752
  init_git_repo(solo_module.module_build_folder, module_name=solo_module.module_name)
747
- _commit_finished_frid(solo_module, "1")
748
- _commit_finished_frid(solo_module, "2")
749
- _write_metadata(solo_module, {"functionalities": ["fr1", "fr2"]})
753
+ _commit_finished_frid(solo_module, "solo-one")
754
+ _commit_finished_frid(solo_module, "solo-two")
755
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one", "solo-two")})
750
756
 
751
757
  solo_module.reconcile_metadata_with_git()
752
758
 
753
- assert solo_module.load_module_metadata()["functionalities"] == ["fr1", "fr2"]
759
+ assert solo_module.load_module_metadata()["functionalities"] == _stored("solo-one", "solo-two")
754
760
 
755
761
 
756
762
  def test_reconcile_metadata_with_git_no_finished_frid_empties_list(solo_module):
757
763
  # Only the initial commit exists (no finished FRID), so the baseline must be emptied.
758
764
  os.makedirs(solo_module.module_build_folder)
759
765
  init_git_repo(solo_module.module_build_folder, module_name=solo_module.module_name)
760
- _write_metadata(solo_module, {"functionalities": ["fr1"]})
766
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one")})
761
767
 
762
768
  solo_module.reconcile_metadata_with_git()
763
769
 
@@ -777,7 +783,7 @@ def test_reconcile_metadata_with_git_ignores_foreign_module_frid(solo_module):
777
783
  module_name="other-module",
778
784
  frid="1",
779
785
  )
780
- _write_metadata(solo_module, {"functionalities": ["fr1"]})
786
+ _write_metadata(solo_module, {"functionalities": _stored("solo-one")})
781
787
 
782
788
  solo_module.reconcile_metadata_with_git()
783
789
 
@@ -92,6 +92,7 @@ def make_args(api_key="test-key", headless=False):
92
92
  api="https://api.example.com",
93
93
  filename="project.plain",
94
94
  template_dir=None,
95
+ tests_folder=[],
95
96
  build_folder="build",
96
97
  render_range=None,
97
98
  render_from=None,
@@ -100,6 +101,7 @@ def make_args(api_key="test-key", headless=False):
100
101
  job_tag=None,
101
102
  log_to_file=False,
102
103
  log_file_name="codeplain.log",
104
+ render_conformance_tests=False,
103
105
  conformance_tests_script=None,
104
106
  unittests_script=None,
105
107
  prepare_environment_script=None,
@@ -4,31 +4,40 @@ import pytest
4
4
 
5
5
  import plain_spec
6
6
 
7
+ FUNC_IDS = ["add-task", "list-tasks", "rename-task", "delete-task"]
8
+
7
9
 
8
10
  def _four_functionalities():
9
- return {plain_spec.FUNCTIONAL_REQUIREMENTS: [{"markdown": f"- Functionality {i}."} for i in range(1, 5)]}
11
+ return {
12
+ plain_spec.FUNCTIONAL_REQUIREMENTS: [
13
+ {"id": func_id, "markdown": f"A :User: can {func_id.replace('-', ' ')}."} for func_id in FUNC_IDS
14
+ ]
15
+ }
10
16
 
11
17
 
12
18
  def test_get_render_range_parses_start_and_end():
13
- assert plain_spec.get_render_range("2,3", _four_functionalities()) == ["2", "3"]
19
+ assert plain_spec.get_render_range("list-tasks,rename-task", _four_functionalities()) == [
20
+ "list-tasks",
21
+ "rename-task",
22
+ ]
14
23
 
15
24
 
16
25
  def test_get_render_range_single_value_renders_one_frid():
17
- assert plain_spec.get_render_range("2", _four_functionalities()) == ["2"]
26
+ assert plain_spec.get_render_range("list-tasks", _four_functionalities()) == ["list-tasks"]
18
27
 
19
28
 
20
29
  def test_get_render_range_from_runs_to_last_frid():
21
- assert plain_spec.get_render_range_from("3", _four_functionalities()) == ["3", "4"]
30
+ assert plain_spec.get_render_range_from("rename-task", _four_functionalities()) == ["rename-task", "delete-task"]
22
31
 
23
32
 
24
33
  def test_compute_render_range_prefers_render_range():
25
- args = SimpleNamespace(render_range="1,2", render_from="3")
26
- assert plain_spec.compute_render_range(args, _four_functionalities()) == ["1", "2"]
34
+ args = SimpleNamespace(render_range="add-task,list-tasks", render_from="rename-task")
35
+ assert plain_spec.compute_render_range(args, _four_functionalities()) == ["add-task", "list-tasks"]
27
36
 
28
37
 
29
38
  def test_compute_render_range_falls_back_to_render_from():
30
- args = SimpleNamespace(render_range=None, render_from="3")
31
- assert plain_spec.compute_render_range(args, _four_functionalities()) == ["3", "4"]
39
+ args = SimpleNamespace(render_range=None, render_from="rename-task")
40
+ assert plain_spec.compute_render_range(args, _four_functionalities()) == ["rename-task", "delete-task"]
32
41
 
33
42
 
34
43
  def test_compute_render_range_none_when_no_arguments():
@@ -37,6 +46,6 @@ def test_compute_render_range_none_when_no_arguments():
37
46
 
38
47
 
39
48
  def test_compute_render_range_invalid_frid_raises():
40
- args = SimpleNamespace(render_range="9", render_from=None)
49
+ args = SimpleNamespace(render_range="no-such-task", render_from=None)
41
50
  with pytest.raises(plain_spec.InvalidFridArgument):
42
51
  plain_spec.compute_render_range(args, _four_functionalities())
@@ -100,7 +100,7 @@ def test_unit_tests_failing_after_the_last_attempt_name_the_cause(workspace, fix
100
100
  render_context = make_render_context(api, build_folder, unittests_script, fixtures_dir)
101
101
  code_renderer = CodeRenderer(render_context)
102
102
 
103
- # The last render attempt of functionality 1, after its last unit-test fix round.
103
+ # The last render attempt of the first functionality, after its last unit-test fix round.
104
104
  render_context.start_implementing_frid()
105
105
  render_context.frid_context.functional_requirement_render_attempts = MAX_CODE_GENERATION_RETRIES
106
106
  render_context.unit_tests_running_context = UnitTestsRunningContext(fix_attempts=MAX_UNITTEST_FIX_ATTEMPTS)
@@ -112,13 +112,13 @@ def test_unit_tests_failing_after_the_last_attempt_name_the_cause(workspace, fix
112
112
  code_renderer.run()
113
113
 
114
114
  assert render_context.state == States.RENDER_FAILED.value
115
- assert api.failed_frids == ["1"]
115
+ assert api.failed_frids == ["solo-one"]
116
116
 
117
117
  last_output_path = render_context.script_execution_history.latest_unit_test_output_path
118
118
  assert last_output_path is not None and os.path.exists(last_output_path)
119
119
 
120
120
  expected_message = (
121
- f"Functionality 1: unit tests still fail after {MAX_CODE_GENERATION_RETRIES} render attempts, "
121
+ f"Functionality pr_solo:solo-one: unit tests still fail after {MAX_CODE_GENERATION_RETRIES} render attempts, "
122
122
  f"{MAX_UNITTEST_FIX_ATTEMPTS} fix rounds each. Last unit tests output: {last_output_path}"
123
123
  )
124
124
  assert error_log_messages(caplog) == [expected_message]
@@ -155,7 +155,7 @@ def test_unit_tests_failing_again_during_conformance_tests_name_the_cause_once(w
155
155
  error_messages = error_log_messages(caplog)
156
156
  assert len(error_messages) == 1
157
157
  assert error_messages[0].startswith("Failed to adjust the unit tests")
158
- assert "functionality 1" in error_messages[0]
158
+ assert "functionality pr_solo:solo-one" in error_messages[0]
159
159
  # The TUI shows the same stop reason as the log, not the unit tests output of the payload.
160
160
  assert render_context.last_error_message == error_messages[0]
161
161
 
@@ -165,7 +165,7 @@ class TestExitWithErrorMessage:
165
165
  def make_context(last_error_message=None):
166
166
  render_context = RenderContext.__new__(RenderContext)
167
167
  render_context.codeplain_api = FakeCodeplainAPI()
168
- render_context.frid_context = SimpleNamespace(frid="1")
168
+ render_context.frid_context = SimpleNamespace(frid="solo-one")
169
169
  render_context.module_name = "mod"
170
170
  render_context.run_state = RunState(spec_filename="mod.plain")
171
171
  render_context.last_error_message = last_error_message
tests/test_telemetry.py CHANGED
@@ -98,7 +98,7 @@ def test_capture_crash_sends_event_with_tags(transport):
98
98
 
99
99
  run_state = RunState(spec_filename="test.plain")
100
100
  run_state.current_module = "my_module"
101
- run_state.current_frid = "2.1"
101
+ run_state.current_frid = "add-task"
102
102
  run_state.current_render_state = "IMPLEMENTING_FRID"
103
103
  run_state.user_email = "user@codeplain.ai"
104
104
 
@@ -110,7 +110,7 @@ def test_capture_crash_sends_event_with_tags(transport):
110
110
  tags = event["tags"]
111
111
  assert tags["render_id"] == run_state.render_id
112
112
  assert tags["current_module"] == "my_module"
113
- assert tags["current_frid"] == "2.1"
113
+ assert tags["current_frid"] == "my_module:add-task"
114
114
  assert tags["render_state"] == "IMPLEMENTING_FRID"
115
115
  assert tags["headless"] is True
116
116
  assert tags["unittests_script_provided"] is True
@@ -78,6 +78,7 @@ def make_args():
78
78
  api="https://api.example.com",
79
79
  filename="project.plain",
80
80
  template_dir=None,
81
+ tests_folder=[],
81
82
  build_folder="build",
82
83
  render_range=None,
83
84
  render_from=None,
@@ -130,7 +131,7 @@ def run_render(succeeded, terminal, render_state=None, render_choices=None):
130
131
  patch("plain2code.codeplain_api.CodeplainAPI"),
131
132
  patch("plain2code._check_connection", return_value="user@codeplain.ai"),
132
133
  patch("plain2code.signal.signal"),
133
- patch("plain2code.warn_if_acceptance_tests_without_conformance_script"),
134
+ patch("plain2code.warn_if_scenarios_without_conformance_script"),
134
135
  patch("plain2code.get_plain_module_render_state", return_value=render_state),
135
136
  patch("plain2code.get_render_choices", return_value=render_choices),
136
137
  patch("plain2code.ModuleRenderer", side_effect=make_module_renderer),
@@ -0,0 +1,91 @@
1
+ """The tests folders: where they come from, and what the client does with the scenarios it finds there."""
2
+
3
+ import os
4
+
5
+ import pytest
6
+
7
+ import file_utils # noqa: F401 # imported before plain_modules, which it imports back from
8
+ from plain2code_arguments import parse_arguments
9
+ from plain_modules import PlainModule
10
+
11
+ FIXTURES = "data/acceptance_tests_warning"
12
+ MAIN_MODULE = "main_requiring_acceptance_tests.plain"
13
+ REQUIRED_MODULE = "required_with_acceptance_tests.plain"
14
+
15
+
16
+ @pytest.fixture
17
+ def fixtures_dir(get_test_data_path):
18
+ return get_test_data_path(FIXTURES)
19
+
20
+
21
+ @pytest.fixture
22
+ def scenarios_dir(fixtures_dir):
23
+ return os.path.join(fixtures_dir, "tests")
24
+
25
+
26
+ def _parse(tmp_path, *extra_args):
27
+ plain_file = tmp_path / "project.plain"
28
+ plain_file.write_text("***functional specs***\n\n# do-something\n:App: does something.\n")
29
+ return parse_arguments([str(plain_file), *extra_args])
30
+
31
+
32
+ def test_the_default_is_tests_next_to_the_plain_file(tmp_path):
33
+ args = _parse(tmp_path)
34
+
35
+ assert args.tests_folder == [str(tmp_path / "tests")]
36
+
37
+
38
+ def test_the_default_holds_when_a_config_file_names_no_tests_folder(tmp_path):
39
+ (tmp_path / "config.yaml").write_text("verbose: true\n")
40
+
41
+ args = _parse(tmp_path)
42
+
43
+ assert args.tests_folder == [str(tmp_path / "tests")]
44
+
45
+
46
+ def test_a_conformance_tests_script_with_a_tests_folder_is_accepted(tmp_path, monkeypatch):
47
+ monkeypatch.chdir(tmp_path)
48
+ script = tmp_path / "run_conformance_tests.sh"
49
+ script.write_text("#!/bin/sh\n")
50
+
51
+ args = _parse(tmp_path, "--conformance-tests-script", str(script), "--tests-folder", "scenarios")
52
+
53
+ assert args.tests_folder == [str(tmp_path / "scenarios")]
54
+
55
+
56
+ def test_tests_folder_can_be_given_more_than_once(tmp_path, monkeypatch):
57
+ monkeypatch.chdir(tmp_path)
58
+ args = _parse(tmp_path, "--tests-folder", "scenarios", "--tests-folder", "extra")
59
+
60
+ assert args.tests_folder == [str(tmp_path / "scenarios"), str(tmp_path / "extra")]
61
+
62
+
63
+ def test_tests_folder_from_the_config_file_resolves_against_the_config_folder(tmp_path):
64
+ (tmp_path / "config.yaml").write_text("tests-folder: scenarios\n")
65
+ args = _parse(tmp_path)
66
+
67
+ assert args.tests_folder == [str(tmp_path / "scenarios")]
68
+
69
+
70
+ def test_scenarios_of_a_test_plain_file_reach_the_functionality(tmp_path, fixtures_dir, scenarios_dir):
71
+ module = PlainModule(REQUIRED_MODULE, str(tmp_path / "build"), [fixtures_dir], [scenarios_dir])
72
+
73
+ functionality = module.plain_source["functional specs"][0]
74
+ assert [scenario["id"] for scenario in functionality["conformance_tests"]] == ["runs-without-errors"]
75
+
76
+
77
+ def test_a_functionality_without_a_conformance_scenario_stops_the_run(tmp_path, fixtures_dir, scenarios_dir):
78
+ with pytest.raises(Exception, match="main_requiring_acceptance_tests:display-hello"):
79
+ PlainModule(
80
+ MAIN_MODULE,
81
+ str(tmp_path / "build"),
82
+ [fixtures_dir],
83
+ [scenarios_dir],
84
+ conformance_tests_enabled=True,
85
+ )
86
+
87
+
88
+ def test_the_run_goes_on_without_a_scenario_when_conformance_tests_are_off(tmp_path, fixtures_dir, scenarios_dir):
89
+ module = PlainModule(MAIN_MODULE, str(tmp_path / "build"), [fixtures_dir], [scenarios_dir])
90
+
91
+ assert module.module_name == "main_requiring_acceptance_tests"
@@ -0,0 +1,69 @@
1
+ """The client warns about a scenario with no conformance test, a test that implements no scenario,
2
+ and a scenario with more than one test. Both test renders report the same traceability, so the
3
+ conformance call and the acceptance call are checked the same way."""
4
+
5
+ from types import SimpleNamespace
6
+ from unittest.mock import patch
7
+
8
+ import file_utils # noqa: F401 # imported before plain_modules, which it imports back from
9
+ from render_machine.actions.render_conformance_tests import RenderConformanceTests
10
+
11
+
12
+ def _render_context(frid: str = "add-task"):
13
+ return SimpleNamespace(
14
+ conformance_tests_running_context=SimpleNamespace(current_testing_frid=frid),
15
+ )
16
+
17
+
18
+ def _warn(traceability: dict) -> list[str]:
19
+ with patch("render_machine.actions.render_conformance_tests.console") as console:
20
+ RenderConformanceTests._warn_about_untraced_scenarios(_render_context(), traceability)
21
+ return [call.args[0] for call in console.warning.call_args_list]
22
+
23
+
24
+ def test_every_scenario_implemented_warns_about_nothing():
25
+ assert _warn({"implemented": {"add-first-task": ["test_add_first_task"]}, "missing": [], "extra": []}) == []
26
+
27
+
28
+ def test_a_scenario_without_a_test_is_named():
29
+ [warning] = _warn({"implemented": {}, "missing": ["add-second-task"], "extra": []})
30
+
31
+ assert "add-task" in warning
32
+ assert "add-second-task" in warning
33
+
34
+
35
+ def test_a_test_implementing_no_scenario_is_named():
36
+ [warning] = _warn({"implemented": {}, "missing": [], "extra": ["test_something_else"]})
37
+
38
+ assert "test_something_else" in warning
39
+
40
+
41
+ def test_a_scenario_with_more_than_one_test_is_named():
42
+ [warning] = _warn(
43
+ {
44
+ "implemented": {"add-first-task": ["test_add_first_task", "test_add_first_task_scenario"]},
45
+ "missing": [],
46
+ "extra": [],
47
+ "duplicated": ["add-first-task"],
48
+ }
49
+ )
50
+
51
+ assert "add-task" in warning
52
+ assert "add-first-task" in warning
53
+
54
+
55
+ def test_every_fault_is_reported():
56
+ warnings = _warn(
57
+ {
58
+ "implemented": {},
59
+ "missing": ["add-second-task"],
60
+ "extra": ["test_something_else"],
61
+ "duplicated": ["add-first-task"],
62
+ }
63
+ )
64
+
65
+ assert len(warnings) == 3
66
+
67
+
68
+ def test_a_response_without_the_lists_warns_about_nothing():
69
+ assert _warn({}) == []
@@ -8,6 +8,7 @@ from textual.widgets import Label, ListItem, ListView, Static
8
8
 
9
9
  import plain_spec
10
10
  from partial_rendering import PlainModuleRenderState, RenderChoice, get_all_affected_modules_from_change
11
+ from plain2code_utils import qualified_frid
11
12
  from plain_modules import PlainModule
12
13
  from tui.components import CustomFooter, TUIComponents
13
14
 
@@ -154,8 +155,8 @@ class PlainModuleRenderChoiceTUI(App):
154
155
  elif pr.last_render_module.is_module_fully_rendered():
155
156
  change_box.mount(Label("The current module is fully rendered.", classes="rendering-info-title"))
156
157
  else:
157
- interrupted_frid = "1"
158
158
  interrupted_module = pr.last_render_module
159
+ interrupted_frid = plain_spec.get_first_frid(interrupted_module.plain_source)
159
160
  if pr.last_render_frid:
160
161
  next_frid, next_module = pr.last_render_module.get_next_frid(
161
162
  pr.last_render_frid, pr.last_render_module.module_name
@@ -164,11 +165,8 @@ class PlainModuleRenderChoiceTUI(App):
164
165
  interrupted_frid = next_frid
165
166
  interrupted_module = next_module
166
167
 
167
- msg = f"--- Rendering interrupted during [#5593FF]functionality {interrupted_frid}"
168
- if interrupted_module != pr.last_render_module:
169
- msg += f" of module {interrupted_module.module_name}[/] ---"
170
- else:
171
- msg += "[/] ---"
168
+ interrupted = qualified_frid(interrupted_module.module_name, interrupted_frid)
169
+ msg = f"--- Rendering interrupted during [#5593FF]functionality {interrupted}[/] ---"
172
170
 
173
171
  change_box.mount(Label(msg, classes="rendering-info-row"))
174
172