Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **`read_backups` RBAC action** ([#377](https://github.com/weaviate/weaviate-csharp-client/issues/377)): `Permissions.Backups.Read`. Setting it requires Weaviate ≥ 1.39.10; listing roles that carry it no longer fails.
- **Backup role and user selection**: `BackupCreateRequest.IncludeRoles` and `IncludeUsers`, with `*` and `?` wildcards. Null backs up all, empty backs up none. Requires Weaviate ≥ 1.40.0.
- **Per-replica shard status**: `ShardInfo.PerNodeStatus`, null on servers before 1.40.

### Fixed

- **Shard statuses from newer servers threw**: `ShardStatus` gains `Loading`, `LazyLoading`, `Shutdown`, `Unavailable` and `Recovering`. An unrecognized status now maps to `Unknown`.

### Changed

- REST DTOs regenerated from the Weaviate v1.40.2 OpenAPI spec.
- **`BackupCreateRequest` gained two trailing optional parameters**: its primary constructor and `Deconstruct` went from seven parameters to nine, so seven-element positional deconstruction no longer compiles and callers built against 1.2.x must recompile.

---

## [1.2.0] — 2026-08-21
Expand Down
27 changes: 27 additions & 0 deletions src/Weaviate.Client.Tests/Integration/TestBackups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,33 @@ await article.Data.Insert(
Assert.Equal(4, after.Objects.Count);
}

/// <summary>
/// Tests that a backup accepts empty role and user selections (Weaviate 1.40+)
/// </summary>
[Fact]
public async Task Test_Create_Backup_With_Include_Roles_And_Users()
{
RequireVersion("1.40.0");
var backupId = Helpers.GenerateUniqueIdentifier("bkp_rbac_select");

var article = await CollectionFactory(
name: "ArticleRbacSelect",
properties: [Property.Text("title")]
);

var created = await _weaviate.Backup.CreateSync(
new BackupCreateRequest(
backupId,
_backend,
IncludeCollections: new[] { article.Name },
IncludeRoles: Array.Empty<string>(),
IncludeUsers: Array.Empty<string>()
),
cancellationToken: TestContext.Current.CancellationToken
);
Assert.Equal(BackupStatus.Success, created.Status);
}

/// <summary>
/// Tests that test fail backup on non existing collection
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Weaviate.Client.Tests/Integration/TestCollectionShards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public async Task Test_Should_Get_Collection_Shards()
Assert.NotEmpty(shard.Name);
// Status is an enum, so it always has a value
Assert.True(Enum.IsDefined(typeof(ShardStatus), shard.Status));
if (ServerVersionIsInRange("1.40.0"))
{
Assert.NotNull(shard.PerNodeStatus);
Assert.NotEmpty(shard.PerNodeStatus);
}
}
);
}
Expand Down
39 changes: 39 additions & 0 deletions src/Weaviate.Client.Tests/Integration/TestRbacRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public async Task ListRoles()
var roles = (await _weaviate.Roles.ListAll(TestContext.Current.CancellationToken)).ToList();
Assert.NotEmpty(roles);
Assert.Contains(roles, r => r.Name == "viewer");

if (ServerVersionIsInRange("1.39.10"))
{
var viewer = roles.Single(r => r.Name == "viewer");
Assert.Contains(viewer.Permissions, p => p is Permissions.Backups { Read: true });
}
}

/// <summary>
Expand Down Expand Up @@ -614,4 +620,37 @@ [new Permissions.Namespaces("*") { Manage = true }],
await _weaviate.Roles.Delete(roleName, TestContext.Current.CancellationToken);
}
}

/// <summary>
/// Tests that create role with backups read permission round trips (Weaviate 1.39.10+)
/// </summary>
[Fact]
public async Task CreateRoleWithBackupsReadPermission()
{
RequireVersion("1.39.10");
var roleName = MakeRoleName("backups-read");
try
{
await _weaviate.Roles.Delete(roleName, TestContext.Current.CancellationToken);
await _weaviate.Roles.Create(
roleName,
[new Permissions.Backups("Article") { Read = true }],
TestContext.Current.CancellationToken
);

var fetched = await _weaviate.Roles.Get(
roleName,
TestContext.Current.CancellationToken
);
Assert.NotNull(fetched);
var scope = Assert.IsType<Permissions.Backups>(fetched!.Permissions.Single());
Assert.True(scope.Read);
Assert.False(scope.Manage);
Assert.Equal("Article", scope.Resource.Collection);
}
finally
{
await _weaviate.Roles.Delete(roleName, TestContext.Current.CancellationToken);
}
}
}
26 changes: 26 additions & 0 deletions src/Weaviate.Client.Tests/Unit/PermissionsScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,31 @@ public void Backups_Aggregates_ManageBackupsOnly()
Assert.True(backups[0].Manage);
}

