mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
## Summary - **Fix CI build failure**: Auth0Client crashes during Next.js prerendering when env vars aren't set. Returns a no-op stub (`getSession → null`) when domain is missing — semantically correct for static generation - **Lazy-load markdown libs (~260kb)**: ReactMarkdown, remarkGfm, and react-syntax-highlighter were eagerly imported in monaco-diff-viewer but only rendered when user expands "Generated Tests". Extracted into a dynamic component - **Parallelize repo detail query**: `getRepositoryById` ran the activity count sequentially after the repo lookup. Since `repoId` is already available, all three queries now run in parallel ## Test plan - [ ] CI `build` check passes (was failing since #2598) - [ ] Trace page still renders generated tests correctly when expanded - [ ] Repository detail page loads correctly with activity status
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { prisma } from "@codeflash-ai/common"
|
|
import { Request, Response } from "express"
|
|
import { logger } from "../utils/logger.js"
|
|
import {
|
|
validationFailure,
|
|
optimizationNotFound,
|
|
internalServerError,
|
|
} from "../exceptions/index.js"
|
|
|
|
// Dependencies interface for easier testing
|
|
export interface OptimizationSuccessDependencies {
|
|
prisma: {
|
|
optimization_events: {
|
|
updateMany: (params: any) => Promise<{ count: number }>
|
|
}
|
|
}
|
|
}
|
|
|
|
// Default dependencies
|
|
let dependencies: OptimizationSuccessDependencies = {
|
|
prisma,
|
|
}
|
|
|
|
// For testing - allow dependency injection
|
|
export function setOptimizationSuccessDependencies(deps: Partial<OptimizationSuccessDependencies>) {
|
|
dependencies = { ...dependencies, ...deps }
|
|
}
|
|
|
|
export function resetOptimizationSuccessDependencies() {
|
|
dependencies = {
|
|
prisma,
|
|
}
|
|
}
|
|
|
|
export async function optimizationSuccess(req: Request, res: Response): Promise<void> {
|
|
const { trace_id, is_optimization_found } = req.body
|
|
|
|
// Fix validation to handle null values properly
|
|
if (trace_id == null || typeof is_optimization_found !== "boolean") {
|
|
throw validationFailure("trace_id and is_optimization_found(boolean) are required")
|
|
}
|
|
|
|
try {
|
|
const result = await dependencies.prisma.optimization_events.updateMany({
|
|
where: { trace_id },
|
|
data: { is_optimization_found },
|
|
})
|
|
|
|
if (result.count === 0) {
|
|
throw optimizationNotFound(trace_id)
|
|
}
|
|
|
|
res.status(200).json({ message: "Optimization status updated." })
|
|
} catch (error) {
|
|
if (error && typeof error === "object" && "getHttpStatus" in error) {
|
|
throw error
|
|
}
|
|
logger.errorWithSentry("Error in markOptimizationSuccess:", req, {}, error as Error)
|
|
throw internalServerError("Error updating optimization status")
|
|
}
|
|
}
|