test(zed): isolate zed-live-models suite DB via temp DATA_DIR
Seeding via createProviderConnection wrote zed-live-* accounts into the real ~/.9router DB, showing up as junk accounts in the running dashboard. Set DATA_DIR to a mkdtemp dir before dynamic-importing the DB-backed modules and clean it up afterwards, matching the pattern in compatible-provider-connections.test.js. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
// Route-level acceptance for the Zed live-model wiring:
|
// Route-level acceptance for the Zed live-model wiring:
|
||||||
// GET /api/providers/[connectionId]/models → resolveZedModels → UI rows
|
// GET /api/providers/[connectionId]/models → resolveZedModels → UI rows
|
||||||
// RUN WITH AN ISOLATED DB: DATA_DIR=$(mktemp -d) npx vitest run ...
|
// Self-isolating: DATA_DIR points at a temp dir so seeding never touches ~/.9router.
|
||||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
import fs from "node:fs";
|
||||||
import { GET } from "@/app/api/providers/[id]/models/route.js";
|
import os from "node:os";
|
||||||
import { createProviderConnection } from "@/models/index.js";
|
import path from "node:path";
|
||||||
|
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach, vi } from "vitest";
|
||||||
|
|
||||||
// Transport stub BELOW resolveZedModels: proxyAwareFetch captures the native
|
// Transport stub BELOW resolveZedModels: proxyAwareFetch captures the native
|
||||||
// fetch at import time, so stubbing globalThis.fetch cannot intercept it.
|
// fetch at import time, so stubbing globalThis.fetch cannot intercept it.
|
||||||
@@ -72,6 +73,24 @@ afterEach(() => {
|
|||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Imports must be dynamic so DATA_DIR is set before the DB layer loads.
|
||||||
|
const originalDataDir = process.env.DATA_DIR;
|
||||||
|
let GET;
|
||||||
|
let createProviderConnection;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "9router-zed-live-"));
|
||||||
|
vi.resetModules();
|
||||||
|
({ GET } = await import("@/app/api/providers/[id]/models/route.js"));
|
||||||
|
({ createProviderConnection } = await import("@/models/index.js"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
fs.rmSync(process.env.DATA_DIR, { recursive: true, force: true });
|
||||||
|
if (originalDataDir === undefined) delete process.env.DATA_DIR;
|
||||||
|
else process.env.DATA_DIR = originalDataDir;
|
||||||
|
});
|
||||||
|
|
||||||
async function seedZed(n) {
|
async function seedZed(n) {
|
||||||
return createProviderConnection({
|
return createProviderConnection({
|
||||||
provider: "zed",
|
provider: "zed",
|
||||||
|
|||||||
Reference in New Issue
Block a user