mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 12:41:02 +02:00
Changed available_in_state to applicable-states
This commit is contained in:
parent
2608fac6bd
commit
4433949cb5
3 changed files with 32 additions and 32 deletions
|
|
@ -31,7 +31,7 @@ def sample_tools():
|
||||||
config={
|
config={
|
||||||
'group': ['read-only', 'knowledge', 'basic'],
|
'group': ['read-only', 'knowledge', 'basic'],
|
||||||
'state': 'analysis',
|
'state': 'analysis',
|
||||||
'available_in_states': ['undefined', 'research']
|
'applicable-states': ['undefined', 'research']
|
||||||
},
|
},
|
||||||
arguments=[]
|
arguments=[]
|
||||||
),
|
),
|
||||||
|
|
@ -41,7 +41,7 @@ def sample_tools():
|
||||||
implementation=Mock(),
|
implementation=Mock(),
|
||||||
config={
|
config={
|
||||||
'group': ['write', 'knowledge', 'admin'],
|
'group': ['write', 'knowledge', 'admin'],
|
||||||
'available_in_states': ['analysis', 'modification']
|
'applicable-states': ['analysis', 'modification']
|
||||||
},
|
},
|
||||||
arguments=[]
|
arguments=[]
|
||||||
),
|
),
|
||||||
|
|
@ -52,7 +52,7 @@ def sample_tools():
|
||||||
config={
|
config={
|
||||||
'group': ['read-only', 'text', 'basic'],
|
'group': ['read-only', 'text', 'basic'],
|
||||||
'state': 'undefined'
|
'state': 'undefined'
|
||||||
# No available_in_states = available in all states
|
# No applicable-states = available in all states
|
||||||
},
|
},
|
||||||
arguments=[]
|
arguments=[]
|
||||||
),
|
),
|
||||||
|
|
@ -63,7 +63,7 @@ def sample_tools():
|
||||||
config={
|
config={
|
||||||
'group': ['advanced', 'compute', 'expensive'],
|
'group': ['advanced', 'compute', 'expensive'],
|
||||||
'state': 'results',
|
'state': 'results',
|
||||||
'available_in_states': ['analysis']
|
'applicable-states': ['analysis']
|
||||||
},
|
},
|
||||||
arguments=[]
|
arguments=[]
|
||||||
)
|
)
|
||||||
|
|
@ -332,7 +332,7 @@ class TestToolConfigurationLoading:
|
||||||
"type": "text-completion",
|
"type": "text-completion",
|
||||||
"group": ["read-only", "text"],
|
"group": ["read-only", "text"],
|
||||||
"state": "analysis",
|
"state": "analysis",
|
||||||
"available_in_states": ["undefined", "research"]
|
"applicable-states": ["undefined", "research"]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,10 @@ class TestToolFiltering:
|
||||||
assert all(tool in filtered for tool in tools)
|
assert all(tool in filtered for tool in tools)
|
||||||
|
|
||||||
def test_filter_tools_by_state(self):
|
def test_filter_tools_by_state(self):
|
||||||
"""Test filtering based on available_in_states."""
|
"""Test filtering based on applicable-states."""
|
||||||
tools = {
|
tools = {
|
||||||
'init_tool': Mock(config={'available_in_states': ['undefined']}),
|
'init_tool': Mock(config={'applicable-states': ['undefined']}),
|
||||||
'analysis_tool': Mock(config={'available_in_states': ['analysis']}),
|
'analysis_tool': Mock(config={'applicable-states': ['analysis']}),
|
||||||
'any_state_tool': Mock(config={}) # available in all states
|
'any_state_tool': Mock(config={}) # available in all states
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,10 +95,10 @@ class TestToolFiltering:
|
||||||
assert 'any_state_tool' in filtered
|
assert 'any_state_tool' in filtered
|
||||||
|
|
||||||
def test_filter_tools_state_wildcard(self):
|
def test_filter_tools_state_wildcard(self):
|
||||||
"""Test tools with '*' in available_in_states are always available."""
|
"""Test tools with '*' in applicable-states are always available."""
|
||||||
tools = {
|
tools = {
|
||||||
'wildcard_tool': Mock(config={'available_in_states': ['*']}),
|
'wildcard_tool': Mock(config={'applicable-states': ['*']}),
|
||||||
'specific_tool': Mock(config={'available_in_states': ['research']})
|
'specific_tool': Mock(config={'applicable-states': ['research']})
|
||||||
}
|
}
|
||||||
|
|
||||||
# Filter for 'analysis' state
|
# Filter for 'analysis' state
|
||||||
|
|
@ -112,19 +112,19 @@ class TestToolFiltering:
|
||||||
tools = {
|
tools = {
|
||||||
'valid_tool': Mock(config={
|
'valid_tool': Mock(config={
|
||||||
'group': ['read-only'],
|
'group': ['read-only'],
|
||||||
'available_in_states': ['analysis']
|
'applicable-states': ['analysis']
|
||||||
}),
|
}),
|
||||||
'wrong_group': Mock(config={
|
'wrong_group': Mock(config={
|
||||||
'group': ['admin'],
|
'group': ['admin'],
|
||||||
'available_in_states': ['analysis']
|
'applicable-states': ['analysis']
|
||||||
}),
|
}),
|
||||||
'wrong_state': Mock(config={
|
'wrong_state': Mock(config={
|
||||||
'group': ['read-only'],
|
'group': ['read-only'],
|
||||||
'available_in_states': ['research']
|
'applicable-states': ['research']
|
||||||
}),
|
}),
|
||||||
'wrong_both': Mock(config={
|
'wrong_both': Mock(config={
|
||||||
'group': ['admin'],
|
'group': ['admin'],
|
||||||
'available_in_states': ['research']
|
'applicable-states': ['research']
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ class TestConfigValidation:
|
||||||
config = {
|
config = {
|
||||||
'group': ['read-only', 'basic'],
|
'group': ['read-only', 'basic'],
|
||||||
'state': 'analysis',
|
'state': 'analysis',
|
||||||
'available_in_states': ['undefined', 'research']
|
'applicable-states': ['undefined', 'research']
|
||||||
}
|
}
|
||||||
|
|
||||||
# Should not raise an exception
|
# Should not raise an exception
|
||||||
|
|
@ -213,16 +213,16 @@ class TestConfigValidation:
|
||||||
with pytest.raises(ValueError, match="'state' field must be a string"):
|
with pytest.raises(ValueError, match="'state' field must be a string"):
|
||||||
validate_tool_config(config)
|
validate_tool_config(config)
|
||||||
|
|
||||||
def test_validate_available_in_states_not_list(self):
|
def test_validate_applicable_states_not_list(self):
|
||||||
"""Test validation fails when available_in_states is not a list."""
|
"""Test validation fails when applicable-states is not a list."""
|
||||||
config = {'available_in_states': 'undefined'} # Should be list
|
config = {'applicable-states': 'undefined'} # Should be list
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="'available_in_states' field must be a list"):
|
with pytest.raises(ValueError, match="'applicable-states' field must be a list"):
|
||||||
validate_tool_config(config)
|
validate_tool_config(config)
|
||||||
|
|
||||||
def test_validate_available_in_states_non_string_elements(self):
|
def test_validate_applicable_states_non_string_elements(self):
|
||||||
"""Test validation fails when available_in_states contains non-strings."""
|
"""Test validation fails when applicable-states contains non-strings."""
|
||||||
config = {'available_in_states': ['undefined', 123]}
|
config = {'applicable-states': ['undefined', 123]}
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="All state names must be strings"):
|
with pytest.raises(ValueError, match="All state names must be strings"):
|
||||||
validate_tool_config(config)
|
validate_tool_config(config)
|
||||||
|
|
@ -257,7 +257,7 @@ class TestToolAvailability:
|
||||||
|
|
||||||
def test_tool_available_string_state_conversion(self):
|
def test_tool_available_string_state_conversion(self):
|
||||||
"""Test that single state string is converted to list."""
|
"""Test that single state string is converted to list."""
|
||||||
tool = Mock(config={'available_in_states': 'analysis'}) # Single string
|
tool = Mock(config={'applicable-states': 'analysis'}) # Single string
|
||||||
|
|
||||||
assert _is_tool_available(tool, ['default'], 'analysis')
|
assert _is_tool_available(tool, ['default'], 'analysis')
|
||||||
assert not _is_tool_available(tool, ['default'], 'research')
|
assert not _is_tool_available(tool, ['default'], 'research')
|
||||||
|
|
@ -281,16 +281,16 @@ class TestWorkflowScenarios:
|
||||||
'knowledge_query': Mock(config={
|
'knowledge_query': Mock(config={
|
||||||
'group': ['read-only', 'knowledge'],
|
'group': ['read-only', 'knowledge'],
|
||||||
'state': 'analysis',
|
'state': 'analysis',
|
||||||
'available_in_states': ['undefined', 'research']
|
'applicable-states': ['undefined', 'research']
|
||||||
}),
|
}),
|
||||||
'complex_analysis': Mock(config={
|
'complex_analysis': Mock(config={
|
||||||
'group': ['advanced', 'compute'],
|
'group': ['advanced', 'compute'],
|
||||||
'state': 'results',
|
'state': 'results',
|
||||||
'available_in_states': ['analysis']
|
'applicable-states': ['analysis']
|
||||||
}),
|
}),
|
||||||
'text_completion': Mock(config={
|
'text_completion': Mock(config={
|
||||||
'group': ['read-only', 'text', 'basic']
|
'group': ['read-only', 'text', 'basic']
|
||||||
# No available_in_states = available in all states
|
# No applicable-states = available in all states
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ def set_tool(
|
||||||
arguments : List[Argument],
|
arguments : List[Argument],
|
||||||
group : List[str],
|
group : List[str],
|
||||||
state : str,
|
state : str,
|
||||||
available_in_states : List[str],
|
applicable_states : List[str],
|
||||||
):
|
):
|
||||||
|
|
||||||
api = Api(url).config()
|
api = Api(url).config()
|
||||||
|
|
@ -100,7 +100,7 @@ def set_tool(
|
||||||
|
|
||||||
if state: object["state"] = state
|
if state: object["state"] = state
|
||||||
|
|
||||||
if available_in_states: object["available_in_states"] = available_in_states
|
if applicable_states: object["applicable-states"] = applicable_states
|
||||||
|
|
||||||
values = api.put([
|
values = api.put([
|
||||||
ConfigValue(
|
ConfigValue(
|
||||||
|
|
@ -200,8 +200,8 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--available-in-states',
|
'--applicable-states',
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help=f'States in which this tool is available',
|
help=f'States in which this tool is available',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ def main():
|
||||||
arguments=arguments,
|
arguments=arguments,
|
||||||
group=args.group or [],
|
group=args.group or [],
|
||||||
state=args.state,
|
state=args.state,
|
||||||
available_in_states=getattr(args, 'available_in_states', None) or [],
|
applicable_states=getattr(args, 'applicable_states', None) or [],
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue