fix feedback forward to prod
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
DB migration compat / Check if migrations changed (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Build and Run / docker (push) Has been cancelled
Runs E2E API Tests (Local Emulator) / E2E Tests (Local Emulator, Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (mock, 22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (prod, 22.x) (push) Has been cancelled
Runs E2E API Tests with custom port prefix / build (22.x) (push) Has been cancelled
Runs E2E Fallback Tests / E2E Fallback Tests (Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Lint & build / lint_and_build (24) (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
DB migration compat / Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code (push) Has been cancelled
DB migration compat / Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations (push) Has been cancelled
DB migration compat / No migration changes (skipped) (push) Has been cancelled

This commit is contained in:
Bilal Godil 2026-04-13 20:48:56 -07:00
parent f78b60bba2
commit ec4dcea629
2 changed files with 2 additions and 32 deletions

View File

@ -1,4 +1,5 @@
import { sendSupportFeedbackEmail } from "@/lib/internal-feedback-emails";
import { isLocalEmulatorEnabled } from "@/lib/local-emulator";
import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler";
import { DEFAULT_BRANCH_ID, getSoleTenancyFromProjectBranch } from "@/lib/tenancies";
import { adaptSchema, emailSchema, yupBoolean, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
@ -45,7 +46,7 @@ export const POST = createSmartRouteHandler({
async handler({ auth, body }) {
// Forward to production in local emulator (same pattern as AI query endpoint)
const feedbackMode = getEnvVariable("STACK_FEEDBACK_MODE", "email");
if (feedbackMode === "FORWARD_TO_PRODUCTION") {
if (feedbackMode === "FORWARD_TO_PRODUCTION" && isLocalEmulatorEnabled()) {
const prodResponse = await fetch("https://api.stack-auth.com/api/latest/internal/feedback", {
method: "POST",
headers: { "content-type": "application/json", "accept-encoding": "identity" },

View File

@ -2,31 +2,8 @@ import { describe } from "vitest";
import { it } from "../../../../../helpers";
import { Auth, backendContext, createMailbox, niceBackendFetch, waitForOutboxEmailWithStatus } from "../../../../backend-helpers";
/**
* Probe the backend to detect whether it's forwarding feedback to production.
* Cached so we only make one probe request per test run.
*/
let cachedIsForwarding: boolean | null = null;
async function isForwardingToProduction(): Promise<boolean> {
if (cachedIsForwarding !== null) return cachedIsForwarding;
const probe = await niceBackendFetch("/api/v1/internal/feedback", {
method: "POST",
body: {
email: "probe@test.stack-auth.com",
message: "mode detection probe",
},
});
// When forwarding, production rejects and we get a non-200 with "forward" in the body
cachedIsForwarding = probe.status !== 200;
return cachedIsForwarding;
}
describe("POST /api/v1/internal/feedback", () => {
it("should send feedback from an authenticated user", async ({ expect }) => {
if (await isForwardingToProduction()) {
return; // forwarding mode — probe already verified endpoint is reachable
}
const senderEmail = backendContext.value.mailbox.emailAddress;
const signInResult = await Auth.Otp.signIn();
const recipientMailbox = createMailbox("team@stack-auth.com");
@ -67,10 +44,6 @@ describe("POST /api/v1/internal/feedback", () => {
});
it("should send feedback without authentication (dev tool)", async ({ expect }) => {
if (await isForwardingToProduction()) {
return;
}
const recipientMailbox = createMailbox("team@stack-auth.com");
const subject = "[Support] devtool-user@example.com";
@ -107,10 +80,6 @@ describe("POST /api/v1/internal/feedback", () => {
});
it("should send bug reports with correct label", async ({ expect }) => {
if (await isForwardingToProduction()) {
return;
}
const recipientMailbox = createMailbox("team@stack-auth.com");
const subject = "[Bug Report] bug@example.com";