mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 23:47:54 +08:00
core/tools: rename run_command_batch to run_argv_batch (steps/argv keys)
This commit is contained in:
@@ -48,23 +48,23 @@ def test_classify_safe_tools() -> None:
|
||||
assert classify_danger("run_argv", {"argv": ["ls", "-la"]}) is None
|
||||
|
||||
|
||||
def test_classify_run_command_batch_risky() -> None:
|
||||
def test_classify_run_argv_batch_risky() -> None:
|
||||
reason = classify_danger(
|
||||
"run_command_batch",
|
||||
"run_argv_batch",
|
||||
{
|
||||
"commands": [
|
||||
{"command": ["echo", "ok"]},
|
||||
{"command": ["bash", "-c", "echo risky"]},
|
||||
"steps": [
|
||||
{"argv": ["echo", "ok"]},
|
||||
{"argv": ["bash", "-c", "echo risky"]},
|
||||
]
|
||||
},
|
||||
)
|
||||
assert reason is not None
|
||||
assert "run_command_batch" in reason
|
||||
assert "run_argv_batch" in reason
|
||||
assert "risky" in reason or "bash" in reason
|
||||
assert (
|
||||
classify_danger(
|
||||
"run_command_batch",
|
||||
{"commands": [{"command": ["echo", "ok"]}]},
|
||||
"run_argv_batch",
|
||||
{"steps": [{"argv": ["echo", "ok"]}]},
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ from plyngent.tools.process import (
|
||||
open_pty,
|
||||
read_pty,
|
||||
run_argv,
|
||||
run_command_batch,
|
||||
run_argv_batch,
|
||||
write_pty,
|
||||
write_pty_keys,
|
||||
)
|
||||
@@ -78,13 +78,13 @@ async def test_open_pty_string_command_error(workspace: object) -> None:
|
||||
assert "only accepts an array" in out
|
||||
|
||||
|
||||
async def test_run_command_batch_serial(workspace: object) -> None:
|
||||
async def test_run_argv_batch_serial(workspace: object) -> None:
|
||||
del workspace
|
||||
out = await call_async(
|
||||
run_command_batch,
|
||||
run_argv_batch,
|
||||
[
|
||||
{"command": _py("print('a')")},
|
||||
{"command": _py("print('b')")},
|
||||
{"argv": _py("print('a')")},
|
||||
{"argv": _py("print('b')")},
|
||||
],
|
||||
)
|
||||
assert "steps=2" in out
|
||||
@@ -95,13 +95,13 @@ async def test_run_command_batch_serial(workspace: object) -> None:
|
||||
assert "a" in out and "b" in out
|
||||
|
||||
|
||||
async def test_run_command_batch_stop_on_error(workspace: object) -> None:
|
||||
async def test_run_argv_batch_stop_on_error(workspace: object) -> None:
|
||||
del workspace
|
||||
out = await call_async(
|
||||
run_command_batch,
|
||||
run_argv_batch,
|
||||
[
|
||||
{"command": _py("import sys; sys.exit(2)")},
|
||||
{"command": _py("print('should-not-run')")},
|
||||
{"argv": _py("import sys; sys.exit(2)")},
|
||||
{"argv": _py("print('should-not-run')")},
|
||||
],
|
||||
stop_on_error=True,
|
||||
)
|
||||
@@ -110,17 +110,17 @@ async def test_run_command_batch_stop_on_error(workspace: object) -> None:
|
||||
assert "should-not-run" not in out
|
||||
|
||||
|
||||
async def test_run_command_batch_pipe_out(workspace: object) -> None:
|
||||
async def test_run_argv_batch_pipe_out(workspace: object) -> None:
|
||||
del workspace
|
||||
out = await call_async(
|
||||
run_command_batch,
|
||||
run_argv_batch,
|
||||
[
|
||||
{
|
||||
"command": _py("print('piped-payload', end='')"),
|
||||
"argv": _py("print('piped-payload', end='')"),
|
||||
"pipe_out": True,
|
||||
},
|
||||
{
|
||||
"command": _py("import sys; print(sys.stdin.read())"),
|
||||
"argv": _py("import sys; print(sys.stdin.read())"),
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -129,27 +129,27 @@ async def test_run_command_batch_pipe_out(workspace: object) -> None:
|
||||
assert "pipe_out=true" in out
|
||||
|
||||
|
||||
async def test_run_command_batch_last_pipe_out_error(workspace: object) -> None:
|
||||
async def test_run_argv_batch_last_pipe_out_error(workspace: object) -> None:
|
||||
del workspace
|
||||
out = await call_async(
|
||||
run_command_batch,
|
||||
[{"command": _py("print(1)"), "pipe_out": True}],
|
||||
run_argv_batch,
|
||||
[{"argv": _py("print(1)"), "pipe_out": True}],
|
||||
)
|
||||
assert "error:" in out
|
||||
assert "pipe_out" in out
|
||||
|
||||
|
||||
async def test_run_command_batch_mix_stderr(workspace: object) -> None:
|
||||
async def test_run_argv_batch_mix_stderr(workspace: object) -> None:
|
||||
del workspace
|
||||
out = await call_async(
|
||||
run_command_batch,
|
||||
run_argv_batch,
|
||||
[
|
||||
{
|
||||
"command": _py("import sys; sys.stdout.write('out'); sys.stderr.write('err')"),
|
||||
"argv": _py("import sys; sys.stdout.write('out'); sys.stderr.write('err')"),
|
||||
"mix_stderr": True,
|
||||
"pipe_out": True,
|
||||
},
|
||||
{"command": _py("import sys; print(repr(sys.stdin.read()))")},
|
||||
{"argv": _py("import sys; print(repr(sys.stdin.read()))")},
|
||||
],
|
||||
)
|
||||
assert "ran=2" in out
|
||||
|
||||
Reference in New Issue
Block a user