changeset 128:7eb79fd91c7e

[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
author June Park <parkjune1995@gmail.com>
date Thu, 08 Jan 2026 19:20:56 -0800
parents 9af248484ba2
children f7860f491a8c
files gui_ze/gui_ze.bzl hg-web/BUILD mrjunejune/BUILD mrjunejune/main.c mrjunejune/test/integration_test.c mrjunejune/test/snapshots/index.html.snapshot mrjunejune/test/snapshots/resume.snapshot mrjunejune/test/snapshots/resume_index.html.snapshot mrjunejune/test/snapshots/root.snapshot mrjunejune/test/snapshots/tools.snapshot mrjunejune/test/snapshots/tools_file_converter.snapshot mrjunejune/test/snapshots/tools_file_converter_index.html.snapshot mrjunejune/test/snapshots/tools_index.html.snapshot mrjunejune/test/snapshots/tools_markdown_to_html.snapshot mrjunejune/test/snapshots/tools_markdown_to_html_index.html.snapshot seobeo/examples/websocket_server_example.c seobeo/s_network.c seobeo/snapshot_creator.c seobeo/tests/seobeo_web_server_test.c
diffstat 19 files changed, 50 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/gui_ze/gui_ze.bzl	Thu Jan 08 18:05:47 2026 -0800
+++ b/gui_ze/gui_ze.bzl	Thu Jan 08 19:20:56 2026 -0800
@@ -32,7 +32,6 @@
     for directory in f.path.split("/"):
       if directory == binary.short_path.split("/")[0]:
         break
-      print("\n\n equals: ", directory, binary.short_path.split("/")[0]);
       start += 1
 
     # Remove the first folder (output) and last file (actaul files that needed to be copied)
@@ -49,9 +48,6 @@
     command = " && ".join(copy_cmd),
     progress_message = "Bundling {}".format(ctx.label.name),
   )
-
-  print("[INFO] See {}".format(out_dir.path))
-
   return [DefaultInfo(files = depset([out_dir]))]
 
 bundle = rule(
--- a/hg-web/BUILD	Thu Jan 08 18:05:47 2026 -0800
+++ b/hg-web/BUILD	Thu Jan 08 19:20:56 2026 -0800
@@ -26,11 +26,3 @@
   name = "hg_web_server_bundle",
   binary = ":hg_web_server",
 )
