Skip to content

Conversation

@argos83
Copy link
Contributor

@argos83 argos83 commented Dec 17, 2025

This change adds support for URLs (http/https) in the CLI arguments, besides filesystem paths, reducing the feature parity gap with the no longer maintained swagger-mock-validator lib (disclaimer: I was one of the co-authors of that library).

The CLI module did not have tests, so before introducing this change I added tests and refactored the implementation to make it testable.

Additionally I introduced a fix for a bug which, although very unlikely to be triggered, could have unwanted consequences: The cli command returns the number of pact files with errors as exit code, most systems will take only the least significant byte as exit code, i.e 0-255. If you happen to have, let's say 256 failed pacts, the exit code will overflow to 0. This number is now capped at 255.

The change was introduced gradually, in case you want to review commit by commit:

  • test: add integration tests for cli prior to refactoring: The current solution is not unit-testable, before refactoring it I've added two integration tests (one for a success case, one for a failed case)

  • refactor(cli): separate command parsing logic from execution: Moved the CLI execution logic (reading files, parsing them, invoking the comparator, printing output, collecting errors) into it's own module, separate from the commander's interface, following the single-responsibility principle. This allows testing the most part of the logic with fast & targeted unit tests. The module has full coverage now. It uses dependency inversion to mock the filesystem, stdout, and the comparator initialization.

  • fix: cap exit code at 255 to avoid overflowing to 0: adds test and fix the exit code bug capping it at 255.

  • feat(cli): support URLs for cli input arguments: detects whether an input argument is a url (http:// - https://) and fetches the content if so, otherwise defaults to the current implementation (interpreting the input as a filesystem path). Adds unit and integration tests for this feature.

The existing implementation was not unit-tested (and hard to test). Following the single responsibility principle, and separating the command parsing logic from its execution allows the implementation to be fully tested with unit-tests.
@vwong
Copy link
Collaborator

vwong commented Jan 12, 2026

Thanks for the feature!

@vwong vwong merged commit e9b06dc into pactflow:main Jan 12, 2026
4 checks passed
@YOU54F
Copy link
Member

YOU54F commented Jan 12, 2026

Thanks @sebastian-tello, great to see you again and thanks for incorporating changes into OPC and again thanks for your work on swagger-mock-validator. We are but standing on the shoulders of giants!

@sebastian-tello
Copy link
Contributor

Thanks @sebastian-tello, great to see you again and thanks for incorporating changes into OPC and again thanks for your work on swagger-mock-validator. We are but standing on the shoulders of giants!

@YOU54F my pleasure! thanks for keeping up with the work.
BTW, I see the release build failed: https://github.com/pactflow/openapi-pact-comparator/actions/runs/20907429905

@YOU54F
Copy link
Member

YOU54F commented Jan 12, 2026

@YOU54F my pleasure! thanks for keeping up with the work. BTW, I see the release build failed: https://github.com/pactflow/openapi-pact-comparator/actions/runs/20907429905

our npm token had expired, so we are taking the opportunity to migrate over to trusted publishing, should be released by tomorrow 👍🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants