Files
aryx/sidecar/tests/Aryx.AgentHost.Tests/StreamingTextMergerTests.cs
T
David KayaandCopilot c7910e6e4b fix: remove streaming text boundary heuristics that injected spurious spaces
The StreamingTextMerger (C#) and mergeStreamingText (TypeScript) contained
custom word-boundary heuristics that inserted spaces between streaming deltas
based on incorrect assumptions. Two bugs caused mid-word spaces:

1. Unconditional space insertion when incoming delta started with uppercase or
   digit characters, breaking acronyms (MDA -> M DA, UAG -> UA G)
2. LooksLikeWordBoundary using global token counts that fired on nearly every
   mid-word token split (writable -> wr itable, fragile -> frag ile)

Both upstream projects (Copilot SDK and Agent Framework) use simple string
concatenation for delta accumulation. LLM streaming tokens natively include
whitespace when needed, so no boundary detection is required.

Removed all boundary heuristic methods and replaced with plain concatenation.
Kept overlap detection and snapshot handling for event redelivery scenarios.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 18:55:34 +02:00

73 lines
2.8 KiB
C#

using Aryx.AgentHost.Services;
namespace Aryx.AgentHost.Tests;
public sealed class StreamingTextMergerTests
{
[Fact]
public void Merge_AppendsPlainDeltas()
{
Assert.Equal("I am going", StreamingTextMerger.Merge("I am", " going"));
}
[Fact]
public void Merge_ReplacesWithGrowingSnapshot()
{
Assert.Equal("I am going", StreamingTextMerger.Merge("I am", "I am going"));
}
[Fact]
public void Merge_PreservesCurrentTextForDuplicateSubset()
{
Assert.Equal("I am going", StreamingTextMerger.Merge("I am going", "going"));
}
[Fact]
public void Merge_UsesOverlapToAvoidDuplicateJoins()
{
Assert.Equal("Hello world", StreamingTextMerger.Merge("Hello wor", "world"));
}
[Fact]
public void Merge_ReplacesWithRevisedSnapshotWhenMostTokensOverlap()
{
const string current = "I mirror the existing button pattern and add brief toggle docs.";
const string incoming = "I found the standalone component pattern and I am updating toggle docs next.";
Assert.Equal(incoming, StreamingTextMerger.Merge(current, incoming));
}
[Theory]
[InlineData("requires all wr", "itable fields", "requires all writable fields")]
[InlineData("becomes frag", "ile for clients", "becomes fragile for clients")]
[InlineData("Endpoint (domain) uniqu", "eness across tenants", "Endpoint (domain) uniqueness across tenants")]
[InlineData("The doc says \"wildc", "ards are allowed\"", "The doc says \"wildcards are allowed\"")]
[InlineData("What wildcard syntax supported (*.cont", "oso.com? contoso.* ?)", "What wildcard syntax supported (*.contoso.com? contoso.* ?)")]
[InlineData("How does Pur", "view match traffic", "How does Purview match traffic")]
[InlineData("more M", "DA properties", "more MDA properties")]
[InlineData("does UA", "G normalize them?", "does UAG normalize them?")]
public void Merge_DoesNotInjectSpacesIntoSplitWords(string current, string incoming, string expected)
{
Assert.Equal(expected, StreamingTextMerger.Merge(current, incoming));
}
[Fact]
public void Merge_PreservesWhitespaceAlreadyPresentInDelta()
{
Assert.Equal(
"How about The **Ashen Crown** feels",
StreamingTextMerger.Merge("How about", " The **Ashen Crown** feels"));
Assert.Equal(
"The **Ashen Crown** feels classic and timeless.",
StreamingTextMerger.Merge("The **Ashen Crown** feels", " classic and timeless."));
}
[Fact]
public void Merge_PreservesNewlineAlreadyPresentInDelta()
{
Assert.Equal(
"If you want, I can also give you\n- darker titles",
StreamingTextMerger.Merge("If you want, I can also give you", "\n- darker titles"));
}
}