test(live): prove Write2 applies a value via supervisory advise on DEV (#212)
On the DEV gateway (wonder-app-vd03, 2b13564e), Write2 after
AdviseSupervisory applied the value to MESReceiver_025.MoveInBatchID
(0 -> 212212, OnWriteComplete Ok), and the value was restored to 0. After a
plain Advise, the same Write2 got SecurityError/1008, which is exactly what
the windev run saw. So that refusal came from the plain advise. It does not
show that windev has no writable attribute.
- Client.Tests: add the opt-in LiveGatewayWrite2Tests (gated by
LiveGatewayWriteFact: endpoint, key file and write item env vars). It runs
supervisory advise -> Write2 -> readback -> restore. The value test passed
live on vd03. The timestamp-parity test needs a second opt-in; it fails on
a non-UTC host until #228 is fixed.
- IntegrationTests: the windev Write2 smoke now uses AdviseSupervisory and
restores the original value. It has not been re-run on windev.
- GatewayTesting.md: document the env vars. code-reviews IntegrationTests-033:
correct the "no writable attribute" limit.
The run also found that the Write2 timestamp is read as host-local time
(stored +5 h on the UTC-5 box); filed as #228.
Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a test that writes to a real Galaxy attribute through a running gateway.
|
||||
/// The test is skipped unless an endpoint, an API key and a write item are all set,
|
||||
/// so it never runs (or writes) by accident. See <c>docs/GatewayTesting.md</c>, "Live gateway write".
|
||||
/// </summary>
|
||||
public sealed class LiveGatewayWriteFactAttribute : FactAttribute
|
||||
{
|
||||
/// <summary>Gateway gRPC endpoint, e.g. <c>http://host:5120</c>.</summary>
|
||||
public const string EndpointVariableName = "MXGATEWAY_LIVE_GATEWAY_ENDPOINT";
|
||||
|
||||
/// <summary>API key (<c>mxgw_<id>_<secret></c>). Prefer the file variant so the key stays out of the environment.</summary>
|
||||
public const string ApiKeyVariableName = "MXGATEWAY_LIVE_GATEWAY_API_KEY";
|
||||
|
||||
/// <summary>Path to a file holding the API key. Takes precedence over <see cref="ApiKeyVariableName"/>.</summary>
|
||||
public const string ApiKeyFileVariableName = "MXGATEWAY_LIVE_GATEWAY_API_KEY_FILE";
|
||||
|
||||
/// <summary>A writable, test-only Int32 attribute. It is written and then restored. No default on purpose.</summary>
|
||||
public const string WriteItemVariableName = "MXGATEWAY_LIVE_GATEWAY_WRITE_ITEM";
|
||||
|
||||
/// <summary>Set to <c>1</c> to also run the Write2 timestamp-parity test (fails on a non-UTC host until #228 is fixed).</summary>
|
||||
public const string AssertWrite2TimestampVariableName = "MXGATEWAY_LIVE_GATEWAY_ASSERT_WRITE2_TIMESTAMP";
|
||||
|
||||
/// <summary>Initializes the attribute, skipping unless the live gateway write variables are set.</summary>
|
||||
/// <param name="requireTimestampOptIn">When true, also require <see cref="AssertWrite2TimestampVariableName"/>=1.</param>
|
||||
public LiveGatewayWriteFactAttribute(bool requireTimestampOptIn = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EndpointVariableName))
|
||||
|| string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(WriteItemVariableName))
|
||||
|| (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ApiKeyVariableName))
|
||||
&& string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ApiKeyFileVariableName))))
|
||||
{
|
||||
Skip = $"Set {EndpointVariableName}, {WriteItemVariableName} and {ApiKeyFileVariableName} (or {ApiKeyVariableName}) to run live gateway write tests.";
|
||||
}
|
||||
else if (requireTimestampOptIn
|
||||
&& Environment.GetEnvironmentVariable(AssertWrite2TimestampVariableName) != "1")
|
||||
{
|
||||
Skip = $"Set {AssertWrite2TimestampVariableName}=1 to assert Write2 timestamp parity (mxaccessgw#228).";
|
||||
}
|
||||
}
|
||||
|
||||
internal static string Endpoint => Environment.GetEnvironmentVariable(EndpointVariableName)!;
|
||||
|
||||
internal static string WriteItem => Environment.GetEnvironmentVariable(WriteItemVariableName)!;
|
||||
|
||||
internal static string ApiKey
|
||||
{
|
||||
get
|
||||
{
|
||||
string? path = Environment.GetEnvironmentVariable(ApiKeyFileVariableName);
|
||||
return !string.IsNullOrWhiteSpace(path)
|
||||
? File.ReadAllText(path).Trim()
|
||||
: Environment.GetEnvironmentVariable(ApiKeyVariableName)!.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user