Skip to content
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

Fix (scaffold): Cleanup on validation failure #2269

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading