Skip to content

Conversation

@bokelley
Copy link
Contributor

Summary

Fixes the update_media_buy endpoint to properly handle creative assignments. Previously, the endpoint ignored creative_ids in package updates and returned empty affected_packages arrays.

Problem

The update_media_buy implementation was incomplete:

  • ❌ Ignored creative_ids in package updates
  • ❌ Returned empty affected_packages array
  • ❌ Changes didn't persist to database
  • ❌ Test agent couldn't verify creative assignments

Solution

Added complete creative assignment logic to _update_media_buy_impl:

  1. Validation: Checks that all creative IDs exist before assignment
  2. Diff Calculation: Determines added/removed creatives from existing state
  3. Persistence: Updates CreativeAssignment table
  4. Response: Returns proper affected_packages with PackageUpdateResult

Example Response

{
  "media_buy_id": "buy_123",
  "buyer_ref": "buyer_ref_123",
  "affected_packages": [
    {
      "buyer_package_ref": "pkg_default",
      "changes_applied": {
        "creative_ids": {
          "added": ["creative_1", "creative_2"],
          "removed": [],
          "current": ["creative_1", "creative_2"]
        }
      }
    }
  ]
}

AdCP Compliance

✅ Fully compliant with AdCP v2.2.0 specification

  • affected_packages includes buyer_package_ref + changes_applied
  • creative_ids shows added/removed/current arrays
  • Matches PackageUpdateResult interface from spec

Testing

Unit Tests (4 tests)

  • ✅ Verify affected_packages structure
  • ✅ Test creative addition and replacement
  • ✅ Test serialization
uv run pytest tests/unit/test_update_media_buy_affected_packages.py -v
# ✅ 4 passed

Integration Tests (3 tests - requires PostgreSQL)

  • ✅ Test database persistence
  • ✅ Test creative validation (reject missing IDs)
  • ✅ Test creative replacement workflow
./run_all_tests.sh ci --test-path tests/integration/test_update_media_buy_creative_assignment.py

Files Changed

  • src/core/main.py: +80 lines (creative assignment logic)
  • tests/unit/test_update_media_buy_affected_packages.py: 4 unit tests
  • tests/integration/test_update_media_buy_creative_assignment.py: 3 integration tests
  • docs/fixes/2025-10-23-update-media-buy-creative-assignment.md: Complete fix documentation
  • docs/testing/postmortems/2025-10-23-test-agent-update-media-buy-stub.md: Test agent issue documentation
  • CLAUDE.md: Updated known test agent issues section

Impact

  • ✅ MCP update_media_buy tool now supports creative assignments
  • ✅ A2A update_media_buy endpoint now supports creative assignments
  • ✅ Test agent will work correctly (uses same codebase)
  • ✅ Enables end-to-end creative assignment testing

Test Plan

  • Unit tests verify schema compliance
  • Integration tests verify database persistence
  • Pre-commit hooks pass
  • Pre-push tests pass (838 unit + 174 integration)
  • Manual testing with test agent (after deployment)
  • E2E creative assignment workflow verification

Documentation

🤖 Generated with Claude Code

bokelley and others added 2 commits October 23, 2025 13:16
Problem:
- update_media_buy ignored creative_ids in package updates
- Returned empty affected_packages array
- Changes didn't persist to database

Solution:
- Add creative assignment logic to _update_media_buy_impl (main.py:5866-5942)
- Validate creative IDs exist before assignment
- Calculate added/removed creatives (diff from existing state)
- Persist to CreativeAssignment table
- Return proper affected_packages with PackageUpdateResult

Tests:
- Unit tests verify affected_packages structure (AdCP spec compliant)
- Integration tests verify database persistence (requires PostgreSQL)

AdCP Compliance:
- affected_packages includes buyer_package_ref + changes_applied
- creative_ids shows added/removed/current arrays
- Fully compliant with AdCP v2.2.0 spec

Files Changed:
- src/core/main.py: +80 lines (creative assignment logic)
- tests/unit/test_update_media_buy_affected_packages.py: 4 unit tests
- tests/integration/test_update_media_buy_creative_assignment.py: 3 integration tests
- docs/fixes/2025-10-23-update-media-buy-creative-assignment.md: Fix documentation
- docs/testing/postmortems/2025-10-23-test-agent-update-media-buy-stub.md: Test agent issue
- CLAUDE.md: Updated known test agent issues section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 99cdcdc into main Oct 23, 2025
8 checks passed
EmmaLouise2018 pushed a commit that referenced this pull request Oct 24, 2025
* Fix: Implement creative assignment in update_media_buy

Problem:
- update_media_buy ignored creative_ids in package updates
- Returned empty affected_packages array
- Changes didn't persist to database

Solution:
- Add creative assignment logic to _update_media_buy_impl (main.py:5866-5942)
- Validate creative IDs exist before assignment
- Calculate added/removed creatives (diff from existing state)
- Persist to CreativeAssignment table
- Return proper affected_packages with PackageUpdateResult

Tests:
- Unit tests verify affected_packages structure (AdCP spec compliant)
- Integration tests verify database persistence (requires PostgreSQL)

AdCP Compliance:
- affected_packages includes buyer_package_ref + changes_applied
- creative_ids shows added/removed/current arrays
- Fully compliant with AdCP v2.2.0 spec

Files Changed:
- src/core/main.py: +80 lines (creative assignment logic)
- tests/unit/test_update_media_buy_affected_packages.py: 4 unit tests
- tests/integration/test_update_media_buy_creative_assignment.py: 3 integration tests
- docs/fixes/2025-10-23-update-media-buy-creative-assignment.md: Fix documentation
- docs/testing/postmortems/2025-10-23-test-agent-update-media-buy-stub.md: Test agent issue
- CLAUDE.md: Updated known test agent issues section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove test agent postmortem (not needed in sales agent repo)

---------

Co-authored-by: Claude <noreply@anthropic.com>
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…ocol#560)

* Fix: Implement creative assignment in update_media_buy

Problem:
- update_media_buy ignored creative_ids in package updates
- Returned empty affected_packages array
- Changes didn't persist to database

Solution:
- Add creative assignment logic to _update_media_buy_impl (main.py:5866-5942)
- Validate creative IDs exist before assignment
- Calculate added/removed creatives (diff from existing state)
- Persist to CreativeAssignment table
- Return proper affected_packages with PackageUpdateResult

Tests:
- Unit tests verify affected_packages structure (AdCP spec compliant)
- Integration tests verify database persistence (requires PostgreSQL)

AdCP Compliance:
- affected_packages includes buyer_package_ref + changes_applied
- creative_ids shows added/removed/current arrays
- Fully compliant with AdCP v2.2.0 spec

Files Changed:
- src/core/main.py: +80 lines (creative assignment logic)
- tests/unit/test_update_media_buy_affected_packages.py: 4 unit tests
- tests/integration/test_update_media_buy_creative_assignment.py: 3 integration tests
- docs/fixes/2025-10-23-update-media-buy-creative-assignment.md: Fix documentation
- docs/testing/postmortems/2025-10-23-test-agent-update-media-buy-stub.md: Test agent issue
- CLAUDE.md: Updated known test agent issues section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove test agent postmortem (not needed in sales agent repo)

---------

Co-authored-by: Claude <noreply@anthropic.com>
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