Skip to content

MPT-27353 add a webhook example in mpt-extension-python-template - #154

Merged
svazquezco merged 1 commit into
mainfrom
feature/MPT-27353/add-webhook-example-in-mpt-extension-python-template
Nov 4, 2026
Merged

svazquezco merged 1 commit into
mainfrom
feature/MPT-27353/add-webhook-example-in-mpt-extension-python-template

Conversation

@svazquezco

@svazquezco svazquezco commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 AI-generated PR — Please review carefully.

Adds the webhook example the template was missing, so a new extension starts from a working validation webhook.

What was done

The webhook. routers/webhooks/order.py registers a validatePurchaseOrderDraft webhook with one criteria per product in MPT_PRODUCTS_IDS, so the Extensions Service creates one platform webhook per product on the same route.

The handler clears the errors of the previous answer with without_errors() — otherwise the wizard keeps showing them after the user fixes the value — then validates the agreementType ordering parameter. An unknown value comes back as a 200 carrying the rejection at both levels the SDK offers: with_ordering_error(...) on the parameter the user has to fix, and with_error(...) as a summary on the order. An order without that parameter is accepted, because there is nothing to validate.

The SDK dependency. The template now depends on mpt-extension-sdk==6.9.*, the first release that ships the webhooks API. This replaces a locally built 6.8.99+webhooks wheel that was pinned through [tool.uv.sources] while the API was unreleased — that wheel lives under a gitignored vendor/, so the pin could never have resolved in CI. The mypy pre-commit hook pins the SDK separately in its own isolated environment, so it moves to 6.9.* in the same change.

Tests and docs. Seven unit tests cover clearing, acceptance, the absent parameter, both rejection levels, the required/hidden constraints that with_ordering_error sets, and the log line; two existing tests already cover route registration and the generated metadata. The two webhook calls — one accepted, one rejected — are added to the Postman collection, and docs/examples.md, docs/architecture.md and docs/testing.md describe the example.

Testing

  • pytest — 49 passed, handler at 100% coverage
  • ruff format --check, ruff check, flake8 (wemake), mypy, uv lock --check — all clean
  • mpt-ext meta generate — the webhooks: block is produced with one entry per configured product
  • Both Postman payloads were run through the real handler and return the documented order/parameter errors

Frontend checks were not run: this change is backend and documentation only.

  • Adds a purchase order draft validation webhook for each configured product.
  • Clears errors from the previous answer. Accepts a missing agreementType or the values New and Migration. For other values, returns parameter-level and order-level errors.
  • Updates mpt-extension-sdk and the mypy pre-commit hook to 6.9.*.
  • Adds handler and route-registration tests, Postman examples, and documentation.

Register a validatePurchaseOrderDraft webhook with one criteria per
configured product, so the Extensions Service creates one platform
webhook per product on the same route. The handler clears the errors of
the previous answer, validates the agreementType ordering parameter and,
when the value is not a known one, answers 200 with the order carrying an
error on the parameter and a summary error on the order itself.

Depend on mpt-extension-sdk 6.9, the first release that ships the
webhooks API, replacing the locally built wheel that was pinned through
tool.uv.sources while the API was unreleased. Move the mypy pre-commit
hook to the same version, because it type-checks in its own environment.

Cover the handler with unit tests, add the accepted and rejected webhook
calls to the Postman collection, and describe the example in
docs/examples.md.
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

✅ Found Jira issue key in the title: MPT-27353

Generated by 🚫 dangerJS against 3cf5dd7

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 672d700 and 3cf5dd7.

