acdream/tests/AcDream.App.Tests/Diagnostics/ConnectedR6SoakContractTests.cs
Erik bca4148739 test(app): add canonical connected soak snapshots
Make scripted lifecycle checkpoints acknowledged post-diagnostics render barriers, capture the exact frame outcome beside canonical resource ownership, and harden the nine-stop route with ordered same-location cache and lifetime gates without weakening process residency thresholds.

Co-authored-by: Codex <codex@openai.com>
2026-07-22 20:01:06 +02:00

133 lines
4.3 KiB
C#

namespace AcDream.App.Tests.Diagnostics;
public sealed class ConnectedR6SoakContractTests
{
private static readonly string[] ExpectedCheckpointNames =
[
"caul-baseline",
"sawato-baseline",
"rynthid",
"aerlinthe",
"sawato-return",
"holtburg",
"caul-return",
"sawato-plateau",
"caul-plateau",
];
[Fact]
public void RouteContainsExactlyNineOrderedCheckpointBarriers()
{
string[] checkpoints = File.ReadAllLines(Path.Combine(
FindRepoRoot(),
"tools",
"connected-r6-soak.route.txt"))
.Select(static line => line.Trim())
.Where(static line => line.StartsWith(
"checkpoint ",
StringComparison.Ordinal))
.Select(static line => line["checkpoint ".Length..])
.ToArray();
Assert.Equal(ExpectedCheckpointNames, checkpoints);
}
[Fact]
public void GateConsumesCanonicalTimelineWithoutWeakeningResidencyFormulas()
{
string source = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"tools",
"run-connected-r6-soak.ps1"));
AssertAppearsInOrder(
source,
"$expectedCheckpointNames = @(",
"'caul-baseline'",
"'sawato-baseline'",
"'rynthid'",
"'aerlinthe'",
"'sawato-return'",
"'holtburg'",
"'caul-return'",
"'sawato-plateau'",
"'caul-plateau'");
AssertAppearsInOrder(
source,
"$canonicalCheckpoints = @(Read-CanonicalCheckpoints)",
"Add-CanonicalCheckpointFailures $process",
"Add-RelativeGateFailures");
Assert.Contains("CanonicalCheckpoints = @($canonicalCheckpoints)", source);
Assert.Contains("CheckpointTimeline = $checkpointTimeline", source);
Assert.Contains(
"Join-Path $artifactDir \"checkpoint-$expectedName.json\"",
source,
StringComparison.Ordinal);
Assert.Contains(
"missing render-world synchronization fields",
source,
StringComparison.Ordinal);
string[] zeroFields =
[
"pendingLiveTeardowns",
"pendingLandblockRetirements",
"stagedMeshUploads",
"stagedMeshBytes",
"compositeWarmupPending",
];
foreach (string field in zeroFields)
Assert.Contains($"'{field}'", source, StringComparison.Ordinal);
Assert.Equal(1, CountOccurrences(
source,
"$privateLimit = [Math]::Max(192.0, $pair.First.PrivateMiB * 0.20)"));
Assert.Equal(1, CountOccurrences(
source,
"$workingLimit = [Math]::Max(192.0, $pair.First.WorkingSetMiB * 0.20)"));
Assert.Equal(1, CountOccurrences(
source,
"$updateLimit = $pair.First.UpdateP95Ms * 1.5 + 0.5"));
Assert.Equal(1, CountOccurrences(
source,
"$allocLimit = $pair.First.AllocP50Kb * 1.5 + 16.0"));
}
private static int CountOccurrences(string source, string value)
{
int count = 0;
int cursor = 0;
while ((cursor = source.IndexOf(value, cursor, StringComparison.Ordinal)) >= 0)
{
count++;
cursor += value.Length;
}
return count;
}
private static void AssertAppearsInOrder(string source, params string[] values)
{
int cursor = -1;
foreach (string value in values)
{
int next = source.IndexOf(value, cursor + 1, StringComparison.Ordinal);
Assert.True(next >= 0, $"Missing expected source fragment: {value}");
Assert.True(next > cursor, $"Out-of-order source fragment: {value}");
cursor = next;
}
}
private static string FindRepoRoot()
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
return directory.FullName;
directory = directory.Parent;
}
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
}
}