mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-11 01:45:58 +00:00
fix: align auth-disabled mode and mock history loading (#3471)
* fix: align auth-disabled mode and mock history loading * fix: address auth-disabled review feedback * test: cover auth-disabled backend contract * style: format frontend tests * fix: address follow-up review comments
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
import { AUTH_DISABLED_USER } from "../../src/core/auth/auth-disabled-user";
|
||||
|
||||
const APP = "http://localhost:3000";
|
||||
|
||||
test.describe("auth-disabled contract (real backend)", () => {
|
||||
test("gateway /auth/me returns the frontend synthetic user without a cookie", async ({
|
||||
context,
|
||||
}) => {
|
||||
const resp = await context.request.get(`${APP}/api/v1/auth/me`);
|
||||
|
||||
expect(resp.status(), await resp.text()).toBe(200);
|
||||
await expect(resp.json()).resolves.toEqual(AUTH_DISABLED_USER);
|
||||
});
|
||||
});
|
||||
@@ -101,10 +101,11 @@ test.describe("real backend render (replay, no API key)", () => {
|
||||
EXPECTED_SUGGESTION,
|
||||
"fixture should contain a suggestions turn (re-record; the record spec waits for /suggestions)",
|
||||
).not.toBe("");
|
||||
await expect(page.getByText(EXPECTED_TITLE)).toBeVisible({
|
||||
const chat = page.locator("#chat");
|
||||
await expect(chat.getByText(EXPECTED_TITLE)).toBeVisible({
|
||||
timeout: 60_000,
|
||||
});
|
||||
await expect(page.getByText(EXPECTED_SUGGESTION)).toBeVisible({
|
||||
await expect(chat.getByText(EXPECTED_SUGGESTION)).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ test.describe("Chat workspace", () => {
|
||||
|
||||
const textarea = page.getByPlaceholder(/how can i assist you/i);
|
||||
await expect(textarea).toBeVisible({ timeout: 15_000 });
|
||||
await expect(page.getByRole("button", { name: /load more/i })).toBeHidden();
|
||||
});
|
||||
|
||||
test("can type a message in the input box", async ({ page }) => {
|
||||
|
||||
@@ -18,6 +18,7 @@ const THREADS = [
|
||||
updated_at: "2025-06-02T12:00:00Z",
|
||||
},
|
||||
];
|
||||
const DEMO_THREAD_ID = "7cfa5f8f-a2f8-47ad-acbd-da7137baf990";
|
||||
|
||||
test.describe("Thread history", () => {
|
||||
test("sidebar shows existing threads", async ({ page }) => {
|
||||
@@ -61,6 +62,84 @@ test.describe("Thread history", () => {
|
||||
).toBeVisible({ timeout: 15_000 });
|
||||
});
|
||||
|
||||
test("mock thread does not load real backend run history", async ({
|
||||
page,
|
||||
}) => {
|
||||
mockLangGraphAPI(page, {
|
||||
threads: [
|
||||
{
|
||||
thread_id: DEMO_THREAD_ID,
|
||||
title: "Forecasting 2026 Trends and Opportunities",
|
||||
updated_at: "2025-06-01T12:00:00Z",
|
||||
messages: [
|
||||
{
|
||||
type: "human",
|
||||
id: `run-human-${DEMO_THREAD_ID}`,
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "This run-message endpoint should not be called.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const backendRunHistoryUrls: string[] = [];
|
||||
await page.route(
|
||||
/\/api\/langgraph\/threads\/[^/]+\/runs(?:\?|$)/,
|
||||
(route) => {
|
||||
if (
|
||||
route.request().method() === "GET" &&
|
||||
route
|
||||
.request()
|
||||
.url()
|
||||
.includes(`/api/langgraph/threads/${DEMO_THREAD_ID}/runs`)
|
||||
) {
|
||||
backendRunHistoryUrls.push(route.request().url());
|
||||
return route.fulfill({
|
||||
status: 500,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
error: "mock=true must not load real runs",
|
||||
}),
|
||||
});
|
||||
}
|
||||
return route.fallback();
|
||||
},
|
||||
);
|
||||
await page.route(
|
||||
/\/api\/threads\/[^/]+\/runs\/[^/]+\/messages(?:\?|$)/,
|
||||
(route) => {
|
||||
if (
|
||||
route.request().method() === "GET" &&
|
||||
route.request().url().includes(`/api/threads/${DEMO_THREAD_ID}/runs/`)
|
||||
) {
|
||||
backendRunHistoryUrls.push(route.request().url());
|
||||
return route.fulfill({
|
||||
status: 500,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
error: "mock=true must not load real run messages",
|
||||
}),
|
||||
});
|
||||
}
|
||||
return route.fallback();
|
||||
},
|
||||
);
|
||||
|
||||
await page.goto(`/workspace/chats/${DEMO_THREAD_ID}?mock=true`);
|
||||
|
||||
await expect(
|
||||
page.getByText("What might be the trends and opportunities in 2026?"),
|
||||
).toBeVisible({ timeout: 15_000 });
|
||||
await expect(
|
||||
page.getByText("I've created a modern, minimalist website"),
|
||||
).toBeVisible();
|
||||
expect(backendRunHistoryUrls).toEqual([]);
|
||||
});
|
||||
|
||||
test("chats list page shows all threads", async ({ page }) => {
|
||||
mockLangGraphAPI(page, { threads: THREADS });
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { AUTH_DISABLED_USER } from "@/core/auth/auth-disabled-user";
|
||||
import { STATIC_WEBSITE_USER } from "@/core/auth/static-user";
|
||||
|
||||
vi.mock("next/headers", () => ({
|
||||
@@ -10,6 +11,8 @@ vi.mock("next/headers", () => ({
|
||||
|
||||
const ENV_KEYS = [
|
||||
"DEER_FLOW_AUTH_DISABLED",
|
||||
"DEER_FLOW_ENV",
|
||||
"ENVIRONMENT",
|
||||
"NEXT_PUBLIC_STATIC_WEBSITE_ONLY",
|
||||
] as const;
|
||||
|
||||
@@ -51,6 +54,8 @@ describe("getServerSideUser", () => {
|
||||
beforeEach(() => {
|
||||
saved = snapshotEnv();
|
||||
setEnv("DEER_FLOW_AUTH_DISABLED", undefined);
|
||||
setEnv("DEER_FLOW_ENV", undefined);
|
||||
setEnv("ENVIRONMENT", undefined);
|
||||
setEnv("NEXT_PUBLIC_STATIC_WEBSITE_ONLY", undefined);
|
||||
});
|
||||
|
||||
@@ -74,4 +79,30 @@ describe("getServerSideUser", () => {
|
||||
});
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("bypasses gateway auth in auth-disabled mode", async () => {
|
||||
setEnv("DEER_FLOW_AUTH_DISABLED", "1");
|
||||
const fetchSpy = vi.fn(() => {
|
||||
throw new Error("fetch should not be called in auth-disabled mode");
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchSpy);
|
||||
|
||||
const { getServerSideUser } = await loadFreshServerAuth();
|
||||
|
||||
await expect(getServerSideUser()).resolves.toEqual({
|
||||
tag: "authenticated",
|
||||
user: AUTH_DISABLED_USER,
|
||||
});
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("does not enable auth-disabled mode in explicit production environments", async () => {
|
||||
setEnv("DEER_FLOW_AUTH_DISABLED", "1");
|
||||
setEnv("DEER_FLOW_ENV", "production");
|
||||
|
||||
const { isAuthDisabledMode } =
|
||||
await import("@/core/auth/auth-disabled-user");
|
||||
|
||||
expect(isAuthDisabledMode()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user