// State persistence lands under `/plugin-state/playnite` — the one dir the // de-privileged Windows runner (LocalService) may write. A regression here (writing straight under // the config dir) would EPERM under the runner and lose the operator's config. import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import { loadConfig, saveRawConfig } from "../src/state.js"; let root: string; let saved: string | undefined; beforeEach(() => { saved = process.env.PUNKTFUNK_CONFIG_DIR; root = fs.mkdtempSync(path.join(os.tmpdir(), "pn-state-")); process.env.PUNKTFUNK_CONFIG_DIR = root; }); afterEach(() => { if (saved === undefined) delete process.env.PUNKTFUNK_CONFIG_DIR; else process.env.PUNKTFUNK_CONFIG_DIR = saved; fs.rmSync(root, { recursive: true, force: true }); }); describe("state location", () => { test("persists under plugin-state/playnite and round-trips", () => { saveRawConfig({ playniteDir: "/games/playnite" }); expect( fs.existsSync(path.join(root, "plugin-state", "playnite", "config.json")), ).toBe(true); // Not written straight under the config dir (the LocalService-unwritable location). expect(fs.existsSync(path.join(root, "playnite", "config.json"))).toBe( false, ); expect(loadConfig().playniteDir).toBe("/games/playnite"); }); });