tests: one source-assertion helper, so the prose trap can't recur

The trap I hit twice today — a file-wide DoesNotContain matching the doc
comment that explains the ban — was possible because three tests each
hand-rolled their own File.ReadAllText + path-walker, two of them mine. Fixed
at the root rather than per-test: SourceAssert now owns path walking and
literal extraction, with Literal(memberName, params parts) and Scopes() that
assert on the parsed VALUE. Tests that genuinely assert structure (the #if
DEBUG arm in InstanceIsolationTests, the absence of a whole API in the
locator) still read the file themselves, because those claims cannot be
reduced to a value — the helper is for literal facts only.

Shipping the fix introduced two defects, both caught by the build: a method
named Path shadowed System.IO.Path and broke the error message that names the
missing file, and Literal(fileName, memberName) invited a call that silently
resolved to a nonexistent path. Argument order is now required-context-first
so a wrong path is visible at the call site.

Suite 380/380, 0 warnings. LayerReorderPersistenceTests.RealMouseDrag flaked
once mid-session with no ytLive instance running and passed in isolation and
on re-run — the environment flake already recorded in HANDOFF.md, not a
regression from this change.
This commit is contained in:
2026-09-28 11:53:52 -07:00
parent b3edc2e42e
commit 967df83925
5 changed files with 101 additions and 53 deletions
+3 -21
View File
@@ -32,24 +32,7 @@ public class FfmpegLocatorTests
return dir;
}
/// <summary>Repo root, found by walking up to a file only the repo has.</summary>
private static string RepoRoot()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir != null)
{
if (File.Exists(Path.Combine(dir.FullName, "ytLive.csproj"))) return dir.FullName;
dir = dir.Parent;
}
throw new FileNotFoundException($"could not locate ytLive.csproj above {AppContext.BaseDirectory}");
}
private static string RepoFile(params string[] parts)
{
var candidate = Path.Combine(new[] { RepoRoot() }.Concat(parts).ToArray());
if (File.Exists(candidate)) return candidate;
throw new FileNotFoundException($"could not locate {Path.Combine(parts)} under {RepoRoot()}");
}
/// <summary>
/// The Good Dog integration test for this unit: prove the whole chain end to end —
@@ -66,7 +49,7 @@ public class FfmpegLocatorTests
// repository folder name. The repo directory happens to also be called "ytLive",
// so naively appending "ytLive" would resolve to a path that only works on this
// machine's checkout.
var projectDir = Path.GetDirectoryName(RepoFile("ytLive.csproj"))!;
var projectDir = Path.GetDirectoryName(SourceAssert.RepoPath("ytLive.csproj"))!;
var binRoot = Path.Combine(projectDir, "bin");
Assert.True(Directory.Exists(binRoot),
$"no build output at {binRoot} — build ytLive.csproj before running this test");
@@ -224,8 +207,7 @@ public class FfmpegLocatorTests
[InlineData("ExtractBinaries(")]
public void TheLocatorCarriesNoNetworkCapability(string forbidden)
{
var source = File.ReadAllText(
RepoFile("Services", "Encoder", "FfmpegLocator.cs"));
var source = SourceAssert.Text("Services", "Encoder", "FfmpegLocator.cs");
Assert.DoesNotContain(forbidden, source, StringComparison.OrdinalIgnoreCase);
}
@@ -238,7 +220,7 @@ public class FfmpegLocatorTests
[Fact]
public void TheBuildRefusesToCompileWithoutTheBundle()
{
var csproj = File.ReadAllText(RepoFile("ytLive.csproj"));
var csproj = SourceAssert.Text("ytLive.csproj");
Assert.Contains("GuardBundledFfmpeg", csproj, StringComparison.Ordinal);
Assert.Contains("ffmpeg\\ffmpeg.exe", csproj, StringComparison.Ordinal);
Assert.Contains("CopyToPublishDirectory=\"Always\"", csproj, StringComparison.Ordinal);