Commit graph naco-api/internal/x402/x402_test.go
Author SHA1 Message Date
f4ae7d9c9f
refactor(x402): fold resolver into AddPayableTool and honor per-tool timeouts
Simplify the payable-tool registration API by merging
AddPayableToolWithResolver into AddPayableTool, and thread a configurable
MaxTimeoutSeconds plus Extra through the payment options. getStyleProfile
keeps its 600s advertise timeout.
2026-09-13 22:24:34 +00:00
e68e02bf20
feat: data-driven upto scheme registration for twitter-enabled tools
Extend x402 actual-cost settlement beyond getStyleProfile to every
Twitter-capable tool (findSimilarUsers, getEngagementMetrics,
getPostingPatterns, getTopicModeling, getSentimentTrends,
getEngagementDrivers). Each carries a twitterPostCount (or source
platform + post count) in its response so settlement passes on the
realized Twitter API lookup and per-post costs.

- tools: payableDef uses UsesTwitter + TwitterPostCap instead of a
  fixed Scheme; registerTools advertises upto at the cap-derived
  maximum when Twitter is enabled, otherwise exact at the flat base
  price.
- x402: export pricing constants and MaxTwitterCostMicro /
  FormatPriceMicro / MicroFromPriceString helpers; add
  AddPayableToolWithResolver and a per-tool settleResolvers map used
  by both the MCP wrapper and REST override; buildSchemeConfigs
  registers only the schemes declared in a tool's requirements.
- analytics: default aggregates include Twitter only when enabled;
  result count recorded before caching and returned as twitterPostCount.
- server/twitterEnabled gates the upto switch (config bearer token).
2026-09-09 13:27:17 +00:00
7aee2fe88c
feat: x402 actual-cost settlement for getStyleProfile + custom MCP wrapper 2026-09-08 01:15:31 +00:00
9c26886957
Self-heal MCP facilitator init so no restart is needed
Some checks failed
CI/CD Go Verification / build_and_test (push) Successful in 1m18s
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 5m43s
The MCP PaymentWrapper verifies against the low-level x402 resource server,
whose facilitatorClients map is only populated by Initialize(), which was
never called - paid MCP calls failed with no_facilitator_for_network once
the amount fix let clients reach server-side verification. INITIALIZE the
resource server at construction (best-effort, warn-only) and retry on every
inbound request via receiving middleware until it succeeds once. 10s bounded
timeout per attempt; after first success the map persists for the process
lifetime so later facilitator outages self-heal without a restart.
2026-09-06 21:32:39 +00:00
9059be5027
Convert MCP Accepts prices to smallest units in AddPayableTool
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m31s
CI/CD Go Verification / build_and_test (push) Successful in 1m18s
MCP clients failed to create payments with invalid_exact_evm_client_amount:
0.01 because the PaymentWrapper advertised raw dollar prices as amounts,
while REST re-runs prices through BuildPaymentRequirementsFromOptions.
Mirror that conversion for the MCP Accepts at registration time; keep the
REST PaymentOption with the raw price to avoid double conversion.
2026-09-06 21:12:05 +00:00
9cee30ff70
Fix x402 scheme registration for all active networks
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m33s
CI/CD Go Verification / build_and_test (push) Successful in 1m7s
The HTTP middleware in AddPayableTool was hardcoded to only register
the exact scheme for eip155:8453 (Base mainnet), while the MCP handler
registered both exact and upto schemes for all networks from ACTIVE_NETWORKS.
This mismatch caused 'no scheme server for exact on eip155:84532' errors
when testing with Sepolia.

Changes:
- Added networks field to X402Server struct to store active networks
- Store networks in NewX402Server constructor
- In AddPayableTool, dynamically register both exact and upto EVM
  schemes for all configured networks instead of hardcoding eip155:8453
- Updated tests to pass correct network configuration
2026-09-04 13:29:38 +00:00
443ecce9c2
fix: register all active networks in x402 server for eip155:84532 support
All checks were successful
Test Every Endpoint on Base Sepolia / test_endpoints (push) Successful in 2m3s
CI/CD Go Verification / build_and_test (push) Successful in 1m5s
- x402.NewX402Server now accepts networks []string parameter to register
  exact/upto EVM schemes for each network
- server_init.go passes resolved active networks (from resolveActiveNetworks)
  to x402 server - includes eip155:84532 (sepolia), eip155:8453 (base),
  and any other configured networks
- Registers both exact and upto schemes per network
- Updates x402_test.go calls to pass []string{}
- Fixes: 'no scheme server for exact on eip155:84532' error
2026-09-04 09:09:00 +00:00
193184675e test(x402): cover Twitter style-profile cost passing and payable boundaries
- add ComputeTwitterStyleProfileCost table and AlwaysProfitable invariant
- add edge cases (case-insensitive, negative, large counts)
- cover MultipleTools and AddPayableTool validation, HTTP 402/MCP boundaries
2026-09-03 17:00:36 +00:00
0dcb74675e fix(analytics,x402): fix coverage gaps, engagement drivers, and Twitter cost passing
Analytics review fixes:
- Store Twitter analytics coverage as discrete intervals instead of a single
  contiguous window so disjoint fetch ranges no longer mask inner gaps as
  covered (fetch per uncovered range, add gap regression tests)
- Compute real AvgEngagement/Correlation in getEngagementDrivers instead of
  all-zero placeholders
- Make parseAnalyticsTimeRange surface invalid timestamps, cap merged analytics
  posts at limit, and normalize sentiment by timestamped posts only
- gofmt: fix misalignment in config.go and types.go
- Include Twitter in the default aggregate analytics scope; its API costs are
  passed to the caller through paid tool pricing

x402 cost passing:
- computeTwitterStyleProfileCost now charges base cost ($0.10) + user lookup
  ($0.01) + $0.005 per Twitter post, guaranteeing the charge always clears the
  underlying API cost (never break-even or loss)
- Return a $-prefixed dollar string for the settlement override, fixing the
  previously off-by-factor-100 raw-atomic-unit amount
- Raise getStyleProfile base registration to $0.36 to authorize the max Twitter
  charge
- Add tests for the cost formula, profitable floor, and dollar formatting
2026-09-02 22:44:02 +00:00
4af4d79940 add: global logging 2026-08-03 11:08:53 +00:00
9f59a7d9d6 add x402 unit test
add test workflow
2026-07-30 06:45:26 +00:00