From b35cbe3f0b1ea789b56dd018955ba3bbef8ab5bd Mon Sep 17 00:00:00 2001 From: hsbedi Date: Fri, 6 Nov 2026 19:12:42 +0000 Subject: [PATCH] fix(sdjwt): serialize pydantic models in json mode to support enum claims in mandates --- .cspell/custom-words.txt | 2 ++ .github/workflows/linter.yaml | 16 +++++++++++-- code/sdk/python/ap2/sdk/sdjwt/common.py | 2 +- .../ap2/tests/agent_recurrence_tests.py | 24 +++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.cspell/custom-words.txt b/.cspell/custom-words.txt index ce73c361..1bb7a3f1 100644 --- a/.cspell/custom-words.txt +++ b/.cspell/custom-words.txt @@ -149,6 +149,8 @@ ropeproject RPCURL Rulebook screenreaders +SDJWT +SECP setlocal sharedpref Shopcider diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index fea1b9c1..ad0c3190 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -4,19 +4,30 @@ on: pull_request: branches: [main] +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: name: Lint Code Base runs-on: ubuntu-latest + permissions: + contents: read # Required to check out repository contents + packages: read # Required to pull container image + statuses: write # Required to post linter commit statuses steps: - name: Checkout Code - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: fetch-depth: 0 + persist-credentials: false - name: Lint Code Base - uses: super-linter/super-linter/slim@v8 + uses: super-linter/super-linter/slim@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0 env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -25,6 +36,7 @@ jobs: VALIDATE_ALL_CODEBASE: false FILTER_REGEX_EXCLUDE: "^(\\.github/|\\.vscode/|code/samples/).*|CODE_OF_CONDUCT.md|CHANGELOG.md" VALIDATE_BIOME_FORMAT: false + VALIDATE_BIOME_LINT: false VALIDATE_PYTHON_BLACK: false VALIDATE_PYTHON_FLAKE8: false VALIDATE_PYTHON_ISORT: false diff --git a/code/sdk/python/ap2/sdk/sdjwt/common.py b/code/sdk/python/ap2/sdk/sdjwt/common.py index cdea78ae..19cb908c 100644 --- a/code/sdk/python/ap2/sdk/sdjwt/common.py +++ b/code/sdk/python/ap2/sdk/sdjwt/common.py @@ -226,7 +226,7 @@ def delegate_claims_from_model(payload: BaseModel) -> dict[str, Any]: """Serialize a Pydantic payload into AP2 delegate claims.""" if not isinstance(payload, BaseModel): raise TypeError('payload must be an instance of pydantic.BaseModel') - return payload.model_dump(by_alias=True, exclude_none=True) + return payload.model_dump(by_alias=True, exclude_none=True, mode='json') def selectively_disclosable_claims( diff --git a/code/sdk/python/ap2/tests/agent_recurrence_tests.py b/code/sdk/python/ap2/tests/agent_recurrence_tests.py index 460261d3..0c9b7812 100644 --- a/code/sdk/python/ap2/tests/agent_recurrence_tests.py +++ b/code/sdk/python/ap2/tests/agent_recurrence_tests.py @@ -18,6 +18,7 @@ from ap2.sdk.generated.types.jwk import JsonWebKey from ap2.sdk.generated.types.merchant import Merchant from ap2.sdk.generated.types.payment_instrument import PaymentInstrument +from ap2.sdk.mandate import MandateClient from ap2.sdk.utils import ec_key_to_jwk from cryptography.hazmat.primitives.asymmetric import ec @@ -178,3 +179,26 @@ def test_payment_agent_recurrence_missing_context(): 'Missing mandate context required to evaluate recurrence' in v for v in violations ) + + +def test_open_payment_mandate_agent_recurrence_can_be_signed(issuer_key): + """OpenPaymentMandate carrying AgentRecurrence signs and verifies.""" + mandate = _open_payment( + constraints=[ + AgentRecurrence(frequency=Frequency.DAILY, max_occurrences=2), + AmountRange(min=100, max=2000, currency='USD'), + Budget(max=5000, currency='USD'), + ] + ) + client = MandateClient() + token = client.create(payloads=[mandate], issuer_key=issuer_key) + assert token + res = client.verify( + token, key_or_provider=issuer_key, payload_type=OpenPaymentMandate + ) + assert res.is_valid + assert len(res.mandate_payload.constraints) == 3 + recurrence = res.mandate_payload.constraints[0] + assert isinstance(recurrence, AgentRecurrence) + assert recurrence.frequency == Frequency.DAILY + assert recurrence.max_occurrences == 2