From 82fcca0533d757309c0fd3897203df4b6c8a7629 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 14:24:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=AD=A5=E9=AA=A4=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=A3=80=E6=9F=A5=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E4=BB=85=E5=9C=A8=E6=A3=80=E6=9F=A5=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E5=90=8E=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VVMs/RecipeEditor/EditorNodes.cs | 9 ++--- .../VVMs/RecipeEditor/RecipeEditor.axaml | 4 -- .../RecipeEditor/SopVideoAgentViewModel.cs | 6 +-- .../Sop/SopEngine.ContinuousChecks.cs | 7 ++-- .../Sop/VisionDecision.cs | 3 +- .../SopAgent/SopStepDesignPrompt.cs | 2 +- .../SopAgent/SopVideoAgentClient.cs | 2 +- .../SopAgent/SopVideoDraftClient.cs | 8 ++-- .../InspectionPolicyChecks.cs | 9 +++-- .../ReferenceToolChecks.cs | 2 +- .../AgentDraftVerificationChecks.cs | 4 +- tests/VideoFlowTest.Smoke/Program.cs | 8 ++-- .../VideoFlowTest.Smoke/StepTransferChecks.cs | 2 +- .../ContinuousCheckTests.cs | 39 ++++++++++++++++--- 14 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index 12b8941..9e1b868 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -425,7 +425,7 @@ public class RecipeNode : EditorNode AiConfirmation = step.AiConfirmation is null ? null : new AiConfirmation { MinConfidence = step.AiConfirmation.MinConfidence, - CheckWindowMs = step.AiConfirmation.CheckWindowMs, MaxChecks = step.AiConfirmation.MaxChecks, CheckSettleMs = step.AiConfirmation.CheckSettleMs, + CheckWindowMs = step.AiConfirmation.CheckWindowMs, CheckSettleMs = step.AiConfirmation.CheckSettleMs, EvidenceMode = step.AiConfirmation.EvidenceMode, ObservationPreRollMs = step.AiConfirmation.ObservationPreRollMs, ObservationMinMs = step.AiConfirmation.ObservationMinMs, ObservationMaxMs = step.AiConfirmation.ObservationMaxMs, ObservationSampleMs = step.AiConfirmation.ObservationSampleMs, @@ -495,7 +495,7 @@ public class RecipeNode : EditorNode AiConfirmation = new AiConfirmation { MinConfidence = step.AiMinConfidence, - CheckWindowMs = step.AiCheckWindowMs, MaxChecks = step.AiMaxChecks, CheckSettleMs = step.AiCheckSettleMs, + CheckWindowMs = step.AiCheckWindowMs, CheckSettleMs = step.AiCheckSettleMs, EvidenceMode = step.AiEvidenceMode, ObservationPreRollMs = step.AiObservationPreRollMs, ObservationMinMs = step.AiObservationMinMs, ObservationMaxMs = step.AiObservationMaxMs, ObservationSampleMs = step.AiObservationSampleMs, ObservationMaxFrames = step.AiObservationMaxFrames, ObservationRequestMaxFrames = step.AiObservationRequestMaxFrames, @@ -825,10 +825,9 @@ public class StepNode : EditorNode public double? KeyFrameSeconds { get => _keyFrameSeconds; set { if (SetProperty(ref _keyFrameSeconds, value)) RaisePropertyChanged(nameof(KeyFrameLabel)); } } public string KeyFrameLabel => string.IsNullOrEmpty(KeyFrameBase64) ? "尚未保存关键帧" : $"已保存关键帧:{KeyFrameSeconds:0.###} 秒(保存配方后持久化)"; - private int _aiCheckWindowMs = 10000, _aiMaxChecks = 20, _aiCheckSettleMs = 100; + private int _aiCheckWindowMs = 10000, _aiCheckSettleMs = 100; public int AiCheckWindowMs { get => _aiCheckWindowMs; set { if (SetProperty(ref _aiCheckWindowMs, value)) RaisePropertyChanged(nameof(AiContinueAfterWindow)); } } public bool AiContinueAfterWindow { get => AiCheckWindowMs > 0; set { if (value != AiContinueAfterWindow) AiCheckWindowMs = value ? 10000 : 0; } } - public int AiMaxChecks { get => _aiMaxChecks; set => SetProperty(ref _aiMaxChecks, value); } public int AiCheckSettleMs { get => _aiCheckSettleMs; set => SetProperty(ref _aiCheckSettleMs, value); } private string _aiEvidenceMode = VisionEvidenceMode.SingleFrame; private int _aiObservationPreRollMs = 1000, _aiObservationMinMs = 2400, _aiObservationMaxMs = 10000, @@ -868,7 +867,7 @@ public class StepNode : EditorNode { if (value is null) return; AiMinConfidence = value.MinConfidence; - AiCheckWindowMs = value.CheckWindowMs; AiMaxChecks = value.MaxChecks; AiCheckSettleMs = value.CheckSettleMs; + AiCheckWindowMs = value.CheckWindowMs; AiCheckSettleMs = value.CheckSettleMs; AiEvidenceMode = value.EvidenceMode; AiObservationPreRollMs = value.ObservationPreRollMs; AiObservationMinMs = value.ObservationMinMs; AiObservationMaxMs = value.ObservationMaxMs; AiObservationSampleMs = value.ObservationSampleMs; AiObservationMaxFrames = value.ObservationMaxFrames; AiObservationRequestMaxFrames = value.ObservationRequestMaxFrames; diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 34a2808..e503e6f 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -173,10 +173,6 @@ - - - - diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs index fa92b77..ee49505 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs @@ -418,7 +418,7 @@ public partial class RecipeEditorViewModel step.StableFrames = node.Detection?.StableFrames; step.Tolerance = node.Detection?.Tolerance; step.ImageMode = node.AiImageMode; step.ImageRegion = node.AiImageRegion; step.Inspection = new() { EvidenceMode = node.AiEvidenceMode, CheckWindowMs = node.AiCheckWindowMs > 0 ? node.AiCheckWindowMs : null, - MaxChecks = node.AiMaxChecks, CheckSettleMs = node.AiCheckSettleMs, ObservationMinMs = node.AiObservationMinMs, + CheckSettleMs = node.AiCheckSettleMs, ObservationMinMs = node.AiObservationMinMs, ObservationMaxMs = node.AiObservationMaxMs, ObservationMaxFrames = node.AiObservationMaxFrames, ObservationRequestMaxFrames = node.AiObservationRequestMaxFrames }; } @@ -433,7 +433,7 @@ public partial class RecipeEditorViewModel { var ai = step.AiConfirmation!; return new SopAgentImageScope(index + 1, VisionImageMode.Resolve(ai), ai.ImageRegion, - ai.HandPadding, ai.HandMinSize, ai.HandMemoryMs, ai.EvidenceMode, ai.CheckWindowMs, ai.MaxChecks, ai.CheckSettleMs, + ai.HandPadding, ai.HandMinSize, ai.HandMemoryMs, ai.EvidenceMode, ai.CheckWindowMs, ai.CheckSettleMs, ai.ObservationMaxMs, ai.ObservationMaxFrames, ai.ObservationRequestMaxFrames, ai.TimeoutSeconds); }).ToArray(); } @@ -479,7 +479,7 @@ public sealed class AgentDraftRow : BindableBase, IDisposable public string Timeline => $"{TimeSpan.FromSeconds(Step.StartSeconds):mm\\:ss\\.f} – {TimeSpan.FromSeconds(Step.EndSeconds):mm\\:ss\\.f}"; public string EvidenceLabel { get; } public string Note => Step.Note + $" 触发:{Step.Method}/{Step.Hand};稳定 {Step.StableFrames?.ToString() ?? "沿用"} 帧;送检:{Step.ImageRegion ?? Region}" - + $";判定:{Step.Inspection?.EvidenceMode ?? "沿用/单帧"};检查窗口:{Step.Inspection?.CheckWindowMs?.ToString() ?? "默认"}ms;最多 {Step.Inspection?.MaxChecks?.ToString() ?? "3"} 次" + + $";判定:{Step.Inspection?.EvidenceMode ?? "沿用/单帧"};检查窗口:{Step.Inspection?.CheckWindowMs?.ToString() ?? "默认"}ms" + (string.IsNullOrWhiteSpace(Region) ? " 触发区域未设置。" : ""); public BitmapSource EvidenceImage { get; } public AgentDraftRow(SopDraftStep step, SopVideoFrame frame, SopDraftVerificationImage? actual = null) diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs index 3d5c5ee..8ea9c75 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs @@ -180,7 +180,6 @@ public partial class SopEngine if (client is null || options.EvidenceMode == VisionEvidenceMode.Sequence && !client.SupportsSequences) { state.Reason = "检查服务未配置或不支持所需证据"; return new() { Message = state.Reason + ";窗口到期后记录未通过并继续" }; } if (state.Window.Error is { } error) { state.Reason = error; return new() { Message = error }; } - if (state.Attempts >= options.MaxChecks) return new() { IsSkipped = true, Message = $"已检查 {state.Attempts} 次仍未通过,已跳过并继续后续步骤:{state.Reason}" }; var quiet = (state.LatestSeconds - state.LastMotionSeconds) * 1000 >= options.CheckSettleMs; // 按配置间隔检查当前新图,不能为历史补判扩大等待时间。 var interval = Math.Max(50, options.RetryDelayMs); @@ -192,7 +191,7 @@ public partial class SopEngine if (discrete && options.EvidenceMode == VisionEvidenceMode.SingleFrame) prior = Math.Max(prior, state.LatestTriggerSeconds); var frames = state.Window.Frames.Where(f => ObservationEvidenceWindow.Time(f) >= prior).ToArray(); - if (!timeToCheck) return new() { Message = $"等待下一次检查时机(已送检 {state.Attempts}/{options.MaxChecks} 次)" }; + if (!timeToCheck) return new() { Message = $"等待下一次检查时机(已送检 {state.Attempts} 次)" }; if (options.EvidenceMode == VisionEvidenceMode.SingleFrame) { var candidates = frames.Concat(state.Boundaries); @@ -213,7 +212,7 @@ public partial class SopEngine if (frames.Length == 0 || state.Inspected.ContainsKey(frames[^1].FrameId) || options.EvidenceMode == VisionEvidenceMode.Sequence && state.Window.Version <= state.SentVersion || options.EvidenceMode == VisionEvidenceMode.Sequence && !processReady) - return new() { Message = $"窗口内观察,优先在手部停稳或离开后检查(已送检 {state.Attempts}/{options.MaxChecks} 次)" }; + return new() { Message = $"窗口内观察,优先在手部停稳或离开后检查(已送检 {state.Attempts} 次)" }; if (options.EvidenceMode == VisionEvidenceMode.Sequence) frames = VisualEvidenceSampler.Select(frames, options.ObservationRequestMaxFrames); var last = frames[^1]; @@ -234,6 +233,6 @@ public partial class SopEngine } _pendingDecision = new(CheckAsync(), last.Jpeg, cancellation, request); DecisionCaptured?.Invoke(request); DecisionSubmitted?.Invoke(request); - return new() { Message = $"已发送第 {state.Attempts}/{options.MaxChecks} 次检查,后续动作持续采集" }; + return new() { Message = $"已发送第 {state.Attempts} 次检查,后续动作持续采集" }; } } diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs b/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs index f004cb7..064e783 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs @@ -8,7 +8,6 @@ public sealed class AiConfirmation { /// 0 保留原来的等待策略;正值为触发后的检查预算,到期未确认则跳过。 public int CheckWindowMs { get; set; } - public int MaxChecks { get; set; } = 20; public int CheckSettleMs { get; set; } = 100; public string EvidenceMode { get; set; } = VisionEvidenceMode.SingleFrame; public int ObservationPreRollMs { get; set; } = 1000; @@ -33,7 +32,7 @@ public static class VisionEvidenceMode { public const string SingleFrame = "single_frame", Sequence = "sequence"; public static bool IsCheckPolicyValid(AiConfirmation options) => options.CheckWindowMs == 0 - || options.CheckWindowMs is >= 500 and <= 60000 && options.MaxChecks is >= 1 and <= 20 + || options.CheckWindowMs is >= 500 and <= 60000 && options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs && IsObservationValid(options); public static bool IsValid(AiConfirmation options) => options.EvidenceMode == SingleFrame diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs index 6a36148..34e692e 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs @@ -18,7 +18,7 @@ public static class SopStepDesignPrompt - 触发区和送检区可以独立。image_mode=fixed_region/full_frame/hand,image_region须覆盖完整验收关系;局部细节优先清晰ROI,整体位置需要完整空间上下文。默认主区域,hand_move默认终点,禁止假设跟手范围必然覆盖主体。 - 已缓存的旧图不能排队补判为实时通过;运行仅检查新鲜单图,记录触发/取图/提交/返回时间、图片数量、耗时和超时。 - inspection:evidence_mode只能为single_frame;check_window_ms=500–60000为本步多次观察总窗口,不是单次模型耗时;max_checks=1–20;check_settle_ms=100–3000且小于总窗口。新步骤默认观察10秒、最多20次、停稳100ms;每次dlite最多500ms,超时不延长。人的动作连续,不能让人停下来等待;适时取新图复查,窗口结束或次数耗尽未通过则跳过,整轮不计合格。 + inspection:evidence_mode只能为single_frame;check_window_ms=500–60000为本步多次观察总窗口,不是单次模型耗时;check_settle_ms=100–3000且小于总窗口。新步骤默认观察10秒、停稳100ms;每次dlite最多500ms,超时不延长。人的动作连续,不能让人停下来等待;适时取新图复查,仅在窗口到期仍未通过时跳过,不限制检查次数,整轮不计合格。 提交前核对:全程操作完整、有据、有序不重叠、区域有效、单图可辨、触发对应本步、正反状态可区分。仅为具体缺口补看,不重复读清楚的图,不凭措辞修改反复调用工具。步骤生成和dlite回测是独立操作。 """; } diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs index f2d6805..20bb5b7 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoAgentClient.cs @@ -73,7 +73,7 @@ public sealed class SopVideoAgentClient(HttpClient http) : ISopVideoDraftClient 严格按用户消息的 mode 输出。工具调用结束后只返回完整 JSON,不输出 Markdown。 mode=generate 时直接返回根节点包含 steps 的完整草稿,不套 reply/draft 外层;确实阻塞时仅返回非空 blocked_reason。 mode=chat 时返回 {"reply":"给用户的自然中文答复","draft":完整草稿或null}。草稿格式如下: - {"summary":"流程简述","warnings":[],"steps":[{"name":"操作名称","description":"对应模式能验证的完成要求","start_seconds":0,"end_seconds":2,"method":"hand_leave_region","region":"<实际已标定区域键>","from_region":"","to_region":"","hand":"any","evidence_frame":0,"image_mode":"fixed_region","image_region":"<实际已标定送检区域键>","inspection":{"evidence_mode":"single_frame","check_window_ms":10000,"max_checks":3},"note":"选择触发及判定模式的依据"}]} + {"summary":"流程简述","warnings":[],"steps":[{"name":"操作名称","description":"对应模式能验证的完成要求","start_seconds":0,"end_seconds":2,"method":"hand_leave_region","region":"<实际已标定区域键>","from_region":"","to_region":"","hand":"any","evidence_frame":0,"image_mode":"fixed_region","image_region":"<实际已标定送检区域键>","inspection":{"evidence_mode":"single_frame","check_window_ms":10000},"note":"选择触发及判定模式的依据"}]} region 的示例占位符必须替换为实际区域键,不能照抄占位符或输出空区域草稿。 """ }, new { role = "user", content = SopAgentJson.Serialize(new { mode = chatting ? "chat" : "generate", video_path = request.Video.Path, recipe = request.Recipe, diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs index 44ccc43..ee7cbd5 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs @@ -21,7 +21,7 @@ public sealed record SopVideoAnalysisRequest(string Recipe, string Instructions, public sealed record SopAgentPrompt(int Round, long EstimatedTokens, int ContextLength, string Compression, string Text); public sealed record SopAgentTrace(string Kind, int Round, string Text, IReadOnlyList? Images = null); public sealed record SopAgentTraceImage(string Name, byte[] Jpeg); -public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int MaxChecks = 3, int CheckSettleMs = 350, int ObservationMaxMs = 10000, int ObservationMaxFrames = 24, int ObservationRequestMaxFrames = 12, int TimeoutSeconds = 30); +public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int CheckSettleMs = 350, int ObservationMaxMs = 10000, int ObservationMaxFrames = 24, int ObservationRequestMaxFrames = 12, int TimeoutSeconds = 30); public sealed record SopAgentChatTurn(string Role, string Text); public sealed record SopAgentChatResult(string Reply, SopVideoDraft? Draft, IReadOnlyList ObservedFrames); public sealed class SopVideoDraft @@ -59,7 +59,6 @@ public sealed class SopDraftInspectionPolicy { [JsonPropertyName("evidence_mode")] public string? EvidenceMode { get; set; } [JsonPropertyName("check_window_ms")] public int? CheckWindowMs { get; set; } - [JsonPropertyName("max_checks")] public int? MaxChecks { get; set; } [JsonPropertyName("check_settle_ms")] public int? CheckSettleMs { get; set; } [JsonPropertyName("observation_min_ms")] public int? ObservationMinMs { get; set; } [JsonPropertyName("observation_max_ms")] public int? ObservationMaxMs { get; set; } @@ -70,7 +69,6 @@ public sealed class SopDraftInspectionPolicy { target.EvidenceMode = EvidenceMode ?? target.EvidenceMode; target.CheckWindowMs = CheckWindowMs ?? target.CheckWindowMs; - target.MaxChecks = MaxChecks ?? target.MaxChecks; target.CheckSettleMs = CheckSettleMs ?? target.CheckSettleMs; target.ObservationMinMs = ObservationMinMs ?? target.ObservationMinMs; target.ObservationMaxMs = ObservationMaxMs ?? target.ObservationMaxMs; @@ -80,7 +78,7 @@ public sealed class SopDraftInspectionPolicy public static SopDraftInspectionPolicy From(AiConfirmation options) => new() { - EvidenceMode = options.EvidenceMode, CheckWindowMs = options.CheckWindowMs > 0 ? options.CheckWindowMs : null, MaxChecks = options.MaxChecks, + EvidenceMode = options.EvidenceMode, CheckWindowMs = options.CheckWindowMs > 0 ? options.CheckWindowMs : null, CheckSettleMs = options.CheckSettleMs, ObservationMinMs = options.ObservationMinMs, ObservationMaxMs = options.ObservationMaxMs, ObservationMaxFrames = options.ObservationMaxFrames, ObservationRequestMaxFrames = options.ObservationRequestMaxFrames @@ -167,7 +165,7 @@ public sealed class SopVideoDraftClient(HttpClient http) : ISopVideoDraftClient 各步时间段按发生顺序且不重叠,必须处于视频时长内;evidence_frame 是对应结果画面的 frame_index。 不因抽样图里没有看到某物就断言不存在。看不清时写入 warnings/note,不能自信猜测。 只输出 JSON,不输出 Markdown: - {"summary":"流程简述","warnings":[],"steps":[{"name":"操作名称","description":"对应模式能验证的完成要求","start_seconds":0,"end_seconds":2,"method":"hand_leave_region","region":"<实际已标定区域键>","from_region":"","to_region":"","hand":"any","evidence_frame":1,"image_mode":"fixed_region","image_region":"<实际已标定送检区域键>","inspection":{"evidence_mode":"single_frame","check_window_ms":10000,"max_checks":3},"note":"模式及触发的依据"}]} + {"summary":"流程简述","warnings":[],"steps":[{"name":"操作名称","description":"对应模式能验证的完成要求","start_seconds":0,"end_seconds":2,"method":"hand_leave_region","region":"<实际已标定区域键>","from_region":"","to_region":"","hand":"any","evidence_frame":1,"image_mode":"fixed_region","image_region":"<实际已标定送检区域键>","inspection":{"evidence_mode":"single_frame","check_window_ms":10000},"note":"模式及触发的依据"}]} region 的示例占位符必须替换为实际区域键;无法确定时不输出空区域草稿。 """ }, new { role = "user", content } diff --git a/tests/SopVideoAgent.Smoke/InspectionPolicyChecks.cs b/tests/SopVideoAgent.Smoke/InspectionPolicyChecks.cs index 192cb7a..479af89 100644 --- a/tests/SopVideoAgent.Smoke/InspectionPolicyChecks.cs +++ b/tests/SopVideoAgent.Smoke/InspectionPolicyChecks.cs @@ -9,11 +9,14 @@ internal static class InspectionPolicyChecks var template = new SopConfig(); template.Sop.Steps = [new() { AiConfirmation = new() { MinConfidence = .94, RetryDelayMs = 4100 } }]; var draft = new SopVideoDraft { Steps = [new() { Inspection = new() { EvidenceMode = "sequence", - CheckWindowMs = 22000, MaxChecks = 4, ObservationMaxFrames = 24, ObservationRequestMaxFrames = 9 } }] }; + CheckWindowMs = 22000, ObservationMaxFrames = 24, ObservationRequestMaxFrames = 9 } }] }; + var legacy = JsonSerializer.Deserialize("""{"check_window_ms":10000,"max_checks":1}""")!; + SopVideoDraftClient.ValidateInspection(legacy); + Check(!JsonSerializer.Serialize(legacy).Contains("max_checks"), "旧草稿次数参数应被忽略且不再输出"); var before = SopConfigLoader.ToYaml(template); var roundTrip = JsonSerializer.Deserialize(JsonSerializer.Serialize(draft))!; var config = SopDraftConfigBuilder.Build(template, roundTrip); - Check(config.Sop.Steps[0].AiConfirmation is { EvidenceMode: "sequence", CheckWindowMs: 22000, MaxChecks: 4, + Check(config.Sop.Steps[0].AiConfirmation is { EvidenceMode: "sequence", CheckWindowMs: 22000, ObservationRequestMaxFrames: 9, ObservationMaxFrames: 24, MinConfidence: .94, RetryDelayMs: 4100 }, "生成及修订的策略须序列化并真正应用,同时保护原阈值和重试间隔"); Check(SopConfigLoader.ToYaml(template) == before, "策略映射不能改动原配方"); @@ -22,7 +25,7 @@ internal static class InspectionPolicyChecks Reject(() => SopVideoDraftClient.ValidateCapabilities(draft, request with { SequenceAvailable = true }), "旧能力开关也不能启用多图"); Reject(() => SopVideoDraftClient.ValidateCapabilities(draft, request with { CurrentDraft = draft }), "旧草稿不能豁免单图要求"); foreach (var invalid in new SopDraftInspectionPolicy[] { - new() { EvidenceMode = "unknown" }, new() { CheckWindowMs = 0 }, new() { MaxChecks = 21 }, + new() { EvidenceMode = "unknown" }, new() { CheckWindowMs = 0 }, new() { CheckWindowMs = 500, CheckSettleMs = 600 }, new() { ObservationMinMs = 11000 }, new() { ObservationRequestMaxFrames = 33 }, new() { ObservationMaxFrames = 2 } }) Reject(() => SopVideoDraftClient.ValidateInspection(invalid), "非法策略不能进入回测或配方"); diff --git a/tests/SopVideoAgent.Smoke/ReferenceToolChecks.cs b/tests/SopVideoAgent.Smoke/ReferenceToolChecks.cs index b0f5d19..b45051c 100644 --- a/tests/SopVideoAgent.Smoke/ReferenceToolChecks.cs +++ b/tests/SopVideoAgent.Smoke/ReferenceToolChecks.cs @@ -59,7 +59,7 @@ internal static class ReferenceToolChecks Bodies.Add(await request.Content!.ReadAsStringAsync(token)); if (mode == "advance_changed" && Bodies.Count == 2) candidate.Steps[0].Description = "已改变的要求"; if (mode == "equivalent_defaults" && Bodies.Count == 2) - foreach (var step in candidate.Steps.Take(2)) step.Inspection = new() { EvidenceMode = "single_frame", CheckWindowMs = 14000, MaxChecks = 4, ObservationMaxFrames = 24, ObservationMaxMs = 10000, ObservationRequestMaxFrames = 12 }; + foreach (var step in candidate.Steps.Take(2)) step.Inspection = new() { EvidenceMode = "single_frame", CheckWindowMs = 14000, ObservationMaxFrames = 24, ObservationMaxMs = 10000, ObservationRequestMaxFrames = 12 }; var arguments = JsonSerializer.Serialize(new { step_id = mode == "out_of_focus" ? 4 : mode is "advance" or "advance_changed" or "follow_failure" or "equivalent_defaults" && Bodies.Count == 2 ? 3 : mode == "follow_failure" ? 2 : 1, draft = candidate }); if (mode == "extra_argument") arguments = arguments[..^1] + ",\"path\":\"other.avi\"}"; diff --git a/tests/VideoFlowTest.Smoke/AgentDraftVerificationChecks.cs b/tests/VideoFlowTest.Smoke/AgentDraftVerificationChecks.cs index febdf5e..915ce0f 100644 --- a/tests/VideoFlowTest.Smoke/AgentDraftVerificationChecks.cs +++ b/tests/VideoFlowTest.Smoke/AgentDraftVerificationChecks.cs @@ -99,7 +99,7 @@ internal static class AgentDraftVerificationChecks && model.Recipe.Regions.Any(r => r.Key == "trigger" && r.X1 == 8 && r.X2 == 28) && model.Recipe.Steps[1].Detection is { StableFrames: 8, Region: "trigger" } && model.Recipe.Steps[1].AiImageRegion == "work" && model.Recipe.Steps[1].AiMinConfidence == .85 - && model.Recipe.Steps[1].AiCheckWindowMs == 14000 && model.Recipe.Steps[1].AiMaxChecks == 4 + && model.Recipe.Steps[1].AiCheckWindowMs == 14000 && model.Recipe.Steps[1].AiObservationRequestMaxFrames == 6, "Explicit application uses the exact tested trigger, crop and debounce while preserving existing steps and AI threshold"); Check(File.ReadAllBytes(path).SequenceEqual(before), "Applying verified draft still requires explicit recipe save"); @@ -155,7 +155,7 @@ internal static class AgentDraftVerificationChecks { Summary = "生成草稿", RegionAdjustments = [new() { Key = "trigger", X1 = 8, Y1 = 8, X2 = 28, Y2 = 28, EvidenceFrame = 0, Note = "标准画面可见" }], Steps = [new() { Name = "放入", Description = "盒内可见零件", Region = "trigger", ImageRegion = "work", StableFrames = 8, EndSeconds = 2, EvidenceFrame = 0, - Inspection = new() { EvidenceMode = "single_frame", CheckWindowMs = 14000, MaxChecks = 4, ObservationRequestMaxFrames = 6 } }] + Inspection = new() { EvidenceMode = "single_frame", CheckWindowMs = 14000, ObservationRequestMaxFrames = 6 } }] }; draft.ObservedFrames = frames; if (request.VerifyDraft is { } verify) draft.Verification = await verify(draft, request.Video with { Frames = frames }, token); diff --git a/tests/VideoFlowTest.Smoke/Program.cs b/tests/VideoFlowTest.Smoke/Program.cs index 03a7fb4..250441f 100644 --- a/tests/VideoFlowTest.Smoke/Program.cs +++ b/tests/VideoFlowTest.Smoke/Program.cs @@ -48,19 +48,19 @@ internal static class Program private static void CheckSequenceEditor() { - Check(new StepNode().AiCheckWindowMs == 10000 && new StepNode().AiMaxChecks == 20, - "新建步骤默认使用10秒限时复检,最多20次"); + Check(new StepNode().AiCheckWindowMs == 10000, + "新建步骤默认使用10秒限时复检"); var config = new SopConfig(); config.Sop.Steps.Add(new() { Id = 1, Description = "状态变化", AiConfirmation = new() { EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationRequestMaxFrames = 7, ObservationSampleMs = 300, - CheckWindowMs = 7000, MaxChecks = 4, CheckSettleMs = 450 } }); + CheckWindowMs = 7000, CheckSettleMs = 450 } }); var editor = RecipeNode.From(config, "试验.yaml", false); Check(editor.Steps[0].UsesSequenceEvidence, "编辑器须识别过程时序模式"); var restored = SopConfigLoader.Parse(SopConfigLoader.ToYaml(editor.ToConfig())).Sop.Steps[0].AiConfirmation!; Check(restored.EvidenceMode == VisionEvidenceMode.Sequence && restored.ObservationMinMs == 1800 && restored.ObservationMaxFrames == 13 && restored.ObservationRequestMaxFrames == 7 && restored.ObservationSampleMs == 300, "编辑保存不得丢失时序模式、缓存容量与单次请求预算"); - Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000 && restored.MaxChecks == 4 + Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000 && restored.CheckSettleMs == 450, "编辑保存须保留连续操作限时复检参数"); editor.Steps[0].AiContinueAfterWindow = false; Check(editor.ToConfig().Sop.Steps[0].AiConfirmation!.CheckWindowMs == 0, "关闭限时复检须恢复原等待策略"); diff --git a/tests/VideoFlowTest.Smoke/StepTransferChecks.cs b/tests/VideoFlowTest.Smoke/StepTransferChecks.cs index 02dd7e0..a5ce51a 100644 --- a/tests/VideoFlowTest.Smoke/StepTransferChecks.cs +++ b/tests/VideoFlowTest.Smoke/StepTransferChecks.cs @@ -17,7 +17,7 @@ internal static class StepTransferChecks ViolationRules = [new() { Type = "object_removed", Description = "工具移除", Severity = 3 }], Detection = new() { Method = "hand_move", FromRegion = "start", ToRegion = "finish", Hand = "left", StableFrames = 7, Tolerance = 9, MinConfidence = .81f }, AiConfirmation = new() { EvidenceMode = "sequence", ImageMode = "fixed_region", ImageRegion = "inspect_area", CheckWindowMs = 32900, - MaxChecks = 4, CheckSettleMs = 550, ObservationMaxFrames = 26, ObservationRequestMaxFrames = 9, MinConfidence = .94, + CheckSettleMs = 550, ObservationMaxFrames = 26, ObservationRequestMaxFrames = 9, MinConfidence = .94, TimeoutSeconds = 25, RetryDelayMs = 1700, HandPadding = 180, HandMemoryMs = 2400 } }]; var original = JsonSerializer.Serialize(source); var text = SopStepTransfer.Export(source); diff --git a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs index 7d0fc8b..e64ab3f 100644 --- a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs +++ b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs @@ -28,7 +28,7 @@ internal static class ContinuousCheckTests config.Sop.Regions["r" + i] = new() { X1 = i * 100, Y1 = 0, X2 = i * 100 + 90, Y2 = 100 }; config.Sop.Steps.Add(new() { Id = i + 1, Name = "工序" + i, Description = "结果到位", Detection = new() { Method = ConditionMethod.HandInRegion, Region = "r" + i, Hand = "right", StableFrames = 1 }, - AiConfirmation = new() { CheckWindowMs = 2000, MaxChecks = 2, CheckSettleMs = 150, + AiConfirmation = new() { CheckWindowMs = 2000, CheckSettleMs = 150, RetryDelayMs = 500, ObservationSampleMs = 100 } }); } return config; @@ -38,6 +38,30 @@ internal static class ContinuousCheckTests Hands = [new() { HandType = HandType.Right, Rect = new(x, 20, 10, 10) }] }; public static async Task RunAsync() { + // 旧配方中的次数上限不再生效,超过原上限20次仍可在窗口内通过。 + var unlimitedConfig = Config(1); + unlimitedConfig.Sop.Steps[0].AiConfirmation!.CheckWindowMs = 10000; + unlimitedConfig.Sop.Steps[0].AiConfirmation!.RetryDelayMs = 50; + var legacyYaml = SopConfigLoader.ToYaml(unlimitedConfig).Replace("check_window_ms: 10000", "check_window_ms: 10000\n max_checks: 1"); + var legacyConfig = SopConfigLoader.Parse(legacyYaml); + Check(!SopConfigLoader.ToYaml(legacyConfig).Contains("max_checks"), "旧次数参数须忽略且不再保存"); + var unlimitedClient = new Client(); + var unlimited = new SopEngine { VisionDecisionClient = unlimitedClient }; + unlimited.Load(legacyConfig); unlimited.Start(); + var unlimitedResults = 0; + unlimited.DecisionEvaluated += (_, _, _) => unlimitedResults++; + void UnlimitedFeed(int id) => unlimited.ProcessFrame(Frame(id, id * .01, 10), () => [(byte)id]); + UnlimitedFeed(0); + for (var attempt = 1; attempt <= 21; attempt++) + { + await Until(() => { UnlimitedFeed(attempt); return unlimitedClient.Calls.Count == attempt; }); + unlimitedClient.Calls.ElementAt(attempt - 1).Result.SetResult(new(attempt == 21, .99, "检查结果")); + await Until(() => { unlimited.ProcessFrame(Frame(attempt, attempt * .01, 10)); return unlimitedResults == attempt; }); + if (attempt < 21) Check(unlimited.CurrentStep?.Id == 1 && unlimited.SkippedSteps.Count == 0, + "窗口内不能因为检查次数提前跳过"); + } + Check(unlimited.State == EngineState.Completed && unlimited.RoundPassed, "第21次检查通过应正常完成"); + unlimited.Stop(); var source = Enumerable.Range(0, 7).Select(i => new VisionEvidenceFrame(i, DateTime.UnixEpoch.AddSeconds(i), [(byte)i], i)).ToArray(); Check(InspectionFrameSelector.Select(source, new Dictionary(), [source[^1]], 2.4)?.FrameId == 3, "已缓存较长操作片段的首次检查应覆盖中段,避免只检查动作结束后的尾图"); @@ -68,14 +92,17 @@ internal static class ContinuousCheckTests Check(retry.Request.StepId == 1 && retry.Request.FrameId > first.Request.FrameId, "窗口内重试应使用新证据"); retry.Result.SetResult(new(false, .9, "仍未完成")); await Until(() => { engine.ProcessFrame(Frame(5, .6, 120)); return evaluated == 2; }); + Check(engine.CurrentStep?.Id == 1 && !snapshots.Any(s => s.IsSkipped) && alarms == 0, + "多次未通过但窗口未到期时必须继续等待,不能提前跳过"); + Feed(6, 2.1, 120); Check(engine.CurrentStep?.Id == 2 && snapshots.Any(s => s.StepId == 1 && s.IsSkipped && !s.IsMet) - && alarms == 1, "限时多次未通过必须标记跳过、告警并继续下一步"); - Feed(7, .9, 120); await Until(() => { Feed(7, .9, 120); return client.Calls.Count == 3; }); + && alarms == 1, "检查窗口到期未通过必须标记跳过、告警并继续下一步"); + Feed(7, 2.3, 120); await Until(() => { Feed(7, 2.3, 120); return client.Calls.Count == 3; }); var next = client.Calls.ElementAt(2); - Check(next.Request.StepId == 2 && next.Request.FrameId == 7 && next.Request.SourceSeconds == .9, + Check(next.Request.StepId == 2 && next.Request.FrameId == 7 && next.Request.SourceSeconds == 2.3, "下一步须使用当前新图,不能回填已经过期的等待期间旧图"); next.Result.SetResult(new(true, .99, "第二步结果可见")); - await Until(() => { engine.ProcessFrame(Frame(7, .9, 120)); return engine.State == EngineState.Completed; }); + await Until(() => { engine.ProcessFrame(Frame(7, 2.3, 120)); return engine.State == EngineState.Completed; }); Check(passed == false && !engine.RoundPassed && engine.Statistics.CompletedCount == 0 && engine.SkippedSteps.Contains(1), "跳过不能算合格完成或增加合格产量"); engine.Reset(); Check(engine.SkippedSteps.Count == 0 && !engine.HasPendingDecision, "复位必须清空跳过状态和所有窗口"); @@ -104,7 +131,7 @@ internal static class ContinuousCheckTests SameFeed(4, .5, 35); Check(secondTriggered, "同区域停稳后开始新运动,应能触发下一步,不能强求手离开操作区"); same.Stop(); - var hintConfig = Config(1); hintConfig.Sop.Steps[0].AiConfirmation!.MaxChecks = 3; + var hintConfig = Config(1); var hinted = new Client(); var following = new SopEngine { VisionDecisionClient = hinted }; following.Load(hintConfig); following.Start(); var hintResults = 0; following.DecisionEvaluated += (_, _, _) => hintResults++;