Skip to content

Commit c7f9a00

Browse files
committed
Refactor JSON comparison in collection and inverted index config tests for improved clarity and accuracy
1 parent acacdde commit c7f9a00

File tree

9 files changed

+912
-268
lines changed

9 files changed

+912
-268
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,3 @@ $RECYCLE.BIN/
486486
*.swp
487487

488488
.serena
489-
490-
src/Weaviate.Client.Tests/PublicApiApprovalTests.PublicApi_Should_Not_Change_Unexpectedly.approved.txt
491-
src/Weaviate.Client.Tests/PublicApiApprovalTests.PublicApi_Should_Not_Change_Unexpectedly.received.txt

docs/CONTRIBUTING.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Contributing to Weaviate C# Client
2+
3+
This document provides guidelines for contributing to the Weaviate C# client.
4+
5+
## Public API Tracking
6+
7+
This project uses [Microsoft.CodeAnalysis.PublicApiAnalyzers](https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md) to track changes to the public API surface. This ensures that breaking changes are intentional and reviewed.
8+
9+
### How It Works
10+
11+
The analyzer tracks public API members in two files located in `src/Weaviate.Client/`:
12+
13+
| File | Purpose |
14+
|------|---------|
15+
| `PublicAPI.Shipped.txt` | APIs that have been released in a published version |
16+
| `PublicAPI.Unshipped.txt` | APIs that are new/changed since the last release |
17+
18+
### When Adding New Public APIs
19+
20+
When you add a new public class, method, property, or other member, you'll see an **RS0016** warning at build time:
21+
22+
```
23+
warning RS0016: Symbol 'YourNewMethod' is not part of the declared public API
24+
```
25+
26+
**To fix this:**
27+
28+
1. Use the IDE quick-fix (lightbulb icon) to add the symbol to `PublicAPI.Unshipped.txt`
29+
2. Or run `dotnet format analyzers --diagnostics RS0016` to auto-fix all missing entries
30+
31+
### When Modifying or Removing Public APIs
32+
33+
If you change or remove a public API member, you'll see an **RS0017** warning:
34+
35+
```
36+
warning RS0017: Symbol 'OldMethod' is part of the declared API, but could not be found
37+
```
38+
39+
This is intentional - it alerts you to a potential **breaking change**. Before proceeding:
40+
41+
1. Consider if the change is backward-compatible
42+
2. If removing/changing is intentional, update the corresponding line in `PublicAPI.Unshipped.txt`
43+
3. Document the breaking change in the changelog
44+
45+
### Release Process
46+
47+
When preparing a release:
48+
49+
1. Review all entries in `PublicAPI.Unshipped.txt`
50+
2. Move the entries to `PublicAPI.Shipped.txt`
51+
3. Clear `PublicAPI.Unshipped.txt` (keeping only `#nullable enable`)
52+
53+
### Suppressed Warnings
54+
55+
The following analyzer warnings are currently suppressed in the project:
56+
57+
| Warning | Reason |
58+
|---------|--------|
59+
| RS0026 | Multiple overloads with optional parameters (API design advisory) |
60+
| RS0027 | Optional parameter ordering (API design advisory) |
61+
| RS0041 | Oblivious reference types (nullability advisory) |
62+
63+
These are design recommendations, not API tracking issues. They may be addressed in future refactoring efforts.
64+
65+
## Building the Project
66+
67+
```bash
68+
# Build the main library
69+
dotnet build src/Weaviate.Client/Weaviate.Client.csproj
70+
71+
# Build and run tests
72+
dotnet test src/Weaviate.Client.Tests/Weaviate.Client.Tests.csproj
73+
```
74+
75+
## Running Tests
76+
77+
The test project includes both unit tests and integration tests. Integration tests require a running Weaviate instance.
78+
79+
```bash
80+
# Run all tests
81+
dotnet test
82+
83+
# Run only unit tests
84+
dotnet test --filter "Category!=Integration"
85+
```

src/Weaviate.Client.Tests/PublicApiApprovalTests.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Weaviate.Client.Tests/Unit/TestCollection.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Text.Json;
2-
using System.Text.Json.JsonDiffPatch;
32
using System.Text.Json.Nodes;
43
using Weaviate.Client.Models;
54

@@ -522,9 +521,12 @@ public void Collection_Import_Export_Are_Equal()
522521
var expectedDoc = JsonNode.Parse(expectedJson);
523522
var actualDoc = JsonNode.Parse(actualJson);
524523

525-
var diff = expectedDoc.Diff(actualDoc);
524+
var eq = JsonNode.DeepEquals(expectedDoc, actualDoc);
526525

527-
Assert.True(diff == null, diff?.ToJsonString());
526+
Assert.True(
527+
eq,
528+
$"JSON structures differ:\nExpected:\n{JsonComparer.SortJsonNode(expectedDoc)}\n\nActual:\n{JsonComparer.SortJsonNode(actualDoc)}"
529+
);
528530
}
529531

530532
/// <summary>

src/Weaviate.Client.Tests/Unit/TestInvertedIndexConfig.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Text.Json.JsonDiffPatch;
21
using System.Text.Json.Nodes;
32
using Weaviate.Client.Models;
43
using Weaviate.Client.Rest;
@@ -349,8 +348,12 @@ public void Serialize_InvertedIndexConfig()
349348
);
350349

351350
// Assert
352-
var diff = expectedJson.Diff(json);
351+
// Parse as JsonElement for semantic comparison (ignoring property order)
352+
var eq = JsonNode.DeepEquals(expectedJson, json);
353353

354-
Assert.True(diff == null, diff?.ToJsonString());
354+
Assert.True(
355+
eq,
356+
$"JSON structures differ:\nExpected:\n{JsonComparer.SortJsonNode(expectedJson)}\n\nActual:\n{JsonComparer.SortJsonNode(json)}"
357+
);
355358
}
356359
}

src/Weaviate.Client.Tests/Weaviate.Client.Tests.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@
2020
<Using Include="Xunit" />
2121
</ItemGroup>
2222
<ItemGroup>
23-
<PackageReference Include="ApprovalTests" Version="7.0.0" />
2423
<PackageReference Include="coverlet.collector" Version="6.0.2">
2524
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2625
<PrivateAssets>all</PrivateAssets>
2726
</PackageReference>
2827
<PackageReference Include="dotenv.net" Version="4.0.0" />
2928
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
30-
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
3129
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
32-
<PackageReference Include="SystemTextJson.JsonDiffPatch" Version="2.0.0" />
33-
<PackageReference Include="xunit.v3" Version="3.2.0" />
30+
<PackageReference Include="xunit.v3" Version="3.2.1" />
3431
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
3532
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3633
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)