Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/lib/tunnel/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

// Import source directly so tests cannot pass against a stale build.
import { registerTunnelOrigin } from "./allowed-origins";
Expand Down Expand Up @@ -445,9 +445,7 @@ describe("stopAll", () => {
let spawnSyncCalls: Array<{ command: string; args: readonly string[] }>;
let originalSpawnSync: typeof childProcess.spawnSync;

beforeEach(() => {
pidDir = mkdtempSync(join(tmpdir(), "nemoclaw-svc-test-"));
spawnSyncCalls = [];
beforeAll(() => {
originalSpawnSync = childProcess.spawnSync;
// @ts-expect-error — partial mock signature is intentional.
childProcess.spawnSync = (command: string, args: readonly string[]) => {
Expand All @@ -468,16 +466,24 @@ describe("stopAll", () => {
return reply;
};
// The Ollama proxy source module destructures `spawnSync` at
// require time, so to make `stopAll` pick up the patched function we
// bust its cache. `services.ts` requires the proxy lazily, so the
// next call sees the freshly-loaded module.
// require time. Load it once with the stable suite-level mock instead of
// re-evaluating the large module under coverage for every stopAll test.
delete require.cache[require.resolve(ollamaProxySourcePath)];
require(ollamaProxySourcePath);
});

beforeEach(() => {
pidDir = mkdtempSync(join(tmpdir(), "nemoclaw-svc-test-"));
spawnSyncCalls = [];
});

afterEach(() => {
rmSync(pidDir, { recursive: true, force: true });
});

afterAll(() => {
childProcess.spawnSync = originalSpawnSync;
delete require.cache[require.resolve(ollamaProxySourcePath)];
rmSync(pidDir, { recursive: true, force: true });
});

// A scripted ProcessControl models PID identity/liveness/signalling without
Expand Down
Loading