Ver Fonte

feat(d2-02): DebugSession.StreamBroken 字段 + DebugSessionManager.TryGet 只读方法(推流端点用,不动既有方法)

huangjie há 1 dia atrás
pai
commit
6855c318ef

+ 36 - 0
ivf_tl_operate_2.0/control/IvfTl.ControlHost.Tests/DebugStreamSessionTests.cs

@@ -0,0 +1,36 @@
+using System;
+using IvfTl.ControlHost.Debug;
+using IvfTl.ControlHost.Tests.Fakes;
+using IvfTl.Hardware;
+using Xunit;
+
+namespace IvfTl.ControlHost.Tests
+{
+    public class DebugStreamSessionTests
+    {
+        private DebugSessionManager NewMgr(FakeGate gate, DateTime now)
+            => new DebugSessionManager(_ => gate, () => now, ttlMs: 10000, log: null);
+
+        [Fact]
+        public void StreamBroken_DefaultsFalse()
+        {
+            var s = new DebugSession("sid1", 2, new FakeLease(new FakeGate(2, new FakeSerial()), new FakeSerial(), HardwareUser.OperateDebug), DateTime.UtcNow);
+            Assert.False(s.StreamBroken);
+            s.StreamBroken = true;
+            Assert.True(s.StreamBroken);
+        }
+
+        [Fact]
+        public void TryGet_ReturnsSession_ForValidSid()
+        {
+            var now = new DateTime(2026, 6, 24, 0, 0, 0, DateTimeKind.Utc);
+            var gate = new FakeGate(2, new FakeSerial());
+            var mgr = NewMgr(gate, now);
+            string sid = (string)mgr.Acquire(2).Result;
+
+            Assert.True(mgr.TryGet(sid, out var s));
+            Assert.Equal(2, s.HouseSn);
+            Assert.False(mgr.TryGet("nope", out _));
+        }
+    }
+}

+ 2 - 0
ivf_tl_operate_2.0/control/ivf_tl_ControlHost/Debug/DebugSession.cs

@@ -11,6 +11,8 @@ namespace IvfTl.ControlHost.Debug
         public DateTime LastSeen { get; set; }
         public int CurrentHor { get; set; } = -1;
         public int CurrentVer { get; set; } = -1;
+        /// <summary>推流线程因任何原因退出时置 true(spec §4.4)。可回收快信号,不替代心跳 TTL。</summary>
+        public bool StreamBroken { get; set; }
         public DebugSession(string sessionId, int houseSn, IHardwareLease lease, DateTime now)
         {
             SessionId = sessionId; HouseSn = houseSn; Lease = lease; LastSeen = now;

+ 6 - 0
ivf_tl_operate_2.0/control/ivf_tl_ControlHost/Debug/DebugSessionManager.cs

@@ -35,6 +35,12 @@ namespace IvfTl.ControlHost.Debug
             if (sid != null && _sessions.TryGetValue(sid, out var s)) { s.LastSeen = _clock(); return DebugCommandResult.Okay(); }
             return DebugCommandResult.Fail("SESSION_EXPIRED", "会话不存在或已过期");
         }
+        /// <summary>只读取会话(供推流端点校验 sid)。不刷新 LastSeen、不改状态。</summary>
+        public bool TryGet(string sid, out DebugSession session)
+        {
+            if (sid != null) return _sessions.TryGetValue(sid, out session);
+            session = null; return false;
+        }
         public DebugCommandResult Release(string sid)
         {
             if (sid != null && _sessions.TryRemove(sid, out var s))