| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/provider" |
| 8 | "reasonix/internal/sandbox" |
| 9 | "reasonix/internal/tool" |
| 10 | "reasonix/internal/tool/builtin" |
| 11 | ) |
| 12 | |
| 13 | func TestLegacyShellAliasesPassArgumentGateWithoutDescription(t *testing.T) { |
| 14 | r := tool.NewRegistry() |
| 15 | r.Add(builtin.ConfineBash(sandbox.Spec{Mode: "enforce", Shell: sandbox.Shell{Kind: sandbox.ShellPowerShell, Path: "pwsh"}}, builtin.SessionDataGuard{})) |
| 16 | for _, name := range []string{"bash", "Bash", "PowerShell", "powershell", "Pwsh", "pwsh"} { |
| 17 | t.Run(name, func(t *testing.T) { |
| 18 | target, _, _ := r.ResolveCall(name) |
| 19 | plan := &toolCallPlan{call: provider.ToolCall{Name: name}, execTool: target, permName: "pwsh", execArgs: json.RawMessage(`{"command":"Write-Output legacy"}`)} |
| 20 | _, blocked := (&Agent{}).applyArgumentValidation(plan) |
| 21 | if blocked != (name == "pwsh") { |
| 22 | t.Fatalf("blocked=%v for %s", blocked, name) |
| 23 | } |
| 24 | if name != "pwsh" { |
| 25 | var args map[string]string |
| 26 | _ = json.Unmarshal(plan.execArgs, &args) |
| 27 | if args["command"] != "Write-Output legacy" || args["description"] == "" { |
| 28 | t.Fatalf("args=%s", plan.execArgs) |
| 29 | } |
| 30 | if string(plan.execArgs) != string(plan.permArgs) { |
| 31 | t.Fatal("permission args diverged") |
| 32 | } |
| 33 | } |
| 34 | }) |
| 35 | } |
| 36 | // Compatibility must not coerce malformed values or drop security arguments. |
| 37 | target, _, _ := r.ResolveCall("bash") |
| 38 | for _, raw := range []string{`{"command":42}`, `{"command":"x","description":42}`, `{"command":"x","sandbox_permissions":"invalid"}`} { |
| 39 | plan := &toolCallPlan{call: provider.ToolCall{Name: "bash"}, execTool: target, permName: "pwsh", execArgs: json.RawMessage(raw)} |
| 40 | if _, blocked := (&Agent{}).applyArgumentValidation(plan); !blocked { |
| 41 | t.Fatalf("invalid args accepted: %s", raw) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 |