Repository navigation
refactor: validate v3 request shape before v2 wire adaptation - #1106
Conversation
The v2 adapters (adaptGetProductsRequestForV2, adaptCreateMediaBuyRequestForV2, adaptUpdateMediaBuyRequestForV2, adaptSyncCreativesRequestForV2) strip v3-only required fields like `buying_mode` and `account` so the request matches the v2 wire contract. The bundled schemas are v3, so AJV strict validation against the adapted shape was falsely throwing `Validation failed for field '/buying_mode'` on every v2-detected agent. Required-field violations on the unadapted request are still caught by the Zod parse in SingleAgentClient.validateRequest before adaptation runs, and strict mode continues to validate v3-detected and version-unknown requests against the v3 schema. Adds two new tests covering both v2 and v3 paths, plus a patch changeset. Also includes auto-formatted skill markdown files and version sync.
Move pre-send AJV validation from TaskExecutor (post-adaptation) to SingleAgentClient (pre-adaptation). The validator now sees the user-facing v3 shape, not the v2-adapted shape, so it stops false- rejecting stripped fields like buying_mode and account on v2-detected agents. Validation coverage is preserved for v2 traffic — including tasks like update_media_buy that have no Zod schema and previously relied entirely on the AJV pass. Replaces the v2-skip introduced in the earlier commit on this branch. TaskExecutor.validateRequest is the public seam; the inline call inside executeTask is removed. Both executeTaskWithHandler and executeTask paths in SingleAgentClient run the check on normalizedParams before adaptRequestForServerVersion.
start_time must be 'asap' or an ISO date-time per core/start-timing.json, and packages requires minItems: 1 per create-media-buy-request.json. The pre-adapt validator now catches these on v2 traffic too, so the fixture has to match the v3 contract.
…entry points
The post-1106 validate seam (executor.validateRequest) is called from
SingleAgentClient.executeAndHandle and SingleAgentClient.executeTask but
not from the three methods that call this.executor.executeTask directly:
syncPlans, getPlanAuditLogs, getAdcpCapabilities. Pre-1106 these got AJV
pre-send validation from the inline call inside TaskExecutor.executeTask
that 1106 removed; post-1106 they silently round-trip malformed requests
to the server. All three task names have v3 schemas in
schemas/cache/3.0.1/{governance,protocol}/, so this is a real coverage
regression.
Adds the validateRequest call before each executor.executeTask. Mirrors
the pattern from SingleAgentClient.executeTask (line 2125).
Plus a regression-guard test confirming that strict mode still rejects
malformed v3 input from the migrated SingleAgentClient seam — closes
the implicit coverage hole the PR description's "validation coverage is
preserved for v2 traffic" claim depended on.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Pushed What it changes: adds Plus a regression-guard test ( Both changes are minimal and additive — same pattern as your line 2125. CI should re-run automatically. Approving + admin-merging once it goes green. Hope this is OK; happy to revert if you'd prefer to take it. |
|
The coverage patch looks right — Generated by Claude Code |
|
Thanks for the confirmation, @bokelley. No changes needed — proceeding as-is. Generated by Claude Code |
…p-strict-validation # Conflicts: # src/lib/version.ts
Symmetric to the existing pre-adapter v3 pass (PR #1106): when the v2 adapter rewrites a request for a v2-detected agent, validate the adapted shape against the cached v2.5 schema bundle. Surfaces drift between adapter output and the v2.5 wire contract. Always warn-only — adapter bugs shouldn't break user requests, and the v3 pre-send pass already vouched for the user-facing input. The pass exists primarily as CI signal for the upcoming adapter-conformance test suite. TaskExecutor.validateAdaptedRequestAgainstV2(taskName, adaptedParams, debugLogs?) is the public seam; mirrors validateRequest's shape. SingleAgentClient.executeAndHandle and SingleAgentClient.executeTask both call it after adaptRequestForServerVersion when serverVersion is 'v2'. Initial baseline against canonical adapter outputs surfaced two real drift items worth follow-up: - adaptCreateMediaBuyRequestForV2 doesn't emit buyer_ref (v2.5 requires top-level + per-package) - adaptSyncCreativesRequestForV2's assets.video shape fails a oneOf These will be addressed alongside the adapter-conformance suite. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…mance suite (#1121) * feat(validation): cache and load AdCP v2.5.3 schemas alongside v3 Pulls the AdCP 2.5.3 schema bundle from a pinned commit on adcontextprotocol/adcp's 2.5-maintenance branch (since v2.5.2 / v2.5.3 were never tagged upstream — adcontextprotocol/adcp#3689). Lands at schemas/cache/v2.5/, ships in dist/lib/schemas-data/v2.5/. Existing resolveBundleKey('v2.5') legacy-alias and copy-schemas-to-dist.ts legacy-prerelease path already routed correctly without resolver changes. schema-loader's ensureCoreLoaded narrows from "skip all fileIndex entries" to "skip only response tool files" so cross-fragment $refs in flat-tree bundles (where v2.5 ships) resolve at compile time. v3's pre-bundled path is unaffected — refs were already inlined. Surfaced via getValidator(tool, direction, 'v2.5'). Internal only; buyer-facing API unchanged. Foundation for upcoming warn-only post-adapter validation pass and adapter-conformance test suite. Pinned source: adcontextprotocol/adcp@4e553ad9 (2.5-maintenance HEAD, 2026-01-23). Refresh by editing SOURCE_SHA in scripts/sync-v2-5-schemas.ts and re-running npm run sync-schemas:v2.5. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(client): warn-only post-adapter v2.5 validation pass Symmetric to the existing pre-adapter v3 pass (PR #1106): when the v2 adapter rewrites a request for a v2-detected agent, validate the adapted shape against the cached v2.5 schema bundle. Surfaces drift between adapter output and the v2.5 wire contract. Always warn-only — adapter bugs shouldn't break user requests, and the v3 pre-send pass already vouched for the user-facing input. The pass exists primarily as CI signal for the upcoming adapter-conformance test suite. TaskExecutor.validateAdaptedRequestAgainstV2(taskName, adaptedParams, debugLogs?) is the public seam; mirrors validateRequest's shape. SingleAgentClient.executeAndHandle and SingleAgentClient.executeTask both call it after adaptRequestForServerVersion when serverVersion is 'v2'. Initial baseline against canonical adapter outputs surfaced two real drift items worth follow-up: - adaptCreateMediaBuyRequestForV2 doesn't emit buyer_ref (v2.5 requires top-level + per-package) - adaptSyncCreativesRequestForV2's assets.video shape fails a oneOf These will be addressed alongside the adapter-conformance suite. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(v2.5): expert-feedback hardening — sha256 pin, symlink defense, provenance Three reviewers (code-reviewer, ad-tech-protocol-expert, security-reviewer) converged on actionable items for the v2.5 schema-cache + warn-only post-adapter passes. Addressed in this commit: - **Tarball SHA-256 pin** (sec M2 / code reviewer Q2): the codeload URL is content-addressed by GitHub but TLS substitution / a compromised CI runner could still swap bytes. Now verifies bytes against SOURCE_TARBALL_SHA256 before any extraction; mismatch fails loud with refresh instructions. - **Symlink defense** (sec M1): cpSync follows symlinks by default, which would let an upstream link copy through to anywhere on disk. Walk the source tree post-extract and refuse any symlinks; pass verbatimSymlinks:true to cpSync as belt-and-suspenders. tar.x now also runs with strict:true to upgrade suspicious entries from warning to throw. - **Provenance file** (protocol expert Q1): write schemas/cache/v2.5/_provenance.json after sync — source repo, branch, pinned SHA, tarball sha256, upstream-declared adcp_version, sync timestamp. Lets downstream consumers diff bundles across refreshes. - **sync-schemas:all umbrella** (code reviewer Q5): single command pulls both v3 and v2.5 bundles. Avoids developer-memory failure mode. - **v3 ensureCoreLoaded regression test** (code reviewer Q1): pins the invariant that bundled-path validators win over flat-tree paths after the narrowing in 036047c. Bundled and flat-tree request schemas have distinct $ids so no AJV-side collision; the test asserts the bundled $id flows through getValidator. Two follow-up issues filed (not in this commit, will be locked in by the upcoming adapter-conformance test suite): - #1115 — adaptCreateMediaBuyRequestForV2 should derive buyer_ref from idempotency_key - #1116 — adaptSyncCreativesRequestForV2 needs to flatten v3 manifest to v2.5 single-asset payload Deferred per expert advice: AJV strict:true (would touch all schemas; broader change), $id-driven file classification (filename-suffix heuristic limitation worth a tracking issue but not urgent), tempdir move to os.tmpdir (cosmetic). DebugLogs plumbing for warn-pass surfacing also deferred — conformance suite is the right consumer for now. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(v2.5): adapter conformance suite against v2.5 schema bundle Pins the canonical v3 fixtures through adaptRequestForServerVersion and asserts each adapted output validates against schemas/cache/v2.5/. CI signal for "the v2 wire adapters produce v2.5-conformant output." Tools with known drift have explicit expected_failures entries pointing at the tracking issue AND pinning the failure-mode pointers. A fix that closes the gap surfaces as an unexpected pass and prompts the entry to be removed. A "every v2-adapted tool has a fixture" guard ensures new adapters can't ship without conformance coverage. Initial state: get_products ✓ conforms clean create_media_buy × known drift at /buyer_ref (#1115) update_media_buy ✓ conforms clean sync_creatives × known drift at /creatives/0/assets/video (#1116) Lib regression: 5541 pass / 7 skipped (pre-existing) / 0 fail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ci(v2.5): wire sync-schemas:all + skip-if-missing guards CI failed on the rebased foundation branch because schemas/cache/v2.5/ isn't populated by the existing sync-schemas step (which only fetches v3). Two fixes: - ci.yml: switch the sync-schemas step to sync-schemas:all (the umbrella that runs both v3 and v2.5) - package.json prepublishOnly: same — ensures the published npm tarball always ships dist/lib/schemas-data/v2.5/ alongside dist/lib/schemas-data/3.0/ For local-dev DX, both v2.5 test suites now check hasSchemaBundle('v2.5') and skip cleanly with an actionable message ("run npm run sync-schemas:v2.5") when the bundle isn't present. CI hits the populated path and runs the tests; a fresh clone without sync gets a skip rather than a confusing AJV "missing schema" error. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(scripts): codegen 'latest cache' resolution ignores legacy aliases Adding `schemas/cache/v2.5/` exposed a latent bug in generate-wellknown-schemas.ts and generate-zod-schemas.ts: their `getLatestCacheDir()` does a `.sort().reverse()` on directory names, and the legacy alias `v2.5` (or `v2.6`) sorts ABOVE `3.0.1` because 'v' > '3' lexically. Result: scripts looking for `brand.json` / `adagents.json` (which only live in the primary v3 cache) probed the v2.5 directory and failed with "brand.json not found in schemas/cache/v2.5". Fix: restrict candidates to MAJOR.MINOR.PATCH-shaped directories and sort by parsed numeric components, with stable releases beating prereleases at the same numeric version. Legacy aliases and the `latest` symlink are now correctly skipped. generate-types.ts uses the `latest` symlink directly (set by sync-schemas to the v3 directory) and was unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Pre-send AJV validation was running inside
TaskExecutor.executeTaskagainst the post-adaptation params. The v2 adapters (adaptGetProductsRequestForV2,adaptCreateMediaBuyRequestForV2,adaptUpdateMediaBuyRequestForV2,adaptSyncCreativesRequestForV2) strip v3-only required fields likebuying_modeandaccountto match the v2 wire contract. The bundled schemas are v3, so strict mode threwValidation failed for field '/buying_mode'on every v2-detected agent — even though the user wrote a perfectly valid v3 request.This PR moves the check upstream: it now runs in
SingleAgentClientagainst the unadapted v3 shape (the same object the caller wrote), before any wire-format adaptation. The earlier v2-skip on this branch (which would have dropped AJV coverage entirely for v2 traffic — includingupdate_media_buy, which has no Zod schema inSingleAgentClient.validateRequestand relied solely on the AJV pass) is replaced.Changes
src/lib/core/TaskExecutor.ts: exposevalidateRequest(taskName, params, debugLogs?)as a public seam; remove the inline call insideexecuteTasksrc/lib/core/SingleAgentClient.ts: callexecutor.validateRequest(taskType, normalizedParams)in bothexecuteTaskWithHandlerandexecuteTaskpaths, beforeadaptRequestForServerVersiontest/lib/request-validation.test.js: 4 tests coveringget_products,create_media_buy,sync_creativesagainst v2 agents (no false reject), plus a v3 happy path.changeset/validate-request-before-v2-adapt.md: patch changeset rewritten to describe the actual fixsrc/lib/version.ts+package-lock.json: version syncskills/*.md: auto-formatted markdown (table formatting, blank lines)Test plan
npm run lint— 0 errorsnpm run build— passesnpm test— pre-existingdist/lib/server/auth.jsrequire("jose")ESM error reproduces on cleanorigin/mainand blocks the suite locally; CI will verify.