Skip to content

refactor: convert the browser auth passthrough to a Hono sub-app - #1726

Merged
ColeMurray merged 1 commit into
mainfrom
refactor/hono-pr7-modules
Sep 3, 2026
Merged

refactor: convert the browser auth passthrough to a Hono sub-app#1726
ColeMurray merged 1 commit into
mainfrom
refactor/hono-pr7-modules

Conversation

@ColeMurray

@ColeMurray ColeMurray commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Rebased onto main after #1724 merged; the diff is this PR alone.

PR 7 of the Hono follow-up series (plan: docs/internal/2026-09-02-control-plane-hono-follow-ups.md in prod).

What changed

  • src/routes/browser-auth.ts is a Hono sub-app. The six routes in BROWSER_AUTH_PROXY_ROUTES register in the allowlist's order, each behind admit({ ...SCM_AGNOSTIC_WEB_SERVICE_ROUTE, authorization: NO_AUTHORIZATION }), and reach handleBrowserAuth through dispatch(). The handler body is unchanged: it still owns Better Auth's status codes and headers.
  • routes/catalog.ts mounts the module where the spread was (after health, before sign-in providers), so precedence is unchanged.
  • src/routes/browser-auth.test.ts dispatches through the production sub-app: one row per allowlisted route asserting which Better Auth entry point served it (direct getSession for the session read, the HTTP handler otherwise), the status and cookie passthrough with no-store / no-referrer, the 503 when the runtime is not configured, the 401 for a non-web caller, and the 404 for a method outside the allowlist.

Routes converted: 6 (running total 60 of 171).

Verification

Check Result
Unit 234 files, 3,505 passed
Integration (workerd, real D1) 96 files, 1,129 passed
Matrix and conformance snapshots both integration snapshots byte-identical
Typecheck, ESLint, Prettier clean

https://claude.ai/code/session_01KdDpTgGEjXpBA9SaGQVUH1

Summary by CodeRabbit

  • Bug Fixes
    • Improved browser authentication request handling across supported routes.
    • Preserved upstream response statuses and headers when proxying authentication requests.
    • Added clear responses for unconfigured authentication, unauthorized callers, and unsupported paths.
  • Tests
    • Expanded coverage for browser authentication routing, authorization, proxying, and error scenarios.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 39c30e69-fca6-4894-9e61-993a89ef188b

📥 Commits

Reviewing files that changed from the base of the PR and between 7b561a5 and 3f5b946.

📒 Files selected for processing (3)
  • packages/control-plane/src/routes/browser-auth.test.ts
  • packages/control-plane/src/routes/browser-auth.ts
  • packages/control-plane/src/routes/catalog.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Browser auth routes now use a Hono sub-app. The catalog mounts this sub-app directly. Tests dispatch requests through the complete route handler and cover proxying, authorization, errors, headers, and allowlisted paths.

Changes

Browser auth routing

Layer / File(s) Summary
Hono route registration and handler wiring
packages/control-plane/src/routes/browser-auth.ts
browserAuthRoutes now uses Hono. Allowlisted method/path pairs use admit and dispatch to handleBrowserAuth.
Catalog mounting and full-handler validation
packages/control-plane/src/routes/catalog.ts, packages/control-plane/src/routes/browser-auth.test.ts
The catalog mounts browserAuthRoutes as one sub-app. Tests exercise the full handler and validate proxying, authorization, error responses, header passthrough, and route filtering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 3f5b9

Browser authentication proxy routes now run through a Hono sub-application while retaining their allowlist, web-service access restriction, response behavior, and catalog precedence. Coverage includes the relevant proxy, authorization, error, and header behavior, with no concrete current-head merge risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: converting the browser authentication passthrough into a Hono sub-application.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/hono-pr7-modules

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.

@open-inspect open-inspect Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

PR #1726, refactor: convert the browser auth passthrough to a Hono sub-app, by @ColeMurray updates 3 files (+161/-16). The conversion preserves the six-route positive allowlist, web-service-only admission, registration precedence, Better Auth response handling, and runtime-misconfiguration behavior. No correctness, security, performance, or maintainability issues were found.

Critical Issues

None.

Suggestions

None.

Nitpicks

None.

Positive Feedback

  • The production sub-app is tested through the real Hono/admission lifecycle rather than by invoking implementation details directly.
  • Coverage includes every allowlisted route plus status/header passthrough, authorization denial, configuration failure, and route/method exclusion.
  • Reusing the declarative admission policy across registrations keeps the converted module concise while retaining route-contract introspection.

Questions

None.

