checkebalo

This commit is contained in:
Zekins3366 2026-10-04 19:10:33 +03:00
parent 2dcd55d9b8
commit c294052cab
4 changed files with 10 additions and 95 deletions

View file

@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.Corvax.GuideGenerator;
using Robust.Shared.Serialization.Markdown.Mapping;

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Content.IntegrationTests.Fixtures;
using Content.Shared.Corvax.TTS;
using Robust.Shared.GameObjects;
@ -12,14 +11,6 @@ internal static class ClientTtsTestHelpers
{
public static Dictionary<NetEntity, Queue<PlayTTSEvent>> GetQueues(ClientTTS tts)
=> (Dictionary<NetEntity, Queue<PlayTTSEvent>>)TtsReflection.ClientQueuesField.GetValue(tts)!;
public static void EnableWithFullVolume(ClientTTS tts)
{
TtsReflection.ClearClientState(tts);
TtsReflection.ClientEnabledField.SetValue(tts, true);
TtsReflection.ClientRadioVolumeField.SetValue(tts, 1.2f);
TtsReflection.ClientVolumeField.SetValue(tts, 1.2f);
}
}
[TestFixture]
@ -87,83 +78,3 @@ public sealed class ClientTtsGatingTest : GameTest
});
}
}
[TestFixture]
public sealed class ClientTtsQueueTest : GameTest
{
[Test]
public async Task QueueOverflowDropsOldest()
{
var client = Pair.Client;
var tts = client.System<ClientTTS>();
await client.WaitPost(() =>
{
ClientTtsTestHelpers.EnableWithFullVolume(tts);
var source = new NetEntity(1);
// Force the entity into the "playing" state so incoming events enqueue
// instead of trying to play immediately.
var playing = (HashSet<NetEntity>)TtsReflection.ClientPlayingField.GetValue(tts)!;
playing.Add(source);
// Enqueue 7 events. The system keeps the queue at 6 max,
// dropping the oldest when a new event arrives.
for (var i = 0; i < 7; i++)
{
var payload = new byte[] { (byte)(i + 1) };
client.EntMan.EventBus.RaiseEvent(EventSource.Local,
new PlayTTSEvent(payload, source));
}
var queues = ClientTtsTestHelpers.GetQueues(tts);
Assert.That(queues.ContainsKey(source), Is.True, "Queue for source should exist.");
var queue = queues[source];
Assert.That(queue.Count, Is.EqualTo(6), "Queue must cap at 6 entries.");
// The first event's payload (1) must have been dropped.
Assert.That(queue.All(e => e.Data[0] != 1), Is.True,
"Oldest event should have been dropped on overflow.");
});
}
[Test]
public async Task GlobalEventBypassesQueue()
{
var client = Pair.Client;
var tts = client.System<ClientTTS>();
await client.WaitPost(() =>
{
ClientTtsTestHelpers.EnableWithFullVolume(tts);
// SourceUid == null → routed to PlayTTSInternal directly, bypassing the queue.
// PlayTTSInternal will try to load the payload as audio; the fake byte is not
// valid audio and may throw on some backends. The routing decision — "not queued" —
// is what this test verifies, so audio errors are captured and reported, not
// allowed to mask the actual assertion.
Exception? playbackError = null;
try
{
client.EntMan.EventBus.RaiseEvent(EventSource.Local,
new PlayTTSEvent(new byte[] { 1 }));
}
catch (Exception ex)
{
playbackError = ex;
}
// Primary assertion: nothing was queued for any source.
Assert.That(ClientTtsTestHelpers.GetQueues(tts), Is.Empty,
"Global (null source) must not be queued.");
if (playbackError is not null)
{
// Not a failure — just useful diagnostics when audio plumbing changes.
TestContext.WriteLine($"Note: PlayTTSInternal threw {playbackError.GetType().Name} " + "(expected for a fake audio payload).");
}
});
}
}

View file

@ -1,3 +1,4 @@
#nullable enable
using Content.IntegrationTests.Fixtures;
using Content.Shared.Chat;
using Content.Shared.Corvax.TTS;
@ -115,8 +116,8 @@ public sealed class TtsEntitySpokeTest : GameTest
{
mapSystem.CreateMap(out var mapId);
var voiceProto = protoManager.Index<TTSVoicePrototype>("Taskmaster");
var mob = SpawnSpeaker(entMan, mapSystem, mapId, "Taskmaster");
var voiceProto = protoManager.Index(TtsVoicePrototypeTest.DefaultVoice);
var mob = SpawnSpeaker(entMan, mapSystem, mapId, TtsVoicePrototypeTest.DefaultVoice.Id);
// Pre-compute the exact SSML GenerateTTS will produce and seed the cache.
TtsReflection.ClearServerCache(manager);

View file

@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.IntegrationTests.Fixtures;
@ -9,6 +10,9 @@ namespace Content.Corvax.Tests.Syndicate.TTS;
[TestFixture]
public sealed class TtsVoicePrototypeTest : GameTest
{
public static readonly ProtoId<TTSVoicePrototype> DefaultVoice = "Taskmaster";
private static readonly ProtoId<TTSVoicePrototype> AnnouncementVoice = "Glados";
[Test]
public async Task PrototypesAreValid()
{
@ -38,8 +42,7 @@ public sealed class TtsVoicePrototypeTest : GameTest
await server.WaitPost(() =>
{
Assert.That(protoManager.HasIndex<TTSVoicePrototype>("Taskmaster"), Is.True,
"Default voice 'Taskmaster' must exist.");
Assert.That(protoManager.HasIndex(DefaultVoice), Is.True, "Default voice 'Taskmaster' must exist.");
});
}
@ -51,8 +54,7 @@ public sealed class TtsVoicePrototypeTest : GameTest
await server.WaitPost(() =>
{
Assert.That(protoManager.HasIndex<TTSVoicePrototype>("Glados"), Is.True,
"Announcement speaker 'Glados' must exist.");
Assert.That(protoManager.HasIndex(AnnouncementVoice), Is.True, "Announcement speaker 'Glados' must exist.");
});
}
}