Merge PR #8842: test(lsp): isolate config tests from the developer's user settings (@pedropaulovc)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from "bun:test";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
|
||||
import * as fs from "node:fs";
|
||||
import * as fsp from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
@@ -281,6 +281,33 @@ function textResult(result: AgentToolResult<LspToolDetails>): string {
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* `loadConfig` walks the user config directories (~/.omp/agent, ~/.pi/agent,
|
||||
* ~/.claude), which resolve from os.homedir(). A developer with a real
|
||||
* lsp.json there flips loadConfig off its auto-detect path onto the override
|
||||
* path, where their rootMarkers replace the packaged ones — so these tests
|
||||
* would assert against that machine's config instead of the defaults. Point
|
||||
* HOME at an empty directory so every case sees a pristine environment.
|
||||
*/
|
||||
let lspHomeOverride: string | undefined;
|
||||
let lspOriginalHome: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
lspOriginalHome = process.env.HOME;
|
||||
lspHomeOverride = fs.mkdtempSync(path.join(os.tmpdir(), "omp-lsp-test-home-"));
|
||||
process.env.HOME = lspHomeOverride;
|
||||
// Bun's os.homedir() reads the passwd entry rather than $HOME, so the env
|
||||
// var alone does not redirect the config walk.
|
||||
vi.spyOn(os, "homedir").mockReturnValue(lspHomeOverride);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (lspOriginalHome === undefined) delete process.env.HOME;
|
||||
else process.env.HOME = lspOriginalHome;
|
||||
if (lspHomeOverride) fs.rmSync(lspHomeOverride, { recursive: true, force: true });
|
||||
lspHomeOverride = undefined;
|
||||
});
|
||||
|
||||
describe("lsp regressions", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
|
||||
Reference in New Issue
Block a user