Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/__tests__/analytics-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import express, { Request, Response } from "express";
import http from "node:http";
import path from "node:path";
import { fileURLToPath } from "node:url";

const mockGetAnalyticsSummary = vi.fn();
const mockGetTopQueries = vi.fn();
Expand Down Expand Up @@ -53,15 +52,22 @@ function buildTestApp() {
const app = express();
app.use(express.json());

const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Resolve docs/analytics.html from the repo root. Vitest runs from the
// repo root, so process.cwd() is stable regardless of whether __dirname
// points into src/__tests__ (source tree) or dist/__tests__ (built).
const analyticsHtmlPath = path.join(process.cwd(), "docs", "analytics.html");

// Dashboard HTML route — mirrors server.ts /analytics
app.get("/analytics", (_req: Request, res: Response) => {
if (!getAnalyticsConfig()?.enabled) {
res.status(404).json({ error: "Analytics not enabled" });
return;
}
res.sendFile(path.resolve(__dirname, "../../docs/analytics.html"));
// `dotfiles: "allow"` is required so the file serves from paths that
// contain a dot-prefixed segment (e.g. git worktrees under `.claude/`).
// Without it, Express's `send` returns 404 for any path containing a
// dotfile component, which is unrelated to the actual file's existence.
res.sendFile(analyticsHtmlPath, { dotfiles: "allow" });
});

// API routes with analyticsAuth middleware
Expand Down
Loading