Skip to content

feat(server): export canonical state-machine transition maps and assert helpers - #1423

Closed
bokelley wants to merge 2 commits into
mainfrom
claude/issue-1416-export-state-machine-helpers
Closed

bokelley wants to merge 2 commits into
mainfrom
claude/issue-1416-export-state-machine-helpers

Conversation

@bokelley

@bokelley bokelley commented May 3, 2026

Copy link
Copy Markdown
Contributor

Closes #1416

Summary

Exports the canonical AdCP state-machine transition maps from @adcp/sdk/server so sellers don't copy-paste the graph (three examples already had diverged copies). The conformance runner's status.monotonic invariant uses the same maps, so sellers who guard handlers with assertMediaBuyTransition are guaranteed to agree with the storyboard runner.

New public exports (available from both @adcp/sdk and @adcp/sdk/server):

Symbol Purpose
MEDIA_BUY_TRANSITIONS ReadonlyMap<MediaBuyStatus, ReadonlySet<MediaBuyStatus>>
isLegalMediaBuyTransition(from, to) boolean predicate
assertMediaBuyTransition(from, to) throws NOT_CANCELLABLE (re-cancel) or INVALID_STATE
CREATIVE_ASSET_TRANSITIONS ReadonlyMap<CreativeStatus, ReadonlySet<CreativeStatus>>
isLegalCreativeTransition(from, to) boolean predicate
assertCreativeTransition(from, to) throws INVALID_STATE
CREATIVE_APPROVAL_TRANSITIONS ReadonlyMap<CreativeApprovalStatus, ReadonlySet<CreativeApprovalStatus>>
isLegalCreativeApprovalTransition(from, to) boolean predicate
assertCreativeApprovalTransition(from, to) throws INVALID_STATE

CreativeApprovalStatus is also newly exported from the root barrel.

Error code semantics for assertMediaBuyTransition:

  • NOT_CANCELLABLE (recovery: correctable) — only for canceled → canceled re-cancel; matches storyboard media_buy_seller/invalid_transitions/second_cancel
  • INVALID_STATE — all other illegal transitions including completed → canceled and rejected → canceled (per manifest example: "updating a completed or canceled media buy")

Structural change: src/lib/testing/storyboard/default-invariants.ts now imports the three exported maps from server/state-machine.ts instead of maintaining its own copies. Import direction is testing → server, which already existed via server/envelope-allowlist. No circular dependency.

Examples updated: seller-test-controller.ts and comply-controller-seller.ts replace inline copy-pasted tables with SDK imports. skills/build-seller-agent/SKILL.md updates the test-controller sketch and adds a production-handler code sample.

What was tested

  • npm run format:check — clean
  • npm run typecheck — 2 pre-existing tsconfig warnings only, no new errors (verified by stash comparison)
  • npx vitest run — same pass/fail as main (all failures are pre-existing dist/ not-built integration tests)

Pre-PR review

  • code-reviewer: approved — no blockers; flagged shadow naming (fixed: assertCreativeTransition → requireLegalCreativeTransition in comply example) and noted absence of unit tests for state-machine.ts (pre-existing low test density pattern; tracked separately)
  • ad-tech-protocol-expert: approved with one blocker addressed — initial NOT_CANCELLABLE scope was too broad (to === 'canceled'); tightened to from === 'canceled' && to === 'canceled' only, per spec manifest distinction between "cannot be canceled" and "wrong lifecycle state"

Nit noted but not fixed (deferred): TransitionGraph-wrapped local variable names in default-invariants.ts shadow the import aliases — cosmetic only, no runtime impact; can be addressed in a follow-up.

Out of scope for this PR: ACCOUNT_TRANSITIONS, SI_SESSION_TRANSITIONS, CATALOG_ITEM_TRANSITIONS, PROPOSAL_TRANSITIONS, AUDIENCE_TRANSITIONS — specialized specialisms, low immediate impact. state-machine.ts unit tests — pre-existing low test density; should be added in a dedicated test PR.

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01Dd2cvBgL7mZiLFHqTMb7pj


Generated by Claude Code

claude added 2 commits May 3, 2026 03:27
Expose MEDIA_BUY_TRANSITIONS, isLegalMediaBuyTransition, assertMediaBuyTransition,
CREATIVE_ASSET_TRANSITIONS, isLegalCreativeTransition, assertCreativeTransition,
CREATIVE_APPROVAL_TRANSITIONS, isLegalCreativeApprovalTransition, and
assertCreativeApprovalTransition from @adcp/sdk/server and the root barrel.

The assertion helpers throw the spec-correct AdcpError codes:
NOT_CANCELLABLE for cancel-on-terminal, INVALID_STATE for other illegal
transitions. The conformance runner's status.monotonic invariant uses the
same maps, so sellers using assertMediaBuyTransition are guaranteed to agree
with the storyboard runner.

Refactors default-invariants.ts to import the maps from the new module
instead of maintaining its own copies. Updates three example files and
SKILL.md to eliminate copy-pasted transition tables.

Closes #1416

https://claude.ai/code/session_01Dd2cvBgL7mZiLFHqTMb7pj
…guard

assertMediaBuyTransition now only throws NOT_CANCELLABLE for the
canceled → canceled re-cancel case (per storyboard second_cancel assertion).
completed → canceled and rejected → canceled correctly use INVALID_STATE,
matching the manifest example ("updating a completed or canceled media buy").

Rename local assertCreativeTransition in comply-controller-seller.ts to
requireLegalCreativeTransition to avoid shadowing the SDK export of the
same name that throws AdcpError instead of TestControllerError.

https://claude.ai/code/session_01Dd2cvBgL7mZiLFHqTMb7pj
@bokelley

bokelley commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Duplicate of #1427 — same scope (state-machine exports for #1416), but #1427 also ships the unit tests #1423 was missing per the prior code-reviewer feedback. Closing in favor of #1427.

@bokelley bokelley closed this May 3, 2026
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.

SDK: export MEDIA_BUY_TRANSITIONS + assertMediaBuyTransition for runtime use

2 participants