- 添加HNSW向量索引提升检索性能 - 实现Hybrid检索模式支持向量和关键词双路召回 - 采用RRF算法融合多路召回结果 - 支持ParentChild分块模式的上下文回填 - 优化向量写入采用批量SQL操作提升性能 - 添加RAG PostgreSQL连接字符串配置 - 更新部署脚本增加PGVector集成测试 - 修正表名引用从document_chunks到b_document_chunks - 重构RagRetrievalService实现完整的检索流程 - 增加重排策略支持关键词和LLM重排 - 修改服务器部署地址配置
70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using File.Application.Features.Files.Commands;
|
||
using File.Application.Features.Files.Handlers;
|
||
using File.Application.Features.Files.Services;
|
||
using File.Domain.Entities.FileMeta;
|
||
using File.Infrastructure.Persistence;
|
||
using File.Infrastructure.Storage;
|
||
using FluentAssertions;
|
||
using Microsoft.Extensions.Logging.Abstractions;
|
||
using Moq;
|
||
using Xunit;
|
||
|
||
namespace BuildFlow.File.Tests;
|
||
|
||
/// <summary>
|
||
/// ProcessUnverifiedFileSizesCommandHandler 测试。该 Handler 仅将命令委托给
|
||
/// FileSizeVerificationProcessor,故覆盖:成功回填大小 + 委托层对越界参数的前置校验。
|
||
/// </summary>
|
||
public class ProcessUnverifiedFileSizesCommandHandlerTests
|
||
{
|
||
private static FileSizeVerificationProcessor NewProcessor(FileDbContext db, Mock<IS3StorageService> s3)
|
||
=> new(db, s3.Object, NullLogger<FileSizeVerificationProcessor>.Instance);
|
||
|
||
private static FileMetaEntity NewUnverifiedFile()
|
||
=> new()
|
||
{
|
||
Name = "f.bin",
|
||
S3Key = Guid.NewGuid().ToString(),
|
||
S3Bucket = "files",
|
||
ContentType = "application/octet-stream",
|
||
OwnerId = "user-001",
|
||
Size = 0,
|
||
SizeVerified = false,
|
||
};
|
||
|
||
[Fact]
|
||
public async Task Process_存在未确认文件_经S3回填大小并标记已确认()
|
||
{
|
||
await using var db = FileTestDb.Create();
|
||
var file = NewUnverifiedFile();
|
||
db.Files.Add(file);
|
||
await db.SaveChangesAsync();
|
||
|
||
var s3 = new Mock<IS3StorageService>();
|
||
s3.Setup(x => x.GetObjectSizeAsync(file.S3Bucket, file.S3Key, It.IsAny<CancellationToken>()))
|
||
.ReturnsAsync(2048L);
|
||
|
||
var handler = new ProcessUnverifiedFileSizesCommandHandler(NewProcessor(db, s3));
|
||
|
||
var processed = await handler.Handle(new ProcessUnverifiedFileSizesCommand(100, 4), CancellationToken.None);
|
||
|
||
processed.Should().Be(1, "应处理 1 个未确认文件");
|
||
// file 为同一 DbContext 跟踪的实例,处理器 SaveChangesAsync 后属性已更新
|
||
file.Size.Should().Be(2048L);
|
||
file.SizeVerified.Should().BeTrue("大小应被标记已确认");
|
||
}
|
||
|
||
[Fact]
|
||
public async Task Process_批量大小越界_委托处理器抛出参数范围异常()
|
||
{
|
||
await using var db = FileTestDb.Create();
|
||
var handler = new ProcessUnverifiedFileSizesCommandHandler(NewProcessor(db, new Mock<IS3StorageService>()));
|
||
|
||
var act = async () => await handler.Handle(
|
||
new ProcessUnverifiedFileSizesCommand(0, 4), CancellationToken.None);
|
||
|
||
// 越界校验在依赖(S3/DB)调用之前,可在 InMemory 直接覆盖。
|
||
await act.Should().ThrowAsync<ArgumentOutOfRangeException>();
|
||
}
|
||
}
|