fix(CLI-37,CLI-38): make status/HRESULT reply validation conformant across all five clients
One cross-client conformance pass; also closes first-cycle CLI-08. CLI-37: an MxStatusProxy entry is a failure iff `category != MX_STATUS_CATEGORY_OK`. The proto contract has always said so — `success` is the raw 16-bit COM member carried verbatim for diagnostics, not a boolean — but four clients branched on `success` alone and .NET required both, so the same gateway reply produced opposite verdicts per language. An absent entry stays success; a present entry with an UNSPECIFIED category is a failure, because the worker always maps a category and an unmapped one is not proven OK. CLI-38: a reply fails on HRESULT iff `hresult` is present and negative, so positive COM success codes such as S_FALSE (1) pass. .NET/Go/Java used `!= 0`, which errored on a parity-preserving S_FALSE that Python and Rust accepted. This makes the existing ClientLibrariesDesign.md claim true rather than rewriting the doc to describe the divergence. Four shared fixtures pin both rules cross-client, and each language suite also carries a table test for the two edges a fixture cannot express (absent entry, UNSPECIFIED category). A Java test fake that built a status with a bare `setSuccess(1)` and no category is fixed — under the category rule that reply was never a success.
This commit is contained in:
@@ -48,6 +48,89 @@ func TestGeneratedGoldenFixturesParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCommandReplyValidationFixtures locks the shared reply-validation rules to
|
||||
// the behavior fixtures: a status entry fails iff its category is not OK (the
|
||||
// raw success member is diagnostics only), and an HRESULT fails iff it is
|
||||
// present and negative (S_FALSE and other positive COM success codes pass).
|
||||
func TestCommandReplyValidationFixtures(t *testing.T) {
|
||||
tests := []struct {
|
||||
fixture string
|
||||
wantFailure bool
|
||||
}{
|
||||
{fixture: "register.ok.reply.json", wantFailure: false},
|
||||
{fixture: "write.mxaccess-failure.reply.json", wantFailure: true},
|
||||
{fixture: "write.status-category-error-success-set.reply.json", wantFailure: true},
|
||||
{fixture: "write.status-category-ok-success-zero.reply.json", wantFailure: false},
|
||||
{fixture: "write.hresult-s-false.reply.json", wantFailure: false},
|
||||
{fixture: "write.hresult-e-fail.reply.json", wantFailure: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.fixture, func(t *testing.T) {
|
||||
data, err := os.ReadFile(filepath.Join(
|
||||
"..", "..", "proto", "fixtures", "behavior", "command-replies", tt.fixture))
|
||||
if err != nil {
|
||||
t.Fatalf("read fixture: %v", err)
|
||||
}
|
||||
|
||||
var reply pb.MxCommandReply
|
||||
if err := protojson.Unmarshal(data, &reply); err != nil {
|
||||
t.Fatalf("parse fixture: %v", err)
|
||||
}
|
||||
|
||||
err = EnsureMxAccessSuccess("invoke", &reply)
|
||||
if got := err != nil; got != tt.wantFailure {
|
||||
t.Fatalf("EnsureMxAccessSuccess() failed = %v (err %v), want %v", got, err, tt.wantFailure)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusSucceededBranchesOnCategory pins the per-entry rule directly,
|
||||
// including the two edges the fixtures cannot express: a nil entry is success
|
||||
// and a present entry with an unspecified category is a failure.
|
||||
func TestStatusSucceededBranchesOnCategory(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
status *MxStatusProxy
|
||||
want bool
|
||||
}{
|
||||
{name: "nil entry", status: nil, want: true},
|
||||
{
|
||||
name: "ok category with zero success",
|
||||
status: &pb.MxStatusProxy{
|
||||
Success: 0,
|
||||
Category: pb.MxStatusCategory_MX_STATUS_CATEGORY_OK,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "error category with success set",
|
||||
status: &pb.MxStatusProxy{
|
||||
Success: 1,
|
||||
Category: pb.MxStatusCategory_MX_STATUS_CATEGORY_COMMUNICATION_ERROR,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "unspecified category with success set",
|
||||
status: &pb.MxStatusProxy{
|
||||
Success: 1,
|
||||
Category: pb.MxStatusCategory_MX_STATUS_CATEGORY_UNSPECIFIED,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := StatusSucceeded(tt.status); got != tt.want {
|
||||
t.Fatalf("StatusSucceeded() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenSessionFixtureProtocolVersions(t *testing.T) {
|
||||
data, err := os.ReadFile(filepath.Join("..", "..", "proto", "fixtures", "golden", "open-session-reply.ok.json"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user