All files / src/app/api/nlq/backend route.ts

40% Statements 4/10
25% Branches 1/4
100% Functions 1/1
33.33% Lines 3/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        1x                               1x 1x                            
import { NextResponse } from "next/server";
import { NEO4J_PROXY_URL, callerHeaders } from "@/lib/proxy";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
 
export const dynamic = "force-dynamic";
 
/**
 * Phase 25f (Issue #13) — proxy for /nlq/backend.
 *
 * Returns the NLP backend detection result from neo4j-proxy: which chat and
 * embeddings providers are wired, which vector indexes exist, and whether
 * GraphRAG is ready.
 *
 * Any signed-in participant. #377 left this route open because
 * `__tests__/e2e/journeys/33-graphrag-nlp.spec.ts` probed it anonymously to
 * decide which GraphRAG branches to run. Every API route needs a session since #404 (ADR-044); the
 * spec now forges a session from NEXTAUTH_SECRET, fails rather than skips
 * when the session is refused, and asserts the 401 without one (J609).
 */
export async function GET() {
  const auth = await requireAuth();
  Eif (isAuthError(auth)) return auth;
  try {
    const resp = await fetch(`${NEO4J_PROXY_URL}/nlq/backend`, {
      headers: callerHeaders(auth.session),
      cache: "no-store",
    });
    const data = await resp.json();
    return NextResponse.json(data, { status: resp.status });
  } catch (err: unknown) {
    const message =
      err instanceof Error ? err.message : "NLQ backend proxy error";
    return NextResponse.json({ error: message }, { status: 502 });
  }
}