Skip to content

Commit

Permalink
Fix (scaffold): Cleanup on validation failure
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <[email protected]>
  • Loading branch information
OjusWiZard committed Oct 16, 2024
1 parent ce255fa commit 44f37d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 1 addition & 2 deletions autonomy/cli/scaffold_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def fsm(ctx: Context, registry: str, skill_name: str, spec: str) -> None:
raise click.ClickException("Skill name must end with '_abci'")

ctx.registry_type = registry
scaffold_fsm = ScaffoldABCISkill(ctx, skill_name, Path(spec))

# check abstract_round_abci is in dependencies; if not, add it
_add_abstract_round_abci_if_not_present(ctx)
Expand All @@ -105,8 +106,6 @@ def fsm(ctx: Context, registry: str, skill_name: str, spec: str) -> None:
preserve_cwd = ctx.cwd
scaffold_item(ctx, SKILL, skill_name)
ctx.cwd = preserve_cwd

scaffold_fsm = ScaffoldABCISkill(ctx, skill_name, Path(spec))
scaffold_fsm.do_scaffolding()

if ctx.config[TO_LOCAL_REGISTRY_FLAG]:
Expand Down
25 changes: 24 additions & 1 deletion tests/test_autonomy/test_cli/test_scaffold_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@

import click.testing
import pytest
import yaml
from aea.cli.utils.config import get_default_author_from_cli_config
from aea.package_manager.base import PACKAGES_FILE
from aea.test_tools.test_cases import AEATestCaseMany

# trigger population of autonomy commands
import autonomy.cli.core # noqa

# trigger population of autonomy commands
from autonomy.analyse.abci.app_spec import DFASpecificationError

from packages.valory import skills
from packages.valory.skills.abstract_round_abci.base import _MetaPayload

Expand Down Expand Up @@ -149,6 +152,26 @@ def test_scaffold_fsm(
self.t / self.agent_name / "skills" / skill_name / fsm_spec_file.name
).exists(), "spec file not copied in scaffolded skill"

def test_failure_cleanup(self) -> None:
"""Test that directory doesn't exist if scaffold fails."""
with open(fsm_specifications[0], "r") as f:
original_raw_spec = f.read()
f.seek(0)
spec = yaml.safe_load(f)

spec["final_states"].append(spec["start_states"][0]) # making the spec wrong

with open(fsm_specifications[0], "w") as f:
yaml.dump(spec, f)

with pytest.raises(DFASpecificationError):
self.scaffold_fsm(fsm_specifications[0], skill_name="test_skill_abci")

assert not (self.t / self.agent_name / "skills" / "test_skill_abci").exists()

with open(fsm_specifications[0], "w") as f:
f.write(original_raw_spec)

def test_failure_due_to_name(self) -> None:
"""Test failure due to name."""
with pytest.raises(click.ClickException):
Expand Down

0 comments on commit 44f37d3

Please sign in to comment.