Add project tools and strict provider execution
This commit is contained in:
@@ -229,6 +229,23 @@ class TestExecutePromptStep:
|
||||
assert success is False
|
||||
assert output == ""
|
||||
|
||||
@patch('cmdforge.runner.call_provider')
|
||||
def test_step_can_deny_fallback_independently_of_caller(self, mock_call):
|
||||
mock_call.return_value = ProviderResult(
|
||||
text="private", success=True,
|
||||
)
|
||||
step = PromptStep(
|
||||
prompt="Private", provider="local", output_var="out",
|
||||
plain_text=True, fallback_policy="deny",
|
||||
)
|
||||
|
||||
output, success = execute_prompt_step(step, {"input": ""})
|
||||
|
||||
assert success is True
|
||||
assert output == "private"
|
||||
policy = mock_call.call_args.kwargs["execution_policy"]
|
||||
assert policy.allow_fallback is False
|
||||
|
||||
@patch('cmdforge.runner.mock_provider')
|
||||
def test_mock_provider_used(self, mock_mock):
|
||||
mock_mock.return_value = ProviderResult(text="mock response", success=True)
|
||||
@@ -988,6 +1005,58 @@ class TestCreateArgumentParser:
|
||||
|
||||
assert args.count == "10"
|
||||
|
||||
def test_parser_enforces_typed_boolean_integer_and_enum_arguments(self):
|
||||
tool = Tool(
|
||||
name="typed",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
flag="--project", variable="project",
|
||||
type="boolean", default=False,
|
||||
),
|
||||
ToolArgument(
|
||||
flag="--count", variable="count",
|
||||
type="integer", required=True,
|
||||
),
|
||||
ToolArgument(
|
||||
flag="--mode", variable="mode",
|
||||
enum=["safe", "fast"], default="safe",
|
||||
),
|
||||
],
|
||||
)
|
||||
parser = create_argument_parser(tool)
|
||||
|
||||
args = parser.parse_args(["--project", "--count", "3", "--mode", "fast"])
|
||||
|
||||
assert args.project is True
|
||||
assert args.count == 3
|
||||
assert args.mode == "fast"
|
||||
|
||||
def test_parser_reuses_matching_legacy_boolean_universal_flag(self):
|
||||
tool = Tool(
|
||||
name="legacy",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
flag="--verbose", variable="verbose", type="bool"
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
args = create_argument_parser(tool).parse_args(["--verbose"])
|
||||
|
||||
assert args.verbose is True
|
||||
assert collect_custom_args(tool, args) == {"verbose": True}
|
||||
|
||||
def test_parser_rejects_incompatible_universal_flag_collision(self):
|
||||
tool = Tool(
|
||||
name="conflict",
|
||||
arguments=[
|
||||
ToolArgument(flag="--provider", variable="destination")
|
||||
],
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="universal run options"):
|
||||
create_argument_parser(tool)
|
||||
|
||||
def test_parser_input_output_flags(self):
|
||||
tool = Tool(name="test")
|
||||
parser = create_argument_parser(tool)
|
||||
|
||||
Reference in New Issue
Block a user