Files
voice-cat/dotnet/tests/VoiceCat.Tests/ManagedCliTests.cs
T
Talon c9ed832459
.NET port / test (macos-latest) (push) Canceled after 0s
.NET port / test (ubuntu-24.04) (push) Canceled after 0s
.NET port / test (windows-latest) (push) Canceled after 0s
.NET port / apple-client (push) Canceled after 0s
Retire legacy sources and verify managed iOS deployment
2026-09-19 22:40:48 +02:00

46 lines
2.9 KiB
C#

using System.Diagnostics;
using static VoiceCat.Tests.ServerTests;
namespace VoiceCat.Tests;
public class ManagedCliTests
{
[Theory]
[InlineData(1u)]
[InlineData(2u)]
public async Task TwoManagedCliProcessesExchangeTextAndDecodedVoice(uint channel)
{
await using var fixture = new ServerFixture();
string root = FindRoot();
string cli = Path.Combine(root, "dotnet", "src", "VoiceCat.Cli", "bin", "Release", "net10.0", "VoiceCat.Cli.dll");
Assert.True(File.Exists(cli), $"Managed CLI was not built at {cli}.");
using Process alice = Start(cli, fixture, "Alice", "Alice says hello", "Bob says hello", channel);
using Process bob = Start(cli, fixture, "Bob", "Bob says hello", "Alice says hello", channel);
Task<string> aliceOut = alice.StandardOutput.ReadToEndAsync(); Task<string> aliceError = alice.StandardError.ReadToEndAsync();
Task<string> bobOut = bob.StandardOutput.ReadToEndAsync(); Task<string> bobError = bob.StandardError.ReadToEndAsync();
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(35));
await Task.WhenAll(alice.WaitForExitAsync(timeout.Token), bob.WaitForExitAsync(timeout.Token));
string aout = await aliceOut, bout = await bobOut;
Assert.True(alice.ExitCode == 0, await aliceError + Environment.NewLine + aout);
Assert.True(bob.ExitCode == 0, await bobError + Environment.NewLine + bout);
Assert.Contains("Bob says hello", aout); Assert.Contains("Alice says hello", bout);
Assert.Contains("\"type\":\"complete\"", aout); Assert.Contains("\"type\":\"complete\"", bout);
Assert.DoesNotContain("\"voiceEnergy\":0", aout); Assert.DoesNotContain("\"voiceEnergy\":0", bout);
}
private static Process Start(string cli, ServerFixture fixture, string name, string send, string expect, uint channel)
{
var start = new ProcessStartInfo("dotnet") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false };
foreach (string argument in new[] { cli, "--host", "127.0.0.1", "--port", fixture.Server.EndPoint.Port.ToString(), "--nickname", name,
"--pins", Path.Combine(fixture.Directory, name + ".cli.pins"), "--trust-first", "--channel", channel.ToString(), "--voice", "--expect-voice", "--send-text", send,
"--expect-text", expect, "--start-delay-ms", "1500", "--timeout-seconds", "20" }) start.ArgumentList.Add(argument);
return Process.Start(start) ?? throw new InvalidOperationException("Could not start managed CLI.");
}
private static string FindRoot()
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "CMakePresets.json"))) directory = directory.Parent;
return directory?.FullName ?? throw new DirectoryNotFoundException("Repository root not found.");
}
}