Files
Wiki/test/Wiki.Contracts/FileIndex/FileDocumentCatalogContractTests.cs
T
claude-botandClaude Sonnet 5 019f046925 feat(fileindex): file-backed vector index and document catalog adapters
FileVectorIndex persists one binary file per model under index/ with
atomic tmp+rename writes; FileDocumentCatalog persists a single
catalog.json, rebuilding the link graph via WikiLinks.Extract on every
upsert. Both start empty and report health Ok with a reset detail if
their file on disk is corrupt, rather than crashing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:32:43 +02:00

46 lines
1.6 KiB
C#

using Microsoft.Extensions.Options;
using Wiki.Adapters.FileIndex;
using Wiki.Core.Ports;
namespace Wiki.Contracts.FileIndex;
public sealed class FileDocumentCatalogContractTests : DocumentCatalogContract, IDisposable
{
private readonly List<string> _directories = [];
private readonly Dictionary<IDocumentCatalog, string> _directoryOf = new(ReferenceEqualityComparer.Instance);
protected override Task<IDocumentCatalog> CreateCatalogAsync()
{
var directory = NewDirectory();
IDocumentCatalog catalog = new Wiki.Adapters.FileIndex.FileDocumentCatalog(Options.Create(new FileIndexOptions { Directory = directory }));
_directoryOf[catalog] = directory;
return Task.FromResult(catalog);
}
protected override Task<IDocumentCatalog> ReopenAsync(IDocumentCatalog catalog)
{
var directory = _directoryOf[catalog];
IDocumentCatalog reopened = new Wiki.Adapters.FileIndex.FileDocumentCatalog(Options.Create(new FileIndexOptions { Directory = directory }));
_directoryOf[reopened] = directory;
return Task.FromResult(reopened);
}
private string NewDirectory()
{
var directory = Path.Combine(Path.GetTempPath(), "wiki-tests", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(directory);
_directories.Add(directory);
return directory;
}
public void Dispose()
{
foreach (var directory in _directories)
{
try { Directory.Delete(directory, recursive: true); }
catch (IOException) { }
catch (UnauthorizedAccessException) { }
}
}
}