mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 17:42:32 +01:00
pulse_read never sends an approval, so any command the agent's policy will not auto-approve fails every time, and the policy never auto-approves a piped or chained command. The model learned this only from a bare "command execution failed: command requires approval". On the third replay of the full-disk fault Patrol chose a piped `du`, then a chained `du; ls`, by itself; three of its ten evidence calls went to refusals and it ran out one level into the camera folders. The agent server now returns a named ErrCommandRequiresApproval, with the same message text, and pulse_read turns it into an APPROVAL_REQUIRED refusal with a hint: piped, chained or substituted commands always need approval, run each part on its own, for example `du -xh -d 3 <directory>`. The command parameter also says one command per call. Other execution failures are reported as before. The hint test now covers this hint's suggested form too, against all three gates.
26 lines
871 B
Go
26 lines
871 B
Go
package agentexec
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// A caller that cannot ask for approval needs to tell this refusal apart from
|
|
// a transport failure, so it is a named error rather than a message.
|
|
func TestUnapprovedCommandReturnsTheNamedApprovalError(t *testing.T) {
|
|
s := &Server{commandPolicy: DefaultPolicy()}
|
|
for _, command := range []string{
|
|
"du -xh -d 3 /mnt/nvr | sort -rh | head -20",
|
|
"du -sh /mnt/nvr/frigate; ls -la /mnt/nvr/frigate",
|
|
"df -h && echo ok",
|
|
} {
|
|
err := s.authorizeCommandPayload(ExecuteCommandPayload{Command: command})
|
|
if !errors.Is(err, ErrCommandRequiresApproval) {
|
|
t.Fatalf("%q: error = %v, want ErrCommandRequiresApproval", command, err)
|
|
}
|
|
}
|
|
if err := s.authorizeCommandPayload(ExecuteCommandPayload{Command: "du -xh -d 3 /mnt/nvr"}); err != nil {
|
|
t.Fatalf("a single auto-approved command was refused: %v", err)
|
|
}
|
|
}
|