Skip to content

Complete backend coverage and simplify test infrastructure - #96

Merged
ANcpLua merged 2 commits into
mainfrom
agent/complete-backend-coverage
Aug 2, 2026
Merged

Complete backend coverage and simplify test infrastructure#96
ANcpLua merged 2 commits into
mainfrom
agent/complete-backend-coverage

Conversation

@ANcpLua

@ANcpLua ANcpLua commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • simplify shared container/test infrastructure and remove redundant or weak tests
  • harden document endpoints, exception mapping, storage/search behavior, cleanup, and cancellation contracts
  • add real Elasticsearch, MinIO, PDF/OCR, endpoint, and error-path coverage
  • remove the obsolete search request DTO and keep the Angular API contract in sync
  • update transitive security pins, including System.Security.Cryptography.Xml 10.0.10

Why

The previous suite mixed duplicated tests, defensive catch padding, environment races, and coverage-only seams. Several boundary paths were either asserted through mocks or not covered at all, and OCR cancellation was converted into a domain failure instead of propagating naturally from CreatePdf.NET.

This change exercises owned behavior at the real external boundaries, makes resource ownership explicit, and leaves only two unreachable Roslyn sequence-point artifacts outside coverage.

Validation

  • ./build.sh UnitTests — 294/294 passed
  • ./build.sh IntegrationTests — 91/91 passed
  • ./build.sh Coverage — 385/385 instrumented tests passed
  • ./build.sh ReportCoverage --coverage-min-line 0 --coverage-min-branch 0 --coverage-format markdown --coverage-exclude-generated-param true — 99.9% lines (1359/1361), 96.1% branches (317/330)
  • Pipeline NuGet vulnerability scan — no vulnerable packages reported
  • focused live Elasticsearch endpoint tests, MinIO contract tests, OCR cancellation/blank-PDF tests, and storage byte-roundtrip tests passed

Copilot AI review requested due to automatic review settings August 1, 2026 22:36
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • PaperlessREST.Tests/Integration/DocumentEndpointTests.cs is excluded by none and included by none
  • PaperlessREST.Tests/Unit/BatchOrchestratorTests.cs is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: af58797d-1e06-4a5a-885d-a6721930467f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Summary by CodeRabbit

  • Chores
    • Updated the System.Security.Cryptography.Xml package to version 10.0.10.
    • Retained existing package version pins.
    • Simplified an internal security-related comment.

Walkthrough

The package configuration updates System.Security.Cryptography.Xml from 10.0.9 to 10.0.10, retains the existing Microsoft.OpenApi and NuGet.Packaging pins, and condenses the security comment.

Changes

Package security pin

