| 1 | using CascadeIDE.Cockpit.DataBus; |
| 2 | using CascadeIDE.Features.Agent.Environment; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class AgentVerifyEpochTrackerTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void NotifyWriteDuringActiveRun_SetsFlagAndStaleEvent() |
| 11 | { |
| 12 | var bus = new InMemoryDataBus(); |
| 13 | var stale = new List<AgentVerifyEpochStale>(); |
| 14 | bus.Subscribe<AgentVerifyEpochStale>(e => stale.Add(e)); |
| 15 | |
| 16 | var t = new AgentVerifyEpochTracker(bus); |
| 17 | var sln = Path.Combine(Path.GetTempPath(), "cide-verify-epoch-test.sln"); |
| 18 | File.WriteAllText(sln, "# stub"); |
| 19 | |
| 20 | t.Begin("run1", "snap1", sln); |
| 21 | Assert.False(t.WritesInvalidatedVerifyEpoch); |
| 22 | |
| 23 | t.NotifyWrite(Path.Combine(Path.GetTempPath(), "SomeFile.cs")); |
| 24 | Assert.True(t.WritesInvalidatedVerifyEpoch); |
| 25 | Assert.Single(stale); |
| 26 | Assert.Equal("write_in_epoch", stale[0].Reason); |
| 27 | |
| 28 | t.End(); |
| 29 | Assert.False(t.WritesInvalidatedVerifyEpoch); |
| 30 | |
| 31 | try { File.Delete(sln); } |
| 32 | catch { /* best-effort */ } |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public void ForBundle_HasExpectedKeys() |
| 37 | { |
| 38 | var root = Path.Combine(Path.GetTempPath(), "substrate-bundle-" + Guid.NewGuid().ToString("N")); |
| 39 | try |
| 40 | { |
| 41 | var bundle = AgentSandboxSubstrate.Allocate(root); |
| 42 | var env = AgentSandboxProcessEnvironmentKeys.ForBundle(bundle); |
| 43 | Assert.Equal(bundle.DatabasePath, env[AgentSandboxProcessEnvironmentKeys.WitDbPath]); |
| 44 | Assert.Equal(bundle.DevPort.ToString(), env[AgentSandboxProcessEnvironmentKeys.DevPort]); |
| 45 | } |
| 46 | finally |
| 47 | { |
| 48 | try { Directory.Delete(root, recursive: true); } |
| 49 | catch { /* best-effort */ } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |