Julie Laursen
07/25/2024, 2:55 PMFailed 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 providerYousaf Nabi (pactflow.io)
Julie Laursen
07/25/2024, 3:11 PMtest:
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
Julie Laursen
07/25/2024, 3:12 PMPACT_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_VERSIONYousaf Nabi (pactflow.io)
consumerVersionSelectors
https://github.com/pactflow/example-provider/blob/master/src/product/product.providerChange.pact.test.js#L30-L34
consumerVersionSelectors: [
{ mainBranch: true },
{ deployed: true },
{ matchingBranch: true }
],
Julie Laursen
07/25/2024, 3:14 PMJulie Laursen
07/25/2024, 3:15 PMconst { 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()
})
})
Julie Laursen
07/25/2024, 3:16 PMYousaf Nabi (pactflow.io)
Julie Laursen
07/25/2024, 3:18 PMJulie Laursen
07/25/2024, 3:19 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
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
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()
})
})
Julie Laursen
07/25/2024, 3:25 PMJulie Laursen
07/25/2024, 3:26 PMYousaf Nabi (pactflow.io)
PACT_CONSUMER_VERSION_SELECTORS_BRANCH
is empty
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)"].
consumerVersionSelectors: [
{ branch: PACT_CONSUMER_VERSION_SELECTORS_BRANCH }
],
Julie Laursen
07/25/2024, 3:29 PMproviderVersion: PACT_PROVIDER_VERSION,
a minute ago and that finished running, I don't see the error at all nowJulie Laursen
07/25/2024, 3:29 PM● 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
Julie Laursen
07/25/2024, 3:29 PMJulie Laursen
07/25/2024, 3:30 PMJulie Laursen
07/25/2024, 3:32 PMYousaf Nabi (pactflow.io)
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
- 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"
Julie Laursen
07/25/2024, 9:28 PMYousaf Nabi (pactflow.io)
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.
- 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.
- 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 freeYousaf Nabi (pactflow.io)
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 tryYou 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
Julie Laursen
07/26/2024, 7:52 PMYousaf Nabi (pactflow.io)
Julie Laursen
07/29/2024, 2:18 PMerror TypeError: providerVersionJest
Because const Verifier: any
I also get a type error on pactBroker, providerVersionBranch
I see this error in CI too:
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:
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 isJulie Laursen
07/29/2024, 2:24 PMYousaf Nabi (pactflow.io)
inputs
values are being set, as there is only a snippet of the CI yaml.
- 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"
Yousaf Nabi (pactflow.io)
Julie Laursen
07/29/2024, 2:32 PMJulie Laursen
07/29/2024, 6:37 PMPACT_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:Julie Laursen
07/29/2024, 6:42 PMJulie Laursen
07/29/2024, 6:54 PMname: 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 knowJulie Laursen
07/29/2024, 8:06 PMJulie Laursen
07/30/2024, 10:00 PMYousaf Nabi (pactflow.io)
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
Yousaf Nabi (pactflow.io)
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 sideYousaf Nabi (pactflow.io)
await new Verifier({
...
providerVersionBranch: 'pact-test'
consumerVersionSelectors: [
{ branch: "foo" }
],
...
}).verifyProvider()
})
Julie Laursen
07/31/2024, 2:53 PMJulie Laursen
07/31/2024, 2:54 PMJulie Laursen
07/31/2024, 3:00 PMFAIL 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
Yousaf Nabi (pactflow.io)
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?Julie Laursen
07/31/2024, 3:13 PMawait 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'Yousaf Nabi (pactflow.io)
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
Yousaf Nabi (pactflow.io)
echo $PACTFLOW_TOKEN
return anything?
nothingYou need to set this in your shell, so
export PACTFLOW_TOKEN=xyz
then echo $PACTFLOW_TOKEN
should return xyz
Julie Laursen
07/31/2024, 3:19 PMJulie Laursen
07/31/2024, 3:21 PMYousaf Nabi (pactflow.io)
Julie Laursen
07/31/2024, 3:29 PMit('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:
[15:26:21.925] INFO (41): pact-core@15.1.1: Verification successful
PASS src/graphql/__tests__/pacts/create-task.pact.test.ts
Julie Laursen
07/31/2024, 3:30 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Julie Laursen
07/31/2024, 3:37 PMYousaf Nabi (pactflow.io)
export PACT_PROVIDER_VERSION=xyz
it should get picked up by the process.envYousaf Nabi (pactflow.io)
Julie Laursen
07/31/2024, 3:49 PMJulie Laursen
07/31/2024, 7:57 PMJulie Laursen
07/31/2024, 8:44 PMpact-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