Files ignored due to path filters: 1
  • backend/uv.lock is excluded by !**/*.lock
Files selected for processing: 11
  • .pre-commit-config.yaml
  • backend/docs/postman_collection.json
  • backend/mpt_extension_python_template/app.py
  • backend/mpt_extension_python_template/routers/webhooks/__init__.py
  • backend/mpt_extension_python_template/routers/webhooks/order.py
  • backend/pyproject.toml
  • backend/tests/routers/test_webhooks.py
  • backend/tests/test_app.py
  • docs/architecture.md
  • docs/examples.md
  • docs/testing.md
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Recent review details
Context from checks skipped due to timeout: 2
  • GitHub Check: CodeRabbit
  • GitHub Check: build
Additional context used
Code guidelines: 3
docs/documentation.md — configured
docs/architecture.md — configured
AGENTS.md — configured
Path-based instructions: 9
Review backend test changes against `docs/testing.md` and the linked repository's `standards/unittests.md`.

CodeRabbit configuration file

Files:

  • backend/tests/test_app.py
  • backend/tests/routers/test_webhooks.py
Follow the linting rules defined in `backend/pyproject.toml` under `[tool.ruff]` and `[tool.flake8]`.

CodeRabbit configuration file

Files:

  • backend/tests/test_app.py
  • backend/mpt_extension_python_template/app.py
  • backend/tests/routers/test_webhooks.py
  • backend/mpt_extension_python_template/routers/webhooks/order.py
Review backend changes against `AGENTS.md`, `docs/architecture.md`, `docs/contributing.md`, and `docs/testing.md`.

CodeRabbit configuration file

Files:

  • backend/pyproject.toml
  • backend/tests/test_app.py
  • backend/docs/postman_collection.json
  • backend/mpt_extension_python_template/app.py
  • backend/tests/routers/test_webhooks.py
  • backend/mpt_extension_python_template/routers/webhooks/order.py
Review documentation changes against `docs/documentation.md` and the linked repository's `standards/documentation.md`.

CodeRabbit configuration file

Files:

  • docs/testing.md
  • docs/architecture.md
  • docs/examples.md
For each subsequent commit in this PR, explicitly verify if previous review comments have been resolved

CodeRabbit configuration file

Files:

  • .pre-commit-config.yaml
  • docs/testing.md
  • backend/pyproject.toml
  • docs/architecture.md
  • backend/tests/test_app.py
  • backend/docs/postman_collection.json
  • docs/examples.md
  • backend/mpt_extension_python_template/app.py
  • backend/tests/routers/test_webhooks.py
  • backend/mpt_extension_python_template/routers/webhooks/order.py
Applicability reference: AGENTS.md: # AGENTS.md When applicable, read the repository in this order: [docs/documentation.md](docs/documentation.md) when changing repository documentation.

CodeRabbit inference engine (docs/documentation.md)

Files:

  • docs/testing.md
  • docs/architecture.md
  • docs/examples.md
Applicability reference: AGENTS.md: # AGENTS.md When applicable, read the repository in this order: [docs/architecture.md](docs/architecture.md) for the repository structure and runtime components.

CodeRabbit inference engine (docs/architecture.md)

Files:

  • docs/architecture.md
Applicability reference: AGENTS.md: # AGENTS.md When applicable, read the repository in this order: [docs/architecture.md](docs/architecture.md) for the repository structure and runtime components.

CodeRabbit inference engine (docs/architecture.md)

Files:

  • docs/testing.md
  • docs/examples.md
Source excerpt: Operational guidance: Keep `README.md` short and navigational.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/testing.md
  • docs/architecture.md
  • docs/examples.md
Learnings: 1
Common learnings
Learnt from: CR
Repo: softwareone-platform/mpt-extension-python-template PR: 0
File: coderabbit-custom-pre-merge-checks-unique-id-file-non-traceable-F7F2B60C-1728-4C9A-8889-4F2235E186CA.txt:0-0
Timestamp: 2026-10-15T13:04:00.013Z
Learning: Applies to docs/testing.md : Source excerpt:
Documentation Up To Date: When this PR changes code or behaviour, verify the relevant documentation was updated in the same PR, following standards/documentation.md. Map changes to documents:
- changed test strategy or scope -> docs/testing.md
Learnt from: CR
Repo: softwareone-platform/mpt-extension-python-template

Timestamp: 2026-11-03T11:57:11.418Z
Learning: Applicability reference:
AGENTS.md: # AGENTS.md
When applicable, read the repository in this order:

3. [docs/examples.md](docs/examples.md) for a tour of the example API, events, pipelines, context, and plugs.

Source excerpt:
# Examples

## Webhooks

The handler first clears the errors of the previous answer with
`without_errors()`, otherwise the wizard keeps showing them after the user fixes
the value. It then checks the `agreementType` ordering parameter against
`VALID_AGREEMENT_TYPES` and returns the order either unchanged or carrying the
rejection. An order whose payload has no `agreementType` parameter is accepted,
because there is nothing to validate.
Learnt from: CR
Repo: softwareone-platform/mpt-extension-python-template

Timestamp: 2026-11-03T11:57:11.418Z
Learning: Applicability reference:
AGENTS.md: # AGENTS.md
When applicable, read the repository in this order:

3. [docs/examples.md](docs/examples.md) for a tour of the example API, events, pipelines, context, and plugs.

Source excerpt:
# Examples

## Webhooks

A rejection is reported at both levels the SDK offers, so the template shows
each one: `with_ordering_error(...)` puts the error on the parameter the user
has to fix, and `with_error(...)` adds a summary on the order itself. Use the
parameter level for a bad value and the order level for a problem with the
order as a whole.
Learnt from: CR
Repo: softwareone-platform/mpt-extension-python-template

Timestamp: 2026-11-03T11:57:11.418Z
Learning: Applicability reference:
AGENTS.md: # AGENTS.md
When applicable, read the repository in this order:

3. [docs/examples.md](docs/examples.md) for a tour of the example API, events, pipelines, context, and plugs.

Source excerpt:
# Examples

## Webhooks

A rejection is still a `200`: the platform reads the validation result from the
returned order, not from the status code, and the wizard shows the error on the
offending parameter. `WebhookResponse.error(...)` is for the handler failing,
not for an order being invalid.
LanguageTool
docs/architecture.md

[style] ~14-~14: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...sion_python_template/routers/webhooks/` declares synchronous platform webhook handlers. ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

Multi-repo context softwareone-platform/mpt-extension-skills

Linked repositories findings

softwareone-platform/mpt-extension-skills

  • Shared dependency guidance requires refreshing uv.lock after every pyproject.toml dependency change. Verify the PR includes the lockfile update. [::softwareone-platform/mpt-extension-skills::standards/packages-and-dependencies.md:19-22] [::softwareone-platform/mpt-extension-skills::knowledge/manage-dependencies.md:24-30]
  • The mpt-extension-sdk==6.9.* pin follows the standard preference for patch-level application/extension pins. [::softwareone-platform/mpt-extension-skills::standards/packages-and-dependencies.md:21-22]
Walkthrough

The backend adds a draft purchase-order validation webhook. It accepts a missing agreement type or New and Migration, and returns order-level and parameter-level errors for other values. The application registers the route, with tests and documentation covering its behavior.

Changes: Order validation webhook

Layer / File(s) Summary
Webhook handler and registration
backend/mpt_extension_python_template/routers/webhooks/order.py, backend/mpt_extension_python_template/app.py, .pre-commit-config.yaml, backend/pyproject.toml
Adds the order validation webhook and registers its router with the application. The handler clears prior errors, accepts a missing agreement type or New and Migration, and adds order-level and parameter-level errors for other values. Updates the mpt-extension-sdk version pins to 6.9.*.
Validation and registration tests
backend/tests/routers/test_webhooks.py, backend/tests/test_app.py, docs/testing.md
Tests accepted and rejected agreement types, error clearing, parameter metadata, logging, route registration, and generated webhook metadata. Updates the documented test scope.
Examples and architecture documentation
backend/docs/postman_collection.json, docs/architecture.md, docs/examples.md
Adds Postman examples for accepted and rejected agreement types. Documents the webhook route, registration, validation behavior, and response semantics.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: Minimal · up to 3cf5d

The webhook behavior and registration are covered by the supplied tests, with no identified issue blocking merge.

Pre-merge checks: Passed 3
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Documentation Up To Date Passed The PR updates the matching documentation. docs/architecture.md:14,28-34 documents the new webhook component and route. docs/examples.md:18-20,32,142-186 documents registration, criteria, validati…
Full details: Documentation Up To Date

Explanation

The PR updates the matching documentation. docs/architecture.md:14,28-34 documents the new webhook component and route. docs/examples.md:18-20,32,142-186 documents registration, criteria, validation behavior, responses, and local Postman usage. docs/testing.md:16-21 updates the test scope. This follows the repository documentation responsibilities in softwareone-platform/mpt-extension-skills at commit 9d8bcd7148e89c32545cf1ad5f80370036713e25, standards/documentation.md:50-68. The SDK and pre-commit dependency updates do not require additional behavior documentation.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@svazquezco
svazquezco merged commit c7a26e2 into main Nov 4, 2026
7 checks passed
@svazquezco
svazquezco deleted the feature/MPT-27353/add-webhook-example-in-mpt-extension-python-template branch November 4, 2026 12:59
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.

2 participants