From d8ee815922d3ea5c61db4a4856d3cfc561dec30f Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 3 Nov 2025 14:16:16 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A4=96=20fix:=20simplify=20worker=20p?= =?UTF-8?q?ath=20resolution=20using=20=5F=5Fdirname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5031e537e6a292cc2c74ac9d196b571d04689b02 Signed-off-by: Test --- src/utils/main/workerPool.ts | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/utils/main/workerPool.ts b/src/utils/main/workerPool.ts index 2a55b85af..6b8a18b49 100644 --- a/src/utils/main/workerPool.ts +++ b/src/utils/main/workerPool.ts @@ -1,5 +1,5 @@ import { Worker } from "node:worker_threads"; -import { join, dirname, sep } from "node:path"; +import { join } from "node:path"; interface WorkerRequest { messageId: number; @@ -28,24 +28,9 @@ const pendingPromises = new Map< { resolve: (value: unknown) => void; reject: (error: Error) => void } >(); -// Resolve worker path - explicitly use .js extension as worker threads require compiled files -// When running tests from src/, __filename is src/utils/main/workerPool.ts -// We need to resolve to dist/utils/main/tokenizer.worker.js -// Use platform-aware path component manipulation to handle Windows backslashes -const currentDir = dirname(__filename); -const pathParts = currentDir.split(sep); -const srcIndex = pathParts.indexOf("src"); - -let workerDir: string; -if (srcIndex !== -1) { - // Replace 'src' with 'dist' in the path (works on Windows and Unix) - pathParts[srcIndex] = "dist"; - workerDir = pathParts.join(sep); -} else { - workerDir = currentDir; -} - -const workerPath = join(workerDir, "tokenizer.worker.js"); +// Resolve worker path - both workerPool.js and tokenizer.worker.js compile to dist/utils/main/ +// Using __dirname ensures we always get the correct compiled location +const workerPath = join(__dirname, "tokenizer.worker.js"); const worker = new Worker(workerPath); // Handle messages from worker From db71290a8670fb2110e147e95a50eb2c318ef0dc Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 3 Nov 2025 14:21:34 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20fix:=20use=20lastIndexOf=20t?= =?UTF-8?q?o=20find=20correct=20src=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8dd32f69c1ef9d48a0110e7103b3964c0191bfaf Signed-off-by: Test --- src/utils/main/workerPool.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/utils/main/workerPool.ts b/src/utils/main/workerPool.ts index 6b8a18b49..c5c8dc003 100644 --- a/src/utils/main/workerPool.ts +++ b/src/utils/main/workerPool.ts @@ -1,5 +1,5 @@ import { Worker } from "node:worker_threads"; -import { join } from "node:path"; +import { join, dirname, sep } from "node:path"; interface WorkerRequest { messageId: number; @@ -28,9 +28,23 @@ const pendingPromises = new Map< { resolve: (value: unknown) => void; reject: (error: Error) => void } >(); -// Resolve worker path - both workerPool.js and tokenizer.worker.js compile to dist/utils/main/ -// Using __dirname ensures we always get the correct compiled location -const workerPath = join(__dirname, "tokenizer.worker.js"); +// Resolve worker path +// In production: both workerPool.js and tokenizer.worker.js are in dist/utils/main/ +// During tests: workerPool.ts is in src/utils/main/ but worker is in dist/utils/main/ +const currentDir = dirname(__filename); +const pathParts = currentDir.split(sep); +const srcIndex = pathParts.lastIndexOf("src"); + +let workerDir: string; +if (srcIndex !== -1) { + // Replace 'src' with 'dist' in the path + pathParts[srcIndex] = "dist"; + workerDir = pathParts.join(sep); +} else { + workerDir = currentDir; +} + +const workerPath = join(workerDir, "tokenizer.worker.js"); const worker = new Worker(workerPath); // Handle messages from worker