mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
Honor an empty allow list in the bash agent tool (#1362)
This commit is contained in:
@@ -32,7 +32,7 @@ class BashTool(Tool):
|
||||
self.output_type = "any"
|
||||
|
||||
# Default list of allowed commands
|
||||
self.allowed = allowed if allowed else ["cat", "cut", "diff", "grep", "head", "ls", "tail"]
|
||||
self.allowed = allowed if allowed is not None else ["cat", "cut", "diff", "grep", "head", "ls", "tail"]
|
||||
|
||||
# Maximum time to wait for a command, None waits indefinitely
|
||||
self.timeout = timeout
|
||||
|
||||
@@ -232,6 +232,21 @@ class TestAgent(unittest.TestCase):
|
||||
# Timeout is disabled when set to None
|
||||
self.assertIsNone(BashTool(timeout=None).timeout)
|
||||
|
||||
def testToolsBashAllowedEmpty(self):
|
||||
"""
|
||||
Test an empty allowed commands list permits no commands
|
||||
"""
|
||||
|
||||
# An empty allow list is an explicit choice and must be honored, not replaced by the defaults
|
||||
self.assertEqual(BashTool(allowed=[]).allowed, [])
|
||||
|
||||
# No command runs when nothing is allowed
|
||||
self.assertIsNone(BashTool(allowed=[])(["cat", "file.txt"]))
|
||||
|
||||
# The defaults still apply when allowed isn't set, including an explicit None
|
||||
self.assertEqual(BashTool().allowed, ["cat", "cut", "diff", "grep", "head", "ls", "tail"])
|
||||
self.assertEqual(BashTool(allowed=None).allowed, ["cat", "cut", "diff", "grep", "head", "ls", "tail"])
|
||||
|
||||
@patch("subprocess.run")
|
||||
def testToolsBashEncoding(self, run):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user