codeplain 0.4.3.dev63__py3-none-any.whl → 0.4.3.dev65__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.
- {codeplain-0.4.3.dev63.dist-info → codeplain-0.4.3.dev65.dist-info}/METADATA +1 -1
- {codeplain-0.4.3.dev63.dist-info → codeplain-0.4.3.dev65.dist-info}/RECORD +10 -10
- git_utils.py +24 -6
- module_renderer.py +4 -4
- plain_modules.py +26 -13
- tests/test_git_utils.py +107 -0
- tests/test_plain_modules.py +148 -0
- {codeplain-0.4.3.dev63.dist-info → codeplain-0.4.3.dev65.dist-info}/WHEEL +0 -0
- {codeplain-0.4.3.dev63.dist-info → codeplain-0.4.3.dev65.dist-info}/entry_points.txt +0 -0
- {codeplain-0.4.3.dev63.dist-info → codeplain-0.4.3.dev65.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,10 +6,10 @@ diff_utils.py,sha256=AjiQlqo5pRos_8hVXZo5yBurl5BzSrTMGrQv4dCtRCg,1198
|
|
|
6
6
|
event_bus.py,sha256=g5XLwRfjrvTIcB6urjREuCJzZj5TA93hy8lKXLGXuCE,650
|
|
7
7
|
file_utils.py,sha256=d46BFIKM97nPTwkiYFoEfTmxAngEajkSKxJbX3orErY,8885
|
|
8
8
|
git_preflight.py,sha256=vB2A8GyYz_iWr8jOE4POFLBHr3qihmedWuidspGdsrw,1509
|
|
9
|
-
git_utils.py,sha256=
|
|
9
|
+
git_utils.py,sha256=2px1u7WyDnRf_37q-lSUw1_wM5sWBk3bgAh6B2S00ck,17108
|
|
10
10
|
memory_management.py,sha256=CwIOQqF7Xo1sNfvP69zQRK_CpjinQD9dbolhRPl6lTk,2446
|
|
11
11
|
metadata_utils.py,sha256=YO17o7IAma5TT1ZN0pTwrLVr_KxFQ8APv02KqKPpI5k,1641
|
|
12
|
-
module_renderer.py,sha256=
|
|
12
|
+
module_renderer.py,sha256=MuMhBJIjFODLghitoIJc45VGh9pT-Zup9oamVHVAn0Y,6959
|
|
13
13
|
partial_rendering.py,sha256=7rQu0EE1H8JND-uePovdKfiQHGfdQncDyepwup7QBSY,15742
|
|
14
14
|
path_resolution.py,sha256=0tMqU0a1g4DYhTOp7QjLVSEkv_cgasb4NI1mK809dUM,2233
|
|
15
15
|
plain2code.py,sha256=w0LJhXj8aF7p8aBo4nLNEeXkHSAuvYayVUN71J4OMU8,24183
|
|
@@ -24,7 +24,7 @@ plain2code_state.py,sha256=Qai9kfsvQ2IYSQ31EyITkqCwlFm_rhO-sO12Y1CCOeA,3615
|
|
|
24
24
|
plain2code_telemetry.py,sha256=NO8zw1i3ucM6Z9xQoSCeWqC5Hr-9Oql58YtgEOhBnaQ,4683
|
|
25
25
|
plain2code_utils.py,sha256=lGrnGavNXjUCQoVLjNYKgLiSTVazJv2o7WByB30M2Nk,2316
|
|
26
26
|
plain_file.py,sha256=50CevjRihjddXbc3WzKKJF_kaVcMHUJ1FH2HJUZawT8,138
|
|
27
|
-
plain_modules.py,sha256=
|
|
27
|
+
plain_modules.py,sha256=PNy5C9nSzo2tQitpm5ytI2DtE1pABuqsFG8P15HQgAk,29881
|
|
28
28
|
plain_spec.py,sha256=AhDbw4GSQ95wC8fkFSPG66MsCu-37Kcz8Skcj66fQhA,1262
|
|
29
29
|
system_config.py,sha256=sA8wiPmBMtRsLwSQ40U5pVdLazAafbV-1Z19Yp0HiSQ,5314
|
|
30
30
|
usage_summary.py,sha256=MA4WcVaAwz6IWCN4k_rgxVcwO4I157wN7BZlFi3h0R4,1282
|
|
@@ -95,7 +95,7 @@ tests/test_frid_arguments.py,sha256=zIEU2HGgJU4YOY2DXkjO9MmTlIUk4Iu5dfEU9OwKbak,
|
|
|
95
95
|
tests/test_functionality_position.py,sha256=QQdhIqZhRC8-30xKZPyOye6dm8kSkJnja4PB53iZkeE,3540
|
|
96
96
|
tests/test_functionality_without_scenarios.py,sha256=kFBqu9UQ7JdIJCs6z5Hu0xsv9YskBXhkEKBKcdN0tvI,2832
|
|
97
97
|
tests/test_git_preflight.py,sha256=6aQqInDzpk03pS-6UfkGQWjErrIXTEdHs5oeq3ZYzTw,3186
|
|
98
|
-
tests/test_git_utils.py,sha256=
|
|
98
|
+
tests/test_git_utils.py,sha256=ZbxO4tQr8-w4j9NBgOSqZpCy3JIHhiVvsQiqSS8ZtaM,19528
|
|
99
99
|
tests/test_headless_logging.py,sha256=soNESeotKQaU-SQyxtjpq35l-dLVsauZ_lJ-wk9i2mI,6419
|
|
100
100
|
tests/test_log_file_name_resolution.py,sha256=99g9NgPF-BZ98CvNyqDcltBAx4sLBE8gpQPAAieKiPc,3619
|
|
101
101
|
tests/test_logging_config_path_resolution.py,sha256=avz_ehRd18INwIXvAy1AwVzNNUz0vS8eu1nRe0bra8g,2650
|
|
@@ -104,7 +104,7 @@ tests/test_path_resolution.py,sha256=yQpd-Unq1lwNv0wkRPwVs5pDT8JmyyDgbpiTQsyt--Y
|
|
|
104
104
|
tests/test_plain2code.py,sha256=BKLIBOc3tON2fODm1ETdPZZkZMbSrvbIG54EWJcKcmE,3411
|
|
105
105
|
tests/test_plain2code_state.py,sha256=O-sDt4F_lF6XtanWKWfh5IsNmDdfuJP_JoGagujzdfM,1440
|
|
106
106
|
tests/test_plain2code_utils.py,sha256=MXAYsWMY_7Vb4im2ZJK46Gsq1ApIjuGkQAEmUz0ISOY,1665
|
|
107
|
-
tests/test_plain_modules.py,sha256=
|
|
107
|
+
tests/test_plain_modules.py,sha256=OyMfeN_E5z5HYmKlrw0UXQ59Pn3DacWxXMlD3RSnwUg,41068
|
|
108
108
|
tests/test_prepare_repositories_layout.py,sha256=PhJQLnHfjfjo6CTWoicyEKgL0_GtjwB2OKYAWSBVHtk,14638
|
|
109
109
|
tests/test_render_finished_report.py,sha256=FmuntIaGGIebUZUnvMQ0nmRHiSVIG3n5WsXRAzEgo90,9944
|
|
110
110
|
tests/test_render_range.py,sha256=N4XS6zQbQmDlQmUvl6vhqLL7VcczET65GG1DWypP-k0,1832
|
|
@@ -133,8 +133,8 @@ tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
|
|
|
133
133
|
tui/state_handlers.py,sha256=5FkF13mCLYAOgpYnzR932U3tYxSnMkCu5jybMFEBVe4,16264
|
|
134
134
|
tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
|
|
135
135
|
tui/widget_helpers.py,sha256=jitm2WHiKj-NVFL-hULxWzckPreRbUTl9OIZLN31-ek,6997
|
|
136
|
-
codeplain-0.4.3.
|
|
137
|
-
codeplain-0.4.3.
|
|
138
|
-
codeplain-0.4.3.
|
|
139
|
-
codeplain-0.4.3.
|
|
140
|
-
codeplain-0.4.3.
|
|
136
|
+
codeplain-0.4.3.dev65.dist-info/METADATA,sha256=Xki0sVnXqAs_ICiP9_SmIqc9fZNuhKae5QAZ2xVab4E,7260
|
|
137
|
+
codeplain-0.4.3.dev65.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
138
|
+
codeplain-0.4.3.dev65.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
|
|
139
|
+
codeplain-0.4.3.dev65.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
|
|
140
|
+
codeplain-0.4.3.dev65.dist-info/RECORD,,
|
git_utils.py
CHANGED
|
@@ -285,6 +285,13 @@ def _get_commit(repo: Repo, frid: Optional[str]) -> str:
|
|
|
285
285
|
return initial_commit
|
|
286
286
|
|
|
287
287
|
|
|
288
|
+
def _escape_exact_grep_line(line: str) -> str:
|
|
289
|
+
"""Return a POSIX BRE pattern matching an entire commit-message line literally."""
|
|
290
|
+
for ch in ("\\", ".", "[", "]", "*", "^", "$"):
|
|
291
|
+
line = line.replace(ch, f"\\{ch}")
|
|
292
|
+
return f"^{line}$"
|
|
293
|
+
|
|
294
|
+
|
|
288
295
|
def _get_commit_with_frid(repo: Repo, frid: str, module_name: Optional[str] = None) -> str:
|
|
289
296
|
"""
|
|
290
297
|
Finds commit with given frid mentioned in the commit message.
|
|
@@ -305,9 +312,9 @@ def _get_commit_with_frid(repo: Repo, frid: str, module_name: Optional[str] = No
|
|
|
305
312
|
return _get_commit_with_message(repo, commit_message_pattern)
|
|
306
313
|
|
|
307
314
|
# Use multiple grep patterns with --all-match for AND condition
|
|
308
|
-
escaped_frid_message = commit_message_pattern
|
|
315
|
+
escaped_frid_message = _escape_exact_grep_line(commit_message_pattern)
|
|
309
316
|
module_name_pattern = MODULE_NAME_MESSAGE.format(module_name)
|
|
310
|
-
escaped_module_message = module_name_pattern
|
|
317
|
+
escaped_module_message = _escape_exact_grep_line(module_name_pattern)
|
|
311
318
|
|
|
312
319
|
return repo.git.rev_list(
|
|
313
320
|
repo.active_branch.name,
|
|
@@ -337,7 +344,7 @@ def _get_initial_commit(repo: Repo) -> str:
|
|
|
337
344
|
|
|
338
345
|
def _get_commit_with_message(repo: Repo, message: str) -> str:
|
|
339
346
|
"""Finds commit with given message."""
|
|
340
|
-
escaped_message = message
|
|
347
|
+
escaped_message = _escape_exact_grep_line(message)
|
|
341
348
|
|
|
342
349
|
return repo.git.rev_list(repo.active_branch.name, "--grep", escaped_message, "-n", "1")
|
|
343
350
|
|
|
@@ -362,7 +369,7 @@ def get_implementation_code_diff(repo_path: Union[str, os.PathLike], frid: str,
|
|
|
362
369
|
return _get_diff_dict(diff_output)
|
|
363
370
|
|
|
364
371
|
|
|
365
|
-
def get_fixed_implementation_code_diff(repo_path: Union[str, os.PathLike], frid: str) -> dict:
|
|
372
|
+
def get_fixed_implementation_code_diff(repo_path: Union[str, os.PathLike], frid: str) -> Optional[dict]:
|
|
366
373
|
repo = Repo(repo_path)
|
|
367
374
|
|
|
368
375
|
implementation_commit = _get_commit_with_message(repo, REFACTORED_CODE_COMMIT_MESSAGE.format(frid))
|
|
@@ -370,9 +377,20 @@ def get_fixed_implementation_code_diff(repo_path: Union[str, os.PathLike], frid:
|
|
|
370
377
|
implementation_commit = _get_commit_with_message(
|
|
371
378
|
repo, FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format(frid)
|
|
372
379
|
)
|
|
380
|
+
if not implementation_commit:
|
|
381
|
+
return None
|
|
373
382
|
|
|
374
|
-
|
|
375
|
-
|
|
383
|
+
escaped_passed_message = _escape_exact_grep_line(CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE)
|
|
384
|
+
escaped_frid_message = _escape_exact_grep_line(RENDERED_FRID_MESSAGE.format(frid))
|
|
385
|
+
conformance_tests_passed_commit = repo.git.rev_list(
|
|
386
|
+
repo.active_branch.name,
|
|
387
|
+
"--grep",
|
|
388
|
+
escaped_passed_message,
|
|
389
|
+
"--grep",
|
|
390
|
+
escaped_frid_message,
|
|
391
|
+
"--all-match",
|
|
392
|
+
"-n",
|
|
393
|
+
"1",
|
|
376
394
|
)
|
|
377
395
|
if not conformance_tests_passed_commit:
|
|
378
396
|
return None
|
module_renderer.py
CHANGED
|
@@ -73,6 +73,9 @@ class ModuleRenderer:
|
|
|
73
73
|
Returns:
|
|
74
74
|
tuple[bool, bool]: (Whether the module was rendered and whether the rendering failed)
|
|
75
75
|
"""
|
|
76
|
+
if any(module.module_name == plain_module.module_name for module in self.loaded_modules):
|
|
77
|
+
return True, False
|
|
78
|
+
|
|
76
79
|
is_render_choice_module = (
|
|
77
80
|
self.render_choice is not None
|
|
78
81
|
and self.render_choice.module is not None
|
|
@@ -99,10 +102,7 @@ class ModuleRenderer:
|
|
|
99
102
|
return False, True
|
|
100
103
|
|
|
101
104
|
if (
|
|
102
|
-
(
|
|
103
|
-
(not force_render)
|
|
104
|
-
or any(module.module_name == plain_module.module_name for module in self.loaded_modules)
|
|
105
|
-
)
|
|
105
|
+
(not force_render)
|
|
106
106
|
and plain_module.get_repo() is not None
|
|
107
107
|
and not has_any_required_module_changed
|
|
108
108
|
and not plain_module.has_plain_spec_changed()
|
plain_modules.py
CHANGED
|
@@ -156,6 +156,7 @@ class PlainModule:
|
|
|
156
156
|
template_dirs: list[str],
|
|
157
157
|
tests_folders: list[str] | None = None,
|
|
158
158
|
conformance_tests_enabled: bool = False,
|
|
159
|
+
_modules_cache: dict[str, PlainModule] | None = None,
|
|
159
160
|
):
|
|
160
161
|
self.filename = filename
|
|
161
162
|
self.build_folder = build_folder
|
|
@@ -174,16 +175,22 @@ class PlainModule:
|
|
|
174
175
|
plain_spec.collect_linked_resources(plain_source, resources_list, None, True)
|
|
175
176
|
self.resources_list = resources_list
|
|
176
177
|
self.functionalities_without_scenarios: list[tuple[str, str]] = []
|
|
178
|
+
if _modules_cache is None:
|
|
179
|
+
_modules_cache = {}
|
|
180
|
+
_modules_cache[self.module_name] = self
|
|
177
181
|
self.required_modules = []
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
for req_name in required_modules_names:
|
|
183
|
+
if req_name in _modules_cache:
|
|
184
|
+
self.required_modules.append(_modules_cache[req_name])
|
|
185
|
+
else:
|
|
186
|
+
self.required_modules.append(
|
|
187
|
+
PlainModule(
|
|
188
|
+
plain_file.get_filename_from_module_name(req_name),
|
|
189
|
+
self.build_folder,
|
|
190
|
+
self.template_dirs,
|
|
191
|
+
_modules_cache=_modules_cache,
|
|
192
|
+
)
|
|
184
193
|
)
|
|
185
|
-
for module_name in required_modules_names
|
|
186
|
-
]
|
|
187
194
|
if tests_folders is not None:
|
|
188
195
|
self._bind_test_scenarios(tests_folders, conformance_tests_enabled)
|
|
189
196
|
|
|
@@ -202,14 +209,20 @@ class PlainModule:
|
|
|
202
209
|
|
|
203
210
|
@cached_property
|
|
204
211
|
def all_required_modules(self) -> list[PlainModule]:
|
|
205
|
-
|
|
212
|
+
result: list[PlainModule] = []
|
|
213
|
+
seen: set[str] = set()
|
|
214
|
+
|
|
206
215
|
for required_module in self.required_modules:
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
for mod in required_module.all_required_modules:
|
|
217
|
+
if mod.module_name not in seen:
|
|
218
|
+
seen.add(mod.module_name)
|
|
219
|
+
result.append(mod)
|
|
209
220
|
|
|
210
|
-
|
|
221
|
+
if required_module.module_name not in seen:
|
|
222
|
+
seen.add(required_module.module_name)
|
|
223
|
+
result.append(required_module)
|
|
211
224
|
|
|
212
|
-
return
|
|
225
|
+
return result
|
|
213
226
|
|
|
214
227
|
@property
|
|
215
228
|
def _default_module_folder(self) -> str:
|
tests/test_git_utils.py
CHANGED
|
@@ -8,10 +8,13 @@ from git import Repo
|
|
|
8
8
|
|
|
9
9
|
from git_utils import (
|
|
10
10
|
BASE_FOLDER_COMMIT_MESSAGE,
|
|
11
|
+
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE,
|
|
11
12
|
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE,
|
|
13
|
+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE,
|
|
12
14
|
REFACTORED_CODE_COMMIT_MESSAGE,
|
|
13
15
|
add_all_files_and_commit,
|
|
14
16
|
diff,
|
|
17
|
+
get_fixed_implementation_code_diff,
|
|
15
18
|
get_last_rendered_functionality,
|
|
16
19
|
init_git_repo,
|
|
17
20
|
revert_changes,
|
|
@@ -508,3 +511,107 @@ def test_get_last_finished_frid_without_module_name(empty_repo):
|
|
|
508
511
|
|
|
509
512
|
with pytest.raises(InvalidGitRepositoryError, match="Could not find module name in finished commit"):
|
|
510
513
|
get_last_rendered_functionality(empty_repo)
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def test_get_fixed_implementation_code_diff_filters_by_specific_frid(empty_repo):
|
|
517
|
+
"""get_fixed_implementation_code_diff must return diff for the specific FRID,
|
|
518
|
+
and return None when an FRID has no conformance fix even if another FRID does."""
|
|
519
|
+
file_path = Path(empty_repo) / "code.py"
|
|
520
|
+
|
|
521
|
+
# FRID 1: implemented, then fixed during conformance tests
|
|
522
|
+
file_path.write_text("def f(): return 1\n")
|
|
523
|
+
add_all_files_and_commit(
|
|
524
|
+
empty_repo,
|
|
525
|
+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format("frid-1"),
|
|
526
|
+
module_name="mod",
|
|
527
|
+
frid="frid-1",
|
|
528
|
+
)
|
|
529
|
+
file_path.write_text("def f(): return 10\n")
|
|
530
|
+
add_all_files_and_commit(
|
|
531
|
+
empty_repo,
|
|
532
|
+
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE,
|
|
533
|
+
module_name="mod",
|
|
534
|
+
frid="frid-1",
|
|
535
|
+
)
|
|
536
|
+
add_all_files_and_commit(
|
|
537
|
+
empty_repo,
|
|
538
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("frid-1"),
|
|
539
|
+
module_name="mod",
|
|
540
|
+
frid="frid-1",
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
# FRID 2: implemented and finished without any conformance fixes
|
|
544
|
+
file_path.write_text("def f(): return 10\ndef g(): return 2\n")
|
|
545
|
+
add_all_files_and_commit(
|
|
546
|
+
empty_repo,
|
|
547
|
+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format("frid-2"),
|
|
548
|
+
module_name="mod",
|
|
549
|
+
frid="frid-2",
|
|
550
|
+
)
|
|
551
|
+
add_all_files_and_commit(
|
|
552
|
+
empty_repo,
|
|
553
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("frid-2"),
|
|
554
|
+
module_name="mod",
|
|
555
|
+
frid="frid-2",
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
# FRID 2 has NO conformance fixes, so it must return None (not FRID 1's commit!)
|
|
559
|
+
assert get_fixed_implementation_code_diff(empty_repo, "frid-2") is None
|
|
560
|
+
|
|
561
|
+
# FRID 1 DOES have conformance fixes, so it must return FRID 1's diff
|
|
562
|
+
diff_frid_1 = get_fixed_implementation_code_diff(empty_repo, "frid-1")
|
|
563
|
+
assert diff_frid_1 is not None
|
|
564
|
+
assert "code.py" in diff_frid_1
|
|
565
|
+
assert "-def f(): return 1" in diff_frid_1["code.py"]
|
|
566
|
+
assert "+def f(): return 10" in diff_frid_1["code.py"]
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def test_get_fixed_implementation_code_diff_does_not_match_prefix_frids(empty_repo):
|
|
570
|
+
"""Exact line matching prevents FRID '1' (or 'add-item') from matching '10' (or 'add-item-v2')."""
|
|
571
|
+
file_path = Path(empty_repo) / "code.py"
|
|
572
|
+
|
|
573
|
+
# FRID "1": implemented and finished without conformance fixes
|
|
574
|
+
file_path.write_text("v = 1\n")
|
|
575
|
+
add_all_files_and_commit(
|
|
576
|
+
empty_repo,
|
|
577
|
+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format("1"),
|
|
578
|
+
module_name="mod",
|
|
579
|
+
frid="1",
|
|
580
|
+
)
|
|
581
|
+
add_all_files_and_commit(
|
|
582
|
+
empty_repo,
|
|
583
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("1"),
|
|
584
|
+
module_name="mod",
|
|
585
|
+
frid="1",
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
# FRID "10": implemented AND fixed during conformance testing
|
|
589
|
+
file_path.write_text("v = 10\n")
|
|
590
|
+
add_all_files_and_commit(
|
|
591
|
+
empty_repo,
|
|
592
|
+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format("10"),
|
|
593
|
+
module_name="mod",
|
|
594
|
+
frid="10",
|
|
595
|
+
)
|
|
596
|
+
file_path.write_text("v = 100\n")
|
|
597
|
+
add_all_files_and_commit(
|
|
598
|
+
empty_repo,
|
|
599
|
+
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE,
|
|
600
|
+
module_name="mod",
|
|
601
|
+
frid="10",
|
|
602
|
+
)
|
|
603
|
+
add_all_files_and_commit(
|
|
604
|
+
empty_repo,
|
|
605
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("10"),
|
|
606
|
+
module_name="mod",
|
|
607
|
+
frid="10",
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
# FRID "1" must not match FRID "10"'s conformance fix commit
|
|
611
|
+
assert get_fixed_implementation_code_diff(empty_repo, "1") is None
|
|
612
|
+
|
|
613
|
+
# FRID "10" returns its own conformance fix diff
|
|
614
|
+
diff_10 = get_fixed_implementation_code_diff(empty_repo, "10")
|
|
615
|
+
assert diff_10 is not None
|
|
616
|
+
assert "-v = 10" in diff_10["code.py"]
|
|
617
|
+
assert "+v = 100" in diff_10["code.py"]
|
tests/test_plain_modules.py
CHANGED
|
@@ -219,6 +219,154 @@ def test_get_next_module_raises_when_module_not_found(root_module):
|
|
|
219
219
|
root_module.get_next_module("unknown")
|
|
220
220
|
|
|
221
221
|
|
|
222
|
+
def test_all_required_modules_diamond_dependency_deduplication():
|
|
223
|
+
"""In a diamond dependency (A requires B and C; B requires C), C appears only once in all_required_modules."""
|
|
224
|
+
mod_c = PlainModule.__new__(PlainModule)
|
|
225
|
+
mod_c.module_name = "mod_c"
|
|
226
|
+
mod_c.required_modules = []
|
|
227
|
+
|
|
228
|
+
mod_b = PlainModule.__new__(PlainModule)
|
|
229
|
+
mod_b.module_name = "mod_b"
|
|
230
|
+
mod_b.required_modules = [mod_c]
|
|
231
|
+
|
|
232
|
+
mod_a = PlainModule.__new__(PlainModule)
|
|
233
|
+
mod_a.module_name = "mod_a"
|
|
234
|
+
mod_a.required_modules = [mod_b, mod_c]
|
|
235
|
+
|
|
236
|
+
all_reqs = mod_a.all_required_modules
|
|
237
|
+
assert [m.module_name for m in all_reqs] == ["mod_c", "mod_b"]
|
|
238
|
+
|
|
239
|
+
assert mod_a.get_next_module("mod_c") == mod_b
|
|
240
|
+
assert mod_a.get_next_module("mod_b") == mod_a
|
|
241
|
+
assert mod_a.get_next_module("mod_a") is None
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_diamond_dependency_shares_instances_preserves_scenarios_and_avoids_double_render(monkeypatch):
|
|
245
|
+
"""Real diamond project (A -> [C, B], B -> [C]) with conformance scenarios:
|
|
246
|
+
1. All references to C share the same PlainModule instance and bound scenarios.
|
|
247
|
+
2. A subsequent run with no spec changes does not flag C as changed or re-render it.
|
|
248
|
+
3. Deleting A and B resumes at B (not C) and never renders C twice.
|
|
249
|
+
4. Even when render_choice targets C, ModuleRenderer renders C only once.
|
|
250
|
+
"""
|
|
251
|
+
from argparse import Namespace
|
|
252
|
+
from unittest.mock import MagicMock
|
|
253
|
+
|
|
254
|
+
import file_utils
|
|
255
|
+
import plain_spec
|
|
256
|
+
from event_bus import EventBus
|
|
257
|
+
from module_renderer import ModuleRenderer
|
|
258
|
+
from partial_rendering import RenderChoice, get_plain_module_render_state, get_render_choices
|
|
259
|
+
from plain2code_state import RunState
|
|
260
|
+
from render_machine.states import States
|
|
261
|
+
|
|
262
|
+
tmp_dir = tempfile.mkdtemp()
|
|
263
|
+
try:
|
|
264
|
+
specs_dir = os.path.join(tmp_dir, "specs")
|
|
265
|
+
tests_dir = os.path.join(specs_dir, "tests")
|
|
266
|
+
build_dir = os.path.join(tmp_dir, "build")
|
|
267
|
+
for mod_name in ("mod_c", "mod_b", "mod_a"):
|
|
268
|
+
os.makedirs(os.path.join(tests_dir, mod_name), exist_ok=True)
|
|
269
|
+
|
|
270
|
+
(Path(specs_dir) / "mod_c.plain").write_text(
|
|
271
|
+
"***implementation reqs***\n\n- C req.\n\n***functional specs***\n\n# func-c\nC func.\n"
|
|
272
|
+
)
|
|
273
|
+
(Path(specs_dir) / "mod_b.plain").write_text(
|
|
274
|
+
"---\nrequires:\n - mod_c\n---\n\n***implementation reqs***\n\n- B req.\n\n***functional specs***\n\n# func-b\nB func.\n"
|
|
275
|
+
)
|
|
276
|
+
(Path(specs_dir) / "mod_a.plain").write_text(
|
|
277
|
+
"---\nrequires:\n - mod_c\n - mod_b\n---\n\n***implementation reqs***\n\n- A req.\n\n***functional specs***\n\n# func-a\nA func.\n"
|
|
278
|
+
)
|
|
279
|
+
for mod_name, frid in (("mod_c", "func-c"), ("mod_b", "func-b"), ("mod_a", "func-a")):
|
|
280
|
+
(Path(tests_dir) / mod_name / f"{frid}.plain").write_text(
|
|
281
|
+
f"---\nmodule: {mod_name}\nfunc_id: {frid}\n---\n\n***conformance tests***\n\n# sc-1\nTest {frid}.\n\n***acceptance tests***\n"
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
mod_a = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
285
|
+
mod_c_from_a = mod_a.required_modules[0]
|
|
286
|
+
mod_b = mod_a.required_modules[1]
|
|
287
|
+
mod_c_from_b = mod_b.required_modules[0]
|
|
288
|
+
|
|
289
|
+
assert mod_c_from_a is mod_c_from_b
|
|
290
|
+
assert [m.module_name for m in mod_a.all_required_modules] == ["mod_c", "mod_b"]
|
|
291
|
+
assert mod_c_from_b.plain_source[plain_spec.FUNCTIONAL_REQUIREMENTS][0][plain_spec.CONFORMANCE_TESTS]
|
|
292
|
+
assert mod_a.get_next_module("mod_c") is mod_b
|
|
293
|
+
|
|
294
|
+
rendered_modules: list[str] = []
|
|
295
|
+
|
|
296
|
+
class FakeCodeRenderer:
|
|
297
|
+
def __init__(self, render_context):
|
|
298
|
+
self.render_context = render_context
|
|
299
|
+
|
|
300
|
+
def run(self):
|
|
301
|
+
m = self.render_context.plain_module
|
|
302
|
+
rendered_modules.append(m.module_name)
|
|
303
|
+
init_git_repo(m.module_build_folder, m.module_name, "r1")
|
|
304
|
+
(Path(m.module_build_folder) / f"{m.module_name}.txt").write_text(m.module_name)
|
|
305
|
+
frid = list(plain_spec.get_frids(m.plain_source))[-1]
|
|
306
|
+
add_all_files_and_commit(
|
|
307
|
+
m.module_build_folder,
|
|
308
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid),
|
|
309
|
+
module_name=m.module_name,
|
|
310
|
+
frid=frid,
|
|
311
|
+
)
|
|
312
|
+
self.render_context.state = States.RENDER_COMPLETED.value
|
|
313
|
+
|
|
314
|
+
monkeypatch.setattr("module_renderer.CodeRenderer", FakeCodeRenderer)
|
|
315
|
+
|
|
316
|
+
args = Namespace(
|
|
317
|
+
build_dest=os.path.join(tmp_dir, "dist"),
|
|
318
|
+
conformance_tests_dest=os.path.join(tmp_dir, "dist_tests"),
|
|
319
|
+
unittests_script=None,
|
|
320
|
+
conformance_tests_script=None,
|
|
321
|
+
prepare_environment_script=None,
|
|
322
|
+
copy_build=False,
|
|
323
|
+
copy_conformance_tests=False,
|
|
324
|
+
render_conformance_tests=False,
|
|
325
|
+
base_folder=None,
|
|
326
|
+
test_script_timeout=None,
|
|
327
|
+
render_machine_graph=False,
|
|
328
|
+
force_render=False,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
# 1. Initial full render: each module renders once in topological order
|
|
332
|
+
ModuleRenderer(MagicMock(), mod_a, None, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
333
|
+
assert rendered_modules == ["mod_c", "mod_b", "mod_a"]
|
|
334
|
+
|
|
335
|
+
# 2. Re-parse with no spec changes: C must not report spec changes on either path
|
|
336
|
+
rendered_modules.clear()
|
|
337
|
+
mod_a2 = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
338
|
+
assert not mod_a2.required_modules[0].has_plain_spec_changed()
|
|
339
|
+
assert not mod_a2.required_modules[1].required_modules[0].has_plain_spec_changed()
|
|
340
|
+
state2 = get_plain_module_render_state(mod_a2)
|
|
341
|
+
assert state2 is not None and state2.change is None
|
|
342
|
+
# Even if ModuleRenderer checks required modules, mod_c and mod_b are skipped
|
|
343
|
+
ModuleRenderer(MagicMock(), mod_a2, None, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
344
|
+
assert "mod_c" not in rendered_modules
|
|
345
|
+
assert "mod_b" not in rendered_modules
|
|
346
|
+
|
|
347
|
+
# 3. Delete A and B after full render: resume choice starts at B (not C) and never renders C twice
|
|
348
|
+
rendered_modules.clear()
|
|
349
|
+
file_utils.delete_folder(os.path.join(build_dir, "mod_a"))
|
|
350
|
+
file_utils.delete_folder(os.path.join(build_dir, "mod_b"))
|
|
351
|
+
mod_a3 = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
352
|
+
state3 = get_plain_module_render_state(mod_a3)
|
|
353
|
+
assert state3 is not None and state3.last_render_module.module_name == "mod_c"
|
|
354
|
+
choices3 = get_render_choices(mod_a3, state3)
|
|
355
|
+
assert choices3["1"].module.module_name == "mod_b"
|
|
356
|
+
ModuleRenderer(
|
|
357
|
+
MagicMock(), mod_a3, choices3["1"], None, args, RunState("mod_a.plain"), EventBus()
|
|
358
|
+
).render_module()
|
|
359
|
+
assert rendered_modules == ["mod_b", "mod_a"]
|
|
360
|
+
|
|
361
|
+
# 4. When render_choice explicitly targets mod_c, mod_c still renders only once
|
|
362
|
+
rendered_modules.clear()
|
|
363
|
+
choice_c = RenderChoice(module=mod_a3.required_modules[0], render_range=None, choice_type="rerender_affected")
|
|
364
|
+
ModuleRenderer(MagicMock(), mod_a3, choice_c, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
365
|
+
assert rendered_modules == ["mod_c", "mod_b", "mod_a"]
|
|
366
|
+
finally:
|
|
367
|
+
file_utils.delete_folder(tmp_dir)
|
|
368
|
+
|
|
369
|
+
|
|
222
370
|
# --------------------------------------------------------------------------
|
|
223
371
|
# get_next_frid
|
|
224
372
|
# --------------------------------------------------------------------------
|
|
File without changes
|
|
File without changes
|
|
File without changes
|