Repository navigation
Commit 4185ced
feat(v3-ref-seller): translator pattern with JS mock-server upstream (#447)
* feat(v3-ref-seller): translator pattern — call upstream over HTTP, drop in-process ad-ops persistence
The v3 reference seller stops being an in-process AdCP seller that
duplicates upstream persistence and becomes a translator: AdCP wire
on the inside, the JS mock-server (@adcp/client sales-guaranteed) on
the outside. Real adopters (Prebid salesagent, GAM-shaped publishers,
etc.) have an existing ad server; the reference should demonstrate the
translator seam — not the inverse "build an ad server inside your
seller" pattern.
Changes:
* New src/upstream.py — httpx-based MockUpstreamClient mirroring the
JS mock's openapi.yaml (products, orders, lineitems, creatives,
delivery, conversions, tasks, forecast).
* models.py drops MediaBuy / Creative / PerformanceFeedback. Account
carries upstream routing (network_code, advertiser_id) on the ext
JSON column.
* platform.py rewires every ad-ops method to call upstream over HTTP
and translate to AdCP wire shapes. create_media_buy returns a
TaskHandoff for the upstream's pending_approval path; the framework
surfaces a Submitted envelope to the buyer and runs a background
poll until the upstream auto-approves. update_media_buy raises
UNSUPPORTED_FEATURE (the mock has no order-update endpoint).
sync_accounts / list_accounts stay local Postgres — the AdCP-account
to upstream-network mapping is the durable record this seller owns.
* Capabilities now claim BOTH sales-non-guaranteed AND sales-guaranteed.
The mock supports delivery_type: guaranteed/non_guaranteed; real
GAM-shaped publishers sell both surfaces.
* Tests use respx to mock httpx so the Python pytest CI run doesn't
need to boot Node. New CI jobs: v3-reference-seller-tests (pytest)
and storyboard-v3-reference-seller (boots the JS mock + Python
seller for the real storyboard runner).
* New MIGRATION.md targeted at maintainers of pre-v3 sales agents
(Prebid salesagent specifically) — fork this directory, replace
MockUpstreamClient with your real ad-server client, reseed
Account.ext, deploy.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(v3-ref-seller): spec-conformant error codes + upstream 400 mapping (PR #447 fix-pack)
Replace non-spec error codes (INTERNAL_ERROR, AUTH_INVALID) with
canonical ErrorCode enum values so wire responses survive strict
validation. Map upstream HTTP 400 to terminal INVALID_REQUEST
instead of falling through to the default code. Tighten CAPI perf
feedback to conversion_rate only (the only AdCP metric_type with
even loose CAPI semantics) and document the gap in MIGRATION.md.
- AdcpError("INTERNAL_ERROR", ...) → SERVICE_UNAVAILABLE / transient
for upstream transient failures and onboarding misconfig
- AdcpError("AUTH_INVALID", ...) → AUTH_REQUIRED / terminal for
missing or rejected bearer / X-Network-Code
- _translate_upstream: add explicit 400 → INVALID_REQUEST branch,
add 429 → RATE_LIMITED branch, fix recovery="retry" (not in spec)
to recovery="transient" on the default-code fall-through
- provide_performance_feedback: gate to metric_type='conversion_rate'
only; raise INVALID_REQUEST with field='metric_type' otherwise
- get_products: filter out non-cpm pricing rows (seller declares
pricing_models=('cpm',); skip-and-log rather than projecting)
- _project_creative_status: paused → pending_review (was approved)
- create_media_buy poll: jitter 0.5–1.5× the base interval
- update_media_buy: clarify GAM LineItemService.performLineItemAction
is the production wiring point
- MIGRATION.md: document spec error codes (canonical enum vs legacy
SDK codes), CAPI semantic mismatch, and "what this seller doesn't
yet support upstream" (update_media_buy)
- Tests: cover _translate_upstream (400/401/429/500), conversion_rate
gate, account-loader SERVICE_UNAVAILABLE projection
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(v3-ref-seller): polling correctness + 404 context + status projection + MIGRATION (PR #447 fix-pack 2)
* create_media_buy polling no longer fabricates success on:
- loop exhaustion (now raises SERVICE_UNAVAILABLE/transient)
- upstream rejected status (now raises PERMISSION_DENIED/terminal)
- missing approval_task_id with non-terminal status (now refetches once
and projects from actual current status, never enters polling loop)
* _translate_upstream gains per-callsite not_found_code; get_products
and list_creatives 404s now surface ACCOUNT_NOT_FOUND instead of
the misleading MEDIA_BUY_NOT_FOUND.
* get_media_buy_delivery double-fetches the order so AdCP MediaBuyStatus
reflects upstream state (DeliveryReport doesn't carry status, so
completed/canceled/rejected buys would have surfaced as 'active').
* list_accounts now sets pagination.total_count.
* MIGRATION.md adds a Pre-v3 to v3 mapping table for Prebid salesagent
porting, plus specialism-declaration upgrade, strict-validation
gotchas, and spec-error-code reference sections.
* CI readiness probe uses /_debug/traffic (non-network-scoped, no auth)
so seed-data renames don't break the boot. Adds a post-seller-boot
upstream-alive probe that fails fast if the seller crashed the upstream.
* Tests: polling timeout, polling rejection, no-task refetch path,
ACCOUNT_NOT_FOUND callsite override, 401/500/429/malformed-JSON
failure paths, completed/canceled status projection.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(ci): install example-local deps in v3-reference-seller-tests job
The new pytest job for the translator pattern was failing all tests
with ModuleNotFoundError: 'sqlalchemy'. The example imports sqlalchemy
+ asyncpg + respx but the SDK's [dev] extras don't carry them.
Install inline rather than adding a one-off optional-dependencies group.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 127f164 commit 4185ced
11 files changed
Lines changed: 3007 additions & 1060 deletions
File tree
- .github/workflows
- examples/v3_reference_seller
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
425 | 454 | | |
426 | | - | |
| 455 | + | |
427 | 456 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
435 | 460 | | |
436 | | - | |
437 | 461 | | |
438 | 462 | | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | 463 | | |
444 | 464 | | |
445 | 465 | | |
| |||
466 | 486 | | |
467 | 487 | | |
468 | 488 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | 489 | | |
474 | 490 | | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
485 | 494 | | |
486 | | - | |
487 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
488 | 517 | | |
489 | | - | |
| 518 | + | |
490 | 519 | | |
491 | | - | |
| 520 | + | |
492 | 521 | | |
493 | 522 | | |
494 | 523 | | |
495 | 524 | | |
496 | | - | |
| 525 | + | |
497 | 526 | | |
498 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
499 | 530 | | |
500 | 531 | | |
501 | 532 | | |
502 | 533 | | |
503 | | - | |
504 | | - | |
| 534 | + | |
| 535 | + | |
505 | 536 | | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | 537 | | |
511 | | - | |
512 | | - | |
513 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
514 | 541 | | |
515 | 542 | | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | 543 | | |
521 | | - | |
522 | | - | |
| 544 | + | |
| 545 | + | |
523 | 546 | | |
524 | 547 | | |
525 | 548 | | |
526 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
527 | 567 | | |
528 | | - | |
| 568 | + | |
529 | 569 | | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
547 | 574 | | |
548 | | - | |
| 575 | + | |
549 | 576 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
| 577 | + | |
| 578 | + | |
613 | 579 | | |
614 | 580 | | |
615 | 581 | | |
616 | 582 | | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
| 583 | + | |
| 584 | + | |
621 | 585 | | |
0 commit comments