리플레이/권한/도구 패리티 안정화: StopRequested·Paused/Resumed 반영 및 검증 보강
Some checks failed
Release Gate / gate (push) Has been cancelled

- TaskRunService에 AgentEventType.Paused/Resumed 처리 로직을 추가해 런타임 상태(일시정지/재개)가 task store에 일관되게 반영되도록 개선

- TaskRunService에 AgentEventType.StopRequested 처리 로직을 추가해 실행 중단 요청 시 agent/tool/permission/hook 범주의 run-scoped 태스크가 cancel 상태로 정리되도록 보강

- replay 복원 경로에서 StopRequested를 terminal 이벤트로 인식하도록 확장하고, TryGetScopedId/IsTerminalExecutionEvent/RemoveRunScopedActiveTasks 연계를 통해 dangling active task가 남지 않도록 수정

- OperationModePolicyTests에 Deny 모드 경계 테스트를 추가(쓰기 차단 + 읽기 허용)하여 권한 4모드 정책의 기대 동작을 명시적으로 고정

- TaskRunServiceTests에 ReplayStability 시나리오 3건 추가: (1) Paused→Resumed 후 agent active 유지, (2) StopRequested 후 dangling task 정리, (3) live StopRequested 적용 시 pending 권한/에이전트 상태 정리

- AgentParityToolsTests에 core agentic loop 도구 등록 검증 추가(file_read/write/edit, glob/grep/process, git/build/test, spawn/wait, task/todo, checkpoint/diff/suggest/tool_search/skill_manager)

- 검증 수행: dotnet build AxCopilot.sln (경고 0 / 오류 0), 대상 테스트(OperationModePolicyTests/TaskRunServiceTests/AgentParityToolsTests) 통과, ReplayStability+ParityBenchmark 필터 테스트 통과
This commit is contained in:
2026-04-03 21:35:45 +09:00
parent e7eec1035f
commit 0176754fa0
4 changed files with 191 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using AxCopilot.Services.Agent;
using FluentAssertions;
@@ -164,4 +165,39 @@ public class AgentParityToolsTests
try { if (Directory.Exists(workDir)) Directory.Delete(workDir, true); } catch { }
}
}
[Fact]
[Trait("Suite", "ParityBenchmark")]
public void ToolRegistry_CreateDefault_ContainsCoreAgenticLoopTools()
{
using var registry = ToolRegistry.CreateDefault();
var names = registry.All.Select(t => t.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
var required = new[]
{
"file_read",
"file_write",
"file_edit",
"glob",
"grep",
"process",
"git_tool",
"build_run",
"test_loop",
"spawn_agent",
"wait_agents",
"todo_write",
"task_create",
"task_update",
"task_output",
"checkpoint",
"diff_preview",
"suggest_actions",
"tool_search",
"skill_manager",
};
foreach (var name in required)
names.Should().Contain(name);
}
}

View File

@@ -138,4 +138,20 @@ public class OperationModePolicyTests
allowed.Should().BeFalse();
askCalled.Should().BeTrue();
}
[Fact]
public async Task AgentContext_CheckToolPermissionAsync_DenyModeBlocksWriteButAllowsRead()
{
var context = new AgentContext
{
OperationMode = OperationModePolicy.ExternalMode,
Permission = "Deny"
};
var writeAllowed = await context.CheckToolPermissionAsync("file_write", @"E:\work\out.txt");
var readAllowed = await context.CheckToolPermissionAsync("file_read", @"E:\work\in.txt");
writeAllowed.Should().BeFalse();
readAllowed.Should().BeTrue();
}
}

View File

@@ -298,7 +298,7 @@ public class TaskRunServiceTests
{
var service = new TaskRunService();
service.StartOrUpdate("agent:1", "agent", "main", "thinking");
service.StartOrUpdate("permission:1:file_write", "permission", "file_write 권한", "ask", "waiting");
service.StartOrUpdate("permission:1:file_write", "permission", "file_write permission", "ask", "waiting");
service.Complete("agent:1", "done", "completed");
var summary = service.GetSummary();
@@ -308,4 +308,62 @@ public class TaskRunServiceTests
summary.LatestRecentTask.Should().NotBeNull();
summary.LatestRecentTask!.Id.Should().Be("agent:1");
}
[Fact]
[Trait("Suite", "ReplayStability")]
public void RestoreRecentFromExecutionEvents_ResumedKeepsAgentTaskActive()
{
var service = new TaskRunService();
var now = DateTime.Now;
service.RestoreRecentFromExecutionEvents(
[
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-3), RunId = "run-r1", Type = "Thinking", Summary = "thinking", Iteration = 1 },
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-2), RunId = "run-r1", Type = "Paused", Summary = "paused", Iteration = 2 },
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-1), RunId = "run-r1", Type = "Resumed", Summary = "resumed", Iteration = 3 },
]);
service.ActiveTasks.Should().Contain(t => t.Kind == "agent" && t.Status == "running");
}
[Fact]
[Trait("Suite", "ReplayStability")]
public void RestoreRecentFromExecutionEvents_StopRequestedClearsDanglingRunScopedTasks()
{
var service = new TaskRunService();
var now = DateTime.Now;
service.RestoreRecentFromExecutionEvents(
[
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-3), RunId = "run-stop", Type = "ToolCall", ToolName = "file_edit", Summary = "call", Iteration = 1 },
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-2), RunId = "run-stop", Type = "PermissionRequest", ToolName = "file_edit", Summary = "ask", Iteration = 2 },
new Models.ChatExecutionEvent { Timestamp = now.AddSeconds(-1), RunId = "run-stop", Type = "StopRequested", Summary = "stop", Iteration = 3 },
]);
service.ActiveTasks.Should().BeEmpty();
service.RecentTasks.Should().Contain(t => t.Kind == "agent");
}
[Fact]
public void ApplyAgentEvent_StopRequestedCompletesRunAndClearsPending()
{
var service = new TaskRunService();
service.ApplyAgentEvent(new AgentEvent
{
RunId = "run-stop-live",
Type = AgentEventType.PermissionRequest,
ToolName = "file_write",
Summary = "ask"
});
service.ApplyAgentEvent(new AgentEvent
{
RunId = "run-stop-live",
Type = AgentEventType.StopRequested,
Summary = "stop"
});
service.ActiveTasks.Should().BeEmpty();
service.RecentTasks.Should().Contain(t => t.Kind == "agent");
}
}