-
-cc_binary(
-  name = "hg_web_server_dev",
-  srcs = ["main.c"],
-  deps = ["//seobeo:seobeo_server_dev"],
-  data = [":src_files"],
-  defines = ["REPO_ROOT=\\\"\"/Users/mrjunejune/zenbu\"\\\""],
-)
--- a/mrjunejune/BUILD	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/BUILD	Thu Jan 08 19:20:56 2026 -0800
@@ -14,7 +14,6 @@
 move_files_into_dir(
   name = "compiled_ts",
   srcs = [
-    "//playground:hello",
     "//markdown_converter:markdown_to_html",
   ],
   dest = "src",
--- a/mrjunejune/main.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/main.c	Thu Jan 08 19:20:56 2026 -0800
@@ -534,7 +534,8 @@
 
   // -- Talk --/
   Seobeo_Router_Register("GET", "/talk", GetTalk);
-  // Seobeo_Router_Register("GET", "/talk/index.html", GetRedirectTalk);
+  // TODO: Bug where I can't est redriect huh...
+  Seobeo_Router_Register("GET", "/talk/index.html", GetRedirectTalk);
 
   printf("Registered Websockets\n");
 
--- a/mrjunejune/test/integration_test.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/integration_test.c	Thu Jan 08 19:20:56 2026 -0800
@@ -1,4 +1,4 @@
-#include "seobeo/test/test.h"
+#include "mrjunejune/test/test.h"
 
 // Test case structure
 typedef struct {
@@ -10,6 +10,37 @@
   size_t response_len;
 } TestCase;
 
+void debug_diff(const char *expected, const char *actual)
+{
+    printf("\n--- DIFF (Expected vs Actual) ---\n");
+    
+    // Create copies to use with strtok (strtok modifies the string)
+    char *exp_copy = strdup(expected);
+    char *act_copy = strdup(actual);
+    
+    char *exp_line = strtok(exp_copy, "\n");
+    char *act_line = strtok(act_copy, "\n");
+    
+    int line_num = 1;
+    while (exp_line != NULL || act_line != NULL) {
+        if (exp_line && act_line && strcmp(exp_line, act_line) == 0) {
+            // Lines match - optional: print nothing or a dot
+        } else {
+            printf("Line %d mismatch:\n", line_num);
+            printf("  EXP: [%s]\n", exp_line ? exp_line : "(end of string)");
+            printf("  ACT: [%s]\n", act_line ? act_line : "(end of string)");
+            printf("  -----------------------------------\n");
+        }
+        
+        exp_line = strtok(NULL, "\n");
+        act_line = strtok(NULL, "\n");
+        line_num++;
+    }
+    
+    free(exp_copy);
+    free(act_copy);
+}
+
 // Helper: Convert URL path to filename
 // "/" -> "root.snapshot"
 // "/index.html" -> "index.html.snapshot"
@@ -149,6 +180,7 @@
     {
       printf("    ✗ Response does not match expected snapshot\n");
       printf("    Expected file: %s\n", test->expected_file_path);
+      debug_diff(p_resp->body, test->expected_content);
       Seobeo_Client_Response_Destroy(p_resp);
       Seobeo_Client_Request_Destroy(p_req);
       return -1;
@@ -297,60 +329,6 @@
   return 0;
 }
 
-pid_t start_test_server(const char *server_binary)
-{
-  pid_t server_pid = fork();
-
-  if (server_pid < 0)
-  {
-    perror("fork");
-    return -1;
-  }
-
-  if (server_pid == 0)
-  {
-    printf("Starting server on port %s...\n", TEST_PORT);
-    execl(server_binary, server_binary, NULL);
-    perror("execl failed");
-    exit(1);
-  }
-
-  printf("Server started (PID: %d)\n", server_pid);
-
-  usleep(100000);
-  int status;
-  pid_t result = waitpid(server_pid, &status, WNOHANG);
-  if (result != 0)
-  {
-    if (WIFEXITED(status))
-    {
-      fprintf(stderr, "Server exited immediately with code: %d\n", WEXITSTATUS(status));
-    }
-    else if (WIFSIGNALED(status))
-    {
-      fprintf(stderr, "Server was killed by signal: %d\n", WTERMSIG(status));
-    }
-    return -1;
-  }
-
-  sleep(2);
-  printf("Server ready\n\n");
-
-  return server_pid;
-}
-
-// Helper: Stop test server
-void stop_test_server(pid_t server_pid)
-{
-  if (server_pid > 0)
-  {
-    printf("\nStopping server (PID: %d)...\n", server_pid);
-    kill(server_pid, SIGTERM);
-    waitpid(server_pid, NULL, 0);
-    printf("Server stopped\n");
-  }
-}
-
 // Helper: Initialize test case with snapshot file
 void init_test_case(TestCase *test)
 {
@@ -413,6 +391,7 @@
     {"/tools", 200, NULL, NULL, NULL, 0},
     {"/tools/markdown_to_html", 200, NULL, NULL, NULL, 0},
     {"/tools/file_converter", 200, NULL, NULL, NULL, 0},
+    {"/talk", 200, NULL, NULL, NULL, 0},
   };
   int num_success_tests = sizeof(success_tests) / sizeof(success_tests[0]);
 
--- a/mrjunejune/test/snapshots/index.html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/index.html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,7 +0,0 @@
-HTTP/1.1 301 Moved Permanently
-Content-Type: text/plain
-Content-Length: 0
-Connection: close
-Body: 
-Location: /
-
--- a/mrjunejune/test/snapshots/resume.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/resume.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,8 +1,3 @@
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 14511
-Connection: close
-
 <!doctype html>
 <html lang="en">
   <head>
--- a/mrjunejune/test/snapshots/resume_index.html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/resume_index.html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,6 +0,0 @@
-HTTP/1.1 301 Moved Permanently
-Content-Type: text/plain
-Content-Length: 0
-Connection: close
-Body: 
-
--- a/mrjunejune/test/snapshots/root.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/root.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,8 +1,3 @@
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 5750
-Connection: close
-
 <!doctype html>
 <html lang="en">
   <head>
--- a/mrjunejune/test/snapshots/tools.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,8 +1,3 @@
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 4273
-Connection: close
-
 <!doctype html>
 <html lang="en">
   <head>
--- a/mrjunejune/test/snapshots/tools_file_converter.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_file_converter.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,8 +1,3 @@
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 8553
-Connection: close
-
 <!DOCTYPE html>
 <html lang="en">
 <head>
--- a/mrjunejune/test/snapshots/tools_file_converter_index.html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_file_converter_index.html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,6 +0,0 @@
-HTTP/1.1 301 Moved Permanently
-Content-Type: text/plain
-Content-Length: 0
-Connection: close
-Body: 
-
--- a/mrjunejune/test/snapshots/tools_index.html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_index.html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,6 +0,0 @@
-HTTP/1.1 301 Moved Permanently
-Content-Type: text/plain
-Content-Length: 0
-Connection: close
-Body: 
-
--- a/mrjunejune/test/snapshots/tools_markdown_to_html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_markdown_to_html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,8 +1,3 @@
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 6012
-Connection: close
-
 <!DOCTYPE html>
 <html lang="en">
 <head>
--- a/mrjunejune/test/snapshots/tools_markdown_to_html_index.html.snapshot	Thu Jan 08 18:05:47 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_markdown_to_html_index.html.snapshot	Thu Jan 08 19:20:56 2026 -0800
@@ -1,6 +0,0 @@
-HTTP/1.1 301 Moved Permanently
-Content-Type: text/plain
-Content-Length: 0
-Connection: close
-Body: 
-
--- a/seobeo/examples/websocket_server_example.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/seobeo/examples/websocket_server_example.c	Thu Jan 08 19:20:56 2026 -0800
@@ -29,7 +29,7 @@
     snprintf(message, sizeof(message), "[%s]: %.*s", p_conn->client_id, (int)p_msg->length, (char*)p_msg->data);
 
     printf("[Chat] Broadcasting: %s\n", message);
-    Seobeo_WebSocket_Server_Broadcast_Text(message);
+    Seobeo_WebSocket_Server_Broadcast_Text(message, p_conn);
   }
 }
 
