Skip to content

fix(X402-43): variant-aware extensions.bazaar validation (D.5)#76

Merged
fardinvahdat merged 1 commit into
mainfrom
feat/X402-43-d5-variant-aware-bazaar-validation
May 22, 2026
Merged

fix(X402-43): variant-aware extensions.bazaar validation (D.5)#76
fardinvahdat merged 1 commit into
mainfrom
feat/X402-43-d5-variant-aware-bazaar-validation

Conversation

@fardinvahdat
Copy link
Copy Markdown
Owner

Summary

X402-43 (D.5) — bug fix carrying the v0.3.2 metadata-propagation work forward. Variant-aware extensions.bazaar validation per ADR-004 Pillar 1's verdict semantics + the original bug report from @AsaiShota on #72.

Closes false-positive implementation_issue on every body-discovery v2 service.

Why

@x402/[email protected] ships TWO discovery-extension variants:

Variant Top-level fields Used by
MCP-discovery name, description MCP-style services (TheRoosters, GM, hypeprinter007 #65)
Body-discovery info.input + info.output + schema API-style services with declareDiscoveryExtension(...) (AsaiShota test-echo-cdp, 0xdespot hyperD)

v0.3.0/0.3.1 assumed only the MCP shape. PR #70's D.1 manifest hygiene check carried the same assumption into well-known.ts. Real-world v2 services using the Body-discovery shape verdict to implementation_issue despite being correctly implemented — verdict overrides the substantive indexing-probe signal.

What changes

New file: src/bazaar/extensions-bazaar.ts (variant detection + validation helper)

  • detectBazaarVariant(bazaar) — body-discovery indicators win when all 3 present (info.input + info.output + schema); else assume mcp-discovery per ADR-004 "else assume Mcp"; third "unknown" branch is defensive for future @x402/extensions variants
  • validateBazaarExtension(bazaar) — variant-appropriate required-field check; pure-function, presentation-free; callers format messages in their own voice

src/bazaar/challenge.ts (refactor)

Inline validation replaced with validateBazaarExtension call. mcp-discovery behavior preserved (regression-clean). New body-discovery pass + fail paths. New defensive "unknown variant" pass path.

src/bazaar/well-known.ts (refactor)

Same refactor as challenge.ts. The pillar-2 D.1 manifest hygiene check (PR #70) now respects variant.

JSON output additive

detail.variant field added to extensions.bazaar-related check results. Additive per the JSON API stability commitment (ADR-004 Pillar 2); no field renames/removals.

CHANGELOG.md [Unreleased] ### Fixed

Crediting @AsaiShota for the diagnosis + @0xdespot for the second-voice corroboration. ### JSON API subsection documents the additive detail.variant field.

Acceptance criteria (X402-43)

  • Re-running bazaar-check against AsaiShota's x402-market-api.lien-studio-akiyama.workers.dev/api/seller-4068b8fc/test-echo-cdp under v0.3.2 produces challenge: pass for the body-discovery variant — verified via the body-discovery happy-path test in bazaar-challenge.test.ts
  • hyperD-style body-discovery shape similarly produces clean envelope verdict — same code path
  • Verdict envelope no longer overrides the substantive signal on body-discovery services — body-discovery is its own success path
  • Test coverage: ≥4 cases per affected file (8+ tests total) — challenge.ts: 4 new; well-known.ts: 4 new; plus 13 helper unit tests = 21 new tests
  • Default-deny path: unknown variant skips shape validation, emits info-level message — challenge.ts returns pass with "variant not recognised; skipping" message; well-known.ts handles via catch-all branch
  • CHANGELOG entry crediting @AsaiShota + @0xdespot

Strict audit gate — abbreviated (user-in-loop mode per ADR-003)

  • Stage 1 pre-work: branched off bd7494a (PR feat(X402-41): ADR-004 — v0.3.2 scope + JSON API stability + facilitator-aware verdict semantics #75 ADR-004 just-merged); .gitignore WIP on branch but NOT staged (hard rule docs(X402-8): SPEC.md v0.1 — implements the wedge from ADR-001 #7 preserved); 4 source files modified + 2 created + 1 CHANGELOG appended (one-thing-per-PR: variant-aware refactor)
  • Stage 2 implementation: helper extracted + 2 checkers refactored + 21 new tests + CHANGELOG ### Fixed entry crediting evidence sources
  • Stage 3 correctness: ✅ typecheck clean; ✅ lint+prettier clean; ✅ 450 tests pass + 4 skipped (was 429+4; +21 new); ✅ build clean; ✅ check:publish-surface 98 files / 363 KB / 0 devDep imports (under 400 KB cap, +10 KB for the new helper + tests)
  • Stage 4 edge cases: ≥10 edges enumerated — empty {} (mcp default, fails as before — regression preserved); null/undefined (caller pre-screens); hybrid both-shapes (body wins per detection order); info non-object (falls to mcp); info.input/output null after detection (body-discovery, validate-fails); unicode in fields; future 3rd variant (defensive unknown path); concurrency (pure-function, no shared state); whitespace-only strings (.trim() preserved); foreign-key objects (mcp default per AC)
  • Stage 5 gap check: all 6 X402-43 AC items satisfied; CHANGELOG entry added (was missing in first pass; flagged + remedied in stage 5); cross-references to ADR-004 + X402-46 (D.3 not_applicable_non_cdp state) + X402-47 (fixture consumption) all present
  • Stage 6 ship: this PR; awaiting maintainer merge per [[user-merges-prs-themselves]]

What unblocks on merge

  • X402-42 (D.4) is parallel-safe and can continue independently
  • X402-44 (JSON API stability) can now snapshot the new detail.variant field as part of the baseline
  • X402-47 (fixture consumption) acceptance against anchor-x402's JPYC Polygon rail will use the new variant-aware path

🤖 Generated with Claude Code

`@x402/[email protected]` ships TWO discovery-extension variants —
MCP-discovery (top-level `name` + `description`) and Body-discovery
(`info.input` + `info.output` + `schema`). v0.3.0/0.3.1 assumed only
the MCP shape and false-positive `implementation_issue` on every
Body-discovery service. AsaiShota surfaced this on #72 with exact
package-source citation; 0xdespot corroborated on #2207 with hyperD.

New `src/bazaar/extensions-bazaar.ts` helper:
- detectBazaarVariant() — body-discovery indicators win, else assume
  mcp-discovery per ADR-004 ("else assume Mcp"); third "unknown"
  branch is defensive for future @x402/extensions variants
- validateBazaarExtension() — variant-appropriate required-field check;
  pure-function, presentation-free; callers format messages in their
  own voice

Both `src/bazaar/challenge.ts` (existing check) and `src/bazaar/
well-known.ts` (the check added by PR #70 for D.1 manifest hygiene)
now consume the helper. Existing mcp-discovery behavior preserved
(29 existing tests still pass); body-discovery is a new pass path.

JSON output gains `detail.variant` on extensions.bazaar-related
check results — additive, per the JSON API stability contract from
ADR-004.

Tests: 21 new (13 helper + 4 challenge + 4 well-known); 450 total
passing (was 429).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402trace-dogfood Ready Ready Preview, Comment May 22, 2026 9:32pm

@fardinvahdat fardinvahdat merged commit e8c1787 into main May 22, 2026
4 checks passed
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