Skip to content

feat(manifest-helpers): handle AssetVariant array slots (4/5 of #1902 sweep) - #1907

Merged
bokelley merged 2 commits into
bokelley/cut-8-0-betafrom
bokelley/asset-variant-union-3-1
May 21, 2026
Merged

bokelley merged 2 commits into
bokelley/cut-8-0-betafrom
bokelley/asset-variant-union-3-1

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Stacked on #1902. Fourth of five structural-break follow-ups.

AdCP 3.1.0-beta.2 widened each `creative_manifest.assets[asset_id]` slot from `AssetVariant` to `AssetVariant | AssetVariant[]` so carousel `cards`, responsive_creative `headlines`, etc. can carry multiple assets per slot.

Changes

  • `getAsset` / `requireAsset`: when the slot is an array, return the first element. Preserves pre-3.1 behavior for single-asset callers without breaking the type signature.
  • New `getAssetSlot(manifest, assetId, assetType)`: returns the full array (or single-element array if the slot is scalar), filtered by `asset_type`. Use when authoring carousel / responsive_creative platforms.

Adopter migration

  • Single-asset callers: no code change. `getAsset(m, 'cover_image', 'image')` keeps working whether `cover_image` is a single asset or a one-element array.
  • Multi-asset callers: switch to `getAssetSlot(m, 'cards', 'image')` to receive the full array.

Verification

  • `tsc --noEmit`: foundation 17 → 14 errors. All 3 AssetVariant sites resolved.
  • 17/17 manifest-helpers tests pass (10 original + 7 new for array-unwrap, getAssetSlot, asset_type filtering).
  • prettier --check clean.

Remaining structural breaks (1 more PR)

  • `creative-asset.format_id/manifest` (4 sites)

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

… widening)

AdCP 3.1.0-beta.2 widened each creative_manifest.assets[asset_id] slot
from AssetVariant to AssetVariant | AssetVariant[] so carousel cards,
responsive_creative headlines, etc. can carry multiple assets per slot.

Changes:
- getAsset / requireAsset: when the slot is an array, return the first
  element. Preserves pre-3.1 behavior for single-asset callers.
- New getAssetSlot(manifest, assetId, assetType): returns the full
  array (or single-element array if scalar), filtered by asset_type.
  Use for carousel / responsive_creative platforms.
- 7 new tests pinning array-unwrap behavior on getAsset, the new
  getAssetSlot helper, and asset_type filtering.

Resolves 3 of 3 AssetVariant compile errors in src/lib/server/decisioning/manifest-helpers.ts.

Part of the #1902 8.0-beta sweep (4/5 structural breaks closed).
@bokelley
bokelley merged commit c7b41be into bokelley/cut-8-0-beta May 21, 2026
@bokelley
bokelley deleted the bokelley/asset-variant-union-3-1 branch May 21, 2026 15:34

@aao-ipr-bot aao-ipr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the manifest-helpers change. Two stowaway symlinks slipped through the diff — flagging for an immediate follow-up PR to scrub.

Things I checked

  • src/lib/server/decisioning/manifest-helpers.ts:43-50 — getAsset array-unwrap is correct for the documented single-asset case. Array.isArray(slot) ? slot[0] : slot plus the existing asset_type guard preserves pre-3.1 behavior.
  • src/lib/server/decisioning/manifest-helpers.ts:68-75 — getAssetSlot shape is right: filter then cast. The cast is sound because AssetInstance is a discriminated union on asset_type and .filter proves the predicate on every retained element.
  • .changeset/asset-variant-array-slots.md — major is correct. New public export plus an observable behavior change at the getAsset seam.
  • test/server-decisioning-manifest-helpers.test.js — 7 new tests cover the happy paths (array unwrap, empty array, single-asset back-compat, full-array access, scalar→[scalar], missing slot, mixed asset_type filter).
  • Witness-not-translator invariant — no fabricated fields, no silent normalization. getAssetSlot returns exactly what the upstream put in the slot, filtered by the asset_type the caller asked for.

