fix: disable unsolicited background UI automation

This commit is contained in:
2026-09-20 18:40:23 +08:00
parent 7bf994de88
commit e17124de59
7 changed files with 56 additions and 17 deletions
@@ -15,6 +15,34 @@ public sealed class EventPumpTests
{ yield return new AgentEvent("evt", "ui-current", "session", "message", "summary", DateTimeOffset.UtcNow); await Task.Delay(Timeout.Infinite, ct); }
}
private sealed class DisabledSourceBackend : IAgentBackend, IAgentEventSource
{
public bool ListenCalled { get; private set; }
public IReadOnlyList<AgentCapability> Capabilities => [new("listener-events", true, true, false, true, false, "read", false, 30, "disabled", [])];
public Task<object> StatusAsync(CancellationToken ct) => Task.FromResult<object>(new { ok = true });
public async IAsyncEnumerable<AgentEvent> ListenAsync([EnumeratorCancellation] CancellationToken ct)
{
ListenCalled = true;
await Task.CompletedTask;
yield break;
}
}
[Fact]
public async Task DisabledListenerDoesNotStartUiSource()
{
var source = new DisabledSourceBackend();
using var pump = new EventPump(source, new EventHub(), new ServiceOptions
{
DataDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")),
CredentialFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"), "credentials.json")
});
await pump.StartAsync(default);
await Task.Delay(100);
await pump.StopAsync(default);
Assert.False(source.ListenCalled);
}
[Fact]
public async Task PumpForwardsToTheConfiguredPrincipal()
{