Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Netclaw.Cli.Tests/Doctor/MemoryCurationLlmDoctorCheckTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// -----------------------------------------------------------------------
// <copyright file="MemoryCurationLlmDoctorCheckTests.cs" company="Petabridge, LLC">
// Copyright (C) 2026 - 2026 Petabridge, LLC <https://petabridge.com>
// </copyright>
// -----------------------------------------------------------------------
using Microsoft.Extensions.Time.Testing;
using Netclaw.Cli.Doctor;
using Netclaw.Configuration;
using Netclaw.Tests.Utilities;
using Xunit;

namespace Netclaw.Cli.Tests.Doctor;

public sealed class MemoryCurationLlmDoctorCheckTests : IDisposable
{
private readonly DisposableTempDir _temp = new();

public void Dispose() => _temp.Dispose();

[Fact]
public async Task Reads_and_classifies_log_while_daemon_keeps_it_open_for_append()
{
var paths = new NetclawPaths(_temp.Path);
paths.EnsureDirectoriesExist();

var logPath = Path.Combine(paths.LogsDirectory, "daemon-2026-05-20.log");
using var writerStream = new FileStream(
logPath,
FileMode.Append,
FileAccess.Write,
FileShare.ReadWrite | FileShare.Delete);
using var writer = new StreamWriter(writerStream);
writer.WriteLine("curation_llm_decision");
writer.WriteLine("curation_llm_timeout");
writer.Flush();

var time = new FakeTimeProvider(
new DateTimeOffset(2026, 5, 20, 12, 0, 0, TimeSpan.Zero));
var result = await new MemoryCurationLlmDoctorCheck(paths, time)
.RunAsync(TestContext.Current.CancellationToken);

Assert.Equal("Memory Curation LLM", result.Name);
Assert.Equal(DoctorSeverity.Warning, result.Severity);
// The percent text follows the current culture ("50%" or "50 %"), so
// check the counts, which do not change with the culture.
Assert.Contains("(1/2)", result.Message);
}
}
7 changes: 6 additions & 1 deletion src/Netclaw.Cli/Doctor/MemoryCurationLlmDoctorCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ private async Task<DoctorCheckResult> RunCoreAsync(CancellationToken cancellatio
continue;

cancellationToken.ThrowIfCancellationRequested();
using var reader = new StreamReader(file);
using var stream = new FileStream(
file,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite | FileShare.Delete);
using var reader = new StreamReader(stream);
while (await reader.ReadLineAsync(cancellationToken) is { } line)
{
// Failure markers first: none of them contains the success
Expand Down
Loading