Procházet zdrojové kódy

fix: proper cleanup of Metal GPU resources in tests

Add test-preload.ts with global afterAll hook that ensures llama.cpp
Metal resources are properly disposed before process exit, avoiding
GGML_ASSERT failures.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tobi Lutke před 3 měsíci
rodič
revize
537d15a9e6
2 změnil soubory, kde provedl 14 přidání a 1 odebrání
  1. 1 1
      package.json
  2. 13 0
      src/test-preload.ts

+ 1 - 1
package.json

@@ -7,7 +7,7 @@
     "qmd": "./qmd"
   },
   "scripts": {
-    "test": "bun test",
+    "test": "bun test --preload ./src/test-preload.ts",
     "qmd": "bun src/qmd.ts",
     "index": "bun src/qmd.ts index",
     "vector": "bun src/qmd.ts vector",

+ 13 - 0
src/test-preload.ts

@@ -0,0 +1,13 @@
+/**
+ * Test preload file to ensure proper cleanup of native resources.
+ *
+ * Uses bun:test afterAll to properly dispose of llama.cpp Metal
+ * resources before the process exits, avoiding GGML_ASSERT failures.
+ */
+import { afterAll } from "bun:test";
+import { disposeDefaultLlamaCpp } from "./llm";
+
+// Global afterAll runs after all test files complete
+afterAll(async () => {
+  await disposeDefaultLlamaCpp();
+});