Skip to content

fix(emulator): move mock OAuth off 8114 to avoid pnpm dev conflict#1385

Merged
BilalG1 merged 1 commit intodevfrom
fix-local-emulator-mock-oauth-conflict
Apr 27, 2026
Merged

fix(emulator): move mock OAuth off 8114 to avoid pnpm dev conflict#1385
BilalG1 merged 1 commit intodevfrom
fix-local-emulator-mock-oauth-conflict

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Apr 24, 2026

Summary

  • The emulator's mock OAuth server bound to ${PORT_PREFIX}14 (8114) inside the VM and the host forwarded the same port, colliding with pnpm dev's mock-oauth-server on 8114.
  • Moves the emulator's mock OAuth to EMULATOR_MOCK_OAUTH_PORT (default 26704, joining the existing 267xx host port block) and binds the VM-internal mock to the same port. Same port on both sides keeps the OIDC issuer URL (http://localhost:26704) resolvable identically from the browser and from the backend inside the VM.
  • Plumbed via runtime-config.iso as STACK_EMULATOR_MOCK_OAUTH_HOST_PORT, read by cloud-init into STACK_OAUTH_MOCK_URL + new STACK_OAUTH_MOCK_PORT; mock-oauth-server now prefers STACK_OAUTH_MOCK_PORT so pnpm dev (which doesn't set it) stays on 8114.

Files

  • docker/local-emulator/qemu/run-emulator.sh — new EMULATOR_MOCK_OAUTH_PORT, hostfwd/ensure_ports_free/runtime.env updates
  • docker/local-emulator/qemu/cloud-init/emulator/user-data — reads the host port, sets STACK_OAUTH_MOCK_URL + STACK_OAUTH_MOCK_PORT
  • apps/mock-oauth-server/src/index.ts — honors STACK_OAUTH_MOCK_PORT
  • packages/stack-cli/src/commands/emulator.ts — default + runtime.env entry

Test plan

  • pnpm emulator:build succeeds and new snapshot boots
  • stack emulator start with pnpm dev running on 8114 — no port collision
  • OAuth sign-in via mock provider completes end-to-end in the emulator
  • pnpm dev mock OAuth unchanged (still 8114)

Summary by CodeRabbit

Release Notes

  • New Features

    • The mock OAuth server port is now configurable in the local emulator with a sensible default, allowing custom port assignments via environment variable.
  • Improvements

    • Updated port forwarding and environment variable handling to ensure consistent mock OAuth endpoint configuration across host and guest systems in the emulator.

Bind mock-oauth-server to EMULATOR_MOCK_OAUTH_PORT (default 26704) inside
the emulator VM and forward the same port on the host. Keeps pnpm dev's
8114 free so both can run side-by-side, and keeps the OIDC issuer URL
identical from browser and in-VM backend (same port both sides).
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

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

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-backend Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-dashboard Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-demo Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-docs Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-preview-backend Ready Ready Preview, Comment Apr 24, 2026 10:30pm
stack-preview-dashboard Ready Ready Preview, Comment Apr 24, 2026 10:30pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e29367a9-4c51-4b5f-bf9a-6acecf0b3545

📥 Commits

Reviewing files that changed from the base of the PR and between 2f71990 and c15451d.

📒 Files selected for processing (4)
  • apps/mock-oauth-server/src/index.ts
  • docker/local-emulator/qemu/cloud-init/emulator/user-data
  • docker/local-emulator/qemu/run-emulator.sh
  • packages/stack-cli/src/commands/emulator.ts

📝 Walkthrough

Walkthrough

The changes make the mock OAuth server's port configurable through a new EMULATOR_MOCK_OAUTH_PORT environment variable (default 26704) instead of using a hard-coded value. This variable is propagated from the CLI through the emulator runtime configuration to the server and VM environment, replacing the previous ${PORT_PREFIX}14 approach.

Changes

Cohort / File(s) Summary
Mock OAuth Server Port Selection
apps/mock-oauth-server/src/index.ts
Updated port priority to check STACK_OAUTH_MOCK_PORT first, then PORT, with fallback to defaultMockOAuthPort.
Emulator Runtime Configuration
packages/stack-cli/src/commands/emulator.ts, docker/local-emulator/qemu/run-emulator.sh
Introduced EMULATOR_MOCK_OAUTH_PORT variable with default 26704; reads from environment and injects STACK_EMULATOR_MOCK_OAUTH_HOST_PORT into VM runtime configuration. Updated QEMU port forwarding rules and removed old port conflict detection.
VM Cloud-init Environment
docker/local-emulator/qemu/cloud-init/emulator/user-data
Modified OAuth endpoint generation to derive from configurable STACK_EMULATOR_MOCK_OAUTH_HOST_PORT via HP_MOCK_OAUTH variable instead of hard-coded offset; exports both STACK_OAUTH_MOCK_URL and STACK_OAUTH_MOCK_PORT.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Customizable ports #962: Directly related mock OAuth server port selection and emulator runtime port configuration changes.

Poem

🐰 A port once hard-coded in stone,
Now dances with numbers we own!
From CLI down through layers so deep,
The OAuth mock port takes its leap—
Twenty-six thousand, seven and four! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: moving the emulator's mock OAuth server from port 8114 to avoid conflict with pnpm dev.
Description check ✅ Passed The description is comprehensive and covers the problem, solution, files changed, and test plan. It meets the repository's contribution guidelines.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-local-emulator-mock-oauth-conflict

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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR resolves a port conflict between the local emulator's mock OAuth server and pnpm dev, by moving the emulator's mock OAuth binding from ${PORT_PREFIX}14 (8114) to a new configurable port (EMULATOR_MOCK_OAUTH_PORT, defaulting to 26704). The host and guest now use the same port number, keeping the OIDC issuer URL consistent from both the browser and VM-internal backend. The change is plumbed correctly end-to-end: run-emulator.shruntime-config.iso → cloud-init render-stack-env → Docker env-file → mock OAuth server.

Confidence Score: 5/5

Safe to merge; the port migration is clean and well-tested end-to-end.

All four files are changed consistently: the new port is defined once and propagated through CLI defaults, shell-script defaults, QEMU hostfwd, runtime ISO, cloud-init env generation, and the mock server itself. Backward-compat fallback to 8114 is correctly guarded. No logic errors, security issues, or missing wiring were found.

No files require special attention; all changes are self-consistent.

Important Files Changed

Filename Overview
apps/mock-oauth-server/src/index.ts Adds STACK_OAUTH_MOCK_PORT env var check with correct precedence before PORT and the default; pnpm dev (which never sets STACK_OAUTH_MOCK_PORT) is unaffected and stays on 8114.
docker/local-emulator/qemu/cloud-init/emulator/user-data Adds HP_MOCK_OAUTH shell variable with a backward-compatible fallback to ${P}14, and emits both STACK_OAUTH_MOCK_URL and STACK_OAUTH_MOCK_PORT into the Docker env-file; works correctly because STACK_EMULATOR_MOCK_OAUTH_HOST_PORT is sourced from runtime.env before the assignment.
docker/local-emulator/qemu/run-emulator.sh Introduces EMULATOR_MOCK_OAUTH_PORT (default 26704), updates hostfwd, ensure_ports_free, write_runtime_config_iso, and startup log; changes are self-consistent and resolve the 8114 collision.
packages/stack-cli/src/commands/emulator.ts Adds DEFAULT_EMULATOR_MOCK_OAUTH_PORT = 26704 constant and plumbs mockOAuthPort through prepareRuntimeConfigIso, matching the shell-script default exactly.

Sequence Diagram

sequenceDiagram
    participant CLI as stack-cli / run-emulator.sh
    participant ISO as runtime-config.iso
    participant VM as VM cloud-init
    participant Mock as mock-oauth-server (port 26704)
    participant Browser as Browser
    participant Backend as Backend inside VM

    CLI->>ISO: write mock OAuth port (26704)
    ISO->>VM: mount and source runtime env
    VM->>Mock: start with port 26704 via env-file
    VM->>Backend: set OAuth mock URL to localhost:26704

    Note over CLI,Mock: QEMU hostfwd host:26704 to VM:26704

    Browser->>Mock: OAuth redirect to localhost:26704
    Mock-->>Browser: OIDC auth code
    Browser->>Backend: callback with auth code
    Backend->>Mock: token exchange at localhost:26704
    Mock-->>Backend: access and id tokens
Loading

Reviews (1): Last reviewed commit: "fix(emulator): move mock OAuth off port ..." | Re-trigger Greptile

@BilalG1 BilalG1 merged commit 04d57d9 into dev Apr 27, 2026
42 of 44 checks passed
@BilalG1 BilalG1 deleted the fix-local-emulator-mock-oauth-conflict branch April 27, 2026 16:39
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