fix(template-engine): verdict-cache key gains the globals-surface discriminator — cross-surface verdict reuse structurally impossible (plan R2-05 T2)

This commit is contained in:
Joseph Doherty
2026-07-13 09:45:54 -04:00
parent 5573a9eeb9
commit 06d79f6516
3 changed files with 41 additions and 11 deletions
@@ -182,6 +182,20 @@ public class ScriptCompilerTests
Assert.Equal(hitsBefore + 1, ScriptCompileVerdictCache.Hits);
}
[Fact]
public void GetOrAdd_SameCodeDifferentSurface_ComputesSeparateVerdicts()
{
ScriptCompileVerdictCache.Clear();
var a = ScriptCompileVerdictCache.GetOrAdd("SurfaceA", "return 1;", () => (true, null));
var hitsAfterA = ScriptCompileVerdictCache.Hits;
var b = ScriptCompileVerdictCache.GetOrAdd("SurfaceB", "return 1;", () => (false, "err"));
Assert.True(a.Ok);
Assert.False(b.Ok); // code-only key would return SurfaceA's verdict
Assert.Equal(hitsAfterA, ScriptCompileVerdictCache.Hits); // no false cross-surface hit
Assert.Equal(2, ScriptCompileVerdictCache.Count);
}
[Fact]
public void TryCompile_CachedFailure_FormatsNameForEachCaller()
{