mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
This commit is contained in:
@@ -58,7 +58,9 @@ class BashTool(Tool):
|
||||
output = None
|
||||
if command and command[0] in self.allowed:
|
||||
try:
|
||||
output = subprocess.run(command, capture_output=True, text=True, check=False, stdin=subprocess.DEVNULL, timeout=self.timeout).stdout
|
||||
output = subprocess.run(
|
||||
command, capture_output=True, text=True, encoding="utf-8", check=False, stdin=subprocess.DEVNULL, timeout=self.timeout
|
||||
).stdout
|
||||
except subprocess.TimeoutExpired:
|
||||
output = f"Command timed out after {self.timeout} seconds"
|
||||
|
||||
|
||||
@@ -232,6 +232,20 @@ class TestAgent(unittest.TestCase):
|
||||
# Timeout is disabled when set to None
|
||||
self.assertIsNone(BashTool(timeout=None).timeout)
|
||||
|
||||
@patch("subprocess.run")
|
||||
def testToolsBashEncoding(self, run):
|
||||
"""
|
||||
Test bash tool decodes subprocess output as UTF-8 instead of the locale encoding
|
||||
"""
|
||||
|
||||
run.return_value.stdout = "output"
|
||||
|
||||
tool = BashTool(allowed=["cat"])
|
||||
tool(["cat", "file.txt"])
|
||||
|
||||
# Subprocess output must be decoded as UTF-8, not left to the locale's default encoding
|
||||
self.assertEqual(run.call_args.kwargs.get("encoding"), "utf-8")
|
||||
|
||||
def testToolsEmbeddings(self):
|
||||
"""
|
||||
Test adding Embeddings as a tool
|
||||
|
||||
Reference in New Issue
Block a user