Skip to content

Support byte[] BSON binary and add tests#29

Merged
mrdevrobot merged 2 commits intomainfrom
27-source-generator-produces-empty-array-for-byte-properties-writebinary-is-never-called
Mar 31, 2026
Merged

Support byte[] BSON binary and add tests#29
mrdevrobot merged 2 commits intomainfrom
27-source-generator-produces-empty-array-for-byte-properties-writebinary-is-never-called

Conversation

@mrdevrobot
Copy link
Copy Markdown
Contributor

@mrdevrobot mrdevrobot commented Mar 31, 2026

  • Fix Dispose to also delete WAL sidecar file using DeleteFileIfExists helper
  • Fix BinaryProperty_PersistsAcrossReopen cleanup to also delete WAL file
  • Fix BinaryProperty_BLiteEngine_WritesBsonBinary_TypedReaderGetsBytes cleanup to also delete WAL file
  • Fix IsValidJson to dispose JsonDocument with using var to avoid pooled buffer leaks
  • Extract DeleteFileIfExists helper and use it consistently throughout all cleanup code

Add full byte[] (BSON Binary) support to the source generator and tests. Map byte[] to WriteBinary/ReadBinary in CodeGenerator, handle ReadBinary's ReadOnlySpan<byte> by calling .ToArray(), and add null handling for nullable byte[] properties. Exclude byte[] from being treated as a sequence in SyntaxHelper. Add BinaryEntity model and register the collection in TestDbContext, and introduce comprehensive BinaryPropertyTests covering round-trips, empty arrays, nullable fields, updates, persistence across reopen, large payloads, BLiteEngine (dynamic/BSON) interop, and JSON base64 behavior.
@mrdevrobot mrdevrobot self-assigned this Mar 31, 2026
@mrdevrobot mrdevrobot added the bug Something isn't working label Mar 31, 2026
Copilot AI review requested due to automatic review settings March 31, 2026 09:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end support for mapping byte[] properties to BSON Binary in the BLite source generator, with new tests that validate typed/dynamic round-trips and nullable handling.

Changes:

  • Extend source generator primitive handling to write/read byte[] as BSON Binary (including nullable cases).
  • Exclude byte[] from being treated as a generic collection/array during analysis.
  • Add BinaryEntity + BinaryEntities collection and a comprehensive BinaryPropertyTests suite.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/BLite.SourceGenerators/CodeGenerator.cs Adds byte[] primitive mapping to WriteBinary/ReadBinary and ensures binary reads materialize spans via ToArray().
src/BLite.SourceGenerators/Helpers/SyntaxHelper.cs Prevents byte[] from being classified as a collection type.
tests/BLite.Shared/MockEntities.cs Introduces BinaryEntity with required + optional binary fields for testing.
tests/BLite.Shared/TestDbContext.cs Registers BinaryEntities collection and maps BinaryEntity to binary_entities.
tests/BLite.Tests/BinaryPropertyTests.cs Adds extensive tests for byte[] persistence, updates, reopen durability, dynamic↔typed compatibility, and JSON caveats.

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

@mrdevrobot
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

@copilot apply changes based on the comments in this thread

Applied all four review suggestions in commit a466b22:

  • Dispose now deletes the .wal sidecar file via a new DeleteFileIfExists helper
  • BinaryProperty_PersistsAcrossReopen and BinaryProperty_BLiteEngine_WritesBsonBinary_TypedReaderGetsBytes both delete the .wal file at cleanup
  • All inline File.Exists/File.Delete calls replaced with DeleteFileIfExists for consistency
  • IsValidJson now uses using var _ = JsonDocument.Parse(json) to properly dispose the document and avoid pooled buffer leaks

@mrdevrobot mrdevrobot merged commit c90ecbe into main Mar 31, 2026
1 check passed
@mrdevrobot mrdevrobot deleted the 27-source-generator-produces-empty-array-for-byte-properties-writebinary-is-never-called branch March 31, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source Generator produces empty array for byte[] properties — WriteBinary is never called

3 participants