-
Notifications
You must be signed in to change notification settings - Fork 0
feat: PLAN §5.1–5.3 — Pact contract testing #23
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
Open
mcalthrop
wants to merge
4
commits into
main
Choose a base branch
from
feat/plan-5-1-5-3-pact-contract-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d1779b9
feat: PLAN §5.1–5.3 — Pact contract testing (consumer, publish, provi…
mcalthrop 251f1d3
chore: fix knip error
mcalthrop 140208b
chore: merge main into feat/plan-5-1-5-3-pact-contract-testing
mcalthrop bfc1ea5
chore(api): bump Python requirement from 3.12 to 3.13 across config a…
mcalthrop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| description: Follow Google Shell Style Guide for Bash scripts | ||
| globs: **/*.sh | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| # Google Shell Style Guide | ||
|
|
||
| - For Bash scripts, follow the [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html). | ||
| - Prefer Bash patterns, naming, quoting, functions, and error-handling conventions from that guide. | ||
| - Keep scripts readable and conservative: use `set -euo pipefail` when appropriate, quote expansions, and prefer clear long-form options when available. | ||
| - Write new Bash in a style consistent with the guide rather than ad hoc shell habits. | ||
|
|
||
| Examples: | ||
|
|
||
| ```bash | ||
| # Prefer | ||
| main() { | ||
| local branch_name="$1" | ||
| git fetch origin --prune | ||
| git checkout "${branch_name}" | ||
| } | ||
|
|
||
| main "$@" | ||
|
|
||
| # Avoid | ||
| f(){ git fetch origin -p; git checkout $1; } | ||
| f $@ | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| description: Prefer long-form command-line options | ||
| alwaysApply: true | ||
| --- | ||
|
|
||
| # Long-Form Command Options | ||
|
|
||
| - Prefer long-form command-line options whenever the tool supports them. | ||
| - Avoid short flags such as `-u`, `-p`, `-r`, or `-m` when the equivalent long option is available. | ||
| - This applies to shell commands, scripts, documentation examples, and generated command snippets. | ||
|
|
||
| Examples: | ||
|
|
||
| ```bash | ||
| # Prefer | ||
| git fetch --prune | ||
| git push --set-upstream origin HEAD | ||
| docker compose up --detach | ||
|
|
||
| # Avoid | ||
| git fetch -p | ||
| git push -u origin HEAD | ||
| docker compose up -d | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,6 @@ htmlcov/ | |
| *.egg-info/ | ||
| dist/ | ||
| build/ | ||
|
|
||
| # Pact | ||
| apps/web/pacts/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "include": ["app"], | ||
| "exclude": [".venv", "**/__pycache__"], | ||
| "pythonVersion": "3.12", | ||
| "pythonVersion": "3.13", | ||
| "venvPath": ".", | ||
| "venv": ".venv" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "$0")" && pwd)" | ||
| readonly script_dir | ||
|
|
||
| package_root="$(cd "${script_dir}/.." && pwd)" | ||
| readonly package_root | ||
|
|
||
| repo_root="$(cd "${package_root}/../.." && pwd)" | ||
| readonly repo_root | ||
|
|
||
| provider_name="${PACT_PROVIDER_NAME:?Missing required environment variable: PACT_PROVIDER_NAME}" | ||
| readonly provider_name | ||
|
|
||
| provider_base_url="${PACT_PROVIDER_BASE_URL:?Missing required environment variable: PACT_PROVIDER_BASE_URL}" | ||
| readonly provider_base_url | ||
|
|
||
| provider_hostname="${PACT_PROVIDER_HOSTNAME:?Missing required environment variable: PACT_PROVIDER_HOSTNAME}" | ||
| readonly provider_hostname | ||
|
|
||
| provider_port="${PACT_PROVIDER_PORT:?Missing required environment variable: PACT_PROVIDER_PORT}" | ||
| readonly provider_port | ||
|
|
||
| provider_transport="${PACT_PROVIDER_TRANSPORT:?Missing required environment variable: PACT_PROVIDER_TRANSPORT}" | ||
| readonly provider_transport | ||
|
|
||
| wait_for_healthy_provider() { | ||
| local healthcheck_url="${provider_base_url}/health" | ||
| local attempt | ||
|
|
||
| for ((attempt = 1; attempt <= 60; attempt += 1)); do | ||
| if wget --quiet --output-document=/dev/null "${healthcheck_url}"; then | ||
|
mcalthrop marked this conversation as resolved.
|
||
| return | ||
| fi | ||
| sleep 0.5 | ||
| done | ||
|
|
||
| echo "Provider did not become healthy at ${healthcheck_url}" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| cleanup() { | ||
| if [[ -n "${provider_pid:-}" ]]; then | ||
| kill -TERM "${provider_pid}" 2>/dev/null || true | ||
| wait "${provider_pid}" 2>/dev/null || true | ||
| fi | ||
| } | ||
|
|
||
| run_local_verification() { | ||
| local command=( | ||
| "${package_root}/node_modules/.bin/pact-verifier" | ||
| --dir "${repo_root}/apps/web/pacts" | ||
| --provider-name "${provider_name}" | ||
| --hostname "${provider_hostname}" | ||
| --port "${provider_port}" | ||
| --transport "${provider_transport}" | ||
| ) | ||
|
|
||
| "${command[@]}" | ||
| } | ||
|
|
||
| run_broker_verification() { | ||
| local command | ||
|
|
||
| command=( | ||
| "${package_root}/node_modules/.bin/pact-verifier" | ||
| --broker-url "${PACT_BROKER_BASE_URL}" | ||
| --provider-name "${provider_name}" | ||
| --hostname "${provider_hostname}" | ||
| --port "${provider_port}" | ||
| --transport "${provider_transport}" | ||
| --consumer-version-selectors '{"mainBranch":true}' | ||
| --consumer-version-selectors '{"matchingBranch":true}' | ||
| --enable-pending | ||
| --provider-branch "${PACT_PROVIDER_BRANCH:?Missing required environment variable: PACT_PROVIDER_BRANCH}" | ||
| --user "${PACT_BROKER_USERNAME:?Missing required environment variable: PACT_BROKER_USERNAME}" | ||
| --password "${PACT_BROKER_PASSWORD:?Missing required environment variable: PACT_BROKER_PASSWORD}" | ||
| ) | ||
|
|
||
| if [[ "${CI:-}" == "true" ]]; then | ||
| command+=( | ||
| --publish | ||
| --provider-version "${PACT_PROVIDER_VERSION:?Missing required environment variable: PACT_PROVIDER_VERSION}" | ||
| ) | ||
| fi | ||
|
|
||
| "${command[@]}" | ||
| } | ||
|
|
||
| main() { | ||
| cd "${package_root}" | ||
|
|
||
| ./.venv/bin/python -m uvicorn app.main:app --host "${provider_hostname}" --port "${provider_port}" & | ||
| provider_pid=$! | ||
| readonly provider_pid | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| wait_for_healthy_provider | ||
|
|
||
| if [[ -n "${PACT_BROKER_BASE_URL:-}" ]]; then | ||
| run_broker_verification | ||
| return | ||
| fi | ||
|
|
||
| run_local_verification | ||
| } | ||
|
|
||
| main "$@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.