--- a/seobeo/s_network.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/seobeo/s_network.c	Thu Jan 08 19:20:56 2026 -0800
@@ -103,6 +103,11 @@
   { perror("connect"); return NULL; }
   freeaddrinfo(server_infos);
 
+  // Set non-blocking
+  int flags = fcntl(socket_fd, F_GETFL, 0);
+  if (flags == -1 || fcntl(socket_fd, F_SETFL, flags | O_NONBLOCK) != 0)
+  { perror("fcntl"); close(socket_fd); free(p_handle); return NULL; }
+
   p_handle->socket = socket_fd;
   p_handle->type = SEOBEO_STREAM_TYPE_CLIENT;
 
--- a/seobeo/snapshot_creator.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/seobeo/snapshot_creator.c	Thu Jan 08 19:20:56 2026 -0800
@@ -186,6 +186,7 @@
   {
     fprintf(stderr, "  ✗ Status mismatch: expected %d, got %d\n",
             config->expected_status, p_resp->status_code);
+    // fprintf(stderr, "%s", p_resp->body);
     Seobeo_Client_Response_Destroy(p_resp);
     Seobeo_Client_Request_Destroy(p_req);
     return -1;
@@ -193,21 +194,6 @@
 
   printf("  ✓ Status: %d\n", p_resp->status_code);
 
-  // Build full HTTP response
-  size_t response_len = 0;
-  char *response = build_full_response(p_resp, &response_len);
-
-  Seobeo_Client_Response_Destroy(p_resp);
-  Seobeo_Client_Request_Destroy(p_req);
-
-  if (!response || response_len == 0)
-  {
-    fprintf(stderr, "  ✗ Failed to build response\n");
-    if (response)
-      free(response);
-    return -1;
-  }
-
   // Generate snapshot filename
   char filename[256];
   path_to_filename(config->path, filename, sizeof(filename));
@@ -216,18 +202,19 @@
   snprintf(filepath, sizeof(filepath), "%s/%s", config->snapshot_dir, filename);
 
   // Write snapshot
-  if (write_snapshot(filepath, response, response_len) == 0)
+  if (write_snapshot(filepath, p_resp->body, p_resp->body_length) == 0)
   {
-    printf("  ✓ Snapshot saved: %s (%zu bytes)\n", filepath, response_len);
-    free(response);
+    printf("  ✓ Snapshot saved: %s (%zu bytes)\n", filepath, p_resp->body_length);
     return 0;
   }
   else
   {
     fprintf(stderr, "  ✗ Failed to write snapshot: %s\n", filepath);
-    free(response);
     return -1;
   }
+
+  Seobeo_Client_Response_Destroy(p_resp);
+  Seobeo_Client_Request_Destroy(p_req);
 }
 
 int Seobeo_Snapshots_Create_Batch(const SnapshotConfig configs[], int count)
@@ -238,13 +225,9 @@
   for (int i = 0; i < count; i++)
   {
     if (Seobeo_Snapshot_Create(&configs[i]) == 0)
-    {
       passed++;
-    }
     else
-    {
       failed++;
-    }
     printf("\n");
   }
 
--- a/seobeo/tests/seobeo_web_server_test.c	Thu Jan 08 18:05:47 2026 -0800
+++ b/seobeo/tests/seobeo_web_server_test.c	Thu Jan 08 19:20:56 2026 -0800
@@ -12,8 +12,8 @@
 
   if (server_pid == 0)
   {
-    printf("Starting server on port 8000...\n");
-    execlp(server_binary, NULL);
+    printf("Starting server on port 8080...\n");
+    execl(server_binary, server_binary, NULL);
     perror("execl failed");
     exit(1);
   }