New error, anyone know what this means? Still unab...
# pact-js
j
New error, anyone know what this means? Still unable to get developer help, but the pact broker saw the tests as failed briefly last night before being unverified again this morning
Copy code
Failed to load pact - No pacts found for provider 'services' matching the given consumer version selectors in pact broker '<https://updaterinc.pactflow.io/>': failed validation - ["consumerVersionSelectors: branch must be filled (at index 0)"].
In pact broker, I see a connection between company-app and services. From what i'm seeing in the docs consumer version selectors refer to tags but none of the existing pact tests have any tags. Environments are also N/A. The branch is just the github sha on both consumer and provider
y
what do your consumer version selectors look like in your code
j
this is what i have in the yaml that seems to be controlling it.
Copy code
test:
    name: Test (${{ inputs.service }})
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Log into harbor
        run: echo ${{ secrets.HARBOR_PASSWORD }} | docker login ${{ inputs.container-image-registry }} -u '${{ secrets.HARBOR_USERNAME }}' --password-stdin
        shell: sh
      - name: Print Environment Variables
        run: printenv   
      - name: Run Tests
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
          PACT_PROVIDER: ${{ inputs.stack }}-${{ inputs.service }}
          PACT_PROVIDER_VERSION: ${{ inputs.provider-version-number }}
          PACT_PROVIDER_VERSION_BRANCH: ${{ inputs.provider-version-branch }}
          PACT_CONSUMER_VERSION_SELECTORS_BRANCH: ${{ inputs.pact-consumer-version-selectors-branch}}
          SERVICE_FOLDER: ${{ github.workspace }}/stacks/${{ inputs.stack }}/${{ inputs.service }}
          DOCKER_BUILDKIT: "1"
          COMPOSE_DOCKER_CLI_BUILD: "1"
        run: make -sC "${SERVICE_FOLDER}" test
        shell: sh
So I only put in
PACT_CONSUMER_VERSION_SELECTORS_BRANCH: ${{ inputs.pact-consumer-version-selectors-branch}}
Looking at the other provider repo though, that other repo is only using four values, PACT_BROKER_BASE_URL, PACTFLOW_TOKEN, PACT_CONSUMER_BRANCH, and PACT_CONSUMER_APP_VERSION
y
Is that env var being passed to your test? you should have an object being passed into the
consumerVersionSelectors
https://github.com/pactflow/example-provider/blob/master/src/product/product.providerChange.pact.test.js#L30-L34
Copy code
consumerVersionSelectors: [
        { mainBranch: true },
        { deployed: true },
        { matchingBranch: true }
      ],
j
Going to try to paste in my test edited for company details...
Copy code
const { Verifier } = require('@pact-foundation/pact')
const path = require('path')

const port = process.env.SERVICE_PORT || 4000

const {
  API_URL,
  PACTFLOW_TOKEN,
  JWT_SECRET,
  PACT_PROVIDER,
  PACT_PROVIDER_VERSION,
  PACT_PROVIDER_VERSION_BRANCH,
  PACT_CONSUMER_VERSION_SELECTORS_BRANCH,
  PACT_BROKER_URL = '<https://updaterinc.pactflow.io/>'
} = process.env