/// <summary>
/// Tests that backups read and manage round trip through the dto (read_backups: Weaviate 1.39.10+)
/// </summary>
[Fact]
public void Backups_ToDto_RoundTrips()
{
var scope = new Permissions.Backups("Article") { Read = true, Manage = true };

var dtos = scope.ToDto().ToList();

Assert.Equal(
[
Weaviate.Client.Rest.Dto.PermissionAction.Read_backups,
Weaviate.Client.Rest.Dto.PermissionAction.Manage_backups,
],
dtos.Select(d => d.Action)
);

var parsed = Assert.Single(Permissions.Backups.Parse(dtos));
var roundTripped = Assert.IsType<Permissions.Backups>(parsed);
Assert.True(roundTripped.Read);
Assert.True(roundTripped.Manage);
Assert.Equal("Article", roundTripped.Resource.Collection);
}

/// <summary>
/// Tests that namespaces aggregates manage namespaces only (Weaviate 1.38+)
/// </summary>
Expand Down Expand Up @@ -458,6 +483,7 @@ public void AllPermissionActions_AreMentioned()
// List of actions covered by tests
var testedActions = new HashSet<string>
{
"Read_backups",
"Manage_backups",
"Manage_namespaces",
"Read_cluster",
Expand Down
19 changes: 19 additions & 0 deletions src/Weaviate.Client.Tests/Unit/RbacTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,23 @@ public async Task RolesClient_MapsPermissions()
r => r.Name == "reader" && r.Permissions.Any(p => p is Permissions.Roles { Read: true })
);
}

/// <summary>
/// Sending read_backups to a server before 1.39.10 is refused client-side.
/// </summary>
[Fact]
public async Task RolesClient_Create_WithBackupsRead_ThrowsOnOlderServer()
{
var (client, _) = MockWeaviateClient.CreateWithMockHandler(serverVersion: "1.39.0");

var exception = await Assert.ThrowsAsync<WeaviateVersionMismatchException>(() =>
client.Roles.Create(
"backup-reader",
[new Permissions.Backups("*") { Read = true }],
TestContext.Current.CancellationToken
)
);

Assert.Equal(new Version(1, 39, 10), exception.RequiredVersion);
}
}
58 changes: 58 additions & 0 deletions src/Weaviate.Client.Tests/Unit/TestBackupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,64 @@ await client.Backup.Create(
Assert.Equal(new Version(1, 36, 0), exception.ActualVersion);
}

/// <summary>
/// Omitted IncludeRoles/IncludeUsers back up everything, so the keys must stay off the wire;
/// an empty list means none and must be sent as <c>[]</c>.
/// </summary>
[Fact]
public async Task Create_SendsIncludeRolesAndUsers_OnlyWhenSet()
{
var (client, handler) = CreateBackupClient("1.40.0");

await client.Backup.Create(
new BackupCreateRequest("my-backup", new FilesystemBackend("/backups")),
TestContext.Current.CancellationToken
);
var unset = await handler.LastRequest!.Content!.ReadAsStringAsync(
TestContext.Current.CancellationToken
);

await client.Backup.Create(
new BackupCreateRequest(
"my-backup",
new FilesystemBackend("/backups"),
IncludeRoles: Array.Empty<string>(),
IncludeUsers: "app-*"
),
TestContext.Current.CancellationToken
);
var set = await handler.LastRequest!.Content!.ReadAsStringAsync(
TestContext.Current.CancellationToken
);

Assert.DoesNotContain("includeRoles", unset);
Assert.DoesNotContain("includeUsers", unset);
Assert.Contains("\"includeRoles\":[]", set);
Assert.Contains("\"includeUsers\":[\"app-*\"]", set);
}

/// <summary>
/// Selecting roles or users is refused below 1.40.0 rather than silently backing up all of them.
/// </summary>
[Fact]
public async Task Create_Throws_WhenIncludeRolesRequestedOnOlderServer()
{
var (client, _) = CreateBackupClient("1.39.0");

var exception = await Assert.ThrowsAsync<WeaviateVersionMismatchException>(async () =>
await client.Backup.Create(
new BackupCreateRequest(
"my-backup",
new FilesystemBackend("/backups"),
IncludeRoles: Array.Empty<string>()
),
TestContext.Current.CancellationToken
)
);

Assert.Equal(new Version(1, 40, 0), exception.RequiredVersion);
}

/// <summary>
/// List() parsed Size and the incremental base id and then dropped both; they must survive
/// onto the model, and be null rather than empty when the server omits them.
Expand Down
64 changes: 64 additions & 0 deletions src/Weaviate.Client.Tests/Unit/TestShardStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Net;
using Weaviate.Client.Models;
using Weaviate.Client.Tests.Unit.Mocks;

namespace Weaviate.Client.Tests.Unit;

