Skip to content

refactor: dedupe research proxy base#411

Merged
jerry609 merged 1 commit intodevfrom
refactor/pr16-research-proxy-dedup
Mar 15, 2026
Merged

refactor: dedupe research proxy base#411
jerry609 merged 1 commit intodevfrom
refactor/pr16-research-proxy-dedup

Conversation

@jerry609
Copy link
Owner

Summary

  • replace the legacy research/_base.ts implementation with a thin adapter over the shared backend proxy helper
  • preserve the existing apiBaseUrl / proxyJson call surface while forcing auth: true at the delegation boundary
  • add a focused _base contract test so the auth-default behavior stays locked

Why

research/_base.ts had drifted into a second JSON proxy stack and was being reused well outside research/. This PR removes that duplicate implementation without widening review scope to dozens of route import rewrites.

Validation

  • cd web && npx vitest run src/app/api/research/_base.test.ts src/app/api/research/repro/context/route.test.ts src/app/api/_utils/backend-proxy.test.ts
  • cd web && npx eslint src/app/api/research/_base.ts src/app/api/research/_base.test.ts
  • cd web && npx tsc --noEmit
  • cd web && npm run build

Copilot AI review requested due to automatic review settings March 15, 2026 07:55
@vercel
Copy link

vercel bot commented Mar 15, 2026

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

Project Deployment Actions Updated (UTC)
paper-bot Ready Ready Preview, Comment Mar 15, 2026 7:56am

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Warning

Rate limit exceeded

@jerry609 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 96fc96df-fca5-426f-8409-ded8af4f55e6

📥 Commits

Reviewing files that changed from the base of the PR and between 4007780 and 8e6ebde.

📒 Files selected for processing (2)
  • web/src/app/api/research/_base.test.ts
  • web/src/app/api/research/_base.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/pr16-research-proxy-dedup
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the research/_base.ts module to eliminate a redundant JSON proxy implementation. By delegating to a shared backend proxy utility, the change streamlines the codebase, reduces maintenance overhead, and ensures consistent proxy behavior across the application, while explicitly enforcing authentication for all requests handled by this module.

Highlights

  • Deduplicated Proxy Implementation: The legacy research/_base.ts implementation has been replaced with a thin adapter that utilizes a shared backend proxy helper, removing duplicate code.
  • Preserved API Surface: The existing apiBaseUrl and proxyJson call surface in research/_base.ts has been maintained, ensuring no breaking changes for consumers.
  • Enforced Authentication: The refactored proxyJson now explicitly forces auth: true at the delegation boundary to the shared backend proxy.
  • Added Contract Test: A new focused test file (_base.test.ts) was added to lock in the auth-default behavior of the refactored _base module.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • web/src/app/api/research/_base.test.ts
    • Added a new test file to verify the functionality of the refactored _base module, specifically testing URL resolution and forced authentication for JSON proxies.
  • web/src/app/api/research/_base.ts
    • Refactored the apiBaseUrl and proxyJson functions to import and delegate to shared utilities from ../_utils/backend-proxy.
    • Removed the custom implementation of proxyJson, including manual request handling, timeout logic, and error handling, in favor of the shared helper.
    • Ensured that proxyJson calls the shared utility with auth: true to enforce backend authentication.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link

@github-actions
Copy link

Vercel Preview

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the research/_base.ts module to eliminate duplicated proxy logic, replacing it with a thin adapter that delegates to a new shared helper in _utils/backend-proxy.ts. This is an excellent change that improves code maintainability and centralizes the backend communication logic. The addition of a dedicated test file for the new adapter ensures that its specific contract, particularly the enforcement of authentication, is verified. I have one minor suggestion to further simplify the adapter code by using a direct re-export for the apiBaseUrl function.

Comment on lines +1 to +9
import {
apiBaseUrl as sharedApiBaseUrl,
proxyJson as sharedProxyJson,
type ProxyMethod,
} from "../_utils/backend-proxy"

export async function proxyJson(req: Request, upstreamUrl: string, method: string) {
const body = method === "GET" ? undefined : await req.text()
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 120_000) // 2 min timeout
export function apiBaseUrl(): string {
return sharedApiBaseUrl()
}

Choose a reason for hiding this comment

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

medium

For better code clarity and conciseness, you can directly re-export apiBaseUrl since it's a simple pass-through. This avoids the need for a wrapper function and an import alias.

Suggested change
import {
apiBaseUrl as sharedApiBaseUrl,
proxyJson as sharedProxyJson,
type ProxyMethod,
} from "../_utils/backend-proxy"
export async function proxyJson(req: Request, upstreamUrl: string, method: string) {
const body = method === "GET" ? undefined : await req.text()
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 120_000) // 2 min timeout
export function apiBaseUrl(): string {
return sharedApiBaseUrl()
}
import {
proxyJson as sharedProxyJson,
type ProxyMethod,
} from "../_utils/backend-proxy"
export { apiBaseUrl } from "../_utils/backend-proxy"

@jerry609 jerry609 merged commit d6023d1 into dev Mar 15, 2026
20 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the research API proxy base to remove the duplicated proxy implementation by delegating to the shared backend proxy helper, while locking in the “always auth” behavior with a focused contract test.

Changes:

  • Replaced research/_base.ts’s legacy proxy logic with a thin adapter over api/_utils/backend-proxy.
  • Forced { auth: true } at the delegation boundary while keeping the same apiBaseUrl/proxyJson surface.
  • Added a dedicated Vitest contract test to ensure the adapter continues to enforce auth.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
web/src/app/api/research/_base.ts Replaces the local proxy implementation with delegation to the shared backend proxy helper (forcing auth).
web/src/app/api/research/_base.test.ts Adds a contract test verifying delegation and enforced auth options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

apiBaseUrl as sharedApiBaseUrl,
proxyJson as sharedProxyJson,
type ProxyMethod,
} from "../_utils/backend-proxy"
@jerry609 jerry609 deleted the refactor/pr16-research-proxy-dedup branch March 15, 2026 13:07
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