From 1edcd1ce06e9015f1bf4ef98393ce135b80c931c Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 02:14:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=89=8D=E5=BA=8F=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E6=9C=89=E6=95=88=E7=89=87=E6=AE=B5=E6=97=B6?= =?UTF-8?q?=E9=95=BF=E8=A7=A6=E5=8F=91=E9=A6=96=E6=AC=A1=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sop/SopEngine.ContinuousChecks.cs | 5 ++++- .../ContinuousCheckTests.cs | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs index 62aea5f..9e3c5c2 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs @@ -190,9 +190,12 @@ public partial class SopEngine var selected = InspectionFrameSelector.Select(valid, state.Inspected, state.Boundaries, options.ObservationMinMs / 1000d, finalChance || followNewResult); frames = selected is null ? [] : [selected]; } + var eof = capture is null && crop is null; + var processReady = frames.Length >= 3 && (eof || state.Window.Ready + && ObservationEvidenceWindow.Time(frames[^1]) - ObservationEvidenceWindow.Time(frames[0]) >= options.ObservationMinMs / 1000d); if (frames.Length == 0 || state.Inspected.ContainsKey(frames[^1].FrameId) || options.EvidenceMode == VisionEvidenceMode.Sequence && state.Window.Version <= state.SentVersion - || options.EvidenceMode == VisionEvidenceMode.Sequence && (frames.Length < 3 || !state.Window.Ready)) + || options.EvidenceMode == VisionEvidenceMode.Sequence && !processReady) return new() { Message = $"窗口内观察,优先在手部停稳或离开后检查(已送检 {state.Attempts}/{options.MaxChecks} 次)" }; var last = frames[^1]; var request = new VisionDecisionRequest(_config.Sop.Name, step.Id, step.Name, step.Description, step.Description, diff --git a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs index 4db108d..649484b 100644 --- a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs +++ b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs @@ -13,6 +13,7 @@ internal static class ContinuousCheckTests } private sealed class Client : IVisionDecisionClient { + public bool SupportsSequences => true; public ConcurrentQueue<(VisionDecisionRequest Request, TaskCompletionSource Result)> Calls = new(); public Task DecideAsync(VisionDecisionRequest request, CancellationToken token) { @@ -115,6 +116,25 @@ internal static class ContinuousCheckTests Check(following.State == EngineState.Running && hinted.Calls.ElementAt(2).Request.FrameId == 4, "低于阈值的正向线索不能放行,但下一次检查应跟进新结果,不能回退到较早历史帧"); following.Stop(); + var temporalConfig = Config(); + temporalConfig.Sop.Steps[0].AiConfirmation = new() { CheckWindowMs = 10000, CheckSettleMs = 2500, ObservationMinMs = 5000 }; + temporalConfig.Sop.Steps[1].AiConfirmation = new() { CheckWindowMs = 10000, EvidenceMode = VisionEvidenceMode.Sequence }; + var temporalClient = new Client(); var temporal = new SopEngine { VisionDecisionClient = temporalClient }; + temporal.Load(temporalConfig); temporal.Start(); var frameIndex = 0; + void TemporalFeed(double seconds, int x = 120) => temporal.ProcessFrame(Frame(frameIndex++, seconds, x), () => [(byte)frameIndex]); + TemporalFeed(0, 10); + foreach (var seconds in new[] { .4, .8, 1.2, 1.6, 2.0, 2.4, 2.8 }) TemporalFeed(seconds); + await Until(() => temporalClient.Calls.Count == 1); + Check(temporalClient.Calls.ElementAt(0).Request.SourceSeconds == 2.8, "测试前序结果必须来自实际较晚帧"); + temporalClient.Calls.ElementAt(0).Result.SetResult(new(true, .99, "前序完成")); + await Until(() => { temporal.ProcessFrame(Frame(frameIndex, 2.8, 120)); return temporal.CurrentStep?.Id == 2; }); + foreach (var seconds in new[] { 3.2, 3.6, 4.0 }) TemporalFeed(seconds); + Check(temporalClient.Calls.Count == 1, "预热窗口就绪不代表前序完成后的有效过程片段已经足够,不能只看三张图就送检"); + foreach (var seconds in new[] { 4.4, 4.8, 5.3, 5.8 }) TemporalFeed(seconds); + await Until(() => temporalClient.Calls.Count == 2); + var effective = temporalClient.Calls.ElementAt(1).Request.Frames!; + Check(effective[^1].SourceSeconds - effective[0].SourceSeconds >= 2.4, "首次过程检查必须覆盖配置要求的实际有效片段时长"); + temporal.Stop(); Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计"); } }