Fix settings log tail reads
PR and Push Build/Test / build-and-test (push) Failing after 12m50s

This commit is contained in:
2026-05-30 14:25:35 +02:00
parent 0342cff64f
commit fd8c33f1ea
3 changed files with 35 additions and 8 deletions
@@ -155,15 +155,18 @@ public sealed class WorkflowRulesEditorTests
new MeetingAssistantOptions(), new MeetingAssistantOptions(),
logDirectory: root); logDirectory: root);
using var provider = new MeetingAssistantFileLoggerProvider(root);
provider.CreateLogger("Test").LogInformation("locked needle");
var tail = await tools.ReadLogs(tail: 2); var tail = await tools.ReadLogs(tail: 2);
var range = await tools.ReadLogs(from: 2, to: 2); var range = await tools.ReadLogs(from: 1, to: 1);
var search = await tools.SearchLogs("needle"); var search = await tools.SearchLogs("needle");
Assert.DoesNotContain("first line", tail); Assert.Contains("locked needle", tail);
Assert.Contains("second needle", tail); Assert.Contains("locked needle", search);
Assert.Equal("second needle", range.Trim()); Assert.Contains("locked needle", range);
Assert.Contains("meeting-assistant.log:2 second needle", search); Assert.Contains("meeting-assistant.log:1", search);
Assert.Contains("meeting-assistant.log.1:1 rotated needle", search); Assert.Contains("meeting-assistant.log.2:1 rotated needle", search);
} }
[Fact] [Fact]
+25 -1
View File
@@ -189,7 +189,7 @@ internal static class AgentFileToolContent
var limit = Math.Clamp(maxMatches, 1, 1000); var limit = Math.Clamp(maxMatches, 1, 1000);
foreach (var source in sources) foreach (var source in sources)
{ {
var lines = File.ReadAllLines(source.Path); var lines = ReadAllLinesShared(source.Path);
for (var index = 0; index < lines.Length; index++) for (var index = 0; index < lines.Length; index++)
{ {
if (regex.IsMatch(lines[index])) if (regex.IsMatch(lines[index]))
@@ -211,6 +211,30 @@ internal static class AgentFileToolContent
return ""; return "";
} }
} }
public static async Task<string> ReadAllTextSharedAsync(string path)
{
await using var stream = new FileStream(
path,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite | FileShare.Delete,
bufferSize: 4096,
useAsync: true);
using var reader = new StreamReader(stream);
return await reader.ReadToEndAsync();
}
private static string[] ReadAllLinesShared(string path)
{
using var stream = new FileStream(
path,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite | FileShare.Delete);
using var reader = new StreamReader(stream);
return SplitLines(reader.ReadToEnd()).ToArray();
}
} }
internal sealed record AgentFileSearchSource(string Path, string DisplayPath); internal sealed record AgentFileSearchSource(string Path, string DisplayPath);
@@ -166,7 +166,7 @@ public sealed class WorkflowRulesEditorTools
return $"Log file was not found: {logFile ?? MeetingAssistantLogFiles.CurrentLogFileName}"; return $"Log file was not found: {logFile ?? MeetingAssistantLogFiles.CurrentLogFileName}";
} }
var content = await File.ReadAllTextAsync(path); var content = await AgentFileToolContent.ReadAllTextSharedAsync(path);
if (from.HasValue || to.HasValue) if (from.HasValue || to.HasValue)
{ {
return AgentFileToolContent.ReadLines(content, from, to); return AgentFileToolContent.ReadLines(content, from, to);