Automating removal of orphaned pacts: Given A had...
# pactflow
n
Automating removal of orphaned pacts: Given A had a pact with B. When A no longer needs to communicate with B And the consumer pact has been removed from code / no json generated. Then I need to go to pactflow and delete the integration so the provider is no longer verifying a pact it doesn’t need to anymore. Is there anyway to automate this?
b
@Nathan Deamer I've been working on a fix for this. You shouldn't need to delete it, just stop publishing.
What is your verification configuration?
The issue was, it was returning "the pact for the latest version with a pact that has tag X", which meant there was always a pact being returned. What it needed to do was return "find the latest version that has tag X and return the pact if it exists".
I think I've updated the logic for branch selectors, but not sure I've done it for tags yet.
What you should just need to do is create an pacticipant version resource that doesn't have the pact with that provider.
If the consumer has pacts with other providers still, then just publish as normal. If the consumer has no more providers then you'll need to create a pacticipant version resource that has no pacts, so the broker knows that there is no pact for that consumer any more.
n
Thanks @Beth (pactflow.io/Pact Broker/pact-ruby) - I’ll give it a go with branches and let you know
b
@Nathan Deamer i've just dug into the code to work out what it's currently doing
Copy code
# The latest pact publication for each tag
      # This uses the old logic of "the latest pact for a version that has a tag" (which always returns a pact)
      # rather than "the pact for the latest version with a tag"
      # Need to see about updating this.
      def latest_by_consumer_tag
the tags are on the old logic
Copy code
# Updated logic - the pacts for the latest version of each main branch,
      # not the latest pact that belongs to the main branch.
      def latest_for_main_branches
the main branch selector is on the new logic
the normal branch selector is unfortunately on the old logic.
I had thought I'd updated that one already
I've coded up the logic change and I'll try and get it out today.
Are you on Pactflow saas?
Sorry, I was wrong. The tags are already on the new logic.
Copy code
# The pacts for the latest versions with the specified tag (new logic)
      # NOT the latest pact that belongs to a version with the specified tag.
      def for_latest_consumer_versions_with_tag(tag_name)
I've created a script with the http data builder to show how this is expected to work.
The instructions for running it locally on docker are here: https://github.com/pact-foundation/pact_broker/blob/master/ISSUES.md
The scenario just needs to be updated to use
script/data/decommissioning-an-integration.rb
instead of
script/data/reproduce-issue.rb
here is the output
(note - I was running this against the head version of the code that has my latest branch fix applied - it will behave differently against the released version).
n
👍. This is still on my todo list.