1d6862016d
Resolves #75 ### Description This pull request implements a smart, Native AOT-compliant contextual recommendation engine for the desktop dashboard to drive user retention and cross-book monetization. ### Key Changes 1. **Application Layer**: - Declared `IUserReadingStateStore` interface to decouple reading state discovery. - Added `IVectorSearchStore.SearchGlobalExcludeAsync(...)` to abstract semantic similarity searches with exclusions. - Defined `GetContextualRecommendationsQuery` and response DTOs (`ContextualRecommendationResponse`, `RecommendationDto`). 2. **Infrastructure Layer**: - Implemented `UserReadingStateStore` using EF Core with DbContext pooling. - Implemented `SearchGlobalExcludeAsync` in `VectorSearchStore` to construct gRPC Qdrant filters (excluding the active book ID) and fetch `bookTitle` and `chapterTitle` from point payloads. - Implemented `GetContextualRecommendationsQueryHandler` using clean abstractions. 3. **Web & Serialization Layer**: - Mapped `GET /api/recommendations` endpoint. - Registered types in `AppJsonContext.cs` for AOT-compliant JSON serialization. 4. **Verification**: - Added complete unit test coverage in `GetContextualRecommendationsQueryTests.cs`. All 30 unit tests pass. --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Reviewed-on: #76 Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System;
|
|
using FluentAssertions;
|
|
using NexusReader.UI.Shared.Services;
|
|
using Xunit;
|
|
|
|
namespace NexusReader.Application.Tests.Services;
|
|
|
|
public class PaywallParserTests
|
|
{
|
|
[Fact]
|
|
public void TryParsePaywallTrigger_WithValidSimpleToken_ReturnsTrueAndCorrectValues()
|
|
{
|
|
// Arrange
|
|
var guid = Guid.NewGuid();
|
|
var rawText = $"Teaser sentence. [PAYWALL_TRIGGER:{guid}:Clean Book Title:45:82]";
|
|
|
|
// Act
|
|
var result = PaywallParser.TryParsePaywallTrigger(
|
|
rawText,
|
|
out var teaser,
|
|
out var bookId,
|
|
out var title,
|
|
out var localScore,
|
|
out var globalScore);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
teaser.Should().Be("Teaser sentence.");
|
|
bookId.Should().Be(guid);
|
|
title.Should().Be("Clean Book Title");
|
|
localScore.Should().Be(45);
|
|
globalScore.Should().Be(82);
|
|
}
|
|
|
|
[Fact]
|
|
public void TryParsePaywallTrigger_WithColonsInBookTitle_ReturnsTrueAndCorrectValues()
|
|
{
|
|
// Arrange
|
|
var guid = Guid.NewGuid();
|
|
var rawText = $"Teaser text. [PAYWALL_TRIGGER:{guid}:Architektura: .NET 10 i C# 14:15:99]";
|
|
|
|
// Act
|
|
var result = PaywallParser.TryParsePaywallTrigger(
|
|
rawText,
|
|
out var teaser,
|
|
out var bookId,
|
|
out var title,
|
|
out var localScore,
|
|
out var globalScore);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
teaser.Should().Be("Teaser text.");
|
|
bookId.Should().Be(guid);
|
|
title.Should().Be("Architektura: .NET 10 i C# 14");
|
|
localScore.Should().Be(15);
|
|
globalScore.Should().Be(99);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("Just plain text with no trigger token.")]
|
|
[InlineData("Plain text [PAYWALL_TRIGGER:invalid-guid:Title:50:80]")]
|
|
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title:50:invalid]")]
|
|
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title:invalid:80]")]
|
|
[InlineData("Plain text [PAYWALL_TRIGGER:00000000-0000-0000-0000-000000000000:Title]")]
|
|
public void TryParsePaywallTrigger_WithInvalidInputs_ReturnsFalse(string rawText)
|
|
{
|
|
// Act
|
|
var result = PaywallParser.TryParsePaywallTrigger(
|
|
rawText,
|
|
out var teaser,
|
|
out var bookId,
|
|
out var title,
|
|
out var localScore,
|
|
out var globalScore);
|
|
|
|
// Assert
|
|
result.Should().BeFalse();
|
|
}
|
|
}
|