mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 11:34:00 +00:00
fix: node-setup caching, validate-inputs optional_inputs type (#320)
* fix: node-setup caching, validate-inputs optional_inputs type * test(validate-inputs): dict optional_inputs backward compatibility Verify that legacy dict format for optional_inputs correctly generates conventions from dict keys. Updates existing test to expect list type for optional_inputs default.
This commit is contained in:
@@ -48,9 +48,47 @@ class TestConventionsValidator:
|
||||
rules = validator._rules
|
||||
assert rules["action_type"] == "nonexistent-action"
|
||||
assert rules["required_inputs"] == []
|
||||
assert isinstance(rules["optional_inputs"], dict)
|
||||
assert isinstance(rules["optional_inputs"], list)
|
||||
assert isinstance(rules["conventions"], dict)
|
||||
|
||||
def test_load_rules_with_dict_optional_inputs(self, tmp_path):
|
||||
"""Test backward compatibility with dict format for optional_inputs."""
|
||||
# Create a rules file with legacy dict format for optional_inputs
|
||||
rules_file = tmp_path / "legacy_rules.yml"
|
||||
rules_file.write_text("""
|
||||
action_type: legacy-action
|
||||
required_inputs: []
|
||||
optional_inputs:
|
||||
foo: int
|
||||
bar: str
|
||||
baz:
|
||||
type: boolean
|
||||
validator: boolean
|
||||
conventions: {}
|
||||
overrides: {}
|
||||
""")
|
||||
# Load rules and verify conventions are built from dict keys
|
||||
validator = ConventionBasedValidator("legacy-action")
|
||||
rules = validator.load_rules(rules_file)
|
||||
|
||||
# Verify optional_inputs is preserved as-is from YAML
|
||||
assert "optional_inputs" in rules
|
||||
assert isinstance(rules["optional_inputs"], dict)
|
||||
|
||||
# Verify conventions were auto-generated from optional_inputs dict keys
|
||||
assert "conventions" in rules
|
||||
assert isinstance(rules["conventions"], dict)
|
||||
conventions_keys = set(rules["conventions"].keys())
|
||||
optional_keys = set(rules["optional_inputs"].keys())
|
||||
assert conventions_keys == optional_keys, (
|
||||
f"Conventions keys {conventions_keys} should match optional_inputs keys {optional_keys}"
|
||||
)
|
||||
|
||||
# Verify each key from the dict is in conventions
|
||||
assert "foo" in rules["conventions"]
|
||||
assert "bar" in rules["conventions"]
|
||||
assert "baz" in rules["conventions"]
|
||||
|
||||
def test_load_rules_with_custom_path(self, tmp_path):
|
||||
"""Test loading rules from custom path."""
|
||||
rules_file = tmp_path / "custom_rules.yml"
|
||||
|
||||
@@ -82,7 +82,7 @@ class ConventionBasedValidator(BaseValidator):
|
||||
return {
|
||||
"action_type": self.action_type,
|
||||
"required_inputs": [],
|
||||
"optional_inputs": {},
|
||||
"optional_inputs": [],
|
||||
"conventions": {},
|
||||
"overrides": {},
|
||||
}
|
||||
@@ -93,16 +93,27 @@ class ConventionBasedValidator(BaseValidator):
|
||||
|
||||
# Ensure all expected keys exist
|
||||
rules.setdefault("required_inputs", [])
|
||||
rules.setdefault("optional_inputs", {})
|
||||
rules.setdefault("optional_inputs", [])
|
||||
rules.setdefault("conventions", {})
|
||||
rules.setdefault("overrides", {})
|
||||
|
||||
# Build conventions from optional_inputs if not explicitly set
|
||||
if not rules["conventions"] and rules["optional_inputs"]:
|
||||
conventions = {}
|
||||
for input_name, input_config in rules["optional_inputs"].items():
|
||||
# Try to infer validator type from the input name or pattern
|
||||
conventions[input_name] = self._infer_validator_type(input_name, input_config)
|
||||
optional_inputs = rules["optional_inputs"]
|
||||
|
||||
# Handle both list and dict formats for optional_inputs
|
||||
if isinstance(optional_inputs, list):
|
||||
# List format: just input names
|
||||
for input_name in optional_inputs:
|
||||
conventions[input_name] = self._infer_validator_type(input_name, {})
|
||||
elif isinstance(optional_inputs, dict):
|
||||
# Dict format: input names with config
|
||||
for input_name, input_config in optional_inputs.items():
|
||||
conventions[input_name] = self._infer_validator_type(
|
||||
input_name, input_config
|
||||
)
|
||||
|
||||
rules["conventions"] = conventions
|
||||
|
||||
return rules
|
||||
@@ -110,7 +121,7 @@ class ConventionBasedValidator(BaseValidator):
|
||||
return {
|
||||
"action_type": self.action_type,
|
||||
"required_inputs": [],
|
||||
"optional_inputs": {},
|
||||
"optional_inputs": [],
|
||||
"conventions": {},
|
||||
"overrides": {},
|
||||
}
|
||||
@@ -285,7 +296,7 @@ class ConventionBasedValidator(BaseValidator):
|
||||
# Get conventions and overrides from rules
|
||||
conventions = self._rules.get("conventions", {})
|
||||
overrides = self._rules.get("overrides", {})
|
||||
optional_inputs = self._rules.get("optional_inputs", {})
|
||||
optional_inputs = self._rules.get("optional_inputs", [])
|
||||
required_inputs = self.get_required_inputs()
|
||||
|
||||
# Validate each input
|
||||
|
||||
Reference in New Issue
Block a user