Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: import vitest APIs explicitly and disable injected globals in server tests (#9049)

[._.]/ Adam Eivyb2faa6a97f98
diff --git a/server/lib/huggingfaceLora.test.js b/server/lib/huggingfaceLora.test.js
index 57420b26bb..a631410540 100644
--- a/server/lib/huggingfaceLora.test.js
+++ b/server/lib/huggingfaceLora.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect } from 'vitest';
+import { describe, it, expect, vi } from 'vitest';
import {
parseHuggingfaceLoraRef,
buildHfResolveUrl,
diff --git a/server/lib/vaultCrypto.test.js b/server/lib/vaultCrypto.test.js
index 8ee407a47d..f324b1e4e6 100644
--- a/server/lib/vaultCrypto.test.js
+++ b/server/lib/vaultCrypto.test.js
@@ -4,7 +4,7 @@
* against a temp .env, and the per-type display masking.
*/
-import { describe, it, expect, beforeEach, beforeAll, afterAll } from 'vitest';
+import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll } from 'vitest';
import { mkdtempSync, rmSync, readFileSync, writeFileSync, existsSync, statSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index 644c94bc3d..fa493d0ce6 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -30,7 +30,7 @@
* `availableSlots <= 0` short-circuit flips a clear red flag.
*/
-import { describe, it, expect, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach } from 'vitest';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
diff --git a/server/services/digital-twin-documents.tombstone.test.js b/server/services/digital-twin-documents.tombstone.test.js
index c49641d51d..36af623853 100644
--- a/server/services/digital-twin-documents.tombstone.test.js
+++ b/server/services/digital-twin-documents.tombstone.test.js
@@ -8,7 +8,7 @@
* at a temp dir, so the merge, the file reap, and the add-only write all run.
*/
-import { describe, it, expect, beforeEach, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { existsSync, rmSync } from 'fs';
import { join } from 'path';
import { createTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
diff --git a/server/services/digital-twin-personas.tombstone.test.js b/server/services/digital-twin-personas.tombstone.test.js
index 6e77d5136f..564e3b50f1 100644
--- a/server/services/digital-twin-personas.tombstone.test.js
+++ b/server/services/digital-twin-personas.tombstone.test.js
@@ -8,7 +8,7 @@
* the service write, the merge, and the apply all run.
*/
-import { describe, it, expect, beforeEach, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { rmSync } from 'fs';
import { join } from 'path';
import { createTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
diff --git a/server/services/meatspacePostRecommendations.test.js b/server/services/meatspacePostRecommendations.test.js
index 950a569944..d9e921dafa 100644
--- a/server/services/meatspacePostRecommendations.test.js
+++ b/server/services/meatspacePostRecommendations.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
// Recommendation composition (issue #2100). The pure functions
// (composePostRecommendations / weakestSkillFromStats / stalledProgressions)
diff --git a/server/services/obsidian.test.js b/server/services/obsidian.test.js
index 19ec9ca2ee..21150f5aa1 100644
--- a/server/services/obsidian.test.js
+++ b/server/services/obsidian.test.js
@@ -8,7 +8,7 @@
* one), and a test that stubs both would only re-assert the order it was handed.
*/
-import { describe, it, expect, beforeEach, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { mkdirSync, rmSync, writeFileSync, readFileSync, existsSync, symlinkSync } from 'fs';
import { join } from 'path';
import { createTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
diff --git a/server/services/orchestrationProfiles.test.js b/server/services/orchestrationProfiles.test.js
index 4d0dbf219e..bb563f2f2e 100644
--- a/server/services/orchestrationProfiles.test.js
+++ b/server/services/orchestrationProfiles.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach } from 'vitest';
import {
getOrchestrationProfiles,
getOrchestrationProfileById,
diff --git a/server/services/socialAccounts.tombstone.test.js b/server/services/socialAccounts.tombstone.test.js
index 3cbc555142..b2862780c6 100644
--- a/server/services/socialAccounts.tombstone.test.js
+++ b/server/services/socialAccounts.tombstone.test.js
@@ -8,7 +8,7 @@
* temp dir, so the service's cached store, the merge, and the sync apply all run.
*/
-import { describe, it, expect, beforeEach, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { rmSync } from 'fs';
import { join } from 'path';
import { createTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
diff --git a/server/vitest.config.db.js b/server/vitest.config.db.js
index 960987bac6..b409e7dac4 100644
--- a/server/vitest.config.db.js
+++ b/server/vitest.config.db.js
@@ -86,7 +86,8 @@ export const DB_TEST_INCLUDE = [
export default defineConfig({
test: {
testTimeout: process.platform === 'win32' ? 30000 : 15000,
- globals: true,
+ // Explicit 'vitest' imports only, matching vitest.config.js (#9049).
+ globals: false,
setupFiles: ['./vitest.setup.js'],
// One file at a time — these suites assume exclusive access to their tables.
fileParallelism: false,
diff --git a/server/vitest.config.js b/server/vitest.config.js
index 8f6f147cce..9cb72b0c86 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -242,7 +242,13 @@ export default defineConfig({
// proves only that the CURRENT test did not call it, never that no earlier
// test in the file did. Assert a cross-test claim inside the test that
// makes it.
- globals: true,
+ //
+ // Vitest APIs (`vi`, `describe`, `afterEach`, …) are NOT injected as
+ // globals: every suite imports what it uses from 'vitest'. A file leaning
+ // on injected globals passed here but threw `vi is not defined` whenever it
+ // ran outside this config — e.g. `vitest run server/…` from the repo root,
+ // where no config applies (#9049). Off, a missing import fails in every run.
+ globals: false,
// Global setup: mocks getPeers → [] so test-created records never fan out
// to live sync peers. Per-suite vi.mock('./instances.js', …) overrides win.
setupFiles: ['./vitest.setup.js'],
diff --git a/server/vitest.setup.js b/server/vitest.setup.js
index 0d1e5318f7..b36193ab91 100644
--- a/server/vitest.setup.js
+++ b/server/vitest.setup.js
@@ -50,6 +50,7 @@
* suites (Option B) for working examples.
*/
+import { vi, afterAll } from 'vitest';
import { rmSync } from 'fs';
import { mockNoPeers } from './lib/mockPathsDataRoot.js';