describe('Provider Tests', () => {
it('tests the createCustomTask mutation', async () => {
    await new Verifier({
      provider: 'services',
      consumer: 'company-app',
      pactBrokerUrl: PACT_BROKER_URL,
      pactBrokerToken: PACTFLOW_TOKEN,
      pactUrls: [
        'https://<company>.<http://pactflow.io/pacts/provider/services/consumer/company-app/version/98aa14fc4c2f2d732e7d9d9a4eb76168a5e04a82|pactflow.io/pacts/provider/services/consumer/company-app/version/98aa14fc4c2f2d732e7d9d9a4eb76168a5e04a82>'
      ],
      dir: path.resolve(process.cwd(), 'pacts'),
      publishVerificationResult: true,
      providerVersion: 'version', 
      consumerVersionSelectors: [
        { branch: PACT_CONSUMER_VERSION_SELECTORS_BRANCH }
      ],
      providerBaseUrl: `<http://localhost>:${port}`
    }).verifyProvider()
  })
})
I guess my version is set because its just a string 'version' in providerVersion. I'm not sure how to use the gitsha inside the test
y
you specify pactUrls if the change has been trigged by a consumer pact changed or requiring verification. you use consumerVersionSelectors when you are validating a provider change, combining the two will result in unwanted validations
j
Right now I assume there are no changes, but I want to know if my pact is actually working at all I'm looking for the most minimal viable test, there's a lot of options but i'm just trying to figure out exactly what the minimal requirements are
Like I don't know how I would know if it breaks if I never got some sort of successful connection in the first place. The other pact tests someone else (who is no longer here) set up seem to be running daily with successful checks
y
You either verify by a pact https://docs.pact.io/pact_nirvana/step_4#c-manually-verify-the-pact-by-url-using-the-pact-broker or by consumer version selectors https://docs.pact.io/pact_nirvana/step_4#d-manually-verify-the-pact-by-consumer-version-selectors-using-the-pact-broker This is worked through in this guide which is worth following https://docs.pactflow.io/docs/workshops/ci-cd from your test it doesn’t look like your branch is being passed through to your code. you would need to debug that. alternatively you can remove the consumer version selectors, and just provide the pact url (if you only want to verify that pact)
Copy code
const { Verifier } = require('@pact-foundation/pact')
const path = require('path')

const port = process.env.SERVICE_PORT || 4000

const {
  API_URL,
  PACTFLOW_TOKEN,
  JWT_SECRET,
  PACT_PROVIDER,
  PACT_PROVIDER_VERSION,
  PACT_PROVIDER_VERSION_BRANCH,
  PACT_CONSUMER_VERSION_SELECTORS_BRANCH,
  PACT_BROKER_URL = '<https://updaterinc.pactflow.io/>'
} = process.env

describe('Provider Tests', () => {
it('tests the createCustomTask mutation', async () => {
    await new Verifier({
      provider: 'services',
      consumer: 'company-app',
      pactBrokerUrl: PACT_BROKER_URL,
      pactBrokerToken: PACTFLOW_TOKEN,
      pactUrls: [
        'https://<company>.pactflow.io/pacts/provider/services/consumer/company-app/version/98aa14fc4c2f2d732e7d9d9a4eb76168a5e04a82'
      ],
      dir: path.resolve(process.cwd(), 'pacts'),
      publishVerificationResult: true,
      providerVersion: 'version',
      providerBaseUrl: `<http://localhost>:${port}`
    }).verifyProvider()
  })
})
or this. note you can hardcode the branch to check if there is just an issue with it being passed in from your ci job
Copy code
const { Verifier } = require('@pact-foundation/pact')
const path = require('path')

const port = process.env.SERVICE_PORT || 4000

const {
  API_URL,
  PACTFLOW_TOKEN,
  JWT_SECRET,
  PACT_PROVIDER,
  PACT_PROVIDER_VERSION,
  PACT_PROVIDER_VERSION_BRANCH,
  PACT_CONSUMER_VERSION_SELECTORS_BRANCH,
  PACT_BROKER_URL = '<https://updaterinc.pactflow.io/>'
} = process.env

describe('Provider Tests', () => {
it('tests the createCustomTask mutation', async () => {
    await new Verifier({
      provider: 'services',
      consumer: 'company-app',
      pactBrokerUrl: PACT_BROKER_URL,
      pactBrokerToken: PACTFLOW_TOKEN,
      dir: path.resolve(process.cwd(), 'pacts'),
      publishVerificationResult: true,
      providerVersion: 'version',
      consumerVersionSelectors: [
        { branch: PACT_CONSUMER_VERSION_SELECTORS_BRANCH }
      ],
      providerBaseUrl: `<http://localhost>:${port}`
    }).verifyProvider()
  })
})
j
The pre reqs for the workshop are really daunting considering i'm not a developer and i haven't used docker in years, but i can give it a try
i think the hardcoded string for the branch was already being passed
y
the error message suggests the value
PACT_CONSUMER_VERSION_SELECTORS_BRANCH
is empty
Copy code
Failed to load pact - No pacts found for provider 'services' matching the given consumer version selectors in pact broker '<https://updaterinc.pactflow.io/>': failed validation - ["consumerVersionSelectors: branch must be filled (at index 0)"].
Copy code
consumerVersionSelectors: [
        { branch: PACT_CONSUMER_VERSION_SELECTORS_BRANCH }
      ],
