Skip to content

Commit

Permalink
fix: let failures to build from a single source fail fast (#640)
Browse files Browse the repository at this point in the history
fixes #638
  • Loading branch information
SurferJeffAtGoogle authored Jun 19, 2020
1 parent 483f186 commit 873bd44
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
26 changes: 25 additions & 1 deletion autosynth/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def synthesize_loop(
"""
if not toolbox.versions:
return 0 # No versions, nothing to synthesize.

try:
if multiple_prs:
commit_count = 0
Expand All @@ -370,8 +371,31 @@ def synthesize_loop(
return commit_count
except Exception as e:
logger.error(e)
pass # Fall back to non-forked loop below.
# Fallback to the single_pr loop to try to make some progress.
synthesize_loop_single_pr(toolbox, change_pusher, synthesizer)
# But still report the failure.
raise

return synthesize_loop_single_pr(toolbox, change_pusher, synthesizer)


def synthesize_loop_single_pr(
toolbox: SynthesizeLoopToolbox,
change_pusher: AbstractChangePusher,
synthesizer: AbstractSynthesizer,
) -> int:
"""Loops through all source versions and creates a commit for every version
changed that caused a change in the generated code.
This function creates a single pull request for all sources.
Arguments:
toolbox {SynthesizeLoopToolbox} -- a toolbox
change_pusher {AbstractChangePusher} -- Used to push changes to github.
synthesizer {AbstractSynthesizer} -- Invokes synthesize.
Returns:
int -- Number of commits committed to this repo.
"""
if change_pusher.check_if_pr_already_exists(toolbox.branch):
return 0
synthesize_inner_loop(toolbox, synthesizer)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,22 @@ def test_synthesize_loop_uses_single_commit_title_for_pr_title(
assert golden_calls == calls


def test_synthesize_loop_always_succeeds_when_latest_version_succeeds(
def test_synthesize_loop_always_pushes_something_when_latest_version_succeeds(
synthesize_loop_fixture: SynthesizeLoopFixture,
):
histories = [
[Failed(), WriteFile("a.txt", "a")],
[Failed(), WriteFile("b.txt", "b")],
]
source_versions = compile_histories(histories, synthesize_loop_fixture.synthesizer)
# Synthesize loop should not throw an exception.
commit_count = synthesize_loop_fixture.synthesize_loop(source_versions, True)
assert commit_count > 0
# Synthesize loop will throw an exception.
try:
synthesize_loop_fixture.synthesize_loop(source_versions, True)
assert False, "Expected an exception to be thrown."
except Exception:
pass
# But the loop still should have pushed a change.
synthesize_loop_fixture.change_pusher.push_changes.assert_called()


def make_working_repo(working_dir: str):
Expand Down

0 comments on commit 873bd44

Please sign in to comment.