Layer / File(s) Summary
Update security package pin
Directory.Packages.props
The security comment is condensed. The System.Security.Cryptography.Xml version changes to 10.0.10. Existing package pins remain unchanged.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested labels: area:infra


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error The title describes the changes but does not use the required Conventional Commit format or an approved scope. Use a title such as chore(infra): complete backend coverage and simplify test infrastructure.
✅ Passed checks (7 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly covers the test infrastructure, backend coverage, security pins, and validation changes in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Otel Instrumentation Required ✅ Passed DI registrations are unchanged from HEAD^ to HEAD, and the production diff adds no class/interface/record/struct declarations; no new injectable service requires instrumentation.
No Unbounded Mcp Responses ✅ Passed The PR changes no files under src/qyl.mcp, and the repository contains no MCP tool definitions to assess.
Duckdb Backpressure On Write Paths ✅ Passed The parent and PR trees contain no DuckDB references or packages; changed database writes use EF Core/Npgsql, so the PR adds no DuckDB write path requiring backpressure.
Cancellationtoken Threading ✅ Passed The production diff adds no new public async methods; modified async APIs retain CancellationToken parameters and forward them to dependent operations.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR significantly refactors the backend test/integration infrastructure and strengthens real-boundary coverage across storage (MinIO), search (Elasticsearch), OCR (CreatePdf.NET), and REST endpoints, while aligning configuration/contracts (notably MinIO endpoint parsing and search DTO removal) and updating security pins.

Changes:

  • Replace several mock-heavy/branch tests with real boundary coverage (MinIO/Elasticsearch behavior, endpoint validation/error paths, OCR cancellation/blank PDFs) and simplify shared container fixtures.
  • Tighten and standardize configuration contracts (MinIO Endpoint as Uri with origin validation; remove UseSsl and obsolete search DTO/types).
  • Update operational/error handling behavior (ProblemDetails enrichment, exception sanitization, delete/search/storage behaviors) and bump transitive security pins (e.g., System.Security.Cryptography.Xml 10.0.10).

Reviewed changes

Copilot reviewed 47 out of 48 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Pipeline/Build.csproj Update/clarify transitive security pins for Pipeline (non-CPM project).
PaperlessUI.Angular/src/app/core/api/generated/api-types.ts Remove obsolete SearchQuery schema/type from generated Angular API types.
PaperlessServices/Host/Extensions/ServiceCollectionExtensions.cs Validate MinIO endpoint as an absolute HTTP(S) origin; build MinIO client from Uri.
PaperlessServices/Features/OcrProcessing/Infrastructure/Storage/StorageService.cs Ensure MemoryStream is disposed if MinIO download fails.
PaperlessServices/Features/OcrProcessing/Infrastructure/PdfExtractor/IPdfExtractor.cs Update cancellation contract documentation to reflect CreatePdf.NET token propagation.
PaperlessServices/Features/OcrProcessing/Infrastructure/PdfExtractor/CreatePdfExtractor.cs Propagate cancellation (don’t convert it into domain failure); refine exception handling.
PaperlessServices/Features/OcrProcessing/Application/OcrProcessor.cs Ensure caller cancellation during download propagates (not converted into error result).
PaperlessServices/Configuration/MinioOptions.cs Change Endpoint to Uri; remove UseSsl option.
PaperlessServices.Tests/Unit/StorageServiceTests.cs Align tests with Uri endpoint; add cancellation propagation test for storage download.
PaperlessServices.Tests/Unit/ServiceCollectionExtensionsTests.cs Update MinIO config expectations; add invalid endpoint validation tests.
PaperlessServices.Tests/Unit/OcrProcessorTests.cs Assert stream ownership/disposal; add cancellation propagation test for download stage.
PaperlessServices.Tests/Unit/FakeLoggerExtensionsTests.cs Add unit coverage for log polling (already-met condition, timeout, caller cancellation).
PaperlessServices.Tests/Unit/CreatePdfExtractorTests.cs Replace weak OCR “maybe success” tests with cancellation + disposed-stream failure tests.
PaperlessServices.Tests/Integration/WorkerTestBase.cs Simplify shared fixture composition; improve host teardown and upload helpers.
PaperlessServices.Tests/Integration/StorageIntegrationTests.cs Strengthen storage round-trip assertions (exact bytes + stream position).
PaperlessServices.Tests/Integration/OcrIntegrationTests.cs Add integration coverage for blank-PDF → Ocr.EmptyDocument.
PaperlessREST/Host/Extensions/ServiceCollectionExtensions.cs Use AddProblemDetails() + enricher; enforce MinIO origin validation; build client from Uri.
PaperlessREST/Features/DocumentManagement/Presentation/Endpoints/DocumentEndpoints.cs Harden search handler validation/defaulting; minor pagination cursor behavior change.
PaperlessREST/Features/DocumentManagement/Infrastructure/Storage/DocumentStorageService.cs Make delete contract fail-fast (no boolean suppression); simplify remove operation.
PaperlessREST/Features/DocumentManagement/Infrastructure/Search/DocumentSearchService.cs Change search API to return materialized results; add cancellation mapping helper.
PaperlessREST/Features/DocumentManagement/Application/DocumentService.cs Update search/delete contracts; refine storage exception mapping and deletion ordering.
PaperlessREST/Features/BatchProcessing/Application/BatchOrchestrator.cs Simplify logging branches; make ProcessFileAsync private; assume .processing invariant.
PaperlessREST/Contracts/DocumentManagement/DocumentDtos.cs Remove obsolete SearchQuery transport DTO.
PaperlessREST/Configuration/MinioOptions.cs Change Endpoint to Uri; remove UseSsl + helper accessor extension.
PaperlessREST/Configuration/Constraints.cs Remove service-layer search truncation constants.
PaperlessREST/API/GlobalExceptionHandler.cs Centralize/expand validation ProblemDetails shaping; sanitize details in production; enrich PD metadata.
PaperlessREST.Tests/Unit/ServiceCollectionExtensionsTests.cs Update wiring/config expectations; validate MinIO endpoint origin rules; adjust ProblemDetails customization assertions.
PaperlessREST.Tests/Unit/PathNormalizationTests.cs Add unit coverage for path normalization and distinct path detection behavior.
PaperlessREST.Tests/Unit/GlobalExceptionHandlerTests.cs Update exception mapping expectations; improve validation-member handling assertions and production sanitization tests.
PaperlessREST.Tests/Unit/ExceptionHandlerTests.cs Remove obsolete/duplicative exception handler test suite (consolidated elsewhere).
PaperlessREST.Tests/Unit/DocumentStorageServiceTests.cs Update MinIO endpoint to Uri; validate delete now propagates failures/cancellation.
PaperlessREST.Tests/Unit/DocumentServiceTestBase.cs Allow injecting storage service for MinIO-backed contract tests.
PaperlessREST.Tests/Unit/DocumentServiceContractTests.cs Replace mocked storage failure mapping tests with MinIO SDK boundary simulations; adjust delete/search contracts.
PaperlessREST.Tests/Unit/DocumentSearchServiceTests.cs Remove obsolete tests for the old search abstraction.
PaperlessREST.Tests/Unit/BatchOrchestratorTests.cs Focus on full-flow file-system tests; add archive-move failure and embedded “processing” filename coverage.
PaperlessREST.Tests/Integration/SharedRestContainerFixture.cs Add collection fixture + deterministic env override/restore; add temp batch root management; robust teardown.
PaperlessREST.Tests/Integration/RabbitMqExtensionsTests.cs Avoid env dependency; ensure DI containers are disposed asynchronously.
PaperlessREST.Tests/Integration/GlobalExceptionHandlerMiddlewareTests.cs Strengthen production sanitization + validation-member behavior coverage.
PaperlessREST.Tests/Integration/DocumentEndpointTests.cs Expand endpoint coverage (pagination defaults, search validation/defaulting, upload constraints, summary, search service contracts).
PaperlessREST.Tests/DocumentBuilder.cs Remove obsolete SearchQueryBuilder.
Paperless.TestSupport/TestEnv.cs Simplify docs and .env.test loading helper.
Paperless.TestSupport/FakeLoggerExtensions.cs Improve timeout vs caller-cancellation semantics and error messaging in log polling helper.
Paperless.TestSupport/ContainerFixtureBase.cs Simplify fixture contract; robust teardown aggregation; improve ES polling cancellation semantics; standardize MinIO endpoint URI formatting.
Paperless.TestSupport/AssemblyInfo.cs Simplify rationale for excluding test-support assembly from coverage.
Directory.Packages.props Bump System.Security.Cryptography.Xml transitive pin to 10.0.10 and clarify pin rationale.
AGENTS.md Update documented coverage metrics/notes to match current state.
.env.test Update MinIO endpoint to include scheme; remove UseSsl.
.env.example Provide concrete MinIO endpoint origin example; remove UseSsl placeholder.
Suppressed comments (1)

PaperlessREST/Features/DocumentManagement/Infrastructure/Search/DocumentSearchService.cs:58

  • DeleteAsync logs success unconditionally after calling the Elasticsearch client. If the client returns an invalid response without throwing, this will log a false success and hide the failure.
		await ExecuteElasticsearchAsync(
			token => elastic.DeleteAsync(deleteRequest, token),
			cancellationToken);

		logger.LogInformation("Document {DocumentId} removed from search index", id);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +36
var response = await ExecuteElasticsearchAsync(
token => elastic.SearchAsync<DocumentSearchResult>(
s => s.Indices(elastic.ElasticsearchClientSettings.DefaultIndex)
.Query(q => q.MultiMatch(mm => mm
.Query(query)
Copilot AI review requested due to automatic review settings August 1, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 47 out of 48 changed files in this pull request and generated no new comments.

Suppressed comments (1)

PaperlessREST/Features/DocumentManagement/Presentation/Endpoints/DocumentEndpoints.cs:55

  • Search query validation currently only checks for null/empty and max length, but the error message references SearchConstraints.QueryMinLength and the handler passes query to the service. If QueryMinLength ever changes (or if whitespace-only input should be rejected), this validation won’t match the declared constraints.

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ANcpLua
ANcpLua merged commit 71957ee into main Aug 2, 2026
9 checks passed
@ANcpLua
ANcpLua deleted the agent/complete-backend-coverage branch August 2, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants