Repository navigation
Do not regenerate a conformance test the render cannot rebuild #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gorandodig
wants to merge
1
commit into
main
Choose a base branch
from
fix/conformance-regeneration-keyerror
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Regenerating a conformance test after the fix attempts run out. | ||
|
|
||
| Two things went wrong on the same path. The regeneration branch was taken for any test | ||
| that exhausted its fix attempts, including one belonging to a required module - which | ||
| RenderConformanceTests cannot rebuild coherently, because it writes the replacement under | ||
| the module being rendered while recording the entry against the module the test belongs | ||
| to. And the handler removed the recorded entry with an unguarded `pop`, so a state where | ||
| the entry was already gone ended the render with a bare `KeyError` naming the | ||
| functionality id. | ||
| """ | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| from render_machine.actions.fix_conformance_test import ( | ||
| MAX_CONFORMANCE_TEST_FIX_ATTEMPTS, | ||
| MAX_CONFORMANCE_TEST_RERENDER_ATTEMPTS, | ||
| FixConformanceTest, | ||
| ) | ||
| from render_machine.render_context import RenderContext | ||
|
|
||
|
|
||
| def exhausted_context(current_module="inventory_api", testing_module="inventory_api", entry=None): | ||
| """A conformance loop one attempt short of its limit, with its regeneration budget intact.""" | ||
| render_context = MagicMock() | ||
| render_context.module_name = current_module | ||
| render_context.frid_context.frid = "2" | ||
|
|
||
| ctx = render_context.conformance_tests_running_context | ||
| ctx.fix_attempts = MAX_CONFORMANCE_TEST_FIX_ATTEMPTS - 1 | ||
| ctx.conformance_tests_render_attempts = MAX_CONFORMANCE_TEST_RERENDER_ATTEMPTS - 1 | ||
| ctx.current_testing_module_name = testing_module | ||
| ctx.current_testing_frid = "2" | ||
| ctx.get_conformance_tests_json.return_value = {} if entry is None else {"2": entry} | ||
| return render_context | ||
|
|
||
|
|
||
| class TestOnlyTheRenderedModulesTestIsRegenerated: | ||
| def test_the_current_modules_test_is_regenerated(self): | ||
| render_context = exhausted_context() | ||
|
|
||
| outcome, payload = FixConformanceTest().execute(render_context, None) | ||
|
|
||
| assert outcome == FixConformanceTest.REGENERATE_CONFORMANCE_TESTS_OUTCOME | ||
| assert payload is None | ||
| assert render_context.conformance_tests_running_context.regenerating_conformance_tests is True | ||
|
|
||
| def test_a_required_modules_test_fails_the_render_instead(self): | ||
| """The replacement would be written for the wrong module, so there is nothing to | ||
| regenerate - the render has failed.""" | ||
| render_context = exhausted_context(current_module="inventory_api", testing_module="store_core") | ||
|
|
||
| outcome, payload = FixConformanceTest().execute(render_context, None) | ||
|
|
||
| assert outcome == FixConformanceTest.LIMIT_EXCEEDED_OUTCOME | ||
| assert payload["error"]["message"] | ||
| assert render_context.conformance_tests_running_context.regenerating_conformance_tests is not True | ||
|
|
||
|
|
||
| class TestRegenerationSurvivesAMissingEntry: | ||
| @staticmethod | ||
| def _context_with(entry): | ||
| context = RenderContext.__new__(RenderContext) | ||
| ctx = MagicMock() | ||
| ctx.current_testing_frid = "2" | ||
| ctx.current_testing_module_name = "store_core" | ||
| ctx.conformance_tests_render_attempts = 0 | ||
| ctx.get_conformance_tests_json.return_value = {} if entry is None else {"2": entry} | ||
| context.conformance_tests_running_context = ctx | ||
| return context, ctx | ||
|
|
||
| def test_a_recorded_entry_is_removed_and_its_folder_deleted(self, monkeypatch): | ||
| deleted = [] | ||
| monkeypatch.setattr("render_machine.render_context.file_utils.delete_folder", deleted.append) | ||
| context, ctx = self._context_with({"folder_name": "/tmp/tests/store_core_2"}) | ||
|
|
||
| context._handle_test_regeneration() | ||
|
|
||
| assert deleted == ["/tmp/tests/store_core_2"] | ||
| assert ctx.conformance_tests_render_attempts == 1 | ||
| assert ctx.fix_attempts == 0 | ||
|
|
||
| def test_a_missing_entry_does_not_end_the_render(self, monkeypatch): | ||
| """This raised `KeyError('2')` out of the render, an hour into it, reported to the | ||
| user as the bare string `'2'`.""" | ||
| deleted = [] | ||
| monkeypatch.setattr("render_machine.render_context.file_utils.delete_folder", deleted.append) | ||
| context, ctx = self._context_with(None) | ||
|
|
||
| context._handle_test_regeneration() | ||
|
|
||
| assert deleted == [] | ||
| assert ctx.conformance_tests_render_attempts == 1 | ||
| assert ctx.fix_attempts == 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash fd -i render_conformance_tests.py --exec cat -n {}Repository: Codeplain-ai/codeplain
Length of output: 10779
Extend the regeneration guard to include the functionality ID.
RenderConformanceTests._render_conformance_testsstores the entry undercurrent_testing_frid, but it takes the replacement specification fromrender_context.frid_context. If regression handling reaches an earlier functionality in the same module, the module-only guard allows regeneration with the wrong specification.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents