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:
@@ -202,7 +202,7 @@ public sealed class InstanceIsolationTests
|
||||
// DataRoot / WebViewDataFolder are present in both configurations. Note a
|
||||
// const like YTLIVE_INSTANCE is INLINED at compile time and therefore never
|
||||
// appears in either binary — grepping for the variable name proves nothing.
|
||||
var source = File.ReadAllText(RepoFile("Helpers", "InstanceProfile.cs"));
|
||||
var source = SourceAssert.Text("Helpers", "InstanceProfile.cs");
|
||||
|
||||
// The whole promise is that a Release build compiles to the #else arm, so assert
|
||||
// that arm IS production: the one real user profile, no alternate folder, and no
|
||||
@@ -225,16 +225,4 @@ public sealed class InstanceIsolationTests
|
||||
Assert.Contains("instances", debugArm);
|
||||
}
|
||||
|
||||
private static string RepoFile(params string[] parts)
|
||||
{
|
||||
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (dir != null)
|
||||
{
|
||||
var candidate = Path.Combine(new[] { dir.FullName }.Concat(parts).ToArray());
|
||||
if (File.Exists(candidate)) return candidate;
|
||||
dir = dir.Parent;
|
||||
}
|
||||
throw new FileNotFoundException(
|
||||
$"could not locate {Path.Combine(parts)} above {AppContext.BaseDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user