From 6c3458a5ec37a5b69957ad17c84de58984698f25 Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Tue, 11 Aug 2026 21:44:53 +0900 Subject: Audit and align v1 runtime design --- tests/Agent.Core.Tests/ObservabilityTests.cs | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/Agent.Core.Tests/ObservabilityTests.cs') diff --git a/tests/Agent.Core.Tests/ObservabilityTests.cs b/tests/Agent.Core.Tests/ObservabilityTests.cs index c259eb0..8231ab9 100644 --- a/tests/Agent.Core.Tests/ObservabilityTests.cs +++ b/tests/Agent.Core.Tests/ObservabilityTests.cs @@ -1,13 +1,69 @@ using Agent.App.Logging; using Agent.Core.Localization; +using Agent.Core.Ollama; +using Agent.Core.Runtime; +using Agent.Core.Tools; using Agent.Mcp; using System.Diagnostics; using System.Text; +using System.Text.Json; namespace Agent.Core.Tests; public sealed class ObservabilityTests { + [Fact] + public void Llm_log_carries_correlation_usage_and_tool_iteration_fields() + { + using var directory = new TestDirectory(); + Guid sessionId = Guid.NewGuid(); + Guid taskId = Guid.NewGuid(); + Guid plannerTaskId = Guid.NewGuid(); + Guid callId = Guid.NewGuid(); + var context = new AgentLlmCallContext(callId, sessionId, taskId, plannerTaskId, "replan", 7, 2, "model-a"); + using (var observer = new JsonLinesRuntimeObserver(directory.Path, 1024 * 1024, 2)) + { + observer.LlmRequest(context, [new OllamaMessage("user", "request")]); + observer.LlmResponse(context, new OllamaResult("response", 11, 13)); + observer.ToolResult(context, "file_read", new ToolExecutionResult(true, "ok", false)); + observer.LlmFailure(context, "planning_failed", "invalid plan"); + } + + JsonElement[] entries = File.ReadLines(Path.Combine(directory.Path, "llm.jsonl")) + .Select(static line => JsonDocument.Parse(line).RootElement.Clone()).ToArray(); + Assert.Equal(4, entries.Length); + Assert.All(entries, entry => + { + Assert.Equal(callId, entry.GetProperty("call_id").GetGuid()); + Assert.Equal(taskId, entry.GetProperty("task_id").GetGuid()); + Assert.Equal(sessionId, entry.GetProperty("session_id").GetGuid()); + Assert.Equal(plannerTaskId, entry.GetProperty("planner_task_id").GetGuid()); + Assert.Equal(7, entry.GetProperty("iteration").GetInt32()); + Assert.Equal(2, entry.GetProperty("replan").GetInt32()); + }); + Assert.Equal(11, entries[1].GetProperty("input_tokens").GetInt64()); + Assert.Equal("file_read", entries[2].GetProperty("tool_name").GetString()); + Assert.Equal("llm.failure", entries[3].GetProperty("event_name").GetString()); + Assert.Equal("planning_failed", entries[3].GetProperty("error_code").GetString()); + } + + [Fact] + public void Read_agent_log_script_exposes_read_only_filters() + { + DirectoryInfo? root = new(AppContext.BaseDirectory); + while (root is not null && !File.Exists(Path.Combine(root.FullName, "scripts", "Read-AgentLog.ps1"))) root = root.Parent; + Assert.NotNull(root); + string scriptPath = Path.Combine(root!.FullName, "scripts", "Read-AgentLog.ps1"); + string script = File.ReadAllText(scriptPath); + Assert.Contains("[string]$TaskId", script, StringComparison.Ordinal); + Assert.Contains("[string]$SessionId", script, StringComparison.Ordinal); + Assert.Contains("[string]$Event", script, StringComparison.Ordinal); + Assert.Contains("[string]$CallId", script, StringComparison.Ordinal); + Assert.Contains("[int]$Tail", script, StringComparison.Ordinal); + Assert.DoesNotContain("Set-Content", script, StringComparison.OrdinalIgnoreCase); + Assert.DoesNotContain("Remove-Item", script, StringComparison.OrdinalIgnoreCase); + } + [Fact] public void Ready_is_always_visible_even_when_log_threshold_is_fatal() { -- cgit v1.2.3