MUST FIX (follow-up PR — PR already merged)

  1. Worktree symlinks committed. The diff added two symlinks pointing at a developer-local path:

    • node_modules -> /tmp/wt-8beta-cut/node_modules
    • schemas/cache -> /tmp/wt-8beta-cut/schemas/cache

    .gitignore lists node_modules/ and schemas/cache/ with trailing slashes — that pattern matches directories, not symlinks-to-directories. Git happily tracked the 120000-mode symlink because the ignore rule didn't match it. Confirmed live on HEAD via git ls-files. These will break the moment anyone checks out the repo without /tmp/wt-8beta-cut/ existing locally — CI included. Land a scrub PR that (a) git rm both symlinks and (b) tightens .gitignore to anchor the patterns (/node_modules and /schemas/cache without trailing slash, which matches both files and dirs at repo root). Worth grep-checking for other /tmp/wt-* symlinks across the tree while you're in there.

Follow-ups (non-blocking — file as issues)

  1. getAsset first-element-only is undocumented. When the first array element has the wrong asset_type, getAsset returns undefined and requireAsset throws — even if element [1] or later matches. getAssetSlot filters then takes all; getAsset takes-first then filters. Defensible (single-asset callers shouldn't shop heterogeneous slots), but pin it in the JSDoc — "first-element-only; use getAssetSlot for heterogeneous slots" — so the next person debugging a phantom undefined doesn't have to read the code to figure out why.
  2. getAssetSlot JSDoc disagrees with the code on empty arrays. Doc at manifest-helpers.ts:60-61 says "Returns undefined if the slot is missing or empty." Code at L71 returns undefined only on !slot (null/missing) — an empty array [] is truthy and falls through to .filter returning []. The two existing array tests pin the missing-slot case; neither covers an empty array on getAssetSlot. Pick one (return undefined for empty, or update the JSDoc to say []) and add the test.
  3. Test coverage gaps (code-reviewer flagged):
    • getAsset(m, 'mixed', 'image') where mixed[0].asset_type === 'text' and mixed[1].asset_type === 'image' — locks in the first-element-only contract (and would catch a future regression that switches to .find).
    • requireAsset on an empty array slot — exercises the unwrap + !asset path.
    • getAssetSlot on an empty array slot — resolves the doc/code disagreement above.

Approving the manifest-helpers logic. Ship the symlink scrub PR before anyone outside /tmp/wt-8beta-cut/ tries to clone.

bokelley added a commit that referenced this pull request May 22, 2026
…ion) (#1902)

* feat!: cut 8.0-beta line (#1580) — flip ADCP_VERSION to 3.1.0-beta.2

Foundation for the 8.0-beta line per docs/development/v8.0-beta-plan.md.
Enters changesets pre-mode with tag 'beta'; subsequent releases publish
as 8.0.0-beta.N under the @beta npm dist-tag until upstream AdCP 3.1
goes GA.

Changes:
- ADCP_VERSION file: 3.0.12 → 3.1.0-beta.2
- src/lib/version.ts regenerated via sync-version --force
- scripts/sync-version.ts: extended buildCompatibleVersions() to accept
  3.1.0-beta.x pins; retains 3.0.x GA compat through LAST_3_0_GA_PATCH=12
  so an 8.0-beta SDK still talks to a 3.0-pinned seller per spec's
  open-enum wire compat.
- schemas/cache/3.1.0-beta.2 synced as primary (cosign verified)
- Regenerated types: tools, schemas, core, manifest (80 codes, 61 tools,
  20 specialisms), enums, entity-hydration map
- FORWARD_COMPAT_ERROR_CODES emptied — AUTH_MISSING/AUTH_INVALID/
  AGENT_SUSPENDED/AGENT_BLOCKED are now in primary manifest-driven
  ErrorCodeValues. Compile-time disjointness assertion would fail if a
  code returned to the overlay after manifest absorption.
- BuyerRetryPolicy.DEFAULT_CODE_POLICY: added 31 entries for new 3.1
  codes (provenance, billing, format-projection, pixel-tracker,
  scope/permission, configuration, brand, idempotency-in-flight,
  credential-in-args, retention, etc.)
- Mechanical undefined-guards in responses.ts, signals.ts,
  test-controller-bridge.ts, test-controller.ts

What's red (separate follow-up PRs, listed in the changeset):
- OutcomeMeasurement export removed (replaced by ?)
- Brand object lost categories field (spec migration)
- AssetVariant became a union with array
- creative-asset shape changed (format_id/manifest)
- ControllerScenario gained new enum values; exhaustiveness guard fails
- Envelope status REQUIRED on auto-registered get_adcp_capabilities

These are all per-feature spec migrations that map to needs:adcp-3.1
queue items; will land as separate PRs against this branch line.

* fix(retry-policy): add 'capability' escalate reason + enumerate divergence

Addresses non-blocking review feedback on #1902:

- code-reviewer: 'capability' missing from RetryDecision.escalate.reason
  union; format-projection + pixel-tracker codes were routed to 'commercial'
  with a TODO comment.
- ad-tech-protocol-expert: divergence comment on the escalate union should
  enumerate the billing- and provenance-family escalations explicitly so
  future readers don't "fix" the apparent drift from spec recovery values.

Changes:
- Add 'capability' to the escalate.reason union with a comment listing the
  7 format-projection and pixel-tracker codes that route to it.
- Route the 7 codes from 'commercial' to 'capability'. Dashboards can now
  filter implementation-choice tickets from commercial-policy ones.
- Extend the JSDoc on the existing reasons to enumerate billing + provenance
  escalations and the new SCOPE_INSUFFICIENT / READ_ONLY_SCOPE / etc. routes.
- Note that FORMAT_DECLARATION_* codes are spec-advisory (emitted in
  errors[] on a 200-success), so the retry policy primarily fires when an
  adopter explicitly routes them; separate follow-up to revisit
  advisory-vs-error policy dispatch.

* fix(types): handle OutcomeMeasurement rename to OutcomeMeasurementDeprecated (#1903)

AdCP 3.1.0-beta.2 renamed the OutcomeMeasurement interface to
OutcomeMeasurementDeprecated to signal the surface is on the 4.0
removal track. Update compat.ts and the index.ts re-export to point
at the new name, with the original name preserved as a re-export
alias so existing adopter imports keep working.

Part of the #1902 8.0-beta sweep (1/5 structural breaks).

* feat(test-controller): promote query_upstream_traffic to CONTROLLER_SCENARIOS (#1905)

AdCP 3.1.0-beta.2 added query_upstream_traffic to
ListScenariosSuccess['scenarios'] (spec PR adcp#3816 landed). Promote
it from the open-extension literal-string path to a first-class
CONTROLLER_SCENARIOS member.

Resolves the test-controller.ts:210 exhaustiveness guard from the
#1902 foundation sweep.

Changes:
- CONTROLLER_SCENARIOS.QUERY_UPSTREAM_TRAFFIC added as first-class.
- SCENARIO_MAP extended with the queryUpstreamTraffic → QUERY_UPSTREAM_TRAFFIC
  mapping (auto-advertised via scenariosFromStore, the canonical typed
  path).
- Removed local QUERY_UPSTREAM_TRAFFIC_SCENARIO literal and the
  `as unknown as ComplyTestControllerResponse` cast at the dispatcher
  call site — UpstreamTrafficSuccess is now in the generated union.
- Exhaustive-scenario test extended with queryUpstreamTraffic store
  method so the CONTROLLER_SCENARIOS / SCENARIO_MAP coverage invariant
  holds. 114/114 affected tests pass.

Part of the #1902 8.0-beta sweep (2/5 structural breaks closed).

* fix(governance): drop categories from governance_agents[] wire emission (#1906)

AdCP 3.1.0-beta.2 narrowed the governance_agents[] wire shape from
{url, categories?} to {url} only. Per-agent category signaling moved
out of band; the wire schema no longer carries categories.

Changes:
- src/lib/server/decisioning/account.ts: projectGovernanceAgent emits
  {url} only; syncGovernanceRowToWire's inline projection mirrors.
- src/lib/server/responses.ts: stripGovernanceAgentSecrets drops the
  categories preservation branch.
- test/lib/sync-governance-credential-strip.test.js: now asserts
  categories is stripped (defense-in-depth with the existing
  authentication.credentials strip). All 82 governance tests pass.
- src/lib/server/wire-spec-fields.generated.ts: regenerated against
  3.1.0-beta.2 schemas (autogenerated).

Adopter migration: the SDK no longer emits categories on
governance_agents[]. Reading the field off the wire returns undefined.
Switch to whatever out-of-band channel the seller now uses for
per-agent category metadata.

Part of the #1902 8.0-beta sweep (3/5 structural breaks closed).

* feat(manifest-helpers): handle AssetVariant array slots (3.1.0-beta.2 widening) (#1907)

AdCP 3.1.0-beta.2 widened each creative_manifest.assets[asset_id] slot
from AssetVariant to AssetVariant | AssetVariant[] so carousel cards,
responsive_creative headlines, etc. can carry multiple assets per slot.

Changes:
- getAsset / requireAsset: when the slot is an array, return the first
  element. Preserves pre-3.1 behavior for single-asset callers.
- New getAssetSlot(manifest, assetId, assetType): returns the full
  array (or single-element array if scalar), filtered by asset_type.
  Use for carousel / responsive_creative platforms.
- 7 new tests pinning array-unwrap behavior on getAsset, the new
  getAssetSlot helper, and asset_type filtering.

Resolves 3 of 3 AssetVariant compile errors in src/lib/server/decisioning/manifest-helpers.ts.

Part of the #1902 8.0-beta sweep (4/5 structural breaks closed).

* feat(preview-utils): adopt self-rendering product_card (5/5 of #1902 sweep — CI green!) (#1908)

* feat(preview-utils): adopt 3.1.0-beta.2 self-rendering product_card

AdCP 3.1.0-beta.2 changed product_card from creative-agent-rendered
({format_id, manifest}) to a self-contained visual card ({image, title,
description, price_label, cta_label}). The card IS the preview now;
no creative-agent round-trip is required.

batchPreviewProducts rewritten to extract product_card.image?.url
directly. The creativeAgentClient + options parameters are retained
for signature compatibility (renamed to _-prefixed unused args)
and marked @deprecated; planned removal in 8.0 final or 9.0.

format_card / batchPreviewFormats are unchanged — only product_card
had this spec migration in 3.1.0-beta.2.

Adopter migration: existing calls keep working (PreviewResult[] still
populated with previewUrl from the new inline image.url). Direct
product.product_card?.image?.url access is the new recommended path.

Part of the #1902 8.0-beta sweep (5/5 structural breaks closed — CI
should now be green on the foundation stack).

* Merge bokelley/cut-8-0-beta: resolve wire-spec-fields timestamp conflict

* fix(beta.3): envelope status + governance/rights field renames sweep

Closes the remaining 45+ compile errors from the beta.2 → beta.3 jump.
The spec broadened the envelope-required-status change AND renamed
several decision-shape fields to free `status` for `TaskStatus` at the
envelope level.

Envelope status added to:
- src/lib/adapters/content-standards-adapter.ts
- src/lib/adapters/governance-adapter.ts
- src/lib/adapters/property-list-adapter.ts
- src/lib/adapters/si-session-manager.ts
- src/lib/core/GovernanceMiddleware.ts
- src/lib/server/create-adcp-server.ts
- src/lib/server/decisioning/account.ts
- src/lib/server/decisioning/list-helpers.ts
- src/lib/server/decisioning/runtime/from-platform.ts
- src/lib/server/governance.ts
- src/lib/server/responses.ts
- src/lib/server/test-controller-bridge.ts
- src/lib/core/GovernanceTypes.ts

Field renames absorbed:
- Governance decision `status: 'approved' | 'denied'` → `verdict`
- ReportPlanOutcomeResponse `status` → `outcome_state`
- Rights response `status: 'acquired'` → `rights_status`
- NotificationConfig[] intersection collision resolved at the two
  account.ts call sites

Subagent-executed mechanical sweep. Build:lib clean (0 errors).

* fix(beta.3): complete governance/outcome/rights rename + STALE_RESPONSE policy

Closes the BLOCK items flagged by code-reviewer + ad-tech-protocol-expert
on the post-rebase foundation:

Governance verdict rename (`CheckGovernanceResponse.status` → `verdict`):
- src/lib/testing/scenarios/governance.ts: 19 sites across 5 scenarios
  (initial check, over-budget, geo, conditions+recheck, delivery+drift).
  Renamed local `const status = data.status` → `const verdict = data.verdict`
  and threaded through step.details log strings ("verdict=approved").
  Plan-sync status sites (867/872/883) left untouched — different field.
- src/lib/testing/storyboard/context.ts:261: extractor `d?.status` → `d?.verdict`.
- src/lib/testing/stubs/governance-agent-stub.ts:288: stub emits `verdict: 'approved'`.

Outcome rename (`ReportPlanOutcomeResponse.status` → `outcome_state`):
- src/lib/testing/storyboard/context.ts:269: extractor → `d?.outcome_state`.
- src/lib/testing/stubs/governance-agent-stub.ts:315: stub emits `outcome_state: 'accepted'`.

Rights rename (`AcquireRights*.status: 'acquired'` → `rights_status`):
- src/lib/server/responses.ts:616 JSDoc autocomplete hint.
- src/lib/server/decisioning/specialisms/brand-rights.ts:85/91/99 JSDoc.

STALE_RESPONSE retry-policy correction:
- src/lib/utils/buyer-retry-policy.ts: was {action: 'mutate-and-retry',
  reason: 'state'} (wrong — implies the payload should be re-fetched).
  Now {action: 'escalate', escalateReason: 'terminal'}. Spec semantics:
  STALE_RESPONSE is a non-fatal advisory paired with a populated success
  payload — consume the payload, surface the advisory, do not retry.
- RetryDecision.escalate.reason JSDoc updated to enumerate STALE_RESPONSE
  alongside CREDENTIAL_IN_ARGS in the 'terminal' branch.

Symmetric pattern with the witness-not-translator memory: stub and
consumer must speak the same wire vocabulary or scenarios silently
pass by reading undefined on both sides.

Build:lib clean (0 errors).

* feat(compat): 3.0.x receiver-side leniency for envelope `status`

Addresses ad-tech-protocol-expert's must-fix on PR #1902.

AdCP 3.1.0-beta.2 made envelope `status` REQUIRED. A 3.1-pinned SDK
acting as a receiver against a 3.0.12 seller that omits envelope
`status` would fail strict validation on every response —
COMPATIBLE_ADCP_VERSIONS enumeration alone doesn't relax the
validators.

New helper: src/lib/utils/envelope-status-compat.ts
- `injectLegacyEnvelopeStatus(response)` synthesizes envelope `status`
  ONLY for responses that declare themselves 3.0.x (adcp_version
  starting with "3.0", or adcp_major_version: 3 with no adcp_version,
  or no version fields at all).
- `completed` when no top-level errors[] present, `failed` otherwise.
- Never overwrites an existing truthy `status`.
- 3.1+ responses that omit `status` still fail strict validation —
  the leniency is back-compat affordance, not permanent loosening.

Wired into 5 validation paths:
- response-unwrapper.ts:165 — unwrapProtocolResponse main path
- response-unwrapper.ts:566 — isAdcpSuccess symmetric path
- validation/schema-validator.ts:693 — Ajv validateResponse
  (applied BEFORE selectResponseVariant so synthesized `completed`
   doesn't misroute to the async-variant schema)
- core/ResponseValidator.ts:327 — runtime ResponseValidator
- testing/client.ts:672 + testing/storyboard/validations.ts:476 —
  storyboard/test-kit direct Zod paths

Tests: test/lib/envelope-status-compat.test.js — 17 cases covering
all required pins (3.0 → completed, 3.0+errors → failed, 3.1
unchanged, 3.1 with status unchanged, 3.0 with explicit status
unchanged, no version → legacy) plus adcp_major_version: 3 legacy,
foreign majors (4.0, 2.5), mutation-safety, and null/non-object
guard. All pass.

Subagent-executed sweep. Build:lib clean.
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.

1 participant