Verdict

Approve: Ready to merge. Focused unit tests (11), focused integration tests (27), route compatibility checks, TypeScript typechecking, and diff whitespace validation all pass.

Base automatically changed from refactor/hono-pr3-sessions to main September 3, 2026 01:49

@open-inspect open-inspect Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review complete. This is a clean conversion to the branch's canonical Hono route-module boundary: admission remains centralized in admit, handler adaptation remains centralized in dispatch, the shared positive allowlist remains the single source of route registration, and catalog precedence is preserved. The production module grows only from 93 to 99 lines; no file-size or decomposition concern is introduced. The added tests exercise every allowlisted route through the production sub-app, denial and non-allowlisted behavior, runtime misconfiguration, and response/header passthrough. I found no structural regression, spaghetti growth, boundary leak, or credible code-judo simplification that would materially improve this change. Verified locally on the PR head: control-plane typecheck, all 234 unit files / 3,505 tests, ESLint on changed files, and Prettier all pass.

The six Better Auth proxy routes register from the shared allowlist in its
order, each behind the web-service admission policy, and reach the one
passthrough handler through `dispatch()`. The handler keeps owning its
status codes and headers; nothing in its body changed.

The module's tests now dispatch through the sub-app: one row per
allowlisted route proves the wiring and which Better Auth entry point
serves it, plus the status passthrough, the 503 for a missing runtime,
the web-service-only refusal, and the 404 for a method outside the list.

Claude-Session: https://claude.ai/code/session_01KdDpTgGEjXpBA9SaGQVUH1
@ColeMurray
ColeMurray force-pushed the refactor/hono-pr7-modules branch from f7d5a9a to 3f5b946 Compare September 3, 2026 01:53
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate
Tests

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

@ColeMurray
ColeMurray merged commit 6f12fa6 into main Sep 3, 2026
13 checks passed
@ColeMurray
ColeMurray deleted the refactor/hono-pr7-modules branch September 3, 2026 02:57
ColeMurray added a commit that referenced this pull request Sep 3, 2026
Last PR of the Hono series (#1720, #1721, #1723, #1724, #1726, #1727,
#1728, #1729). Every route module is a Hono sub-app, so the adapter that
carried catalog routes through admission has nothing left to serve.

## Removed

- `legacy()` and `legacyMatch()` in `routing/hono-app.ts`;
`createControlPlaneApp(modules, host)` mounts modules only.
- `RouteDefinition`, `Route`, `defineRoute()`, `defineRoutes()`, and
`extractRepoParams()` in `routes/shared.ts`. `RouteAdmissionPolicy` is
now an interface over `RoutePolicy` plus `authorization` and
`serviceActorClaims`; `cacheControl` lives on `AdmissionPolicy` in
`routing/admit.ts`.
- `RouteCatalogEntry`; the catalog is `readonly RouteModule[]`.
- `legacyRoutes()` in test support; `matchRoute()` no longer fabricates
a `RegExpMatchArray`.
- `routes/shared.test.ts`, replaced by
`routes/repository-params.test.ts` over the decoded pair.

## Kept on purpose

- `RouteParams`: admission's decoded-parameter dictionary. Hono exports
no such type.
- `rawRouteParams()`: the malformed-encoding guard's raw read-back
(added in #1724).

## Tests

Fixtures that need synthetic routes build a `Hono` module and pass it to
`createTestRequestHandler([module])`: the lifecycle suite, the contract
lister's suite, and the authorization-audit suite's eleven routes. The
two Worker-boundary suites build their shadow catalogs the same way:
conformance echoes the raw read-back through `rawRouteParams()`, and the
matrix's "raw path segments" probe from #1720 is now the decode-once
assertion on what handlers receive (`abc%2Fdef` arrives as `abc/def`,
`web%252Fapp` as `web%2Fapp`).

## Verification

| Check | Result |
|---|---|
| Typecheck (src, test, integration) | clean |
| ESLint, Prettier | clean |
| Unit | 234 files, 3,512 passed |
| Integration (workerd, real D1) | 96 files, 1,129 passed |
| Matrix and conformance snapshots | byte-identical |

https://claude.ai/code/session_01KdDpTgGEjXpBA9SaGQVUH1


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Repository paths now support nested owner namespaces, such as
`group/subgroup`.
- Repository names containing slash characters are rejected with a clear
validation message.
- URL path parameters are decoded consistently, improving handling of
encoded repository and member identifiers.

- **Refactor**
- Control-plane routing now uses the current route-module system,
providing consistent admission, route matching, and request handling
behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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