Skip to content

docs(recipes): add composeMethod testing recipe and matching tests (#1345) - #1371

Merged
bokelley merged 1 commit into
mainfrom
claude/issue-1345-composemethid-testing-recipes
May 3, 2026
Merged

bokelley merged 1 commit into
mainfrom
claude/issue-1345-composemethid-testing-recipes

Conversation

@bokelley

@bokelley bokelley commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1345

Adopters writing composeMethod-wrapped handlers had no canonical test scaffolding — every team reinvented their own. This PR adds a recipe doc with six test patterns and matching running tests so the patterns can't rot independently of the implementation.

What changed

File Change
docs/recipes/composeMethod-testing.md New recipe doc (six patterns)
test/server-decisioning-compose-recipes.test.js Matching running tests (node:test, same import style as existing compose tests)
docs/llms.txt cookbook entry in server section + table row
scripts/generate-agent-docs.ts Same two additions, so the changes survive npm run generate-agent-docs regeneration
.changeset/compose-method-testing-recipes.md patch changeset (docs/llms.txt is in the published files)

Six patterns

  1. Mock the base, assert pass-through — track inner calls with a simple counter; no mocking library needed
  2. Short-circuit from a before hook — including the { shortCircuit: undefined } vs bare undefined gotcha
  3. Layering two composeMethod calls — before takes a single function (not an array); stacking means nesting calls; outer fires first
  4. after hook enrichment — after receives (result, params, ctx); also runs on short-circuit values
  5. composeMethod + typed errors — PermissionDeniedError thrown from inner or before propagates naturally
  6. requireAdvertiserMatch with composeMethod — demonstrates resolve-preset shape; requireAccountMatch and requireOrgScope follow the same pattern

Notes

  • docs/llms.txt is auto-generated — both the file and its generator (scripts/generate-agent-docs.ts) were updated identically so the content survives npm run generate-agent-docs.
  • Doc snippets use require('@adcp/sdk/server') (public import); test file uses require('../dist/lib/server') (repo-internal, consistent with all other test files).

What tested

  • Build: npm run build:lib unavailable in this environment (missing tsc/tsx from node_modules). Test file follows identical import and assertion style as test/server-decisioning-compose.test.js. CI will validate.
  • No generated files touched (src/lib/types/*.generated.ts, src/lib/agents/index.generated.ts).

Pre-PR review:

  • code-reviewer: approved after 2 blockers fixed — requireAccountMatch missing from llms.txt preset list; Pattern 6 header scope mismatch with snippet. 1 nit fixed (add run command to authoritative note).
  • docs-expert: approved after 2 blockers fixed — changeset filename typo (composemethid → compose-method); doc snippets used internal dist path instead of @adcp/sdk/server. 2 issues fixed (missing innerCalled reset; undeclared inner in Pattern 4 second snippet). 1 nit fixed (JSDoc cross-reference clarification).

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 1371 →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

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

…1345)

Closes #1345.

Adopters writing composeMethod-wrapped handlers had no canonical test
scaffolding — every team reinvented their own. This PR adds a recipe
doc with six test patterns and matching running tests so the patterns
can't rot independently of the implementation.

What changed:
- docs/recipes/composeMethod-testing.md — new recipe doc (six patterns)
- test/server-decisioning-compose-recipes.test.js — matching running
  tests (node:test, same import style as existing compose tests)
- docs/llms.txt — cookbook entry in server section + table row
- scripts/generate-agent-docs.ts — same two additions, so the changes
  survive `npm run generate-agent-docs` regeneration
- .changeset/compose-method-testing-recipes.md — patch changeset
  (docs/llms.txt is in the published `files`)

Six patterns:
1. Mock the base, assert pass-through (counter, no mocking library)
2. Short-circuit from a `before` hook
3. Stacked `before` hooks (ordering, early-exit semantics)
4. `after` hook enrichment
5. composeMethod + typed errors (AdcpError throw)
6. composeMethod over `accounts.resolve` with security presets

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley force-pushed the claude/issue-1345-composemethid-testing-recipes branch from 78391cf to 342891e Compare May 3, 2026 01:59
bokelley added a commit that referenced this pull request May 3, 2026
Came in via the main merge (#1342 → #1395). Buyers calling
get_media_buy_delivery / get_creative_delivery with multiple
media_buy_ids hand the array to the platform as-is — framework
doesn't synthesize per-buy fan-out because cross-buy aggregates
(reach, new_to_brand_rate, frequency) depend on dedup capability
that's platform-domain knowledge.

Closes one of the gaps the upstream-feedback screenshot flagged as
"Not yet — adapters can still silently truncate." composeMethod
test recipes (the other gap) are tracked separately in #1371.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley marked this pull request as ready for review May 3, 2026 02:06
@bokelley
bokelley merged commit 655280e into main May 3, 2026
10 checks passed
bokelley added a commit that referenced this pull request May 3, 2026
Final review of what's queued for 6.7 ship surfaced four
adopter-relevant changes that weren't in the migration recipe yet:

New recipes (12 → 15):
- #13 createTenantStore — opinionated multi-tenant AccountStore
  builder with built-in fail-closed tenant-isolation gate. Resolves
  the screenshot's "RosterAccountStore (Postgres)" item — Postgres
  was always blocked on adopter persistence layer; the helper is
  the SDK side of that contract.
- #14 state-machine helpers (MEDIA_BUY_TRANSITIONS,
  assertMediaBuyTransition, CREATIVE_ASSET_TRANSITIONS,
  assertCreativeTransition). Drop-in replacements for the local
  status-graph copy three example files were carrying.
- #15 createMediaBuyStore — opt-in targeting_overlay echo on
  get_media_buys for sellers claiming property-lists /
  collection-lists.

Recipe updates:
- #5 — note AccountStore.syncGovernance is now typed (drops the v5
  escape-hatch + `as any` pattern); credentials stripped on emit.
- #10 — add Shape C (createRosterAccountStore) for publisher-curated
  rosters alongside Shape A (InMemoryImplicitAccountStore) and
  Shape B (createOAuthPassthroughResolver). Three-shape table.
- #12 — `createOAuthPassthroughResolver` now also re-exported from
  `@adcp/sdk/server` (the patch landed on main); all three import
  paths work.

What-else-changed additions:
- Account<TCtxMeta> v3 wire alignment — billing_entity (with bank
  stripped on emit), rate_card, payment_terms, credit_limit, setup
  (drives pending_approval → active lifecycle), account_scope,
  governance_agents, reporting_bucket. Promoted from a footnote per
  adtech-product-expert's earlier review.
- multi_id truncation dev warn paired with the existing
  media_buy_ids[] fan-out item.
- Cross-specialism dispatch docs — no ctx.platform.<X> accessor;
  class instance + this OR closure capture.
- composeMethod testing recipes link (docs/recipes/composeMethod-testing.md
  is now merged on main from #1371).
- Sales-social + sales-guaranteed planning surface mocks
  (delivery_estimate / forecast / availability) — adopters can now
  wire Product.forecast against the mocks.
- narrowAccountRef export.
- Storyboard-runner task_completion.<key> capture + webhook fallback.

CLAUDE.md and AGENTS.md blurbs updated from "twelve" to "fifteen"
with the three new helper names called out.

Picked up via merge from main (20 commits since the last sync):
createTenantStore (#1420), createMediaBuyStore (#1424),
state-machine helpers (#1427), createRosterAccountStore + Shape C
docs, syncGovernance typed, Account v3 wire alignment, Account.bank
strip, sales-* planning surface (#1414), task_completion capture
(#1426), runner webhook fallback (#1434), narrowAccountRef (#1428),
composeMethod testing recipes (#1371 merged), oauth-passthrough
re-export, multi-id truncation warn.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: composeMethod test patterns — mocking inner method, asserting short-circuit, stacking before-hooks

1 participant