import assert from "node:assert/strict"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { afterEach, describe, it } from "node:test"; import { readFooterSettings } from "../settings.ts"; let tempDir: string | undefined; afterEach(() => { if (tempDir) { rmSync(tempDir, { recursive: true, force: true }); tempDir = undefined; } }); function configPath(contents: string): string { tempDir = mkdtempSync(join(tmpdir(), "pi-minimal-footer-settings-")); const path = join(tempDir, "pi-minimal-footer.json"); writeFileSync(path, contents); return path; } const expectedDefaults = { showCwd: true, showBranch: true }; describe("readFooterSettings", () => { it("returns all defaults when the config file is missing", () => { assert.deepEqual(readFooterSettings("/does/not/exist/pi-minimal-footer.json"), expectedDefaults); }); it("returns all defaults for malformed or non-object JSON", () => { for (const contents of ["not json", "[1,2]", "42"]) { assert.deepEqual(readFooterSettings(configPath(contents)), expectedDefaults, contents); } }); it("adopts explicit boolean values", () => { assert.deepEqual( readFooterSettings(configPath(JSON.stringify({ showCwd: false, showBranch: false }))), { showCwd: false, showBranch: false }, ); }); it("falls back per-field for non-boolean values", () => { assert.deepEqual( readFooterSettings(configPath(JSON.stringify({ showCwd: "no", showBranch: 0 }))), expectedDefaults, ); }); });