Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/Netclaw.Actors.Tests/Tools/ScopedShellSafeVerbPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// -----------------------------------------------------------------------
using Netclaw.Actors.Tools;
using Netclaw.Configuration;
using Netclaw.Security;
using Netclaw.Tools;
using Xunit;

Expand Down Expand Up @@ -59,6 +60,9 @@ private static void SafeDelete(string path)
private static SafeVerbList VerbList(params string[] verbs)
=> SafeVerbList.FromVerbs(verbs);

private static IReadOnlyList<ApprovalCandidate> Candidates(params string[] verbs)
=> verbs.Select(verb => new ApprovalCandidate(verb, Directory: null)).ToList();

private ToolInvocationContext PersonalContext(string? projectDir = null, string? sessionDir = null)
=> TestToolExecutionContext.CreateBound("session-1", sessionDir ?? _sessionDir, new TestToolExecutionContextOptions
{
Expand Down Expand Up @@ -153,7 +157,7 @@ public void All_short_circuit_returns_false_when_any_verb_is_unsafe()
var policy = new ScopedShellSafeVerbPolicy(VerbList("grep", "cat"));
var ctx = PersonalContext(projectDir: _projectDir);

Assert.False(policy.AllShortCircuit(["grep", "git push"], _projectDir, ctx));
Assert.False(policy.AllShortCircuit(Candidates("grep", "git push"), _projectDir, ctx));
}

[Fact]
Expand All @@ -162,7 +166,7 @@ public void All_short_circuit_returns_true_when_every_verb_is_safe_and_in_space(
var policy = new ScopedShellSafeVerbPolicy(VerbList("grep", "cat", "wc"));
var ctx = PersonalContext(projectDir: _projectDir);

Assert.True(policy.AllShortCircuit(["grep", "cat", "wc"], _projectDir, ctx));
Assert.True(policy.AllShortCircuit(Candidates("grep", "cat", "wc"), _projectDir, ctx));
}

[Fact]
Expand Down Expand Up @@ -206,6 +210,16 @@ public void New_safe_verb_chained_with_mutating_verb_still_prompts()
var policy = new ScopedShellSafeVerbPolicy(VerbList("date"));
var ctx = PersonalContext(projectDir: _projectDir);

Assert.False(policy.AllShortCircuit(["date", "git push origin main"], _projectDir, ctx));
Assert.False(policy.AllShortCircuit(Candidates("date", "git push origin main"), _projectDir, ctx));
}

[Fact]
public void Candidate_path_outside_safe_spaces_falls_through_to_prompt()
{
var policy = new ScopedShellSafeVerbPolicy(VerbList("cat"));
var ctx = PersonalContext(projectDir: _projectDir);
var candidates = new[] { new ApprovalCandidate("cat", _outsideDir) };

Assert.False(policy.AllShortCircuit(candidates, _projectDir, ctx));
}
}
Loading
Loading