Add bulk read/write CLI subcommands and e2e matrix coverage
The previous commit added the bulk read/write library surface in every
client; this commit makes that surface reachable from each client's CLI
and exercises it through scripts/run-client-e2e-tests.ps1.
Five new subcommands in every client CLI (.NET / Go / Rust / Python /
Java): read-bulk, write-bulk, write2-bulk, write-secured-bulk, and
write-secured2-bulk. Each follows the existing subscribe-bulk shape:
- read-bulk takes --server-handle, --items <csv tag list>, and
--timeout-ms (0 = worker default). JSON output carries the
BulkReadResult fields, including was_cached so the e2e matrix can
verify the cached-path semantics.
- The four bulk-write families take --server-handle, --item-handles
<csv>, --type, --values <csv>. write2-bulk and write-secured2-bulk
add a single --timestamp applied to every entry; the secured
variants take --current-user-id and --verifier-user-id. All four
output BulkWriteResult JSON.
A new -SkipReadWriteBulk switch on the matrix script (default OFF)
controls two new e2e phases:
- After the existing subscribe-bulk phase leaves tags advised, the
script runs read-bulk against the same tag list and asserts most
results return was_cached = true. This is the only e2e coverage of
the cache-then-snapshot fork — the unit + gateway tests verify the
semantics with a fake worker, but only the live cross-language
matrix proves the cache populates from real OnDataChange events and
survives the round-trip through every client''s JSON parser.
- When -VerifyWrite is set, the write phase now also runs a single-
entry write-bulk against the same writable item handle (using a
distinct sentinel value) and asserts a per-entry success. Confirms
the BulkWriteResult wire format end-to-end without complicating
the OnWriteComplete echo assertion the single-item phase already
verifies.
Dry-run validation passes for all five clients: each emits the correct
read-bulk and write-bulk CLI invocations with the right flags.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,16 @@ public static class MxGatewayClientCli
|
||||
.ConfigureAwait(false),
|
||||
"unsubscribe-bulk" => await UnsubscribeBulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"read-bulk" => await ReadBulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"write-bulk" => await WriteBulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"write2-bulk" => await Write2BulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"write-secured-bulk" => await WriteSecuredBulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"write-secured2-bulk" => await WriteSecured2BulkAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"stream-events" => await StreamEventsAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
.ConfigureAwait(false),
|
||||
"write" => await WriteAsync(arguments, client, standardOutput, cancellation.Token)
|
||||
@@ -386,6 +396,220 @@ public static class MxGatewayClientCli
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private static Task<int> ReadBulkAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
TextWriter output,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ReadBulkCommand command = new()
|
||||
{
|
||||
ServerHandle = arguments.GetInt32("server-handle"),
|
||||
TimeoutMs = (uint)arguments.GetInt32("timeout-ms", 0),
|
||||
};
|
||||
command.TagAddresses.Add(ParseStringList(arguments.GetRequired("items")));
|
||||
|
||||
return InvokeAndWriteAsync(
|
||||
arguments,
|
||||
client,
|
||||
output,
|
||||
new MxCommand
|
||||
{
|
||||
Kind = MxCommandKind.ReadBulk,
|
||||
ReadBulk = command,
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private static Task<int> WriteBulkAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
TextWriter output,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
WriteBulkCommand command = new()
|
||||
{
|
||||
ServerHandle = arguments.GetInt32("server-handle"),
|
||||
};
|
||||
|
||||
IReadOnlyList<int> handles = ParseInt32List(arguments.GetRequired("item-handles"));
|
||||
IReadOnlyList<MxValue> values = ParseValuesList(arguments);
|
||||
int userId = arguments.GetInt32("user-id", 0);
|
||||
EnsureSameLength(handles.Count, values.Count);
|
||||
|
||||
for (int i = 0; i < handles.Count; i++)
|
||||
{
|
||||
command.Entries.Add(new WriteBulkEntry
|
||||
{
|
||||
ItemHandle = handles[i],
|
||||
Value = values[i],
|
||||
UserId = userId,
|
||||
});
|
||||
}
|
||||
|
||||
return InvokeAndWriteAsync(
|
||||
arguments,
|
||||
client,
|
||||
output,
|
||||
new MxCommand
|
||||
{
|
||||
Kind = MxCommandKind.WriteBulk,
|
||||
WriteBulk = command,
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private static Task<int> Write2BulkAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
TextWriter output,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Write2BulkCommand command = new()
|
||||
{
|
||||
ServerHandle = arguments.GetInt32("server-handle"),
|
||||
};
|
||||
|
||||
IReadOnlyList<int> handles = ParseInt32List(arguments.GetRequired("item-handles"));
|
||||
IReadOnlyList<MxValue> values = ParseValuesList(arguments);
|
||||
MxValue timestampValue = ParseTimestampValue(arguments);
|
||||
int userId = arguments.GetInt32("user-id", 0);
|
||||
EnsureSameLength(handles.Count, values.Count);
|
||||
|
||||
for (int i = 0; i < handles.Count; i++)
|
||||
{
|
||||
command.Entries.Add(new Write2BulkEntry
|
||||
{
|
||||
ItemHandle = handles[i],
|
||||
Value = values[i],
|
||||
TimestampValue = timestampValue,
|
||||
UserId = userId,
|
||||
});
|
||||
}
|
||||
|
||||
return InvokeAndWriteAsync(
|
||||
arguments,
|
||||
client,
|
||||
output,
|
||||
new MxCommand
|
||||
{
|
||||
Kind = MxCommandKind.Write2Bulk,
|
||||
Write2Bulk = command,
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private static Task<int> WriteSecuredBulkAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
TextWriter output,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
WriteSecuredBulkCommand command = new()
|
||||
{
|
||||
ServerHandle = arguments.GetInt32("server-handle"),
|
||||
};
|
||||
|
||||
IReadOnlyList<int> handles = ParseInt32List(arguments.GetRequired("item-handles"));
|
||||
IReadOnlyList<MxValue> values = ParseValuesList(arguments);
|
||||
int currentUserId = arguments.GetInt32("current-user-id");
|
||||
int verifierUserId = arguments.GetInt32("verifier-user-id", 0);
|
||||
EnsureSameLength(handles.Count, values.Count);
|
||||
|
||||
for (int i = 0; i < handles.Count; i++)
|
||||
{
|
||||
command.Entries.Add(new WriteSecuredBulkEntry
|
||||
{
|
||||
ItemHandle = handles[i],
|
||||
Value = values[i],
|
||||
CurrentUserId = currentUserId,
|
||||
VerifierUserId = verifierUserId,
|
||||
});
|
||||
}
|
||||
|
||||
return InvokeAndWriteAsync(
|
||||
arguments,
|
||||
client,
|
||||
output,
|
||||
new MxCommand
|
||||
{
|
||||
Kind = MxCommandKind.WriteSecuredBulk,
|
||||
WriteSecuredBulk = command,
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private static Task<int> WriteSecured2BulkAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
TextWriter output,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
WriteSecured2BulkCommand command = new()
|
||||
{
|
||||
ServerHandle = arguments.GetInt32("server-handle"),
|
||||
};
|
||||
|
||||
IReadOnlyList<int> handles = ParseInt32List(arguments.GetRequired("item-handles"));
|
||||
IReadOnlyList<MxValue> values = ParseValuesList(arguments);
|
||||
MxValue timestampValue = ParseTimestampValue(arguments);
|
||||
int currentUserId = arguments.GetInt32("current-user-id");
|
||||
int verifierUserId = arguments.GetInt32("verifier-user-id", 0);
|
||||
EnsureSameLength(handles.Count, values.Count);
|
||||
|
||||
for (int i = 0; i < handles.Count; i++)
|
||||
{
|
||||
command.Entries.Add(new WriteSecured2BulkEntry
|
||||
{
|
||||
ItemHandle = handles[i],
|
||||
Value = values[i],
|
||||
TimestampValue = timestampValue,
|
||||
CurrentUserId = currentUserId,
|
||||
VerifierUserId = verifierUserId,
|
||||
});
|
||||
}
|
||||
|
||||
return InvokeAndWriteAsync(
|
||||
arguments,
|
||||
client,
|
||||
output,
|
||||
new MxCommand
|
||||
{
|
||||
Kind = MxCommandKind.WriteSecured2Bulk,
|
||||
WriteSecured2Bulk = command,
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the bulk-write CLI's <c>--values</c> list. All entries share
|
||||
/// the single <c>--type</c> argument; the comma-separated values are
|
||||
/// each parsed via <see cref="ParseValue"/> on a per-entry basis. This
|
||||
/// keeps the CLI simple for e2e use (one type, N values) — callers
|
||||
/// that need heterogeneous types per entry should drive the library
|
||||
/// directly.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<MxValue> ParseValuesList(CliArguments arguments)
|
||||
{
|
||||
string type = arguments.GetRequired("type");
|
||||
string[] values = ParseStringList(arguments.GetRequired("values")).ToArray();
|
||||
MxValue[] result = new MxValue[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
result[i] = ParseValue(type, values[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void EnsureSameLength(int handles, int values)
|
||||
{
|
||||
if (handles != values)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Bulk write requires the same number of --item-handles ({handles}) and --values ({values}).");
|
||||
}
|
||||
}
|
||||
|
||||
private static Task<int> WriteAsync(
|
||||
CliArguments arguments,
|
||||
IMxGatewayCliClient client,
|
||||
@@ -772,8 +996,12 @@ public static class MxGatewayClientCli
|
||||
|
||||
private static MxValue ParseValue(CliArguments arguments)
|
||||
{
|
||||
string type = arguments.GetRequired("type").ToLowerInvariant();
|
||||
string value = arguments.GetRequired("value");
|
||||
return ParseValue(arguments.GetRequired("type"), arguments.GetRequired("value"));
|
||||
}
|
||||
|
||||
private static MxValue ParseValue(string typeName, string value)
|
||||
{
|
||||
string type = typeName.ToLowerInvariant();
|
||||
string[] values = value.Split(',', StringSplitOptions.TrimEntries);
|
||||
|
||||
return type switch
|
||||
|
||||
Reference in New Issue
Block a user