Clean action runtime project state
This commit is contained in:
@@ -7,12 +7,15 @@ import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from flow.actions import ActionExecutor, ActionPlan, PrimitiveAction, RollbackPolicy
|
||||
from flow.actions import ActionExecutor, ActionPlan, DomainAction, PrimitiveAction, RollbackPolicy
|
||||
from flow.adapters.containers import ContainerRuntime
|
||||
from flow.adapters.tmux import TmuxClient
|
||||
from flow.core.config import AppConfig, FlowContext
|
||||
from flow.core.console import Console
|
||||
from flow.core.errors import FlowError
|
||||
from flow.core.platform import PlatformInfo
|
||||
from flow.core.runtime import SystemRuntime
|
||||
from tests.fakes import FakeRunner
|
||||
|
||||
|
||||
def _ctx() -> FlowContext:
|
||||
@@ -138,3 +141,72 @@ def test_barrier_prevents_rollback_across_external_boundary(tmp_path):
|
||||
|
||||
assert target.is_symlink()
|
||||
|
||||
|
||||
def test_domain_action_expands_embedded_primitives(tmp_path):
|
||||
target = tmp_path / "completion"
|
||||
primitive = PrimitiveAction(
|
||||
id="completion.write",
|
||||
type="file.write",
|
||||
description="Write completion",
|
||||
payload={"path": target, "content": "complete"},
|
||||
)
|
||||
plan = ActionPlan(
|
||||
name="completion.install",
|
||||
domain_actions=(
|
||||
DomainAction(
|
||||
id="completion.install",
|
||||
kind="completion",
|
||||
action="install-zsh",
|
||||
description="Install completion",
|
||||
payload={"primitive_actions": (primitive,)},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
ActionExecutor(_ctx(), audit_path=tmp_path / "actions.jsonl").execute(plan)
|
||||
|
||||
assert target.read_text() == "complete"
|
||||
|
||||
|
||||
def test_executor_dispatches_container_and_tmux_primitives(tmp_path):
|
||||
runner = FakeRunner()
|
||||
ctx = _ctx()
|
||||
ctx.runtime.runner = runner
|
||||
ctx.runtime.containers = ContainerRuntime(runner, binary="docker")
|
||||
ctx.runtime.tmux = TmuxClient(runner)
|
||||
plan = ActionPlan(
|
||||
name="runtime-dispatch",
|
||||
primitive_actions=(
|
||||
PrimitiveAction(
|
||||
id="container.exec",
|
||||
type="container.exec",
|
||||
description="Run command in container",
|
||||
payload={"name": "dev-api", "argv": ("echo", "hello")},
|
||||
),
|
||||
PrimitiveAction(
|
||||
id="tmux.session",
|
||||
type="tmux.new_session",
|
||||
description="Create session",
|
||||
payload={"name": "dev-api", "detached": True, "command": "flow dev exec api"},
|
||||
),
|
||||
PrimitiveAction(
|
||||
id="tmux.option",
|
||||
type="tmux.set_option",
|
||||
description="Set option",
|
||||
payload={
|
||||
"session": "dev-api",
|
||||
"option": "default-command",
|
||||
"value": "flow dev exec api",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
summary = ActionExecutor(ctx, audit_path=tmp_path / "actions.jsonl").execute(plan)
|
||||
|
||||
assert summary.results[0].returncode == 0
|
||||
assert ["docker", "exec", "dev-api", "echo", "hello"] in runner.calls
|
||||
assert ["tmux", "new-session", "-ds", "dev-api", "flow dev exec api"] in runner.calls
|
||||
assert [
|
||||
"tmux", "set-option", "-t", "dev-api", "default-command", "flow dev exec api",
|
||||
] in runner.calls
|
||||
|
||||
Reference in New Issue
Block a user