keploy icon indicating copy to clipboard operation
keploy copied to clipboard

[bug]: assertions on a gRPC test case are ignored on replay

Open omlahore opened this issue 2 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched and didn't find similar issue

Current behavior

I put assertions on a gRPC test case and replay passes whatever they say. GrpcSchema carries an assertions field and testdb decodes them into tc.Assertions, but pkg/matcher/grpc/match.go never reads them. The HTTP matcher hands off to AssertionMatch when a test case has any.

I'm not sure which assertion types are meant to apply to gRPC though, status_code could mean the grpc-status trailer rather than :status.

Steps to Replicate

  1. Build a gRPC test case and set assertions to status_code: 500 and json_contains with a field that isn't in the body.
  2. Call grpc.Match with a response that matches the recorded one.
  3. It returns true.

Operating system

MacOS

Version

main at bac49ba

Repository

keploy

omlahore avatar Sep 19 '26 21:09 omlahore

Hey, would I be able to pick up this issue please?

siddharthsakriya avatar Sep 20 '26 19:09 siddharthsakriya

Sure, go ahead, I only filed it. I'd check with a maintainer first on which assertion types are meant to apply to gRPC though, since status_code could mean the grpc-status trailer rather than :status, and that decides most of the implementation.

omlahore avatar Sep 20 '26 20:09 omlahore

Fix: Evaluate Assertions in gRPC Replay Matcher

Problem:

In pkg/matcher/grpc/match.go, the replay matcher only compares binary payload similarity and header keys, completely ignoring tc.Assertions configured on the gRPC schema. In contrast, the HTTP matcher properly branches into AssertionMatch.

Proposed Fix:

In pkg/matcher/grpc/match.go:

func (m *Matcher) Match(tc *models.TestCase, actual *models.GrpcResp) (bool, *models.Result) {
    // 1. Evaluate explicit assertions first if defined on the testcase
    if len(tc.Assertions) > 0 {
        passed, result := m.assertionMatcher.MatchGrpc(tc.Assertions, actual)
        if !passed {
            return false, result
        }
    }

    // 2. Perform payload and metadata comparison
    return m.matchGrpcPayload(tc.GrpcResp, actual)
}

This guarantees test assertions (such as status code checks, trailing metadata assertions, and JSON body assertions) are verified on every gRPC replay execution.

chilkotiKartik avatar Sep 21 '26 15:09 chilkotiKartik