Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in beta.58 for query generators #869

Open
wabrit opened this issue May 25, 2022 · 23 comments
Open

Regression in beta.58 for query generators #869

wabrit opened this issue May 25, 2022 · 23 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior upstream Indicates that an issue relates to an upstream problem (such as in pact-reference)

Comments

@wabrit
Copy link

wabrit commented May 25, 2022

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 wabrit added the bug Indicates an unexpected problem or unintended behavior label May 25, 2022
@mefellows
Copy link
Member

Thanks for raising this.

@mefellows
Copy link
Member

@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?

@rholshausen
Copy link

Is it forcing the output to V2 format?

@mefellows
Copy link
Member

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

@wabrit
Copy link
Author

wabrit commented Aug 1, 2022

Hi @mefellows do you mean the generated json file?

@mefellows
Copy link
Member

Yes please! Also any relevant code snippets.

@wabrit
Copy link
Author

wabrit commented Aug 2, 2022

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"
  }
}

@dianaDBB
Copy link

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
Copy link

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 :(

@mefellows
Copy link
Member

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?

@dianaDBB
Copy link

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 node-pre-gyp@1.0.5
npm ERR! node-pre-gyp info using node@19.4.0 | 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:

@mefellows
Copy link
Member

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.

@dianaDBB
Copy link

dianaDBB commented Feb 2, 2023

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?

@mefellows
Copy link
Member

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 pact-foundation/pact-reference#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?

@wabrit
Copy link
Author

wabrit commented Feb 2, 2023

@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.

@mefellows
Copy link
Member

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

@dianaDBB
Copy link

dianaDBB commented Feb 3, 2023

@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 :)

@wabrit
Copy link
Author

wabrit commented Feb 3, 2023

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

@dianaDBB
Copy link

dianaDBB commented Feb 3, 2023

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 :)

@wabrit
Copy link
Author

wabrit commented Feb 3, 2023

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

@dianaDBB
Copy link

dianaDBB commented Feb 3, 2023

Thank you @wabrit. Your solution worked!

@daniel-m-s
Copy link

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

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

👋 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.

@mefellows mefellows added the upstream Indicates that an issue relates to an upstream problem (such as in pact-reference) label Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior upstream Indicates that an issue relates to an upstream problem (such as in pact-reference)
Projects
Status: New Issue
Development

No branches or pull requests

5 participants