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>
46 lines
1.6 KiB
C#
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 FileVectorIndexContractTests : VectorIndexContract, IDisposable
|
|
{
|
|
private readonly List<string> _directories = [];
|
|
private readonly Dictionary<IVectorIndex, string> _directoryOf = new(ReferenceEqualityComparer.Instance);
|
|
|
|
protected override Task<IVectorIndex> CreateIndexAsync()
|
|
{
|
|
var directory = NewDirectory();
|
|
IVectorIndex index = new Wiki.Adapters.FileIndex.FileVectorIndex(Options.Create(new FileIndexOptions { Directory = directory }));
|
|
_directoryOf[index] = directory;
|
|
return Task.FromResult(index);
|
|
}
|
|
|
|
protected override Task<IVectorIndex> ReopenAsync(IVectorIndex index)
|
|
{
|
|
var directory = _directoryOf[index];
|
|
IVectorIndex reopened = new Wiki.Adapters.FileIndex.FileVectorIndex(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) { }
|
|
}
|
|
}
|
|
}
|