MCPcopy Create free account
hub / github.com/AutoForgeAI/autoforge / test_extract_commands

Function test_extract_commands

test_security.py:97–124  ·  view source on GitHub ↗

Test the command extraction logic.

()

Source from the content-addressed store, hash-verified

95
96
97def test_extract_commands():
98 """Test the command extraction logic."""
99 print("\nTesting command extraction:\n")
100 passed = 0
101 failed = 0
102
103 test_cases = [
104 ("ls -la", ["ls"]),
105 ("npm install && npm run build", ["npm", "npm"]),
106 ("cat file.txt | grep pattern", ["cat", "grep"]),
107 ("/usr/bin/node script.js", ["node"]),
108 ("VAR=value ls", ["ls"]),
109 ("git status || git init", ["git", "git"]),
110 # Fallback parser test: complex nested quotes that break shlex
111 ('docker exec container php -r "echo \\"test\\";"', ["docker"]),
112 ]
113
114 for cmd, expected in test_cases:
115 result = extract_commands(cmd)
116 if result == expected:
117 print(f" PASS: {cmd!r} -> {result}")
118 passed += 1
119 else:
120 print(f" FAIL: {cmd!r}")
121 print(f" Expected: {expected}, Got: {result}")
122 failed += 1
123
124 return passed, failed
125
126
127def test_validate_chmod():

Callers 1

mainFunction · 0.85

Calls 1

extract_commandsFunction · 0.90

Tested by

no test coverage detected