refactor(dotnet): centralize runtime audit trail
Validators (Pushes and Pull Requests) / validate-ui-and-storage (push) Successful in 16s
Validators (Pushes and Pull Requests) / validate-core (push) Has been cancelled

This commit is contained in:
2026-07-13 00:52:32 +09:00
parent aa61465ce0
commit 99377e9ca9
7 changed files with 68 additions and 89 deletions
@@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Moq;
using QuantEngine.Application.Interfaces;
using QuantEngine.Application.Services;
using QuantEngine.Core.Domain;
using QuantEngine.Core.Interfaces;
@@ -15,39 +16,17 @@ public class FactorComputationServiceTests
public async Task ComputeAndAppendFactorOutputs_WritesAuditAndHistory()
{
var storeMock = new Mock<IPostgresqlHistoryStore>();
var auditTrailMock = new Mock<IRuntimeAuditTrailService>();
storeMock.Setup(s => s.AppendAsync(It.IsAny<string>(), It.IsAny<IDictionary<string, object?>>()))
.ReturnsAsync(1);
var history = new HistoryIngestionService(storeMock.Object);
var service = new FactorComputationService(history);
var root = FindRepoRoot();
var auditPath = Path.Combine(root, "Temp", "factor_audit", "005930.jsonl");
if (File.Exists(auditPath))
{
File.Delete(auditPath);
}
var service = new FactorComputationService(history, auditTrailMock.Object);
var outputs = new FactorOutputs(1, 2, 3, 4, 5, 6, 7);
await service.AppendFactorOutputsAsync("005930", "v1", outputs);
storeMock.Verify(s => s.AppendAsync("factor_output_history", It.IsAny<IDictionary<string, object?>>()), Times.Exactly(7));
Assert.True(File.Exists(auditPath));
Assert.Contains("PERSISTED", File.ReadAllText(auditPath));
}
private static string FindRepoRoot()
{
var current = new DirectoryInfo(System.AppContext.BaseDirectory);
while (current != null)
{
if (Directory.Exists(Path.Combine(current.FullName, ".git")))
{
return current.FullName;
}
current = current.Parent;
}
throw new InvalidOperationException("Repository root not found.");
auditTrailMock.Verify(a => a.Append("factor_audit", "005930", It.IsAny<FactorComputationAudit>()), Times.Once);
}
}