pact-js icon indicating copy to clipboard operation
pact-js copied to clipboard

Regression in beta.58 for query generators

Open wabrit opened this issue 2 years ago • 23 comments

Software versions

Please provide at least OS and version of pact-js

  • OS: Windows 10 Enterprise
  • Consumer Pact library: @pact-foundation/pact 10.0.0-beta.58
  • Provider Pact library: n/a
  • Node Version: `v16.3.2

Expected behaviour

With this contract:

    provider
        .given('fooByIds')
        .uponReceiving('a request for existing Foo by id')
        .withRequest({
          method: 'GET',
          path: '/foo',
          query: {
            id: fromProviderState('${id}', '1')
          }
        })
        .willRespondWith({
          ...
        })

I would expect to see (as output by e.g. beta51)

"request": {
        "generators": {
          "query": {
            "id": {
              "expression": "${id}",
              "type": "ProviderState"
            }
          }
        },

Actual behaviour

With beta.58 we get an output pact:

"request": {
        "generators": {
          "query": {
            "$.id[0]": {
              "expression": "${id}",
              "type": "ProviderState"
            }
          }
        },

The key under query is now $.id[0] instead of just id, which causes the provider verification to fail.

wabrit avatar May 25 '22 08:05 wabrit

Thanks for raising this.

mefellows avatar May 25 '22 10:05 mefellows

@rholshausen do you know if there has been any recent activity on the Rust side that may have addressed this? Should we look to create an issue there / migrate this one?

mefellows avatar Jul 07 '22 13:07 mefellows

Is it forcing the output to V2 format?

rholshausen avatar Jul 07 '22 23:07 rholshausen

@wabrit any chance you could please share the whole pact file or your consumer code (or both, preferably)?

mefellows avatar Jul 29 '22 11:07 mefellows

Hi @mefellows do you mean the generated json file?

wabrit avatar Aug 01 '22 09:08 wabrit

Yes please! Also any relevant code snippets.

mefellows avatar Aug 01 '22 09:08 mefellows

Apologies for the delay, but I wanted to strip our "real" examples down to the bare essentials necessary to demonstrate the issue:

Here's a simple contract (minus the actual test): note the presence of a single REST query parameter activeOnly whose value is expressed as provider state.

import { MatchersV3, PactV3 } from '@pact-foundation/pact';
import path from 'path';
const { fromProviderState, integer } = MatchersV3;

const provider = new PactV3({
  dir: path.resolve(process.cwd(), 'pacts'),
  consumer: 'foo',
  provider: 'bar'
});


provider
  .given('FooBar')
  .uponReceiving('a request')
  .withRequest({
    method: 'GET',
    path: '/bar',
    query: {
      activeOnly: fromProviderState('${activeOnly}', 'true')
    },
    headers: { Accept: 'application/json' }
  })
  .willRespondWith({
    status: 200,
    headers: { 'Content-Type': 'application/json' },
    body: {
      id: integer(6),
      version: integer(0),
    }
  });

And here is the generated JSON pact. Note the expression $.activeOnly[0] in the generators, which is where I believe the problem lies for the provider. I believe previously this would have been just activeOnly.

The same expression occurs in the matching rules, but AFAIK that has not caused issues on the provider side.

{
  "consumer": {
    "name": "foo"
  },
  "interactions": [
    {
      "description": "a request",
      "providerStates": [
        {
          "name": "FooBar"
        }
      ],
      "request": {
        "generators": {
          "query": {
            "$.activeOnly[0]": {
              "expression": "${activeOnly}",
              "type": "ProviderState"
            }
          }
        },
        "headers": {
          "Accept": "application/json"
        },
        "matchingRules": {
          "header": {},
          "query": {
            "$.activeOnly[0]": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            }
          }
        },
        "method": "GET",
        "path": "/bar",
        "query": {
          "activeOnly": [
            "true"
          ]
        }
      },
      "response": {
        "body": {
          "id": 6,
          "version": 0
        },
        "headers": {
          "Content-Type": "application/json"
        },
        "matchingRules": {
          "body": {
            "$.id": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            },
            "$.version": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            }
          },
          "header": {}
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-js": {
      "version": "10.0.0-beta.58"
    },
    "pactRust": {
      "ffi": "0.2.2",
      "mockserver": "0.8.7",
      "models": "0.2.7"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "bar"
  }
}

wabrit avatar Aug 02 '22 08:08 wabrit

I updated my version from 10.0.0-beta.54 to 10.1.4 (latest one) and I'm also facing this issue now. Any idea of when a fix will be done?

PS: I tested with all the versions and I think it is happening since version 10.0.0-beta.55

dianaDBB avatar Sep 22 '22 15:09 dianaDBB

Any update on this issue?

I'm sorry for being so pushy, but this is blocking me to update the node version (from 16 to 19). Something that I really need to do :(

dianaDBB avatar Jan 24 '23 14:01 dianaDBB

Any update on this issue?

No, sorry.

I'm sorry for being so pushy, but this is blocking me to update the node version (from 16 to 19). Something that I really need to do :(

Why is the node version update tied to a Pact library upgrade?

mefellows avatar Jan 25 '23 04:01 mefellows

Why is the node version update tied to a Pact library upgrade?

Hi,

I cannot update to node 19 because this specific Pact release (10.0.0-beta.54) does not exists for node 19 (v111):

npm ERR! code 127
npm ERR! path /.../node_modules/@pact-foundation/pact
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build=false || neon build --release
npm ERR! response status 404 Not Found on https://github.com/pact-foundation/pact-js/releases/download/v10.0.0-beta.54/node-v111-linux-x64-glibc.tar.gz
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using [email protected]
npm ERR! node-pre-gyp info using [email protected] | linux | x64
npm ERR! node-pre-gyp info check checked for "/.../node_modules/@pact-foundation/pact/native/index.node" (not found)
npm ERR! node-pre-gyp http GET https://github.com/pact-foundation/pact-js/releases/download/v10.0.0-beta.54/node-v111-linux-x64-glibc.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/pact-foundation/pact-js/releases/download/v10.0.0-beta.54/node-v111-linux-x64-glibc.tar.gz 
npm ERR! node-pre-gyp ERR! install error 
npm ERR! node-pre-gyp ERR! stack Error: response status 404 Not Found on https://github.com/pact-foundation/pact-js/releases/download/v10.0.0-beta.54/node-v111-linux-x64-glibc.tar.gz
npm ERR! node-pre-gyp ERR! stack     at /.../node_modules/@mapbox/node-pre-gyp/lib/install.js:67:15
npm ERR! node-pre-gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
npm ERR! node-pre-gyp ERR! System Linux 5.4.0-131-generic
npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/.../node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build=false"
npm ERR! node-pre-gyp ERR! cwd /.../node_modules/@pact-foundation/pact
npm ERR! node-pre-gyp ERR! node -v v19.4.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.5
npm ERR! node-pre-gyp ERR! not ok 
npm ERR! sh: 1: neon: not found
npm ERR! A complete log of this run can be found in:

dianaDBB avatar Jan 25 '23 14:01 dianaDBB

I cannot update to node 19 because this specific Pact release (10.0.0-beta.54) does not exists for node 19 (v111):

the latest version is v10.1.4 which should work on node 19, albeit we don't currently test 19. What problem are you having on node 19? I wouldn't recommend using the betas now that stable is out.

mefellows avatar Feb 02 '23 06:02 mefellows

the latest version is v10.1.4 which should work on node 19, albeit we don't currently test 19. What problem are you having on node 19? I wouldn't recommend using the betas now that stable is out.

Yes, but the version 10.1.4 has this bug (issue #869, this issue where we are comment :D)... The last version that works for fromProviderState on query is the 10.0.0-beta.54.

So I cannot use the 10.1.4 because I have a lot of tests that use the query: fromProviderState and the version 10.1.4 does not work for that. I'm stuck with the version 10.0.0-beta.54 until the #869 is fixed. But the version 10.0.0-beta.54 is not compatible wit node 19... Do you see my problem?

dianaDBB avatar Feb 02 '23 08:02 dianaDBB

Thanks for clarifying, I can see the challenge.

Unfortunately I don't have an answer for when that bug will be resolved.

@rholshausen this looks a bit like https://github.com/pact-foundation/pact-reference/issues/238 (in that it's applied to an indexed value). Would you like me to create an issue on the pact reference project or is it OK to track here?

mefellows avatar Feb 02 '23 10:02 mefellows

@dianaDBB I got around this while still using beta with a "pre-process" step run on the generated consumer pacts just before the pacts are published (this is in a nodejs environment).

Happy to share the small amount of js code I wrote if it would be of help to you.

wabrit avatar Feb 02 '23 11:02 wabrit

That's a great point and suggestion, thanks @wabrit!

mefellows avatar Feb 02 '23 22:02 mefellows

@dianaDBB I got around this while still using beta with a "pre-process" step run on the generated consumer pacts just before the pacts are published (this is in a nodejs environment).

Happy to share the small amount of js code I wrote if it would be of help to you.

Oh, that would be amazing and would really help me out! Thank you @wabrit so much :)

dianaDBB avatar Feb 03 '23 12:02 dianaDBB

No problem @dianaDBB just let me know how best to send it (its about 30-50 lines IIRC)

wabrit avatar Feb 03 '23 12:02 wabrit

No problem @dianaDBB just let me know how best to send it (its about 30-50 lines IIRC)

If you don't mind, I think it would be really great to the community if you shared it in a public way. For example, can you create a public git repository with that and then share the link here?

Just because that way, everyone else that encounters with this issue will have a solution available.

And again, thank you so much for the help :)

dianaDBB avatar Feb 03 '23 14:02 dianaDBB

np - here it is https://github.com/wabrit/pactjs-workaround

wabrit avatar Feb 03 '23 14:02 wabrit

Thank you @wabrit. Your solution worked!

dianaDBB avatar Feb 03 '23 15:02 dianaDBB

Having the same issue since several months now...any updates on when this might be fixed ?

daniel-m-s avatar Feb 22 '23 16:02 daniel-m-s

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-787). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

github-actions[bot] avatar Mar 03 '23 05:03 github-actions[bot]