Skip to content

Commit 3bbb33f

Browse files
committed
fix(IPv6 issue): fix dotenv.ts which was creating mistmatch in IP versions.
1 parent 7163c7f commit 3bbb33f

File tree

11 files changed

+35
-32
lines changed

11 files changed

+35
-32
lines changed

backend/.env.sample

Lines changed: 0 additions & 13 deletions
This file was deleted.

backend/src/config/dotenv.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@ import dotenv from "dotenv";
22
import path from "path";
33
import logger from "../lib/logger";
44

5+
// Load .env from project root
56
logger.info("Trying to load .env file from the project folder...");
67
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
78

9+
// Helper to clean quotes & force IPv4 if needed
10+
function cleanEnvVar(
11+
val: string | undefined,
12+
fallback?: string
13+
): string | undefined {
14+
if (!val) return fallback;
15+
return val.replace(/^"|"$/g, "").replace("localhost", "127.0.0.1");
16+
}
17+
818
export const SERVER_ENV = {
9-
PORT: process.env.PORT || "3001",
19+
PORT: process.env.PORT || "3000",
1020
NODE_ENV: process.env.NODE_ENV || "development",
11-
LOCAL_HOST: process.env.LOCAL_HOST || "http://localhost:3001",
12-
CORS_ORIGIN: process.env.CORS_ORIGIN || "http://localhost:5173",
21+
LOCAL_HOST: process.env.LOCAL_HOST || "http://127.0.0.1",
22+
CORS_ORIGIN: process.env.CORS_ORIGIN || "*",
1323
};
24+
1425
export const MODEL_ENV = {
15-
OLLAMA_HOST: process.env.OLLAMA_HOST || "http://localhost:11434",
16-
MODEL_NAME: process.env.MODEL_NAME || "phi3:mini",
26+
OLLAMA_HOST: cleanEnvVar(process.env.OLLAMA_HOST, "http://127.0.0.1:11434"),
27+
MODEL_NAME: cleanEnvVar(process.env.MODEL_NAME, "phi3"),
1728
};

backend/src/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ app.use("/api/upload-schema", genSummaryRoute);
1919
app.use("/api/generate-testcases", genTestcasesRoute);
2020

2121
// Configure websockets
22-
const port = SERVER_ENV.PORT || 3001;
22+
const port = SERVER_ENV.PORT;
2323
const server = http.createServer(app);
2424
setUpWebSocket(server);
2525

26-
2726
logger.info("Starting the server...");
2827
server.listen(port, () => {
2928
logger.info(`Server is running on port ${port}`);

backend/src/services/ai-test-generator.service.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ JSON Response:
5050
stream: false,
5151
});
5252

53-
let aiResponseText: string = (response.data.response || "").trim();
53+
let aiResponseText: string = (response.data.response || "").trim() ?? "";
5454

5555
if (aiResponseText.startsWith("```")) {
5656
aiResponseText = aiResponseText
@@ -78,11 +78,14 @@ JSON Response:
7878
// Type guard to safely access message
7979
const message = error instanceof Error ? error.message : String(error);
8080

81-
logger.error("AI test generation failed", {
82-
error: message,
83-
method,
84-
path,
85-
});
81+
logger.error(
82+
"AI test generation failed" +
83+
{
84+
error: message,
85+
method,
86+
path,
87+
}
88+
);
8689

8790
console.error(error);
8891

frontend/src/components/TerminalView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function TerminalView() {
1010
const { registerTerminal } = useTerminal();
1111

1212
// Use your custom WebSocket hook
13-
const { messages, isConnected, error } = useWebSocket("ws://localhost:3001");
13+
const { messages, isConnected, error } = useWebSocket("ws://localhost:3000");
1414

1515
useEffect(() => {
1616
if (!terminalRef.current) return;

frontend/src/features/test-details/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const TestDetailsPane: React.FC = () => {
6464
const handleRunTests = async () => {
6565
if (!spec) return;
6666
try {
67+
6768
setLoading(true);
6869
await runTests(spec, logToTerminal);
6970
} finally {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { apiClient } from "@/lib/api-client";
21
import type { OpenApiData } from "@/types/openapi.type";
2+
import axios from "axios";
33

44
export async function generateTestCasesAPI(spec: OpenApiData) {
5-
return apiClient.post("/generate-testcases/", spec, {
5+
console.log("API Spec:", spec, spec.info);
6+
return axios.post("http://localhost:3000/api/generate-testcases/", spec, {
67
headers: { "Content-Type": "application/json" },
78
});
89
}

frontend/src/hooks/useWebSocket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef, useEffect, useState, useCallback } from "react";
22

3-
export function useWebSocket(url: string = "ws://localhost:3001") {
3+
export function useWebSocket(url: string = "ws://localhost:3000") {
44
const socketRef = useRef<WebSocket | null>(null);
55
const [messages, setMessages] = useState<string[]>([]);
66
const [isConnected, setIsConnected] = useState(false);

frontend/src/lib/test-generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export async function generateTestCases(
99
logToTerminal("Sending POST request to /api/generate-testcases...");
1010
try {
1111
const res = await generateTestCasesAPI(spec);
12+
console.log(res, res.data);
1213
logToTerminal("Test cases generated successfully!");
1314
return res.data;
1415
} catch (err: unknown) {

frontend/src/lib/upload-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const uploadSchemaFile = async (
1313
try {
1414
const response = await uploadSchemaFileAPI(file);
1515
logToTerminal("File uploaded successfully!");
16-
setSpec(response.data.data);
16+
setSpec(response.data);
1717
return response.data;
1818
} catch (error) {
1919
logToTerminal(`Error uploading file: ${error}`);

0 commit comments

Comments
 (0)