codeplain 0.4.3.dev64__py3-none-any.whl → 0.4.3.dev66__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.dev64.dist-info → codeplain-0.4.3.dev66.dist-info}/METADATA +1 -1
- {codeplain-0.4.3.dev64.dist-info → codeplain-0.4.3.dev66.dist-info}/RECORD +37 -33
- codeplain_REST_api.py +12 -0
- git_utils.py +66 -0
- module_renderer.py +23 -5
- partial_rendering.py +34 -10
- plain2code.py +18 -4
- plain2code_arguments.py +6 -0
- plain_modules.py +95 -13
- render_machine/actions/commit_conformance_tests_changes.py +7 -3
- render_machine/actions/exit_with_error.py +7 -6
- render_machine/actions/finish_functional_requirement.py +16 -4
- render_machine/actions/fix_unit_tests.py +19 -0
- render_machine/actions/prepare_repositories.py +68 -0
- render_machine/actions/render_conformance_tests.py +20 -2
- render_machine/actions/render_functional_requirement.py +3 -0
- render_machine/render_context.py +63 -17
- render_machine/render_types.py +4 -1
- render_machine/render_utils.py +6 -0
- render_machine/state_machine_config.py +2 -4
- tests/test_conformance_fix_conversation.py +1 -0
- tests/test_conformance_tests_json_order.py +37 -0
- tests/test_fix_unit_tests_action.py +35 -0
- tests/test_fix_unit_tests_conformance_context.py +1 -0
- tests/test_git_utils.py +26 -0
- tests/test_partial_rendering.py +3 -0
- tests/test_plain_modules.py +240 -0
- tests/test_prepare_repositories_layout.py +2 -1
- tests/test_regenerate_checks.py +173 -0
- tests/test_regenerate_reset.py +167 -0
- tests/test_render_context_conformance_regression.py +198 -0
- tests/test_render_stop_reason.py +27 -2
- tests/test_terminal_attachment.py +1 -0
- tui/plain_module_render_choice_tui.py +7 -0
- {codeplain-0.4.3.dev64.dist-info → codeplain-0.4.3.dev66.dist-info}/WHEEL +0 -0
- {codeplain-0.4.3.dev64.dist-info → codeplain-0.4.3.dev66.dist-info}/entry_points.txt +0 -0
- {codeplain-0.4.3.dev64.dist-info → codeplain-0.4.3.dev66.dist-info}/licenses/LICENSE +0 -0
|
@@ -63,6 +63,7 @@ def render_context(tmp_path, monkeypatch):
|
|
|
63
63
|
codeplain_api=None,
|
|
64
64
|
build_folder=str(build),
|
|
65
65
|
module_name="m",
|
|
66
|
+
is_regenerate=False,
|
|
66
67
|
run_state=object(),
|
|
67
68
|
plain_source_tree=plain_source_tree,
|
|
68
69
|
unittests_script=None,
|
|
@@ -244,3 +245,37 @@ def test_other_http_errors_on_continue_are_not_swallowed(render_context):
|
|
|
244
245
|
render_context.codeplain_api = FakeAPI([requests.exceptions.HTTPError(response=SimpleNamespace(status_code=500))])
|
|
245
246
|
with pytest.raises(requests.exceptions.HTTPError):
|
|
246
247
|
FixUnitTests().execute(render_context, {"previous_unittests_issue": "FAILED"})
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def test_a_regeneration_shows_the_functionalities_after_the_regenerated_one(render_context, monkeypatch):
|
|
251
|
+
"""The functionalities after the regenerated one keep their code. The agent must see their specs, as
|
|
252
|
+
their code implements them, or it can change that code to agree with a wrong unit test."""
|
|
253
|
+
render_context.is_regenerate = True
|
|
254
|
+
plain_module = SimpleNamespace(
|
|
255
|
+
load_module_metadata=lambda: {
|
|
256
|
+
"functionalities": [
|
|
257
|
+
{"id": "1", "markdown": "- Old feature."},
|
|
258
|
+
{"id": "2", "markdown": "- New feature, as it was before."},
|
|
259
|
+
{"id": "3", "markdown": "- Later feature."},
|
|
260
|
+
{"id": "4", "markdown": "- Last feature."},
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
monkeypatch.setattr(FakeRenderContext, "plain_module", property(lambda self: plain_module))
|
|
265
|
+
specifications = plain_spec.get_specifications_for_frid(render_context.plain_source_tree, "2")[0]
|
|
266
|
+
|
|
267
|
+
section = FixUnitTests._functional_requirements_section(render_context, specifications)
|
|
268
|
+
|
|
269
|
+
assert section.endswith(
|
|
270
|
+
"### Module: m (Currently Being Implemented)\n- New feature.\n\n"
|
|
271
|
+
"### Module: m (Already Implemented, for context)\n- Later feature.\n- Last feature."
|
|
272
|
+
)
|
|
273
|
+
assert "as it was before" not in section
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def test_a_normal_render_shows_no_functionality_after_the_current_one(render_context):
|
|
277
|
+
specifications = plain_spec.get_specifications_for_frid(render_context.plain_source_tree, "2")[0]
|
|
278
|
+
|
|
279
|
+
section = FixUnitTests._functional_requirements_section(render_context, specifications)
|
|
280
|
+
|
|
281
|
+
assert section.endswith("### Module: m (Currently Being Implemented)\n- New feature.")
|
|
@@ -112,6 +112,7 @@ def make_render_context(api, build_folder, memory_folder, conformance_tests_runn
|
|
|
112
112
|
unit_tests_running_context=UnitTestsRunningContext(fix_attempts=1),
|
|
113
113
|
plain_source_tree={},
|
|
114
114
|
module_name="mod",
|
|
115
|
+
is_regenerate=False,
|
|
115
116
|
required_modules=None,
|
|
116
117
|
frid_context=SimpleNamespace(frid="1", linked_resources={}, changed_files=set()),
|
|
117
118
|
get_required_modules_functionalities=lambda: {},
|
tests/test_git_utils.py
CHANGED
|
@@ -11,6 +11,7 @@ from git_utils import (
|
|
|
11
11
|
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE,
|
|
12
12
|
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE,
|
|
13
13
|
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE,
|
|
14
|
+
FUNCTIONAL_REQUIREMENT_REGENERATED_COMMIT_MESSAGE,
|
|
14
15
|
REFACTORED_CODE_COMMIT_MESSAGE,
|
|
15
16
|
add_all_files_and_commit,
|
|
16
17
|
diff,
|
|
@@ -498,6 +499,31 @@ def test_get_last_finished_frid_ignores_non_finished_commits(empty_repo):
|
|
|
498
499
|
assert get_last_rendered_functionality(empty_repo) == ("module_a", "add-task")
|
|
499
500
|
|
|
500
501
|
|
|
502
|
+
def test_get_last_finished_frid_ignores_regenerated_commits(empty_repo):
|
|
503
|
+
"""A regenerated commit sits on top of the frontier and must not become the last rendered frid."""
|
|
504
|
+
file_path = Path(empty_repo) / "a.txt"
|
|
505
|
+
for frid in ("1", "2", "3"):
|
|
506
|
+
file_path.write_text(f"v{frid}")
|
|
507
|
+
add_all_files_and_commit(
|
|
508
|
+
empty_repo,
|
|
509
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid),
|
|
510
|
+
module_name="module_a",
|
|
511
|
+
frid=frid,
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
# Functionality 1 is rendered again in place, so its commit is the most recent one.
|
|
515
|
+
file_path.write_text("v1 again")
|
|
516
|
+
add_all_files_and_commit(
|
|
517
|
+
empty_repo,
|
|
518
|
+
FUNCTIONAL_REQUIREMENT_REGENERATED_COMMIT_MESSAGE.format("1"),
|
|
519
|
+
module_name="module_a",
|
|
520
|
+
frid="1",
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
# The module is still rendered up to functionality 3.
|
|
524
|
+
assert get_last_rendered_functionality(empty_repo) == ("module_a", "3")
|
|
525
|
+
|
|
526
|
+
|
|
501
527
|
def test_get_last_finished_frid_without_module_name(empty_repo):
|
|
502
528
|
"""Raise InvalidGitRepositoryError when the finished commit omits the module name line."""
|
|
503
529
|
file_path = Path(empty_repo) / "a.txt"
|
tests/test_partial_rendering.py
CHANGED
tests/test_plain_modules.py
CHANGED
|
@@ -60,6 +60,11 @@ def _stored(*frids: str) -> list[dict[str, str]]:
|
|
|
60
60
|
return [{"id": frid, "markdown": f"{frid} markdown."} for frid in frids]
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
def _stale(*frids: str) -> list[dict[str, str]]:
|
|
64
|
+
"""Metadata entries holding an older markdown than the one the spec file now carries."""
|
|
65
|
+
return [{"id": frid, "markdown": f"old {frid}."} for frid in frids]
|
|
66
|
+
|
|
67
|
+
|
|
63
68
|
def _write_metadata(module: PlainModule, metadata: dict) -> None:
|
|
64
69
|
folder = module.get_codeplain_folder()
|
|
65
70
|
os.makedirs(folder, exist_ok=True)
|
|
@@ -219,6 +224,154 @@ def test_get_next_module_raises_when_module_not_found(root_module):
|
|
|
219
224
|
root_module.get_next_module("unknown")
|
|
220
225
|
|
|
221
226
|
|
|
227
|
+
def test_all_required_modules_diamond_dependency_deduplication():
|
|
228
|
+
"""In a diamond dependency (A requires B and C; B requires C), C appears only once in all_required_modules."""
|
|
229
|
+
mod_c = PlainModule.__new__(PlainModule)
|
|
230
|
+
mod_c.module_name = "mod_c"
|
|
231
|
+
mod_c.required_modules = []
|
|
232
|
+
|
|
233
|
+
mod_b = PlainModule.__new__(PlainModule)
|
|
234
|
+
mod_b.module_name = "mod_b"
|
|
235
|
+
mod_b.required_modules = [mod_c]
|
|
236
|
+
|
|
237
|
+
mod_a = PlainModule.__new__(PlainModule)
|
|
238
|
+
mod_a.module_name = "mod_a"
|
|
239
|
+
mod_a.required_modules = [mod_b, mod_c]
|
|
240
|
+
|
|
241
|
+
all_reqs = mod_a.all_required_modules
|
|
242
|
+
assert [m.module_name for m in all_reqs] == ["mod_c", "mod_b"]
|
|
243
|
+
|
|
244
|
+
assert mod_a.get_next_module("mod_c") == mod_b
|
|
245
|
+
assert mod_a.get_next_module("mod_b") == mod_a
|
|
246
|
+
assert mod_a.get_next_module("mod_a") is None
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def test_diamond_dependency_shares_instances_preserves_scenarios_and_avoids_double_render(monkeypatch):
|
|
250
|
+
"""Real diamond project (A -> [C, B], B -> [C]) with conformance scenarios:
|
|
251
|
+
1. All references to C share the same PlainModule instance and bound scenarios.
|
|
252
|
+
2. A subsequent run with no spec changes does not flag C as changed or re-render it.
|
|
253
|
+
3. Deleting A and B resumes at B (not C) and never renders C twice.
|
|
254
|
+
4. Even when render_choice targets C, ModuleRenderer renders C only once.
|
|
255
|
+
"""
|
|
256
|
+
from argparse import Namespace
|
|
257
|
+
from unittest.mock import MagicMock
|
|
258
|
+
|
|
259
|
+
import file_utils
|
|
260
|
+
import plain_spec
|
|
261
|
+
from event_bus import EventBus
|
|
262
|
+
from module_renderer import ModuleRenderer
|
|
263
|
+
from partial_rendering import RenderChoice, get_plain_module_render_state, get_render_choices
|
|
264
|
+
from plain2code_state import RunState
|
|
265
|
+
from render_machine.states import States
|
|
266
|
+
|
|
267
|
+
tmp_dir = tempfile.mkdtemp()
|
|
268
|
+
try:
|
|
269
|
+
specs_dir = os.path.join(tmp_dir, "specs")
|
|
270
|
+
tests_dir = os.path.join(specs_dir, "tests")
|
|
271
|
+
build_dir = os.path.join(tmp_dir, "build")
|
|
272
|
+
for mod_name in ("mod_c", "mod_b", "mod_a"):
|
|
273
|
+
os.makedirs(os.path.join(tests_dir, mod_name), exist_ok=True)
|
|
274
|
+
|
|
275
|
+
(Path(specs_dir) / "mod_c.plain").write_text(
|
|
276
|
+
"***implementation reqs***\n\n- C req.\n\n***functional specs***\n\n# func-c\nC func.\n"
|
|
277
|
+
)
|
|
278
|
+
(Path(specs_dir) / "mod_b.plain").write_text(
|
|
279
|
+
"---\nrequires:\n - mod_c\n---\n\n***implementation reqs***\n\n- B req.\n\n***functional specs***\n\n# func-b\nB func.\n"
|
|
280
|
+
)
|
|
281
|
+
(Path(specs_dir) / "mod_a.plain").write_text(
|
|
282
|
+
"---\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"
|
|
283
|
+
)
|
|
284
|
+
for mod_name, frid in (("mod_c", "func-c"), ("mod_b", "func-b"), ("mod_a", "func-a")):
|
|
285
|
+
(Path(tests_dir) / mod_name / f"{frid}.plain").write_text(
|
|
286
|
+
f"---\nmodule: {mod_name}\nfunc_id: {frid}\n---\n\n***conformance tests***\n\n# sc-1\nTest {frid}.\n\n***acceptance tests***\n"
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
mod_a = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
290
|
+
mod_c_from_a = mod_a.required_modules[0]
|
|
291
|
+
mod_b = mod_a.required_modules[1]
|
|
292
|
+
mod_c_from_b = mod_b.required_modules[0]
|
|
293
|
+
|
|
294
|
+
assert mod_c_from_a is mod_c_from_b
|
|
295
|
+
assert [m.module_name for m in mod_a.all_required_modules] == ["mod_c", "mod_b"]
|
|
296
|
+
assert mod_c_from_b.plain_source[plain_spec.FUNCTIONAL_REQUIREMENTS][0][plain_spec.CONFORMANCE_TESTS]
|
|
297
|
+
assert mod_a.get_next_module("mod_c") is mod_b
|
|
298
|
+
|
|
299
|
+
rendered_modules: list[str] = []
|
|
300
|
+
|
|
301
|
+
class FakeCodeRenderer:
|
|
302
|
+
def __init__(self, render_context):
|
|
303
|
+
self.render_context = render_context
|
|
304
|
+
|
|
305
|
+
def run(self):
|
|
306
|
+
m = self.render_context.plain_module
|
|
307
|
+
rendered_modules.append(m.module_name)
|
|
308
|
+
init_git_repo(m.module_build_folder, m.module_name, "r1")
|
|
309
|
+
(Path(m.module_build_folder) / f"{m.module_name}.txt").write_text(m.module_name)
|
|
310
|
+
frid = list(plain_spec.get_frids(m.plain_source))[-1]
|
|
311
|
+
add_all_files_and_commit(
|
|
312
|
+
m.module_build_folder,
|
|
313
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid),
|
|
314
|
+
module_name=m.module_name,
|
|
315
|
+
frid=frid,
|
|
316
|
+
)
|
|
317
|
+
self.render_context.state = States.RENDER_COMPLETED.value
|
|
318
|
+
|
|
319
|
+
monkeypatch.setattr("module_renderer.CodeRenderer", FakeCodeRenderer)
|
|
320
|
+
|
|
321
|
+
args = Namespace(
|
|
322
|
+
build_dest=os.path.join(tmp_dir, "dist"),
|
|
323
|
+
conformance_tests_dest=os.path.join(tmp_dir, "dist_tests"),
|
|
324
|
+
unittests_script=None,
|
|
325
|
+
conformance_tests_script=None,
|
|
326
|
+
prepare_environment_script=None,
|
|
327
|
+
copy_build=False,
|
|
328
|
+
copy_conformance_tests=False,
|
|
329
|
+
render_conformance_tests=False,
|
|
330
|
+
base_folder=None,
|
|
331
|
+
test_script_timeout=None,
|
|
332
|
+
render_machine_graph=False,
|
|
333
|
+
force_render=False,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
# 1. Initial full render: each module renders once in topological order
|
|
337
|
+
ModuleRenderer(MagicMock(), mod_a, None, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
338
|
+
assert rendered_modules == ["mod_c", "mod_b", "mod_a"]
|
|
339
|
+
|
|
340
|
+
# 2. Re-parse with no spec changes: C must not report spec changes on either path
|
|
341
|
+
rendered_modules.clear()
|
|
342
|
+
mod_a2 = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
343
|
+
assert not mod_a2.required_modules[0].has_plain_spec_changed()
|
|
344
|
+
assert not mod_a2.required_modules[1].required_modules[0].has_plain_spec_changed()
|
|
345
|
+
state2 = get_plain_module_render_state(mod_a2)
|
|
346
|
+
assert state2 is not None and state2.change is None
|
|
347
|
+
# Even if ModuleRenderer checks required modules, mod_c and mod_b are skipped
|
|
348
|
+
ModuleRenderer(MagicMock(), mod_a2, None, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
349
|
+
assert "mod_c" not in rendered_modules
|
|
350
|
+
assert "mod_b" not in rendered_modules
|
|
351
|
+
|
|
352
|
+
# 3. Delete A and B after full render: resume choice starts at B (not C) and never renders C twice
|
|
353
|
+
rendered_modules.clear()
|
|
354
|
+
file_utils.delete_folder(os.path.join(build_dir, "mod_a"))
|
|
355
|
+
file_utils.delete_folder(os.path.join(build_dir, "mod_b"))
|
|
356
|
+
mod_a3 = PlainModule("mod_a.plain", build_dir, [specs_dir], [tests_dir], conformance_tests_enabled=True)
|
|
357
|
+
state3 = get_plain_module_render_state(mod_a3)
|
|
358
|
+
assert state3 is not None and state3.last_render_module.module_name == "mod_c"
|
|
359
|
+
choices3 = get_render_choices(mod_a3, state3)
|
|
360
|
+
assert choices3["1"].module.module_name == "mod_b"
|
|
361
|
+
ModuleRenderer(
|
|
362
|
+
MagicMock(), mod_a3, choices3["1"], None, args, RunState("mod_a.plain"), EventBus()
|
|
363
|
+
).render_module()
|
|
364
|
+
assert rendered_modules == ["mod_b", "mod_a"]
|
|
365
|
+
|
|
366
|
+
# 4. When render_choice explicitly targets mod_c, mod_c still renders only once
|
|
367
|
+
rendered_modules.clear()
|
|
368
|
+
choice_c = RenderChoice(module=mod_a3.required_modules[0], render_range=None, choice_type="rerender_affected")
|
|
369
|
+
ModuleRenderer(MagicMock(), mod_a3, choice_c, None, args, RunState("mod_a.plain"), EventBus()).render_module()
|
|
370
|
+
assert rendered_modules == ["mod_c", "mod_b", "mod_a"]
|
|
371
|
+
finally:
|
|
372
|
+
file_utils.delete_folder(tmp_dir)
|
|
373
|
+
|
|
374
|
+
|
|
222
375
|
# --------------------------------------------------------------------------
|
|
223
376
|
# get_next_frid
|
|
224
377
|
# --------------------------------------------------------------------------
|
|
@@ -346,6 +499,93 @@ def test_code_variable_frid_not_flagged_as_change(code_var_module):
|
|
|
346
499
|
assert determine_partial_render_start(code_var_module) is None
|
|
347
500
|
|
|
348
501
|
|
|
502
|
+
# --------------------------------------------------------------------------
|
|
503
|
+
# update_frid_in_module_metadata — regenerate of a single functionality
|
|
504
|
+
# --------------------------------------------------------------------------
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def test_save_module_metadata_restates_every_functionality(solo_module):
|
|
508
|
+
"""save_module_metadata records the whole module against the current spec. That is why the
|
|
509
|
+
regenerate path must not call it: it would restate the functionalities that were not rendered."""
|
|
510
|
+
_write_metadata(solo_module, {"functionalities": ["old one", "old two", "old three"]})
|
|
511
|
+
|
|
512
|
+
solo_module.save_module_metadata()
|
|
513
|
+
|
|
514
|
+
metadata = solo_module.load_module_metadata()
|
|
515
|
+
assert metadata["functionalities"] == solo_module._get_module_functional_requirements()
|
|
516
|
+
assert metadata["source_hash"] == solo_module.get_module_source_hash()
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def test_update_frid_leaves_other_functionalities_untouched(solo_module):
|
|
520
|
+
"""Regenerating one functionality must not restate the spec of the others. Their code was not
|
|
521
|
+
regenerated, so their metadata entries have to keep the spec the code implements."""
|
|
522
|
+
current = solo_module._get_module_functional_requirements()
|
|
523
|
+
stale = _stale("solo-one", "solo-two", "solo-three")
|
|
524
|
+
_write_metadata(solo_module, {"functionalities": stale})
|
|
525
|
+
|
|
526
|
+
solo_module.update_frid_in_module_metadata("solo-two")
|
|
527
|
+
|
|
528
|
+
metadata = solo_module.load_module_metadata()
|
|
529
|
+
assert metadata["functionalities"] == [stale[0], current[1], stale[2]]
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def test_update_frid_keeps_source_hash_while_another_frid_differs(solo_module):
|
|
533
|
+
"""source_hash claims the code implements the whole spec, so it must stay stale while the other
|
|
534
|
+
functionalities still hold their old spec."""
|
|
535
|
+
_write_metadata(
|
|
536
|
+
solo_module,
|
|
537
|
+
{
|
|
538
|
+
"source_hash": "stale",
|
|
539
|
+
"non_functional_source_hash": solo_module.get_module_non_functional_source_hash(),
|
|
540
|
+
"functionalities": _stale("solo-one", "solo-two", "solo-three"),
|
|
541
|
+
},
|
|
542
|
+
)
|
|
543
|
+
|
|
544
|
+
solo_module.update_frid_in_module_metadata("solo-two")
|
|
545
|
+
|
|
546
|
+
assert solo_module.load_module_metadata()["source_hash"] == "stale"
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def test_update_frid_refreshes_source_hash_when_module_matches_spec(solo_module):
|
|
550
|
+
"""Once the last outstanding functionality is regenerated, the module matches the spec again and
|
|
551
|
+
source_hash is stamped, so no further change is reported."""
|
|
552
|
+
current = solo_module._get_module_functional_requirements()
|
|
553
|
+
_write_metadata(
|
|
554
|
+
solo_module,
|
|
555
|
+
{
|
|
556
|
+
"source_hash": "stale",
|
|
557
|
+
"non_functional_source_hash": solo_module.get_module_non_functional_source_hash(),
|
|
558
|
+
"functionalities": [current[0], _stale("solo-two")[0], current[2]],
|
|
559
|
+
},
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
solo_module.update_frid_in_module_metadata("solo-two")
|
|
563
|
+
|
|
564
|
+
metadata = solo_module.load_module_metadata()
|
|
565
|
+
assert metadata["functionalities"] == current
|
|
566
|
+
assert metadata["source_hash"] == solo_module.get_module_source_hash()
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def test_update_frid_keeps_source_hash_when_non_functional_content_changed(solo_module):
|
|
570
|
+
"""Every functionality matches, but a definition or requirement changed. The code of the other
|
|
571
|
+
functionalities was generated against the old text, so the module is not in sync."""
|
|
572
|
+
current = solo_module._get_module_functional_requirements()
|
|
573
|
+
_write_metadata(
|
|
574
|
+
solo_module,
|
|
575
|
+
{
|
|
576
|
+
"source_hash": "stale",
|
|
577
|
+
"non_functional_source_hash": "different",
|
|
578
|
+
"functionalities": [current[0], _stale("solo-two")[0], current[2]],
|
|
579
|
+
},
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
solo_module.update_frid_in_module_metadata("solo-two")
|
|
583
|
+
|
|
584
|
+
metadata = solo_module.load_module_metadata()
|
|
585
|
+
assert metadata["functionalities"] == current
|
|
586
|
+
assert metadata["source_hash"] == "stale"
|
|
587
|
+
|
|
588
|
+
|
|
349
589
|
# --------------------------------------------------------------------------
|
|
350
590
|
# module folder layout
|
|
351
591
|
# --------------------------------------------------------------------------
|
|
@@ -45,6 +45,7 @@ def solo_module(get_test_data_path, tmp_build_folder):
|
|
|
45
45
|
def _make_render_context(module: PlainModule, render_conformance_tests: bool) -> SimpleNamespace:
|
|
46
46
|
return SimpleNamespace(
|
|
47
47
|
render_range=None,
|
|
48
|
+
is_regenerate=False,
|
|
48
49
|
plain_module=module,
|
|
49
50
|
required_modules=module.required_modules,
|
|
50
51
|
build_folder=module.module_build_folder,
|
|
@@ -244,7 +245,7 @@ def test_archive_with_tests_not_flagged(root_module):
|
|
|
244
245
|
|
|
245
246
|
def test_render_state_flags_missing_tests_and_offers_rerender(root_module):
|
|
246
247
|
"""A code-only archive (conformance on) surfaces a 'missing_conformance_tests' render state with
|
|
247
|
-
a
|
|
248
|
+
a regenerate choice and a quit choice."""
|
|
248
249
|
previous = root_module.required_modules[-1]
|
|
249
250
|
_init_repo_with_finished_frid(previous.module_build_folder, previous.module_name)
|
|
250
251
|
_archive_module(previous) # code/ only
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""The checks that stop a regeneration that cannot run, or a render that would remove a regeneration.
|
|
2
|
+
|
|
3
|
+
Both checks run before anything is rendered, and both name the regeneration. The checks for
|
|
4
|
+
--render-from would otherwise answer first and talk about starting a render the user did not ask for.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import tempfile
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from types import SimpleNamespace
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
import plain2code
|
|
15
|
+
from git_utils import (
|
|
16
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE,
|
|
17
|
+
FUNCTIONAL_REQUIREMENT_REGENERATED_COMMIT_MESSAGE,
|
|
18
|
+
add_all_files_and_commit,
|
|
19
|
+
init_git_repo,
|
|
20
|
+
)
|
|
21
|
+
from partial_rendering import RenderChoice, _keep_regenerations
|
|
22
|
+
from plain2code_exceptions import InvalidFridArgument, MissingPreviousFunctionalitiesError
|
|
23
|
+
from plain_modules import PlainModule
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.fixture
|
|
27
|
+
def solo_module(get_test_data_path):
|
|
28
|
+
with tempfile.TemporaryDirectory() as build_folder:
|
|
29
|
+
yield PlainModule("pr_solo.plain", build_folder, [get_test_data_path("data/partial_rendering")])
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _commit_finished_frid(module: PlainModule, frid: str) -> None:
|
|
33
|
+
(Path(module.module_build_folder) / f"frid_{frid}.txt").write_text(f"frid {frid}\n")
|
|
34
|
+
add_all_files_and_commit(
|
|
35
|
+
module.module_build_folder,
|
|
36
|
+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid),
|
|
37
|
+
module_name=module.module_name,
|
|
38
|
+
frid=frid,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _rendered_up_to(module: PlainModule, *frids: str) -> None:
|
|
43
|
+
os.makedirs(module.module_build_folder)
|
|
44
|
+
init_git_repo(module.module_build_folder, module_name=module.module_name)
|
|
45
|
+
for frid in frids:
|
|
46
|
+
_commit_finished_frid(module, frid)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_a_rendered_functionality_can_be_regenerated(solo_module):
|
|
50
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
51
|
+
|
|
52
|
+
solo_module.ensure_frid_can_be_regenerated("solo-two", render_conformance_tests=False)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_a_functionality_after_the_rendered_ones_cannot_be_regenerated(solo_module):
|
|
56
|
+
"""The previous functionality is not rendered either, but the message is about the regeneration."""
|
|
57
|
+
_rendered_up_to(solo_module, "solo-one")
|
|
58
|
+
|
|
59
|
+
with pytest.raises(MissingPreviousFunctionalitiesError) as error:
|
|
60
|
+
solo_module.ensure_frid_can_be_regenerated("solo-three", render_conformance_tests=False)
|
|
61
|
+
|
|
62
|
+
assert str(error.value).startswith("Cannot regenerate functionality solo-three because it has not been")
|
|
63
|
+
assert "--render-from" not in str(error.value)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_a_module_that_was_never_rendered_cannot_be_regenerated(solo_module):
|
|
67
|
+
with pytest.raises(MissingPreviousFunctionalitiesError) as error:
|
|
68
|
+
solo_module.ensure_frid_can_be_regenerated("solo-one", render_conformance_tests=False)
|
|
69
|
+
|
|
70
|
+
assert str(error.value).startswith("Cannot regenerate functionality solo-one because it has not been")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_a_module_rendered_without_conformance_tests_cannot_be_regenerated_with_them(solo_module):
|
|
74
|
+
"""The first functionality has no earlier one, so no other check looks at the tests folder."""
|
|
75
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
76
|
+
|
|
77
|
+
with pytest.raises(MissingPreviousFunctionalitiesError) as error:
|
|
78
|
+
solo_module.ensure_frid_can_be_regenerated("solo-one", render_conformance_tests=True)
|
|
79
|
+
|
|
80
|
+
assert str(error.value).startswith(
|
|
81
|
+
"Cannot regenerate functionality solo-one because module pr_solo was rendered without conformance tests."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_a_module_rendered_without_conformance_tests_can_be_regenerated_without_them(solo_module):
|
|
86
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
87
|
+
|
|
88
|
+
solo_module.ensure_frid_can_be_regenerated("solo-two", render_conformance_tests=False)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_a_module_rendered_with_conformance_tests_can_be_regenerated_with_them(solo_module):
|
|
92
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
93
|
+
os.makedirs(solo_module.module_conformance_tests_folder)
|
|
94
|
+
|
|
95
|
+
solo_module.ensure_frid_can_be_regenerated("solo-two", render_conformance_tests=True)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_an_unknown_func_id_names_the_regeneration(solo_module):
|
|
99
|
+
args = SimpleNamespace(render_range=None, render_from=None, regenerate="no-such-id")
|
|
100
|
+
|
|
101
|
+
with pytest.raises(InvalidFridArgument) as error:
|
|
102
|
+
plain2code.render(solo_module, None, args, None, None)
|
|
103
|
+
|
|
104
|
+
assert str(error.value) == (
|
|
105
|
+
"Cannot regenerate functionality no-such-id because module pr_solo has no such functionality. "
|
|
106
|
+
"Its functionalities are: solo-one, solo-two, solo-three."
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _commit_regenerated_frid(module: PlainModule, frid: str) -> None:
|
|
111
|
+
(Path(module.module_build_folder) / f"frid_{frid}.txt").write_text(f"frid {frid} again\n")
|
|
112
|
+
add_all_files_and_commit(
|
|
113
|
+
module.module_build_folder,
|
|
114
|
+
FUNCTIONAL_REQUIREMENT_REGENERATED_COMMIT_MESSAGE.format(frid),
|
|
115
|
+
module_name=module.module_name,
|
|
116
|
+
frid=frid,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_a_render_from_that_removes_an_earlier_regeneration_is_stopped(solo_module):
|
|
121
|
+
"""The render from solo-three resets to the solo-two checkpoint, which is before the regeneration."""
|
|
122
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two", "solo-three")
|
|
123
|
+
_commit_regenerated_frid(solo_module, "solo-one")
|
|
124
|
+
|
|
125
|
+
with pytest.raises(MissingPreviousFunctionalitiesError) as error:
|
|
126
|
+
solo_module.ensure_render_from_keeps_regenerations("solo-three")
|
|
127
|
+
|
|
128
|
+
assert str(error.value).startswith(
|
|
129
|
+
"Cannot render from functionality solo-three of module pr_solo. Functionality solo-one was regenerated"
|
|
130
|
+
)
|
|
131
|
+
assert "--render-from solo-one" in str(error.value)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@pytest.mark.parametrize("regenerated, start", [("solo-two", "solo-two"), ("solo-three", "solo-two")])
|
|
135
|
+
def test_a_render_from_that_renders_the_regenerated_functionality_again_can_run(solo_module, regenerated, start):
|
|
136
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two", "solo-three")
|
|
137
|
+
_commit_regenerated_frid(solo_module, regenerated)
|
|
138
|
+
|
|
139
|
+
solo_module.ensure_render_from_keeps_regenerations(start)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_a_render_from_without_a_regeneration_can_run(solo_module):
|
|
143
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two", "solo-three")
|
|
144
|
+
|
|
145
|
+
solo_module.ensure_render_from_keeps_regenerations("solo-three")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_the_earliest_removed_regeneration_is_named(solo_module):
|
|
149
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two", "solo-three")
|
|
150
|
+
_commit_regenerated_frid(solo_module, "solo-two")
|
|
151
|
+
_commit_regenerated_frid(solo_module, "solo-one")
|
|
152
|
+
|
|
153
|
+
assert solo_module.get_regenerated_frid_removed_by_render_from("solo-three") == "solo-one"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_a_continue_choice_that_removes_a_regeneration_starts_at_the_regenerated_functionality(solo_module):
|
|
157
|
+
"""An interrupted render: solo-one and solo-two are rendered, then solo-one is regenerated."""
|
|
158
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
159
|
+
_commit_regenerated_frid(solo_module, "solo-one")
|
|
160
|
+
choice = RenderChoice(module=solo_module, render_range=["solo-three"], choice_type="continue_from_frid")
|
|
161
|
+
|
|
162
|
+
moved = _keep_regenerations(choice)
|
|
163
|
+
|
|
164
|
+
assert moved.choice_type == "render_from_regenerated"
|
|
165
|
+
assert moved.render_range == ["solo-one", "solo-two", "solo-three"]
|
|
166
|
+
assert moved.is_destructive
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_a_choice_that_removes_no_regeneration_is_not_changed(solo_module):
|
|
170
|
+
_rendered_up_to(solo_module, "solo-one", "solo-two")
|
|
171
|
+
choice = RenderChoice(module=solo_module, render_range=["solo-three"], choice_type="continue_from_frid")
|
|
172
|
+
|
|
173
|
+
assert _keep_regenerations(choice) is choice
|