diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs index 91c3d92..665cb50 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs @@ -386,6 +386,10 @@ public partial class RecipeEditorViewModel node.StandardDurationMs = Math.Max(1, (int)Math.Round((step.EndSeconds - step.StartSeconds) * 1000)); node.Detection = ConditionNode.From(resolved.Sop.Steps[i].Detection!); node.AiConfirmation = resolved.Sop.Steps[i].AiConfirmation; + // 直接复用草稿参考画面的整图 JPEG 和视频时间,供步骤按送检规则裁剪。 + var frame = _agentSample.Frames[step.EvidenceFrame]; + node.KeyFrameBase64 = Convert.ToBase64String(frame.Jpeg); + node.KeyFrameSeconds = frame.Seconds; } if (choice == AgentRecipeApplyChoice.Overwrite) { diff --git a/tests/VideoFlowTest.Smoke/AgentDraftGenerationChecks.cs b/tests/VideoFlowTest.Smoke/AgentDraftGenerationChecks.cs index 3a6958d..9fcf3bf 100644 --- a/tests/VideoFlowTest.Smoke/AgentDraftGenerationChecks.cs +++ b/tests/VideoFlowTest.Smoke/AgentDraftGenerationChecks.cs @@ -16,6 +16,9 @@ internal static class AgentDraftGenerationChecks { var store = new RecipeWorkspace(root); Directory.CreateDirectory(root); + // 测试使用临时工作区的管理员账号验证模型设置写入。 + var access = SopHelper.Models.UserAccess.Current; + if (!access.IsAdministrator) access.Setup("agent-smoke-admin", "AgentSmokePassword123"); var video = Path.Combine(root, "agent-generation.avi"); using (var writer = new VideoWriter(video, FourCC.MJPG, 10, new OpenCvSharp.Size(64, 48))) { @@ -98,6 +101,11 @@ internal static class AgentDraftGenerationChecks && model.Recipe.Steps[1].AiCheckWindowMs == 14000 && model.Recipe.Steps[1].AiObservationRequestMaxFrames == 6, "Explicit application uses the generated trigger, crop and debounce while preserving existing steps and AI threshold"); + // 比对实际采样的 JPEG 和时间,确保步骤沿用草稿的参考画面。 + var evidence = client.Evidence!; + var keyFrame = Convert.ToBase64String(evidence.Jpeg); + Check(model.Recipe.Steps[1].KeyFrameBase64 == keyFrame && model.Recipe.Steps[1].KeyFrameSeconds == evidence.Seconds, + "应用草稿时将参考图及视频时间写入步骤关键帧"); Check(File.ReadAllBytes(path).SequenceEqual(before), "Applying generated draft still requires explicit recipe save"); model.GenerateStepsCommand.Execute(); Until(() => !model.IsAgentBusy); Check(!client.SawVerification&&model.ApplyAgentDraftCommand.CanExecute(),"Regenerated draft is directly applicable"); @@ -116,6 +124,10 @@ internal static class AgentDraftGenerationChecks Check(File.ReadAllText(runningLog).Contains("cancelled_or_timeout") && File.ReadAllText(runningLog).Contains("session_end"), "Cancellation finishes the persistent log without losing earlier events"); Check(model.Recipe.Steps.Count == 2 && File.ReadAllBytes(path).SequenceEqual(before), "Cancelling generation leaves the recipe untouched"); + model.SaveCommand.Execute(); + var savedStep = SopConfigLoader.Load(path).Sop.Steps[1]; + Check(savedStep.KeyFrameBase64 == keyFrame && savedStep.KeyFrameSeconds == evidence.Seconds, + "保存并重新读取配方后保留草稿关键帧及视频时间"); model.ConfirmCloseAsync = () => Task.FromResult(RecipeCloseChoice.Discard); Pump(model.ShutdownAsync()); window.Close(); Until(() => !window.IsVisible); model.OnDialogClosed(); } @@ -133,6 +145,7 @@ internal static class AgentDraftGenerationChecks { public Exception? Failure; public int Calls; + public SopVideoFrame? Evidence { get; private set; } public bool Hold, Entered; public bool SawVerification, SawCurrentDraft, SawDirectVerification; public async Task AnalyzeAsync(SopVideoAnalysisRequest request, SopAgentConnection connection, CancellationToken token) @@ -153,6 +166,7 @@ internal static class AgentDraftGenerationChecks Inspection = new() { EvidenceMode = "single_frame", CheckWindowMs = 14000, ObservationRequestMaxFrames = 6 } }] }; draft.ObservedFrames = frames; + Evidence = frames[draft.Steps[0].EvidenceFrame]; Check(request.VerifyDraft is null && request.CheckReference is null && !request.VerifyCurrentDraftFirst, "Generation and chat never supply replay callbacks"); return draft; }