mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
仓库规则要求 config/ 为唯一配置来源、不以环境变量作持久默认值: - pi-notify 改读 config/pi-notify.json(逐字段校验回退,复用原 parsers 钳制) - pi-minimal-footer 改读 config/pi-minimal-footer.json - pi-chrome 移除 PI_CHROME_BRIDGE_HOST/PORT,固定 127.0.0.1:17318 (浏览器端 service_worker.js 硬编码同一地址,单侧可配只会断连) Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
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,
|
|
);
|
|
});
|
|
});
|