/// <summary>
/// Unit tests for shard status parsing and the shards endpoint mapping.
/// </summary>
public class TestShardStatus
{
/// <summary>
/// Every status core 1.40 reports parses, and an unrecognized one maps to Unknown instead of throwing.
/// </summary>
[Theory]
[InlineData("READY", ShardStatus.Ready)]
[InlineData("READONLY", ShardStatus.ReadOnly)]
[InlineData("INDEXING", ShardStatus.Indexing)]
[InlineData("LOADING", ShardStatus.Loading)]
[InlineData("LAZY_LOADING", ShardStatus.LazyLoading)]
[InlineData("SHUTDOWN", ShardStatus.Shutdown)]
[InlineData("UNAVAILABLE", ShardStatus.Unavailable)]
[InlineData("RECOVERING", ShardStatus.Recovering)]
[InlineData("SOMETHING_NEW", ShardStatus.Unknown)]
[InlineData(null, ShardStatus.Ready)]
public void ParseStatus_MapsWireValue(string? value, ShardStatus expected)
{
Assert.Equal(expected, ShardStatusExtensions.ParseStatus(value));
}

/// <summary>
/// GetShards surfaces per_node_status, and leaves it null when an older server omits it.
/// </summary>
[Fact]
public async Task GetShards_MapsPerNodeStatus()
{
var json = """
[
{"name":"s1","status":"READY","vectorQueueSize":0,"per_node_status":{"node1":"READY","node2":"LOADING"}},
{"name":"s2","status":"READY","vectorQueueSize":0}
]
""";
var (client, _) = MockWeaviateClient.CreateWithMockHandler(
syncHandler: _ => new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"),
}
);

var shards = await client
.Collections.Use("Article")
.Config.GetShards(TestContext.Current.CancellationToken);

Assert.Equal(
new Dictionary<string, ShardStatus>
{
["node1"] = ShardStatus.Ready,
["node2"] = ShardStatus.Loading,
},
shards[0].PerNodeStatus
);
Assert.Null(shards[1].PerNodeStatus);
}
}
44 changes: 22 additions & 22 deletions src/Weaviate.Client/BackupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ public async Task<BackupCreateOperation> Create(
CancellationToken cancellationToken = default
)
{
await EnsureIncrementalBackupSupported(request);
await EnsureFieldSupported(
!string.IsNullOrEmpty(request.IncrementalBaseBackupId),
nameof(BackupCreateRequest.IncrementalBaseBackupId),
IncrementalBackupMinimumVersion
);
await EnsureFieldSupported(
request.IncludeRoles is not null || request.IncludeUsers is not null,
request.IncludeRoles is not null
? nameof(BackupCreateRequest.IncludeRoles)
: nameof(BackupCreateRequest.IncludeUsers),
RbacSelectionMinimumVersion
);

var restRequest = BuildBackupCreateRequest(request);
var response = await _client.RestClient.BackupCreate(
Expand Down Expand Up @@ -92,36 +103,23 @@ public async Task<Backup> CreateSync(
/// is older (1.34.18). Gate on the documented floor, as the python client does.
/// </summary>
private static readonly Version IncrementalBackupMinimumVersion = new(1, 37, 0);
private static readonly Version RbacSelectionMinimumVersion = new(1, 40, 0);

/// <summary>
/// Throws <see cref="WeaviateVersionMismatchException"/> when the request asks for an
/// incremental backup and the connected server predates support for it. Gated on the field
/// rather than on the whole operation, because plain backups still work on older servers.
/// Throws <see cref="WeaviateVersionMismatchException"/> when a request field is set and the
/// connected server predates it. Gated on the field rather than on the whole operation,
/// because plain backups still work on older servers. An unknown server version passes.
/// </summary>
/// <param name="request">The request</param>
/// <exception cref="WeaviateVersionMismatchException">
/// Thrown when <see cref="BackupCreateRequest.IncrementalBaseBackupId"/> is set and the
/// connected server version is below 1.37.0.
/// </exception>
private async Task EnsureIncrementalBackupSupported(BackupCreateRequest request)
private async Task EnsureFieldSupported(bool isSet, string field, Version minimumVersion)
{
if (string.IsNullOrEmpty(request.IncrementalBaseBackupId))
if (!isSet)
return;

await _client.EnsureInitializedAsync();

var serverVersion = _client.WeaviateVersion;
if (serverVersion is null)
return;

if (serverVersion < IncrementalBackupMinimumVersion)
{
throw new WeaviateVersionMismatchException(
nameof(BackupCreateRequest.IncrementalBaseBackupId),
IncrementalBackupMinimumVersion,
serverVersion
);
}
if (serverVersion is not null && serverVersion < minimumVersion)
throw new WeaviateVersionMismatchException(field, minimumVersion, serverVersion);
}

/// <summary>
Expand All @@ -141,6 +139,8 @@ private Rest.Dto.BackupCreateRequest BuildBackupCreateRequest(BackupCreateReques
Include = request.IncludeCollections?.ToList(),
Exclude = request.ExcludeCollections?.ToList(),
Incremental_base_backup_id = request.IncrementalBaseBackupId,
IncludeRoles = request.IncludeRoles?.ToList(),
IncludeUsers = request.IncludeUsers?.ToList(),
Config = new Rest.Dto.BackupConfig
{
Bucket = bucket,
Expand Down
Loading
Loading