Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(web): prevent workspace redirect loop (#432)
joptimus6ddcd1145d39
diff --git a/package-lock.json b/package-lock.jsonindex 5d299f411..c6892b80d 100644--- a/package-lock.json+++ b/package-lock.json@@ -14736,7 +14736,8 @@"eslint": "^9","eslint-config-next": "^15.2.4","tailwindcss": "^4.0.0",- "typescript": "^5.7"+ "typescript": "^5.7",+ "vitest": "^4.1.5"},"engines": {"node": ">=20.0.0"diff --git a/packages/web/package.json b/packages/web/package.jsonindex 55395dede..04c7e1b3b 100644--- a/packages/web/package.json+++ b/packages/web/package.json@@ -8,7 +8,8 @@"build": "next build","start": "next start --port 3000","lint": "next lint",- "type-check": "tsc --noEmit"+ "type-check": "tsc --noEmit",+ "test": "vitest run"},"dependencies": {"@lottiefiles/dotlottie-react": "^0.19.4",@@ -43,7 +44,8 @@"eslint": "^9","eslint-config-next": "^15.2.4","tailwindcss": "^4.0.0",- "typescript": "^5.7"+ "typescript": "^5.7",+ "vitest": "^4.1.5"},"engines": {"node": ">=20.0.0"diff --git a/packages/web/src/app/page.tsx b/packages/web/src/app/page.tsxindex 91dd01cf9..e09a92548 100644--- a/packages/web/src/app/page.tsx+++ b/packages/web/src/app/page.tsx@@ -32,7 +32,7 @@ export default async function DashboardPage() {const [repos, jobs, ws] = await Promise.allSettled([listRepos(),listJobs({ limit: 10 }),- getWorkspace(),+ getWorkspace({ cache: "no-store" }),]);const repoList = repos.status === "fulfilled" ? repos.value : [];diff --git a/packages/web/src/app/workspace/layout.tsx b/packages/web/src/app/workspace/layout.tsxindex 39bc91a65..4ddb40c51 100644--- a/packages/web/src/app/workspace/layout.tsx+++ b/packages/web/src/app/workspace/layout.tsx@@ -1,20 +1,21 @@import { redirect } from "next/navigation";import { getWorkspace } from "@/lib/api/workspace";+import { shouldRedirectFromWorkspace } from "@/lib/workspace-mode";export default async function WorkspaceLayout({children,}: {children: React.ReactNode;}) {- let isWorkspace = false;+ let isWorkspace: boolean | null = null;try {- const ws = await getWorkspace();+ const ws = await getWorkspace({ cache: "no-store" });isWorkspace = ws.is_workspace;} catch {// API unavailable}- if (!isWorkspace) {+ if (shouldRedirectFromWorkspace(isWorkspace)) {redirect("/");}diff --git a/packages/web/src/lib/api/workspace.ts b/packages/web/src/lib/api/workspace.tsindex 11230ad8a..5ea32ef58 100644--- a/packages/web/src/lib/api/workspace.ts+++ b/packages/web/src/lib/api/workspace.ts@@ -7,8 +7,10 @@ import type {WorkspaceSyncResponse,} from "./types";-export async function getWorkspace(): Promise<WorkspaceResponse> {- return apiGet<WorkspaceResponse>("/api/workspace");+export async function getWorkspace(+ fetchOptions?: RequestInit,+): Promise<WorkspaceResponse> {+ return apiGet<WorkspaceResponse>("/api/workspace", undefined, fetchOptions);}export async function getWorkspaceContracts(opts?: {diff --git a/packages/web/src/lib/workspace-mode.test.ts b/packages/web/src/lib/workspace-mode.test.tsnew file mode 100644index 000000000..c1731f955--- /dev/null+++ b/packages/web/src/lib/workspace-mode.test.ts@@ -0,0 +1,10 @@+import { describe, expect, it } from "vitest";+import { shouldRedirectFromWorkspace } from "./workspace-mode";++describe("shouldRedirectFromWorkspace", () => {+ it("redirects only when workspace mode is explicitly false", () => {+ expect(shouldRedirectFromWorkspace(false)).toBe(true);+ expect(shouldRedirectFromWorkspace(true)).toBe(false);+ expect(shouldRedirectFromWorkspace(null)).toBe(false);+ });+});diff --git a/packages/web/src/lib/workspace-mode.ts b/packages/web/src/lib/workspace-mode.tsnew file mode 100644index 000000000..c52d6a74e--- /dev/null+++ b/packages/web/src/lib/workspace-mode.ts@@ -0,0 +1,3 @@+export function shouldRedirectFromWorkspace(isWorkspace: boolean | null): boolean {+ return isWorkspace === false;+}diff --git a/packages/web/vitest.config.ts b/packages/web/vitest.config.tsnew file mode 100644index 000000000..37a6fab48--- /dev/null+++ b/packages/web/vitest.config.ts@@ -0,0 +1,7 @@+import { defineConfig } from "vitest/config";++export default defineConfig({+ test: {+ include: ["src/**/*.{test,spec}.{ts,tsx}"],+ },+});