j
oh wait i just tried changing
providerVersion: PACT_PROVIDER_VERSION,
a minute ago and that finished running, I don't see the error at all now
or maybe it just doesn't like the change:
Copy code
● Provider Tests › tests the createCustomTask mutation
    TypeError: providerVersion
      37 |
      38 |   it('tests the createCustomTask mutation', async () => {
    > 39 |     await new Verifier({
         |     ^
      40 |       provider: 'services',
      41 |       consumer: 'company-app',
      42 |       pactBrokerUrl: PACT_BROKER_URL,
      at assertImpl (node_modules/check-types/src/check-types.js:730:11)
      at assertPredicate (node_modules/check-types/src/check-types.js:718:5)
      at Function.nonEmptyString (node_modules/check-types/src/check-types.js:710:14)
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:84:23
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:273:22
          at Array.forEach (<anonymous>)
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:272:21
          at Array.forEach (<anonymous>)
      at validateOptions (node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:260:5)
      at new Verifier (node_modules/@pact-foundation/pact-core/src/verifier/index.ts:16:35)
      at Object.<anonymous>.exports.default (node_modules/@pact-foundation/pact-core/src/verifier/index.ts:30:56)
      at Pact.verifyPacts (node_modules/@pact-foundation/pact-core/src/pact.ts:14:27)
      at node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:137:29
      at async Object.<anonymous> (src/graphql/__tests__/pacts/create-task.pact.test.ts:39:5)
PASS src/graphql/__tests__/delete-task.test.ts
PASS src/graphql/__tests__/client.test.ts
PASS src/graphql/__tests__/generate-custom-task-document-signed-url.test.ts
PASS src/graphql/__tests__/get-signed-url.test.ts
Test Suites: 1 failed, 9 passed, 10 total
Tests:       1 failed, 11 passed, 12 total
Snapshots:   0 total
Time:        2.208 s
Are consumerVersionSelectors a requirement or an option? I can't tell
Yeah, I think that's why i had 'version' hard coded, nevermind
gotta run to the doctor. y'all are very helpful. i'll try to set up the workshop this afternoon if i still can't get it finished
y
consumerVersionSelectors
are optional, as they aren’t used in the verification flow which is triggered from a webhook and uses
pactUrls
option. both are optional, you should choose one or the other yep that error suggest the env vars aren’t populated. the printenv in your CI job won’t show these env vars set in the next step. I imagine the
inputs.pact-consumer-version-selectors-branch
is empty (along with provider version) and no worries take care and we will help get you sorted at some point 😅 fingerscrossed
Copy code
- name: Print Environment Variables
        run: printenv   
      - name: Run Tests
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
          PACT_PROVIDER: ${{ inputs.stack }}-${{ inputs.service }}
          PACT_PROVIDER_VERSION: ${{ inputs.provider-version-number }}
          PACT_PROVIDER_VERSION_BRANCH: ${{ inputs.provider-version-branch }}
          PACT_CONSUMER_VERSION_SELECTORS_BRANCH: ${{ inputs.pact-consumer-version-selectors-branch}}
          SERVICE_FOLDER: ${{ github.workspace }}/stacks/${{ inputs.stack }}/${{ inputs.service }}
          DOCKER_BUILDKIT: "1"
          COMPOSE_DOCKER_CLI_BUILD: "1"
thanks 1
j
oof it is very hard to support a team of 30 devs who like the 'run fast and break things' as the lone QA and do any sort of deep, uninterrupted work. I will try my best to get the workshop example up over the weekend In the meantime i already had printenv in there and did not see PACT at all I see GITHUB_REF_NAME=add-pact-package but not a single value of any of the PACT_ envs in my env block of my yaml. Too much sensitive data to copy pasta
y
Hey, totally appreciate that. I would really expect the developers to writing these tests on the consumer side as part of their changes, and on the provider side, running pact verifications whenever they make a change, rather than it being a separate activity. I’ve definitely felt the pain as a lone QA, but if you can help educate the team, on the merits of quality, and the impact their lack of it has further up the stack with QA (if you guys are feeling it, it will be felt further up too). Pairing with them or some of them can help impart your QA thought pattern into their heads and help make 30 Julies out of them, and you can sit back and review the tests being written. Anyway, that aside - the reason the printenv does not show the
PACT_*
env vars, is a) because they are only set at an individual step level for the tests, so they won’t be set when printenv is called. The snippet below will add them to the env in the printenv step.
Copy code
- name: Print Environment Variables
        run: printenv
        env:
          PACT_PROVIDER: ${{ inputs.stack }}-${{ inputs.service }}
          PACT_PROVIDER_VERSION: ${{ inputs.provider-version-number }}
          PACT_PROVIDER_VERSION_BRANCH: ${{ inputs.provider-version-branch }}
          PACT_CONSUMER_VERSION_SELECTORS_BRANCH: ${{ inputs.pact-consumer-version-selectors-branch}}
      - name: Run Tests
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
          PACT_PROVIDER: ${{ inputs.stack }}-${{ inputs.service }}
          PACT_PROVIDER_VERSION: ${{ inputs.provider-version-number }}
          PACT_PROVIDER_VERSION_BRANCH: ${{ inputs.provider-version-branch }}
          PACT_CONSUMER_VERSION_SELECTORS_BRANCH: ${{ inputs.pact-consumer-version-selectors-branch}}
          SERVICE_FOLDER: ${{ github.workspace }}/stacks/${{ inputs.stack }}/${{ inputs.service }}
          DOCKER_BUILDKIT: "1"
          COMPOSE_DOCKER_CLI_BUILD: "1"
You can also try echoing the inputs value, which I think is possibly the value that isn’t set.
Copy code
- name: Print Input
        run: echo ${{ inputs.provider-version-branch }}
If you want to send anything in private to avoid any change of leaking sensitive information in. public, feel free
The pre reqs for the workshop are really daunting considering i’m not a developer and i haven’t used docker in years, but i can give it a try
You can run it all in github by forking the example repos, and updating via the UI, or using github.dev for a vscode session rather than on your local machine. if that helps
j
I forked to https://github.com/julielaursen/pact-workshop-js but when I open in vscode I only get the main branch, is there a way to clone and get all the branches? When I print out PACT_PROVIDER PACT_PROVIDER_VERSION PACT_PROVIDER_VERSION_BRANCH PACT_CONSUMER_VERSION_SELECTORS_BRANCH I get echo partner-custom-tasks echo echo echo So I guess my service is custom-tasks maybe and not 'services'? The consumer was set up to look for services. The services is a monorepo with a folder called 'stacks' and my test is under stacks/partner/custom-tasks which has it's own package.json and /src folder. So I think this means i have to update both the provider name in the consumer repo and the provider name in the provider repo?
y
it looks like the inputs value in your github wokrflow is empty which will the cause of your issue. ref docs for inputs https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs you can do git checkout stepX in the terminal or in the bottom left nav bar it should say master, clicking on that will show available branches.
j
This is still incredibly challenging without dev help. I have asked 🤷 The import for Verifier is using require right now, but I was getting type error on almost all of the options. ex)
Copy code
error TypeError: providerVersionJest
Because const Verifier: any I also get a type error on pactBroker, providerVersionBranch I see this error in CI too:
Copy code
FAIL src/graphql/__tests__/pacts/create-task.pact.test.ts
  ● Provider Tests › tests the createCustomTask mutation

    TypeError: providerVersionBranch
I tried setting the import to just the regular newer version of the import
import { Verifier } from '@pact-foundation/pact'
and that seemed to get rid of the typeerrors But then i get this error:
Copy code
Dockerfile:66
--------------------
  64 |     
  65 |     RUN npx prisma generate --schema=./src/prisma/schema.prisma
  66 | >>> RUN yarn build
  67 |     RUN rm -rf $(npm get cache)
  68 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn build" did not complete successfully: exit code: 2
Service 'custom-tasks' failed to build : Build failed
I went through the workshop in full this weekend, but I feel like it was more of a tutorial about how pact works and I feel like the issues I have are more specific to the environment variables and possibly the docker or node configuration of my repo. The pact broker is a little further along to displaying information, Provider version wasn't showing on Friday in pact broker and now it is
Also I noticed this error in the watch if I change the import to a regular import, even though jest tests are using regular imports import { Verifier } from '@pact-foundation/pact'; ^^^^^^ SyntaxError: Cannot use import statement outside a module My ability to get a promotion is pretty much dependent on me adding pact tests to our company, so I can't give up on this
y
try hardcoding the values here in the CI step. The issues are with the values not being passed into your code, are these are not being populated, but we can't see where the
inputs
values are being set, as there is only a snippet of the CI yaml.
Copy code
- name: Run Tests
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
          PACT_PROVIDER: xyz
          PACT_PROVIDER_VERSION: 1.0.0
          PACT_PROVIDER_VERSION_BRANCH: main
          PACT_CONSUMER_VERSION_SELECTORS_BRANCH: main
          SERVICE_FOLDER: ${{ github.workspace }}/stacks/${{ inputs.stack }}/${{ inputs.service }}
          DOCKER_BUILDKIT: "1"
          COMPOSE_DOCKER_CLI_BUILD: "1"
👀 1
You will probably want to identify where those inputs are being set, and set them correctly. That should be something a dev can help with, but you can also check the github reference docs on inputs shared above, to try and ascertain where they are set, and how they are passed.
j
ok going to ignore type and build errors in CI and just concentrate on looking at the pact broker dashboard
So in my printenv:
Copy code
PACT_PROVIDER_VERSION_BRANCH: add-pact-package
I just don't get it. add-pact-package is the branch I'm on, and it's coming from github.ref_name. Why does pact broker not just print it, even if it's a random value like 'XYZ'? I can change the value and see the change in the CI, it just never gets to the broker. I just can't tell what controls this value:
Some docs about the minimum requirements as far as what keywords are required on both the broker and consumer to match to the four required (i think it's just four) values on pact broker would be extremely helpful Also maybe the PACT_PROVIDER_VERSION is fine, but it's because of the type error or the ECONNECT REFUSE error? I don't know where the input values are set as there are dozens and dozens of yaml files in this one repository. I don't think they are set in the services.yaml which is what's being called.
There is a pact verification yaml in the root of the project that has this
Copy code
name: Pact Verification

on:
  workflow_call:
    # anchors would be super cool here ;_;
    inputs:
      stack:
        description: Name of the service stack
        required: true
        type: string
      service:
        description: Name of the service within the stack
        required: true
        type: string
      ... edited out company iformation
However, whether it's passed down to every part of the repo I don't know
also keep in mind i have never been able to get the pact test running LOCALLY either because of the typeError which i don't understand as I don't control the verifier, i just import it
Suggestions on whether i should try to fix the local stuff first before bothering to even try and figure out why pact broker is not able to verify? I'm now inundated with another issue where i have to resolve docker issues in github actions with a different, new third party tool. I am not a dev, i'm also not devops. And I've never worked with node or javascript before this job. The learning curve is kind of insane without being able to ask for help or pairing.
y
yeah agreed, but you need to be able to ask for help, it really wont show that you are incapable, but rather willing to learn and step outside your comfort zone. so from your ci, those inputs are set by a calling workflow, so you would want to find out where and make sure there are values passed https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#wo[…]all to answer some questions how is the branch populated in PactFlow? For consumers, it is when you publish pact files. you provide a version number, and optionally but ideally a branch. For providers you supply a provider version, and branch (that relates to the provider). Additionaly you provide one of two items • PactUrl - Usually a http file path to pact, this is triggered when an new consumer pact is published to the broker that requires verification. For example version
1.0.0
, branch
foo
• Consumer version selectors - This is used when the provider build runs because of a change in its code. The consumer version selectors relate to the pacts published from a consumer. If you are using the branch selector, it needs to match the branch that the consumer pact is published on, so
foo
in our example, even if the provider is running on branch
pact-test
the consumer versions selectors of branch`foo` would pick up the any consumer pacts for that provider, which were published under the branch
foo
. When the verifier results are published, the providerVersionBranch is used so
pact-test
would appear in the branch section of the provider in pactflow. The verification result would appear would branch
foo
on the consumer side
Copy code
await new Verifier({
...
providerVersionBranch: 'pact-test'
      consumerVersionSelectors: [
        { branch: "foo" }
      ],
...
    }).verifyProvider()
  })
j
Oh, I ask for help all the time. But I can't force someone to help 🤷 I had to figure out a complex permissions issue with docker and github actions this week, no one from devops responded. I've said I was blocked in every sprint for the past week. I just haven't gotten anyone from that team to respond.
sadge 1
I'm kind of thinking i need to get past the local TypeError before I figure out why this is even broken in CI since it's the same error in both local and CI
💯 1
Copy code
FAIL  src/graphql/__tests__/pacts/create-task.pact.test.ts
  ● Provider Tests › tests the createCustomTask mutation

    TypeError: pactBrokerToken

      35 |
      36 |   it('tests the createCustomTask mutation', async () => {
    > 37 |     await new Verifier({
         |     ^
      38 |       provider: 'custom-tasks',
      39 |       consumer: 'company-app',
      40 |       pactBrokerUrl: PACT_BROKER_URL,

      at assertImpl (node_modules/check-types/src/check-types.js:730:11)
      at assertPredicate (node_modules/check-types/src/check-types.js:718:5)
      at Function.nonEmptyString (node_modules/check-types/src/check-types.js:710:14)
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:84:23
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:273:22
          at Array.forEach (<anonymous>)
      at node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:272:21
          at Array.forEach (<anonymous>)
      at validateOptions (node_modules/@pact-foundation/pact-core/src/verifier/validateOptions.ts:260:5)
      at new Verifier (node_modules/@pact-foundation/pact-core/src/verifier/index.ts:16:35)
      at Object.<anonymous>.exports.default (node_modules/@pact-foundation/pact-core/src/verifier/index.ts:30:56)
      at Pact.verifyPacts (node_modules/@pact-foundation/pact-core/src/pact.ts:14:27)
      at node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:137:29
      at Object.<anonymous> (src/graphql/__tests__/pacts/create-task.pact.test.ts:37:5)

 PASS  src/graphql/__tests__/history.test.ts
 PASS  src/graphql/__tests__/create-task.test.ts
 PASS  src/graphql/__tests__/edit-task.test.ts
 PASS  src/graphql/__tests__/bulk-delete-task.test.ts
[14:49:19.165] INFO (167): pact@13.1.1: Verifying provider
[14:49:19.175] INFO (167): pact-core@15.1.1: Verifying Pacts.

Test Suites: 1 failed, 9 passed, 10 total
Tests:       1 failed, 11 passed, 12 total
Snapshots:   0 total
y
that is stating
PACTFLOW_TOKEN
is an empty string, so it looks like it isn’t being passed to your test. assuming you have exported the token in your shell? does
echo $PACTFLOW_TOKEN
return anything?
j
nothing Interestingly when I try commenting everything out except these values in my verifier
Copy code
await new Verifier({
      provider: 'custom-tasks',
      consumer: 'company-app',
      pactBrokerUrl: PACT_BROKER_URL,
      pactUrls: [   'https://<company>.<http://pactflow.io/pacts/provider/services/consumer/company-app/version/98aa14fc4c2f2d732e7d9d9a4eb76168a5e04a82|pactflow.io/pacts/provider/services/consumer/company-app/version/98aa14fc4c2f2d732e7d9d9a4eb76168a5e04a82>'
      ],
      providerBaseUrl: `<http://localhost>:${port}`
    }).verifyProvider()
I get - Request failed with status - 401 Unauthorized and pact_verifier: No pacts found for provider 'custom-tasks' matching the given consumer version selectors in pact broker 'https://<company>.pactflow.io/': IO Error - Request to pact broker path '' failed: 401 Unauthorized. URL: '<company>.pactflow.io'
y
Can you comment out
pactUrls
and hardcode both your
pactBrokerUrl
and
pactBrokerToken
could you also confirm the name of the consumer-provider pair in pactflow, which you are trying to verify. Your provider here is
customer-tasks
but the
pactUrls
relates to a provider called
services
echo $PACTFLOW_TOKEN
return anything?
nothing
You need to set this in your shell, so
export PACTFLOW_TOKEN=xyz
then
echo $PACTFLOW_TOKEN
should return
xyz
j
Running now, another thing is that these tests can ONLY be run through the make command using docker
exporting works locally for echo $PACTFLOW_TOKEN to return something
y
make just issues shell commands can that otherwise be entered manually. Docker may be relevant for your setup but isn’t a pre-req of Pact-js. It works inside containers, or on local machines.
j
In CI now with this test:
Copy code
it('tests the createCustomTask mutation', async () => {
    await new Verifier({
      provider: 'custom-tasks',
      consumer: 'company-app',
      PACT_BROKER_BASE_URL: 'xyz',
      pactBrokerToken: 'xyz',
      providerBaseUrl: `<http://localhost>:${port}`
    }).verifyProvider()
  })

Then in CI:
[15:26:21.816] INFO (41): pact@13.1.1: Verifying provider
[15:26:21.825] INFO (41): pact-core@15.1.1: Verifying Pacts.
[15:26:21.826] INFO (41): pact-core@15.1.1: Verifying Pact Files
[15:26:21.830] INFO (41): 0.4.22: pact native library successfully found, and the correct version
2024-07-31T15:26:21.832628Z  WARN ThreadId(03) pact_matching::metrics:
Copy code
[15:26:21.925] INFO (41): pact-core@15.1.1: Verification successful
PASS src/graphql/__tests__/pacts/create-task.pact.test.ts
In pact, no updates. services was the repo that i thought originally would be the provider app but then i realized it needed to be at the microservices level within the repo
y
i think consumer is an incorrect option. you also need publishVerificationResults set to true to publish results to a broker.
also you will need at minimum a providerVersion to publish a verification result
j
if i add back in providerVersion as PACT_PROVIDER_VERSION I get a failure. If I then set providerVersion to 'xyz', I don't get a failure So the consts I'm getting from process.env don't seem to be doing anything
y
i think the inputs are just empty in CI. if you
export PACT_PROVIDER_VERSION=xyz
it should get picked up by the process.env
you can also run a shell command from node to pick a version and branch if you are using git, like the example below https://github.com/pactflow/example-provider-js-sns/blob/67cff06d5a1f3b7c8beec3cf9bc844992189a126/src/product/product.pact.test.js#L11-L30
j
In the other pacts i have in my broker, the provider and consumer version look like they're shas and not branch names
Ah! From what i can tell these env vars like PACTFLOW_TOKEN are probably in our docker file I found something like this in our Dockerfile and added PACTFLOW_TOKEN, PACT_PROVIDER and PACT_PROVIDER_VERSION but i dont think these are getting to process.env. still looking
Interestingly there is another job called Pact Consumer Test for custom-tasks that kicks off when you do anything in that part of the code base and that test failed by default when I tried to start over from the beginning and just add in the env vars and install pact. It's looking for a docker-compose in the folder, but there is no docker-compose, and then failing I'm not sure why this job was in the root level yaml in the first place, we so far have no pact tests in the repo at all. Git blame shows two people wrote this 9 months ago and both left the company:
Copy code
pact-consumer-test:
    name: Pact Consumer Test for ${{ inputs.service }}
    # This job is required for pact-can-i-merge, but only if a consumer needs to actually run the tests. pact-can-i-merge still needs to run for a provider,
    # but the provider pipeline does NOT need the consumer tests to run by default.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Log into harbor
        run: echo ${{ secrets.HARBOR_PASSWORD }} | docker login ${{ inputs.container-image-registry }} -u '${{ secrets.HARBOR_USERNAME }}' --password-stdin
        shell: sh
      - name: Run Consumer Tests
        env:
          PACT_BROKER_BASE_URL: https://<company>.<http://pactflow.io/|pactflow.io/>
          PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
          PACT_CONSUMER_BRANCH: ${{ github.ref_name }}
          PACT_CONSUMER_APP_VERSION: ${{ github.sha }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SERVICE_FOLDER: ${{ github.workspace }}/stacks/${{ inputs.stack }}/${{ inputs.service }}
          DOCKER_BUILDKIT: "1"
          COMPOSE_DOCKER_CLI_BUILD: "1"
        run: |
          make -sC "${SERVICE_FOLDER}" service_pact_consumer_test
          make -sC "${SERVICE_FOLDER}" pact_consumer_test_publish
        shell: sh
      - name: Force this job to run for can-i-merge to work in the provider
        run: echo "Pacticipant ${{ inputs.stack }}-${{ inputs.service }} does not require consumer tests to run at this time."
        shell: sh