Skip to content

Add integration tests for x402 premium endpoints (#18)#74

Merged
Flamki merged 2 commits into
Flamki:masterfrom
Kirtiman-55:feat/premium-endpoint-integration-tests
Jun 3, 2026
Merged

Add integration tests for x402 premium endpoints (#18)#74
Flamki merged 2 commits into
Flamki:masterfrom
Kirtiman-55:feat/premium-endpoint-integration-tests

Conversation

@Kirtiman-55

@Kirtiman-55 Kirtiman-55 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

#18

Summary

This PR adds integration coverage for all premium x402 routes and validates behavior with and without payment context.

What changed

  • Added integration tests for:
    • /api/premium/research
    • /api/premium/summarize
    • /api/premium/analyze
    • /api/premium/code
  • Added deterministic payment-middleware mock in tests:
    • no payment context -> 402
    • payment context present -> route executes and returns 200
  • Extracted premium route registration into src/routes/premium-routes.js so behavior can be tested cleanly and consistently
  • Updated npm test to include the new premium integration suite

Why this is CI-safe

  • No live facilitator/network dependencies are used
  • Tests rely on in-process Express app + mocked middleware/agents
  • Failures clearly isolate payment-gating vs route-handler regressions

Acceptance Criteria

  • Premium route behavior verified reliably: ✅
  • CI-friendly and non-flaky (no external dependency): ✅
  • Regressions clearly attributable to payment/middleware wiring: ✅

Validation

  • npm test passes locally

Summary by CodeRabbit

  • New Features

    • Added four premium API endpoints for research, summarization, analysis, and code generation with integrated payment processing.
    • Premium endpoints enforce payment verification via header validation.
  • Tests

    • Added integration tests verifying payment gating and endpoint functionality.
  • Chores

    • Updated test scripts to include integration tests for premium features.

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

@Kirtiman-55 is attempting to deploy a commit to the flamki's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ade1d0aa-ab2e-4d15-ab97-be8b6f8802ca

📥 Commits

Reviewing files that changed from the base of the PR and between abf04f5 and f07c7e3.

📒 Files selected for processing (4)
  • package.json
  • src/routes/premium-routes.js
  • src/server.js
  • tests/premium-endpoints.integration.test.js

📝 Walkthrough

Walkthrough

This pull request extracts four premium API endpoints from inline server.js handlers into a dedicated, testable registerPremiumRoutes module. It verifies the extraction with integration tests that validate payment gating enforcement and handler behavior.

Changes

Premium Routes Refactoring and Testing

Layer / File(s) Summary
Extract premium routes to dedicated module
src/routes/premium-routes.js
New registerPremiumRoutes function defines four GET endpoints that derive cost from pricingConfig, broadcast call/response events with truncated previews, invoke agent runners, and return JSON with agent id, inputs, results, model label, USDC-formatted cost, and x402 payment identifier. All handlers forward errors to Express middleware.
Integrate extracted routes into server
src/server.js
Imports registerPremiumRoutes and replaces 128 lines of inline premium endpoint handlers with a single delegating call, passing app and dependencies (pricingConfig, broadcast, agent runners, MODEL_LABELS).
Integration tests for payment gating and premium endpoints
tests/premium-endpoints.integration.test.js
Adds comprehensive test suite with app factory that blocks /api/premium/* requests lacking x-payment-context header. Verifies payment gating returns HTTP 402 with handlers not executing, and valid payment context returns HTTP 200 with required response fields and handler invocation exactly once per endpoint. Includes HTTP helpers and ephemeral server lifecycle management.
Update test scripts
package.json
Adds premium endpoints integration test to default test script and creates standalone test:premium script.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Flamki/stellarmind#18: This PR implements the exact integration tests for premium endpoint payment gating and route behavior described in the issue.

Possibly related PRs

  • Flamki/stellarmind#53: Premium endpoint handlers continue to depend on pricingConfig.getEndpointInfo and x402 payment wiring introduced in PR #53.

Poem

🐰 Routes hopped from server to their own sweet home,
Four endpoints now proudly roam,
Tests guard the gate with payment care,
Refactored and tested with flair! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@drips-wave

drips-wave Bot commented Jun 1, 2026

Copy link
Copy Markdown

Hey @Kirtiman-55! 👋 It looks like this PR isn't linked to any issue.

If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g., Closes #123), or by clicking a button below:

Issue Title
#16 Implement structured logging with request correlation IDs Link to this issue
#31 Stop printing wallet secrets in setup output by default Link to this issue
#22 Add timeout and retry controls for Anthropic API calls Link to this issue
#18 Add integration tests for x402 premium endpoints Link to this issue

ℹ️ Learn more about linking PRs to issues

@Flamki

Flamki commented Jun 3, 2026

Copy link
Copy Markdown
Owner

@Kirtiman-55 kindly resolve the conflict

…nt-integration-tests

# Conflicts:
#	package.json
#	src/server.js
@Flamki Flamki merged commit 5334700 into Flamki:master Jun 3, 2026
1 of 2 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.

2 participants